setBoundingInfo not centered on object

Hello,
I try to display the bounding box of a complex mesh when i click on it, but the bounding box is displayed centered on {0,0,0}. How to set it around the mesh ?

function showBoundingBox(obj) {
	let { min, max } = obj.getHierarchyBoundingVectors()
	let bi = new BABYLON.BoundingInfo(min, max)
	obj.setBoundingInfo(bi)
	obj.showBoundingBox = ! obj.showBoundingBox
}

Best regards.

getHierarchyBoundingVectors may help here - Babylon.js docs

Also, you may have a look how it is explained (for multiple objects) in the docs here - Babylon.js docs

Thanks,
But the problem is the same with unique object.
Object is first created in origin (x:0, y:0, z:0) of the world. And then move to a place.
But the bounding info seems to be always in origin.
How to update them ?
Best regards.

Did you try refreshBoundingInfo for meshes after their movement?- Babylon.js docs

If you can setup a repro in the Playground, it will be easier for us to help.

1 Like

Here is a sample : https://www.babylonjs-playground.com/#JDCVDK#7
Best regards

center, minimum and maximum are in local coordinate space. You should use centerWorld, minimumWorld and maximumWorld instead. Also, you should recompute the world matrix after you update the position, because the world matrix is recomputed automatically only when you are in the render loop:

2 Likes

Thank you, I discover these structures. It’s a good direction for me.
Best regards