I have 2 SCNViews next to each other and both should show the same scene but through different cameras. It seems to me that Scene Kit uses that node with a camera that is highest in the node hierarchy so I tried something like that
leftSceneView.scene?.rootNode.addChildNode(scene.rootNode)
rightSceneView.scene?.rootNode.addChildNode(scene.rootNode)
leftSceneView.scene?.rootNode.addChildNode(cameraNodeLeft)
rightSceneView.scene?.rootNode.addChildNode(cameraNodeRight)
but I got the error message [SCNKit ERROR] removing the root node of a scene from its scene is not allowed
and it did not work at all.
Has anybody a suggestion how I can achieve that?
Toby
This answer regards the issue (mentioned by @WolfLink) that having multiple SCNView objects with different cameras showing the same SCNScene causes the entire update sequence to occur multiple times.
To fix this, all you have to do is set the SCNSceneRendererDelegate to only one of the SCNView objects used. Assuming that the delegate is taking care of all of the nodes in the SCNScene and is updating them accordingly, the other SCNView objects that don't have an assigned delegate would still be able to see all of the changes occurring. This is because the changes are updated in the actual SCNScene that all of the SCNView objects are hooked up to.
So, using the original answer by @Toyos, the way to go about using 2 cameras without causing the entire update sequence to fire twice is:
// Set up sceneView 1
sceneView1.scene = scnScene
sceneView1.pointOfView = scnScene.camera1
sceneView1.delegate = scnScene
// Set up sceneView 2
sceneView2.scene = scnScene
sceneView2.pointOfView = scnScene.camera2
(Disclaimer: I was going to comment on the answer by @Toyos, but I currently don't have enough reputation for that since I'm still new to the StackOverflow community).
Set the point of view to render the scene with the "pointOfView" property of the SCNView.
scnView.pointOfView = cameraNodeLeft;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With