Bounding box not correct

Hi there,

I have a question regarding the bounding box of models/primitives.

I am working with cylinders as dummies and as soon as i rotate them, the bounding box seems to get to big.See attached images.

The cylinders on the top are not rotated, the cylinders on the bottom are rotated by 45 degrees. I attached a box to visualize the rotation, the bounding box is exactly the same without the box.

Screenshot from playmode with bounding box visualized:

It seems like the cylinders assume a box as base shape for calculating the bounding box, adn that’s why it stretches when turning.

Is there a way around this? I would like the bounding boxes to be as tight as possible.

Screenshot in Editor, see the selection brackets showing the bounding box too large:

Can you share the project? I want to check object setup.

Edit: Nevermind, I see the box was for extra visualisation. That looks like it could be a bug in the engine code :thinking: If you can post a bug report here, that would be great: https://github.com/playcanvas/engine/issues

Bear in mind that they are Axis Aligned Bounding Boxes if that makes a difference.

In the meantime, you could create your own AABB with pc.BoundingBox: https://developer.playcanvas.com/en/api/pc.BoundingBox.html

Or use one that can oriented https://developer.playcanvas.com/en/api/pc.OrientedBox.html

Depending on your use case for the bounding boxes

Aha, when OrientedBoxes where added to the engine? I remember a PR was on hold for quite some time. That’s quite useful, spam off :innocent:

I think the engine stores AABB in local space for your mesh and that is tight. Then the matrix is applied to transform it to another AABB in world space, and that depending on rotation angle makes it larger. It’s not ideal, but that’s the current implementation, and not a bug. The cost to keep them tight might be not worth it considering they’re used for frustum culling.

2 Likes

I thought I added them back in 2016 :sweat_smile:

1 Like

Thanks for the replies everyone.

It seems like OrientedBox doesn’t provide all the functions BoundingBox does, specifically compute() and add().

I think for now I’m okay with having them not tight, just wasn’t sure if it’s a bug or working as intended.