Skip to content

Bug: scaleBoundingBox scales from origin instead of center #326

@csouls

Description

@csouls

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

https://github.com/margelo/react-native-filament/blob/42dca91/package/cpp/core/RNFRenderableManagerImpl.cpp#L287-L288

// 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 to y=2 (incorrect)
  • Expected: min(-1, -1, -1), max(1, 3, 1) - center stays at y=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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions