BabylonJS + its documentation + forum + team + playground is really amazing and great.
I am a newbie, but It took me really lots of efforts to setup a “simple” scene coming from a gltf import.
My question is :
Is there any way to use a simple feature like camera.fitAll();
Usually many samples are explaining:
scene.target = mesh;
But what if user has collection of meshes
For example the way I took is not that easy (2 days) to have https://playground.babylonjs.com/#U5SSCN#185 with a correct camera + light position by computing scene bbox and reacting in a “classic” way with mouse without inertia and stuff going out of my mouse or turning in a weird manner by default
Hopefully the library is so versatile that anything is possible. But its also very rich so finding how to tweak is not that easy for beginners
To conclude, that means the kind of sample (cleaned) would be very great to find for a beginner
I can’t see anything about fitAll() features in documentation. Did I miss something ?
I tried the 3 samples in doc and then I tried in playground
About : BABYLON.FramingBehavior.FitFrustumSidesMode working
Althougth it works very well on cube sample https://playground.babylonjs.com/#6FBD14#2
Here is the example with your model loaded into Babylon Viewer which has a kind of “camera.fitAll()” by default - Framing testing – Babylon.js 3D WordPress Plugin
Is it closer to what you’d like to achieve?
Thank you. Yes it is much closer to what I’m looking for.
So fitAll() features exists somewhere inside BabylonJS viewer ?
And in your sample the framingBehavior seems to work.
It does not in my playground https://playground.babylonjs.com/#U5SSCN#187
To be very close to your sample with one box only, I tried to set camera.target = bbox; where bbox is red transparent below
I still have same issue, the camera is going iniside the meshes
This code has no effect camera.framingBehavior = BABYLON.FramingBehavior.FitFrustumSidesMode;
Ok, to do what you are suggesting, I would also need to compute scene bbox and change the origin of model. Which is like setting camera (lookAt, lookFrom) from bbow. When you have scene bbox from meshes. That means fitAll() must be implemented by user.
There is still something weird in my sample here https://playground.babylonjs.com/#U5SSCN#187
Why the sphere at the center of the scene (= center of scene bbox) does not move when camera is panning ?
I am sorry, I see no reason why an object should “stay” static when camera panning is done
Normally pannig is like a travelling operation in movies with a camera
So all objects should visually move, indeed the camera frustrum does
I hope panning does not affect the model position and it does a translation of model instead of moving camera frustrum
Did I miss a concept I’m not used too ?
Your sphere does not move because you set its position to lookAt (sphere.position = lookAt), which is also the target of the camera (camera.target = lookAt). So, sphere position and camera target are always the same, so the sphere does not move on screen. Set the position of the sphere to lookAt.clone() instead.
You also have a bug here var material = new BABYLON.StandardMaterial(scene); where you should pass the name of the material before scene: it makes the inspector crash when selecting the center mesh.
I did not know there was some variable passed as “reference” like in C# in Babylon (typescript).
So cloning position seems very logical…and solve the “issue”