I am attempting to use kvo to observe my node's geometry because Scenekit does not provide some sort of callback to let me know when the level of detail of a node has been updated. The purpose of this is that my of my nodes have idle animations and I would like to remove animations from my nodes when the level of detail changes to anything other than the most detailed version to avoid running unnecessary idle animations.
Below is the observation setup. The code to add the levels of detail to the geometry is elsewhere but it does run because I can see the geometry change as the pixel radius of the node changes.
The change handler is never called. If I instead observe the node's position, the change handler is triggered when I place my nodes at positions in my scene. Is there another property I should be monitoring or is there another way to determine that a node has changed the level of detail in use so that I can remove animations from that node?
import SceneKit
class ObservableNode: SCNReferenceNode {
private var geometryObservation: NSKeyValueObservation?
override init?(url referenceURL: URL) {
super.init(url: referenceURL)
self.load()
geometryObservation = observe(
\.geometry,
options: [.old, .new]
) { node, change in
print("geometry did change")
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}