How to create box mesh base on bounding box

https://playground.babylonjs.com/#4F33I3#205

I want to create a box base on bounding box, but I do not know how to find bouding box corner position.

1 Like

One way of doing that would be this - Bounding Box Fun | Babylon.js Playground (babylonjs.com)

2 Likes

https://playground.babylonjs.com/#4F33I3#206

Hi. Not sure what exactly you want to achieve, but this might help you. Basically I’ve created a box based on bounding box, but note here that because the parent bounding box is slightly tilted the info you get from extendSize is from the most top right left bottom points of that bounding box (check image)
image

You can also go through vectors (points), which basically represents corners that you are looking for.

1 Like

My bad here, if you remove computeWorldMatrix from the code, you will get proper dimensions of the box.

1 Like

https://playground.babylonjs.com/#4F33I3#208

here is modified playground if needed (combined with the RaananW answer above)

2 Likes

Thank you so much, I did not notice that there is a vectorsWorld attribute. and the idea of using the dimensions of boundingbox to construct a box mesh also help a lot.

1 Like

Hi. I am a bit confused on why we have to use onAfterRenderObservable here to set the position to the center of the boundingBox, while without it it will not be properly positioned?

scene.onAfterRenderObservable.addOnce(() => {
b.position.copyFrom(bi.boundingBox.centerWorld)
})

that’s because of the not-updated world matrix of the rotated element. On after render, the bounding information is being updated with the right center.
You can force-update the world matrix:
Bounding Box Fun | Babylon.js Playground (babylonjs.com)

2 Likes