Skip to content

Commit

Permalink
Merge pull request #14467 from sebavan/rotatefix
Browse files Browse the repository at this point in the history
Fix transform node world space rotation when parent has negative world matrix determinant
  • Loading branch information
sebavan committed Oct 26, 2023
2 parents 381a602 + efa3e35 commit f559ef9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/dev/core/src/Meshes/transformNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,14 @@ export class TransformNode extends Node {
this.rotationQuaternion.multiplyToRef(rotationQuaternion, this.rotationQuaternion);
} else {
if (this.parent) {
const parentWorldMatrix = this.parent.getWorldMatrix();
const invertParentWorldMatrix = TmpVectors.Matrix[0];
this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);
parentWorldMatrix.invertToRef(invertParentWorldMatrix);
axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);

if (parentWorldMatrix.determinant() < 0) {
amount *= -1;
}
}
rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._RotationAxisCache);
rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
Expand Down

0 comments on commit f559ef9

Please sign in to comment.