Multi Scene & Camera

I made one camera each scenes.
cameraA~C = new BABYLON.ArcRotateCamera(… , sceneA~C);

sceneA.activeCamera = cameraA;
sceneB.activeCamera = cameraB;
sceneC.activeCamera = cameraC;

and…

engine.runRenderLoop(function() {
sceneA.render();
sceneB.render();
sceneC.render();
}

I can’t see the cameraB’s viewport.

I tried not set the sceneA’s activeCamera. Still, cameraA’s viewport was drawn.

And this time, I commented out ’ sceneA.render()’.

finally, both camerasA,B’s viewports was Disappeared.

What is problem?

It is possible to use ‘activeCameras’.

@nedcrow Welcome to the Babylon community!!! Awesome to have you here and solid first question!

I think you’re looking for the following code snippet:

scene.activeCamera = cameraB;

Check out this playground I put together that shows off the concept. We create 2 different cameras, then we attach the control of the camera to the canvas, and then set the active camera in the scene to the camera we want.

https://playground.babylonjs.com/#HI28QP#2

Hope this helps!

sceneA.activeCameras = [e.mainCamera, camera_2nd];
sceneB.activeCameras = [e.mainCamera, camera_2nd];

In two cases, the results are different.
1st case, both scenes were visible.
but 2nd case, only sceneA.

Maybe an ‘Scene.autoClear’ is involved?

Would it be possible to post a playground example where we can take a closer look?

example is ready it.
point is ‘//ActiveCameras lines’. :slightly_smiling_face:

playground : https://playground.babylonjs.com/index.html#5DPV7M#7

Sweet thanks for the playground. I think I understand what you’re trying to do. In the example you sent, you are able to see both cameras because there are 2 cameras added to the same scene (sceneA), with the ground, sphere, and light also added to sceneA.

If I understand what you’re asking about here, it seems like you’d like to have 2 different scenes, each one with it’s own camera, and then render them together on screen. This is possible, however you need to have the same assets in both scenes for it to look correct.

Check out this updated playground as an example:
https://playground.babylonjs.com/index.html#5DPV7M#8

We’re duplicated the assets and adding them to sceneB, so now there is a set in sceneA, and sceneB.

Technically, it was working before, however sceneB was empty, so there was nothing to draw on screen.

Also for some efficiency, there’s some added bits at the bottom of this playground to stop the render loop, and then spin it up again with rendering the exact scenes you’d like. When working in the playground, there is existing render loop logic that you don’t deal with in your own project. This means we need special consideration to tell the playground to do exactly what we want.

You can read more about this here:
https://doc.babylonjs.com/how_to/multi_scenes

Hope this is helpful!

2 Likes

Wow, i Got it!

Your code has been a great help.

I thought Scene was a camera director.
Because Scene is on the same Canvase and thought of Unity.
I was wrong.
It was just another space.

Triple thank you!

1 Like

Awesome! And again welcome to the Babylon community!