@@ -36,11 +36,6 @@ class ViewportController: NSObject, ObservableObject, SCNSceneRendererDelegate {
3636 didSet { updateCameraProjection ( ) }
3737 }
3838
39- // Parts
40- @Published var hiddenPartIDs : Set < ModelData . Part . ID > = [ ] {
41- didSet { updatePartNodeVisibility ( ) }
42- }
43-
4439 @Published var highlightedPartID : ModelData . Part . ID ? {
4540 didSet { updateHighlightedPart ( oldID: oldValue, newID: highlightedPartID) }
4641 }
@@ -135,13 +130,16 @@ class ViewportController: NSObject, ObservableObject, SCNSceneRendererDelegate {
135130
136131 grid. updateBounds ( geometry: sceneController. modelContainer)
137132 setEdgeVisibilityInParts ( viewOptions. edgeVisibility)
133+ updatePartNodeVisibility ( viewOptions. hiddenPartIDs)
134+ objectWillChange. send ( )
138135 } . store ( in: & observers)
139136
140137 $viewOptions. sink { [ weak self] viewOptions in
141138 guard let self else { return }
142139 setEdgeVisibilityInParts ( viewOptions. edgeVisibility)
143140 grid. showGrid = viewOptions. showGrid
144141 grid. showOrigin = viewOptions. showOrigin
142+ updatePartNodeVisibility ( viewOptions. hiddenPartIDs)
145143 } . store ( in: & observers)
146144
147145 cameraNodeChanged ( cameraNode)
@@ -282,10 +280,11 @@ class ViewportController: NSObject, ObservableObject, SCNSceneRendererDelegate {
282280 self . viewOptions = viewOptions
283281 grid. showGrid = viewOptions. showGrid
284282 grid. showOrigin = viewOptions. showOrigin
285- Preferences ( ) . viewOptions = viewOptions
286283 cameraNode. transform = viewOptions. cameraTransform
287284 setEdgeVisibilityInParts ( viewOptions. edgeVisibility)
285+ updatePartNodeVisibility ( viewOptions. hiddenPartIDs)
288286 hasSetInitialView = true
287+ Preferences ( ) . viewOptions = viewOptions
289288 }
290289
291290 func showSceneKitRenderingOptions( ) {
@@ -300,46 +299,4 @@ class ViewportController: NSObject, ObservableObject, SCNSceneRendererDelegate {
300299 case orthographic
301300 case perspective
302301 }
303-
304- struct ViewOptions : Codable {
305- var showGrid = true
306- var showOrigin = true
307- var showCoordinateSystemIndicator = true
308- var edgeVisibility : EdgeVisibility = . sharp
309- var cameraTransform : SCNMatrix4 = SCNMatrix4Identity
310-
311- enum CodingKeys : String , CodingKey {
312- case showGrid
313- case showOrigin
314- case showCoordinateSystemIndicator
315- case cameraTransform
316- case edgeVisibility
317- }
318-
319- init ( ) { }
320-
321- init ( from decoder: any Decoder ) throws {
322- let container = try decoder. container ( keyedBy: CodingKeys . self)
323- showGrid = try container. decode ( Bool . self, forKey: . showGrid)
324- showOrigin = try container. decode ( Bool . self, forKey: . showOrigin)
325- showCoordinateSystemIndicator = try container. decode ( Bool . self, forKey: . showCoordinateSystemIndicator)
326- cameraTransform = try container. decode ( SCNMatrix4 . CodingWrapper. self, forKey: . cameraTransform) . scnMatrix4
327- edgeVisibility = ( try ? container. decode ( EdgeVisibility . self, forKey: . edgeVisibility) ) ?? . sharp
328- }
329-
330- func encode( to encoder: any Encoder ) throws {
331- var container = encoder. container ( keyedBy: CodingKeys . self)
332- try container. encode ( showGrid, forKey: . showGrid)
333- try container. encode ( showOrigin, forKey: . showOrigin)
334- try container. encode ( showCoordinateSystemIndicator, forKey: . showCoordinateSystemIndicator)
335- try container. encode ( SCNMatrix4 . CodingWrapper ( cameraTransform) , forKey: . cameraTransform)
336- try container. encode ( edgeVisibility, forKey: . edgeVisibility)
337- }
338-
339- enum EdgeVisibility : String , Codable {
340- case none
341- case sharp
342- case all
343- }
344- }
345302}
0 commit comments