How camera is initialized?

Hello

We have a glb file that has 3d character. Using three is, we try to setup a simple scene and camera to view the character. But we are struggling to initialize the camera properties inorder to view the character in the best fit.

Using Babylon editor, we noticed that the camera view fits the character perfectly, but how can we copy the camera settings from Babylon editor to our project? Also, is there any script that we can include in our project that would help us initialize the camera as it would at Babylon editor?

Adding @julien-moreau who is the owner of the Editor

1 Like

@Samir_Sabri - Welcome to the Babylon family! Awesome to see you’re using the Editor. @julien-moreau is definitely the right person to connect with as @Deltakosh mentioned!

Great to have you as a part of the Babylon family!

1 Like

Hello @PirateJC , thanks for the warm greetings! I am happy to be part of the Babylon family :slightly_smiling_face:

Hi @Samir_Sabri and welcome!

You can take a look at Framing Behavior for arc rotate cameras (Camera Behaviors | Babylon.js Documentation)

For the editor, i can share you the script i use which is more open as it tries to fit the entire scene while computing previews in assets panel: Editor/assets.ts at feature/workspace-assets · BabylonJS/Editor · GitHub the script simply computes the minimum and maximum values available for each mesh bounding-box in the scene and sets the camera position according to the center and distance. With this line (Editor/assets.ts at feature/workspace-assets · BabylonJS/Editor · GitHub) I played with the Y value but you can obviously set

this._camera.position = center.add(new Vector3(distance, distance, distance));
this._camera.setTarget(center);
1 Like

Thanks @julien-moreau for quick response.
Regarding your approach of setting camera target, I am using THREE.PerspectiveCamera, which has no setTarget method.

How would I use the TargetCamera ? I could not find TargetCamera at THREE js library.

Is it Ok to use BabylonTools package? is there any license restriction for commercial usage?
Finally, is there any simple project that uses glb file with BabylonTools package to play with and experiment?

Thanks in advance.

I would say that you should ask on the Three.js forum ??? We could definitely help you with the babylon.js setup but know almost nothing about Three :slight_smile:

If you use the babylon editor, why not using the babylon runtime ???

To be honest, I thought Babylon editor within the THREE js tools.
Yes I would use babylon runtime, is there any example of importing 3d object in glb file using babylon?

Here we are: glTF Loader Demo | Babylon.js Playground (babylonjs.com)

1 Like

And you can find plenty of info in the doc Importing Assets | Babylon.js Documentation

Thanks very much.