如何平滑地更改不会设置动画的 SCNCamera 的 FoV?
How to smoothly change the FoV of an SCNCamera that won't animate?
我有一个 SCNCamera 在 iOS 的 3D SceneKit 视图中工作。
当我改变屏幕的方向时,为了保持世界对象相同的大小和相对位置,我需要改变 SCNCamera 的 FoV。
但是,我无法为这种变化设置动画,因此世界 'flashes' 或 'pulses' 随着 FoV 从一种设置更改为另一种设置。
有没有一种方法可以顺利地做到这一点,以便 FoV 的变化不会突然导致世界中的物体 'pulse'?
当设备改变方向时,执行这段代码:
if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight
{
self.cameraNode?.camera?.fieldOfView = 38
}
else
{
self.cameraNode?.camera?.fieldOfView = 50
}
我试过将 FoV 更改包装在 UIView 动画块中,但这没有用。
我已经尝试 运行 它在线程上有延迟,但随着 FoV 的改变,这仍然导致视觉 'pulse'。
有什么方法可以使这种过渡顺利进行吗?
您需要像下面这样使用 SCNTransaction
添加代码来制作动画。
The SCNTransaction class defines SceneKit's architecture for scene
content changes, including implicit animations: A transaction is a
single atomic operation that combines multiple changes to nodes,
geometries, materials, or other scene content.
if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight {
SCNTransaction.begin()
SCNTransaction.animationDuration = 1.5
self.cameraNode?.camera?.fieldOfView = 38
SCNTransaction.commit()
} else {
SCNTransaction.begin()
SCNTransaction.animationDuration = 1.5
self.cameraNode?.camera?.fieldOfView = 50
SCNTransaction.commit()
}
我有一个 SCNCamera 在 iOS 的 3D SceneKit 视图中工作。
当我改变屏幕的方向时,为了保持世界对象相同的大小和相对位置,我需要改变 SCNCamera 的 FoV。
但是,我无法为这种变化设置动画,因此世界 'flashes' 或 'pulses' 随着 FoV 从一种设置更改为另一种设置。
有没有一种方法可以顺利地做到这一点,以便 FoV 的变化不会突然导致世界中的物体 'pulse'?
当设备改变方向时,执行这段代码:
if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight
{
self.cameraNode?.camera?.fieldOfView = 38
}
else
{
self.cameraNode?.camera?.fieldOfView = 50
}
我试过将 FoV 更改包装在 UIView 动画块中,但这没有用。
我已经尝试 运行 它在线程上有延迟,但随着 FoV 的改变,这仍然导致视觉 'pulse'。
有什么方法可以使这种过渡顺利进行吗?
您需要像下面这样使用 SCNTransaction
添加代码来制作动画。
The SCNTransaction class defines SceneKit's architecture for scene content changes, including implicit animations: A transaction is a single atomic operation that combines multiple changes to nodes, geometries, materials, or other scene content.
if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight {
SCNTransaction.begin()
SCNTransaction.animationDuration = 1.5
self.cameraNode?.camera?.fieldOfView = 38
SCNTransaction.commit()
} else {
SCNTransaction.begin()
SCNTransaction.animationDuration = 1.5
self.cameraNode?.camera?.fieldOfView = 50
SCNTransaction.commit()
}