Bounding Boxes Info

Can some one help me, how to get the bounding boxes info (values/ coordinates where my image has been on the scene).
I tried using

> var meshTask = assetsManager.addMeshTask("meshTask", [MeshNamePage_1, MeshNamePage_2], "assets/AR-3-4/", "Book_Perfect_Binding_MidOpen_BothCurve_ThicknessOffset.glb");
> meshTask.onSuccess = function(task){
>             try{
>                 mapTexture(scene, pageTexture);
>                 const mesh = task.loadedMeshes[0];
>                 mesh.showBoundingBox = true;
>                 var bb = mesh.getBoundingInfo();
>                 var width = bb.maximum.x - bb.minimum.x;
>                 var height = bb.maximum.y - bb.minimum.y;
>                 var depth = bb.maximum.z - bb.minimum.z;
>                 //mesh.scaling = new Vector3(0.005, 0.005, 0.005);
>                 mesh.scaling = new Vector3(width, height, depth);
>             }
>             catch(error) {
>                 console.log("Texture mapping failed" + error);
>             }           

But getting (0, 0, 0) as the output, though I’ve image.

Just for reference - I’m using this image.

And here is the glb file i’m using (564.3 KB)


When you load a glb/gltf file, the first mesh is a transform mesh and not actual mesh geometry. You should probably use task.loadedMeshes[1] instead.

1 Like

Thanks @Evgeni_Popov I can see the bounding box now by using loadedMeshes[0]. But how can I get the co ordinates.
I actually have two meshes and I’ve placed them together. (In the reference image, it looks like a book, left side page is one mesh and right side page is another mesh)

See how it is done for the sphere + ground in this doc: Drawing Bounding Boxes | Babylon.js Documentation

Basically, you take the minimum(sphere.minimum, ground.minimum) and maximum(sphere.maximum, ground.maximum).

1 Like