Skip to content

Commit 9916af8

Browse files
authored
[FIX] Fix glTF node matrix decomposition with negative scale (#8329)
1 parent 47acaa2 commit 9916af8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/framework/parsers/glb-parser.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ const createAnimation = (gltfAnimation, animationIndex, gltfAccessors, bufferVie
15171517

15181518
const tempMat = new Mat4();
15191519
const tempVec = new Vec3();
1520+
const tempQuat = new Quat();
15201521

15211522
const createNode = (gltfNode, nodeIndex, nodeInstancingMap) => {
15221523
const entity = new GraphNode();
@@ -1532,9 +1533,14 @@ const createNode = (gltfNode, nodeIndex, nodeInstancingMap) => {
15321533
tempMat.data.set(gltfNode.matrix);
15331534
tempMat.getTranslation(tempVec);
15341535
entity.setLocalPosition(tempVec);
1535-
tempMat.getEulerAngles(tempVec);
1536-
entity.setLocalEulerAngles(tempVec);
1536+
// Use Quat.setFromMat4 which properly handles negative determinant (mirrored matrices)
1537+
// by normalizing the rotation before extraction
1538+
tempQuat.setFromMat4(tempMat);
1539+
entity.setLocalRotation(tempQuat);
15371540
tempMat.getScale(tempVec);
1541+
// Apply negative sign to X scale if the matrix is mirrored (negative determinant).
1542+
// This matches the convention used in Quat.setFromMat4 which flips the X axis.
1543+
tempVec.x *= tempMat.scaleSign;
15381544
entity.setLocalScale(tempVec);
15391545
}
15401546

0 commit comments

Comments
 (0)