Vector3 Project method gives different results with multiple cameras

I have a question regarding the Project method. I’m trying to add a html div on screen based on coordinates from the scene.

My question is why is the method affected by the fact that I have 2+ cameras in the scene, I specify in the parameter which viewport to use, but it still gives different results.

Is there a way to get the same results or am I missing something?

Here’s a playground of it, if you comment out one of the cameras and click on a mesh you’ll see different values show up.

Thanks for the help!

Hey @CristianLemeni , how are you doing?

Thanks for finding this issue. I believe the problem is related to which camera gets its transform assigned to the scene’s _transformMatrix.

When you have multiple cameras, the _transformMatrix will be calculated for each camera during the rendering loop, and the last value that is going to stay in _transformMatrix is the matrix from the last camera. This will make all calculations performed after rendering to be done using the values for the last camera in the array.

You can see that if you add another “scene.activeCameras.push(camera);” the values will became the same as they were when you only had a single camera.

This seems like unintended behavior, but I will ping @RaananW , just to be sure.


This is the right answer :slight_smile:

And this is a cleaner version that fixes it - Vector Project affected by multiple cameras | Babylon.js Playground (


Awesome, that fixed it for me. Thanks for the explanation and everything else! :smile:

1 Like