-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Description
scaleBoundingBox currently scales the bounding box from world origin (0,0,0) instead of the box's center. This causes the bounding box position to shift for models not centered at origin, leading to incorrect frustum culling during skeletal animations.
Current behavior
// Create a new box that is twice the size
Box box = Box().set(boundingBox.getMin() * scaleFactor, boundingBox.getMax() * scaleFactor);This multiplies min/max directly by scaleFactor, which scales from origin.
Example
A character model with bounding box min(-0.5, 0, -0.5), max(0.5, 2, 0.5) (center at y=1):
With scaleFactor=2:
- Current:
min(-1, 0, -1),max(1, 4, 1)- center moves toy=2(incorrect) - Expected:
min(-1, -1, -1),max(1, 3, 1)- center stays aty=1(correct)
The shifted bounding box no longer correctly contains the mesh, causing parts to be incorrectly culled.
Proposed fix
Scale from the bounding box center:
// Scale from center to preserve bounding box position
float3 center = (boundingBox.getMin() + boundingBox.getMax()) * 0.5f;
float3 scaledHalfExtent = (boundingBox.getMax() - boundingBox.getMin()) * 0.5f * static_cast<float>(scaleFactor);
Box box = Box().set(center - scaledHalfExtent, center + scaledHalfExtent);Breaking change note
This changes behavior for models not centered at origin. Models with bounding boxes symmetric around origin are not affected.
I have a fix ready and can open a PR if this approach sounds good.