[FIX] Fix glTF node matrix decomposition with negative scale #8329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #8328
Description
When a glTF node uses a
matrixproperty (instead of separatetranslation,rotation,scaleproperties) that contains a negative scale component (creating a reflection/flip), the model was displayed incorrectly - appearing flipped or upside down.Changes
Quat.setFromMat4()for rotation extraction instead ofMat4.getEulerAngles()when decomposing node matricesscaleSignto the X scale component to preserve negative determinant (mirrored) transformsTechnical Details
The root cause was that
Mat4.getScale()returns only positive values (it computes vector lengths), andMat4.getEulerAngles()doesn't coordinate with negative determinant handling. This could cause the flip to be absorbed into the rotation as an extra 180° rotation, or be lost entirely.The fix uses
Quat.setFromMat4()which already properly handles negative determinant matrices by normalizing the X axis before rotation extraction (see lines 589-597 inquat.js). The negative scale is then preserved by multiplying the X scale byMat4.scaleSign, which returns -1 for mirrored matrices.This approach is consistent with how the engine handles mirrored transforms elsewhere (e.g., batch manager,
GraphNode._worldScaleSign).Checklist