Skip to content

OBB: Fix applyMatrix4() with rotated boxes and negative determinants. - #35261

Merged
Mugen87 merged 3 commits into
mrdoob:devfrom
Enesuygurs:fix/obb-apply-matrix4
Oct 28, 2026
Merged

Mugen87 merged 3 commits into
mrdoob:devfrom
Enesuygurs:fix/obb-apply-matrix4

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

Related issue: -

Description

OBB.applyMatrix4() had two problems:

  • The rotation extracted from the matrix was post-multiplied (rotation.multiply()), so for an OBB that already has a non-identity rotation the result was R_obb * R_matrix instead of R_matrix * R_obb. This went unnoticed because the OBB example only uses boxes with an identity rotation.
  • For matrices with a negative determinant, the negated sx (used to keep the extracted rotation proper) was also applied to halfSize.x, leaving a negative half size. containsPoint() then always returns false, and intersectsOBB() gives wrong results.
const obb = new OBB( new Vector3(), new Vector3( 1, 1, 1 ) );
obb.applyMatrix4( new Matrix4().makeScale( - 1, 1, 1 ) );

obb.halfSize; // before: ( - 1, 1, 1 ), after: ( 1, 1, 1 )
obb.containsPoint( new Vector3() ); // before: false, after: true

This PR uses premultiply(), applies the absolute value of sx to the half size, and adds unit tests for both cases. The new tests fail without the fix.

@Mugen87
Mugen87 merged commit 83f6bd0 into mrdoob:dev Oct 28, 2026
7 of 8 checks passed
@Mugen87 Mugen87 added this to the r187 milestone Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants