I was trying to fetch values from a certain SceneKit object that is modified by a SCNTransaction like so:
(focalLength is initially 50)
SCNTransaction.begin()
SCNTransaction.animationDuration = 5.0
cameraNode.camera?.focalLength = 24
SCNTransaction.commit()
The SCNTransaction exectutes normally and does exactly what it should and the camera object zooms out.
During this transaction period I want to fetch the current "focalLength" as it is applied by the SCNTransaction at any exact point in time.
print("Current focalLength: \(cameraNode.camera?.focalLength)")
The result is always 24 - the end value - regardless if I fetch the value at 0, 1 or 3 seconds. So I assume the SCNTransaction performs this smooth modification somehow internally. Is there a way to fetch the real values from the ongoing SCNTransaction. Can anyone explain, what's going on within a SCNTransaction in detail?
PS: of course I could make a SCNAction.cutomAction or a CABasicAnimation - but I was wondering if there is a way to obtain the values from the SCNTransaction.
This can be accessed via the node's presentationNode
:
When you use implicit animation (see SCNTransaction) to change a node’s properties, those node properties are set immediately to their target values, even though the animated node content appears to transition from the old property values to the new. During the animation SceneKit maintains a copy of the node, called the presentation node, whose properties reflect the transitory values determined by any in-flight animations currently affecting the node. The presentation node’s properties provide a close approximation to the version of the node that is currently displayed. SceneKit also uses the presentation node when computing the results of explicit animations, physics, and constraints.
print("Current focalLength: \(cameraNode.presentation.camera?.focalLength)")