Boundingbox of object with rotation

Hey, Im trying to use Box3 on a rotated model. The result I get is wrong.

I guess the images demonstrate the problem pretty good. All objects are rotated around the y axis.

What I dont understand is why the boundingbox is not “touching” the geometry anymore? I know the boundingbox is axis aligned and increases volume when rotated, but it should fit the object exactly, shouldnt it? Is this intentionally?

Here is the object with rotation = 0 and rotation = .7. (Boundingbox on each nested object)

Here is a comparison to a BoxGeometry with rotation. There is a gap between boundingbox and model, but no gap between the boundingbox and cube

Test files (137.0 KB)

Code:

// Inside loading callback

            obj = gltf.scene

            scene.add(obj)

            obj.rotation.y = .7
            obj.updateMatrix()

            const box = new THREE.Box3().setFromObject(obj)

            // box.applyMatrix4(obj.matrixWorld)
            
            const h = new THREE.Box3Helper(box)

            scene.add(h)

Applying the matrixWorld as shown in the docs, does increase the size of the boundingbox even more.

bounding boxes are non inclusive of the rotation of objects and will always return the min and max dimensions of a given object, you will find the OBB class is what you’ll need to use for your case as it returns an oriented bounding box relative to the updated matrix of an object, I hope this helps.

Hey thanks for your reply. Can you explain what you said? As mentioned boundingboxes are axes aligned, but they still take rotation into account, as seen in img2, where the rotated cuboid is framed exactly inside of the boundingbox. On the other hand my model is not framed exactly, au contraire the boundingbox is actually way bigger than the model.

Here I painted the desired boundingbox in red. The yellow boundingboxes are calculated via Box3

The oriented boundingbox looks nice, but it looks like its only for cubes? Not for cuboids

I wonder, is this something exceptional? Doesnt look like a big deal to me at first. I checked the model in blender and tested it in two projects. Cant really figure out whats happening

@Fluqz
See, what happens here: three.js/Box3.js at 309b00afb6dcbc5e6c58e72f10eaa8d2e8888c83 · mrdoob/three.js · GitHub
If you won’t set the second parameter of .setFromObject() method to true (by default, it’s false), you’ll get exactly what you have on the pic with that bent and rotated figure, kind of AABB of OBB.

3 Likes

That worked! Thanks a lot man :smiley: