getBoundingBox around mesh that is rotated

I have a mesh of a house that I have loaded from a gltf file.
the house is not perpendicular to the world, so when i do a mesh.getBoundingInfo().boundingBox
the bounding box is larger than the square house.

How can I get a boundingbox that fits around the house even though it is rotated?

I understand you’re looking for a object aligned bounding box instead of an axis aligned one, is that right?

@carolhmj yes that is correct :slight_smile:

All right! There are a few techniques for getting the oriented/minimum bounding box. If you know how much the house is rotated relative to the world, the simplest way is to rotate it back, find the bounding box, then rotate everything again, like this example: 3D Oriented bounding boxes made simple | Scratchpad (
If you don’t know the rotation, then it becomes a computational geometry problem which is more complex, like this algorithm O’Rourke Papers (


I had a though but I’m not sure on how to execute it.

The meshes that i’m working with are hitbox meshes which are simple boxes, but they are created in blender and exported as glb files. and their rotation is applied so I have no idea which orentation they have.

but my though is, since they are simple objects, and I only need to figure out the 2d footprint.
I could some how get a single face that is vertical
then get the normal of that face
then calculate the rotation of that normal against the world.
and then use that rotation to create the bounding box.

I’m really struggling with the math, and feel very lost :sweat_smile:

Do you think the flow above would be a possible solution?
and if so, where do I begin

1 Like

If you know the mesh is a box, and its aligned with the YAxis, you can try to “unapply” the rotation.

Here’s a demo of how it can work Babylon.js Playground

The “setup” part is what you do when you import your cube from a .glb file.

Then the VertexData is extracted, and a 2D shape is detected.

Because you expect the shape to be a rectangle, the angle between the first side of the shape and X is the rotation applied to your mesh (modulo 90°)

So after 3 seconds, the opposite rotation is applied to the VertexData, and the rotation is given to the mesh, which gives an aligned BoundingBox.

Note : I did not code it, but at this point it can also be interesting to unapply the translation, because you already know the center of the shape)

(your approach based on normals would work too, I chose this one because it easier to have some tolerance on the fact the house shape is not a perfect 90° rectangle)

1 Like

@SvenFrankson Thanks for the great demo.
I’ll try to implement it in my project and see how it goes :slight_smile:

1 Like