Mesh not importing in the center of scene

Hello everyone,
My model is loading 1000 meters (I think 1 unit in my scene is 1 meter) away from the (0,0,0) point and it’s rotated 90 degres. So I hardcoded it and when I’m loading model I am doing those fixes:

Promise.all( =>
        ).then((mesh) => {
          // FIRST FIX
          // First rotate tower 90 degrees, model originally is set horizontally
            Math.PI / 2,
          // SECOND FIX
          // Then move it to (0,0,0) position (kind of hardcode here - different models can be in different positions at start)
           mesh.meshes[0].translate(BABYLON.Axis.Y, -1007, BABYLON.Space.WORLD);

          return mesh;

Is there any way to move the camera to the model so I shouldn’t move it with given offset (-1007)? I’ll have to handle multiple model’s which can have differet offsets.

When I do something like this:

camera.position = mesh.meshes[0].position

it doesn’t make anything because mesh.meshes[0].position shows the LOCAL position of this mesh and it’s (0,0,0) but in global axis it’s (0, -1007, 0) .

you can set the camera’s target using camera.setTarget(meshOrVector);

Would changing the pivot point work for you?

You could also re-center the mesh with the same boundingbox data and then bake the transformation

This solution works the best

Would changing the pivot point work for you?

But I changed it to

let a2 = mesh.meshes[1];
freeCamera.position = a2.getBoundingInfo().boundingBox.centerWorld
arcRotateCamera.position = a2.getBoundingInfo().boundingBox.centerWorld = a2.getBoundingInfo().boundingBox.centerWorld

It’s good bcuz a2.getBoundingInfo().boundingBox.centerWorld takes global position of mesh

Cameras now jumps from mesh to mesh (till every mesh is loaded) so I guess what I’m going to do is just take first mesh position and then stop taking new positions. And move it back a lil bit from it.


1 Like