Search code examples
javascriptwebglscreenscalingbabylonjs

How to calculate in babylon.js the camera position to the loaded model intermeddle in screen?


I need to boot the entire model got completely into the viewport. enter image description here Because if the model has a large size, it does not got completely into the viewport, for example:

enter image description here

To solve this problem I need set the desired camera position:

camera.setPosition( new BABYLON.Vector3(216, 93, -17) );

for example: test page

How do I automatically calculate the coordinates of the camera in which the model will got completely into the viewport?


Solution

  • You can set:

    camera.parent = yourMesh;
    

    Then you can change: camera.position like you want

    But note that: the camera is parent so the position is relative to his parent!

    So you can't simply use your vector: (216, 93, -17)