donmccurdy / donmccurdy/glTF-Transform

flatten node with non uniform scaling in hierarchy changes its shape

Open
#1,680 2 comments 0 reactions 0 assignees View on GitHub
needs investigation package:core package:functions question
Dominant language
TypeScript
Stars
2k
Forks
206
Avg merge
2d 2h
Merged PRs (30d)
16

Description

**Describe the bug**
When `flatten` is called, it [uses](https://github.com/donmccurdy/glTF-Transform/blob/98a84642a77c7e48efdc203d786b2985726cacfa/packages/functions/src/clear-node-parent.ts#L34) [`node.setMatrix`](https://github.com/donmccurdy/glTF-Transform/blob/98a84642a77c7e48efdc203d786b2985726cacfa/packages/core/src/properties/node.ts#L121) internally, which [decomposes ](https://github.com/donmccurdy/glTF-Transform/blob/98a84642a77c7e48efdc203d786b2985726cacfa/packages/core/src/utils/math-utils.ts#L77)the matrix with three.js' impl, which does not handle sheared matrix correctly as [documented](https://threejs.org/docs/#api/en/math/Matrix4.decompose).

**To Reproduce**
Steps to reproduce the behavior:
1. Go to and open this example model [untitled.zip](https://github.com/user-attachments/files/21073583/untitled.zip)
2. Click on "Script"
3. Run `await document.transform(flatten());`
4. See the shape change

![Image](https://github.com/user-attachments/assets/c689f670-4be9-486d-98a8-0fd13bb08fa4)

**Expected behavior**
The shape of mesh does not change.

**Versions:**
- Version: [4.0.2 - git master]
- Environment: [ Browser, Node.js]

**Additional context**

The gltf spec [allowed](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#transformations) nodes to have a `matrix` for transformation, so the matrix could be kept.
Maybe an option can be added to let users decide the behavior to use in case of indecomposable matrices, candidates could be:
* decompose: the behavior now
* skip: skip flatten
* bake: bake transform into vertices (slow)

Contributor guide

Open the contributing guide

Research direction

Start with packages/functions/src/clear-node-parent.ts, packages/core/src/properties/node.ts, and packages/core/src/utils/math-utils.ts, then reproduce the issue with flatten() using the linked example model. Determine how flatten should handle indecomposable matrices—decompose, skip, or bake—and verify that the chosen behavior preserves the mesh shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
three.js, typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.