经过一番研究和睡眠后,我得出了以下可行的解决方案(包括一些无法解释的障碍):
目前,附加的 SCNCamera feed 未链接到 SCNPlane 上的 SCNMaterial,因为这是最初的想法,但我将使用附加的 SCNView(目前)
在定义中我添加了另一个视图,如下所示:
let overlayView = SCNView() // (also tested with ARSCNView(), no difference)
let camera = SCNCamera()
let cameraNode = SCNNode()
然后,在 viewDidLoad 中,我设置了这样的东西......
camera.automaticallyAdjustsZRange = true
camera.usesOrthographicProjection = false
cameraNode.camera = camera
cameraNode.camera?.focalLength = 50
sceneView.scene.rootNode.addChildNode(cameraNode) // add the node to the default scene
overlayView.scene = scene // the same scene as sceneView
overlayView.allowsCameraControl = false
overlayView.isUserInteractionEnabled = false
overlayView.pointOfView = cameraNode // this links the new SCNView to the created SCNCamera
self.view.addSubview(overlayView) // don't forget to add as subview
// Size and place the view on the bottom
overlayView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width * 0.8, height: self.view.bounds.height * 0.25)
overlayView.center = CGPoint(x: self.view.bounds.width * 0.5, y: self.view.bounds.height - 175)
然后,在其他一些函数中,我将包含 SCNCamera 的节点放置到我想要的位置和角度。
// (exemplary)
cameraNode.position = initialStartPosition + SCNVector3(x: -0.5, y: 0.5, z: -(Float(shiftCurrentDistance * 2.0 - 2.0)))
cameraNode.eulerAngles = SCNVector3(-15.0.degreesToRadians, -15.0.degreesToRadians, 0.0)
结果是屏幕底部出现一种窗口(新的 SCNView),显示与主场景视图中相同的 SceneKit 内容,通过 SCNCamera 的视角及其节点位置进行查看,效果非常好。
在常见的 iOS/Swift/ARKit 项目中,这种构造会产生一些可能难以解决的副作用。
1) 主要是,新的 SCNView 从所需的角度显示 SceneKit 内容,但背景始终是实际的物理摄像机源。我无法弄清楚如何通过仍然显示所有 SceneKit 内容来使背景成为静态颜色。更改新场景的背景属性也会影响整个主场景,这实际上是不希望的。
2)这可能听起来令人困惑,但是一旦包含以下代码(这对于使其工作至关重要):
overlayView.scene = scene
整个场景的动画速度(两者)双倍! (为什么?)
我通过添加/更改以下属性来纠正此问题,该属性几乎恢复了动画速度行为(默认):
// add or change this in the scene setup
scene.physicsWorld.speed = 0.5
3)如果项目中有像 SCNAction.playAudio 这样的动作,所有效果将不再播放 - 只要我不这样做:
overlayView.scene = nil
当然,附加的 SCNView 停止工作,但其他一切都会恢复正常。