如何在其运行时从 SCNTransaction 获取正确的值?

How to fetch correct values from SCNTransaction over its runtime?

我试图从某个被 SCNTransaction 修改的 SceneKit 对象中获取值,如下所示:

(focalLength 初始值为 50)

SCNTransaction.begin()
SCNTransaction.animationDuration = 5.0
cameraNode.camera?.focalLength = 24
SCNTransaction.commit()

SCNTransaction 正常执行并执行其应有的操作并且相机对象缩小。

在此事务期间,我想获取当前“focalLength”,因为它在任何确切时间点由 SCNTransaction 应用。

print("Current focalLength: \(cameraNode.camera?.focalLength)")

结果始终是 24 - 最终值 - 无论我是在 0、1 还是 3 秒获取值。所以我假设 SCNTransaction 在内部以某种方式执行了这种平滑的修改。有没有办法从正在进行的 SCNTransaction 中获取实际值。谁能详细解释一下 SCNTransaction 中发生了什么?

PS:我当然可以制作 SCNAction.cutomAction 或 CABasicAnimation - 但我想知道是否有办法从 SCNTransaction 获取值。

这可以通过节点的 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)")