Imported mesh not visible when using UniversalCamera and PointLight

See above code, and the problem is marked with red circle:

// Below line works well.

//scene.createDefaultCameraOrLight(true, true, true);

// Replace with below lines, mesh is invisible. And we can check mesh's properties are all right.

var light = new BABYLON.PointLight ("light",new BABYLON.Vector3(1,100,1), scene);

var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(1, 100, 1), scene);

scene.activeCamera = camera;

camera.setTarget(mesh.position);

camera.attachControl(canvas, true);

The gbl file is sourced by NASA : A 3D model of Earth

Have you checked in the inspector to see the camera and light values when you use the CreateDefault option? This will tell you whether the values you use are in range.

2 Likes

Yeah, thanks, I found the solution with your suggestion by changing position and fov of camera. There must be a soft coding solution for each glb file, so as that the application will be suitable for everything.

How could I read the useful information from *.glb file to make a smarter mesh loader?

You could use the camera’s framing behavior for that:

3 Likes

This feature seems to be for `ArcRotateCamera. But I use The FollowCamera.
I got another way:

  1. Input size softly.
  2. Obtain vertices data with Mesh.getverticesData and estimate the biggest diameter of the mesh with a subtraction between the max and min value.
  3. Compute scaling value and set it to Mesh.scaling.

Code like below:

Is there any better way than above?

If you are fine with scaling the mesh you can always use mesh.normalizeToUnitCube() which will normalize the mesh and scale it down to a 1,1,1 size cube. Then you can position your camera correctly

Thanks for telling me that. “normalizeToUnitCube” is the nicest way.

1 Like