Repository navigation
Scene: Matrix4.decompose leaves a singular matrix as identity rotation and unit scale, as three.js does - #126
Merged
Conversation
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
three.js's
Matrix4.decomposechecks the affine determinant first. When it is 0 (a zero-scaled axis, say), it still writes the position but sets the rotation to identity and the scale to (1, 1, 1) instead of dividing by a zero axis length (r187Matrix4.js#L1071-L1095).packages/scenedivides by the zero length, so the quaternion comes out[NaN, NaN, NaN, NaN].Change:
Matrix4.decomposeinmath.tswrites the position, computes the affine determinant, and returns identity rotation and unit scale when it is 0. Otherwise it is unchanged; the same determinant now also picks the sign ofsx.Behaviour change, matching three.js: callers that decompose a zero-scaled matrix (for example
getWorldScale,getWorldQuaternion,attach,Object3D.applyMatrix4,lookAtunder a parent and the light orientation inengine.ts) now get scale (1, 1, 1) and an identity rotation where they used to get the true scale with a NaN rotation. Checked with an object scaled (0, 2, 3): on maingetWorldScalegives (0, 2, 3) andgetWorldQuaterniongives NaN; on this branch they give (1, 1, 1) and (0, 0, 0, 1), the same asthree@0.187.0.attachandObject3D.applyMatrix4on such an object change the same way. Code that hides objects by scaling an axis to 0 and then calls one of these will see the three.js result.Test: one
node:testcase in a new file,packages/scene/test/three-compat-matrix4.test.ts: amakeScale(0, 2, 3)matrix with a translation keeps its position, gets identity rotation and unit scale, and is not itself modified.The test is in its own file so it merges independently of the other open three.js-parity PRs.
Tier T (
packages/sceneTypeScript; no kernel, IR or export changes).Merge gate
npm run typecheck: pass, with main 1b1aa13 merged in.npm test: 175 tests, 174 pass, 0 fail, 1 skipped. The skip is the physics arena test intools/three/test/physics.test.ts, which needs a builtphysics_scene.wasm; main skips it too (174 tests, 173 pass).[NaN, NaN, NaN, NaN]rotation). At the head it passes.three@0.187.0, passes unchanged.npm test(187 tests, 186 pass, 0 fail, 1 skipped).npm run test:render: not run, because no idle GPU was available.packages/sceneis in scope, so please run it before merging.Runs were on a Linux VM (Node 24.22.1) in a fresh home directory, from a fresh clone and
npm ci.