How to use multiple cameras for one scene in a scene set

I have 2 SCNViews next to each other and they both need to show the same scene, but through different cameras. It seems to me that the Scene Kit is using the node with the highest camera in the node hierarchy, so I tried something like this

    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 an error [SCNKit ERROR] removing the root node of a scene from its scene is not allowed

and it didn't work at all.

Does anyone have a suggestion how I can achieve this?

Toby

+3


source to share


2 answers


Set the point of view for rendering the scene using the "pointOfView" property of the SCNView.



scnView.pointOfView = cameraNodeLeft;

+8


source


This answer addresses the issue (mentioned by @WolfLink) that having multiple SCNViews with different cameras displaying the same SCNScene causes multiple update sequences.

To fix this, all you have to do is set SCNSceneRendererDelegate to just one SCNView object. Assuming the delegate takes care of all the nodes in the SCNScene and updates them accordingly, other SCNViews that do not have an assigned delegate can still see any changes that occur. This is because the changes are updated in the actual SCNScene to which all SCNView objects are connected.

So, using the original answer from @ Toyos, a way to use two cameras without running the entire refresh sequence at the same time:



// 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'm going to comment on @ Toyos' answer, but I currently don't have enough reputation as I'm still new to the StackOverflow community).

+8


source







All Articles