Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling affects exported animation #1083

Closed
emackey opened this issue Jun 2, 2020 · 9 comments
Closed

Scaling affects exported animation #1083

emackey opened this issue Jun 2, 2020 · 9 comments
Labels
Animation bug Something isn't working exporter This involves or affects the export process

Comments

@emackey
Copy link
Member

emackey commented Jun 2, 2020

I feel like this might already be known, but I'll write it up anyway, as I have a nearly minimal reproduce case for it.

If a parent object has non-uniform scaling (or possibly, non-identity scaling), animations on child objects can become distorted on export.

In this sample Blender 2.8x project, there are two cubes. The orange cube has a node scaling that makes it elongated, and the blue cube is a child.

ScaleExport_Blender

When exporting to glTF, the orange cube exports correctly. But the blue child cube has its rotation distorted by the scaling factor.

ScaleExport_glTF

Here's the Blender project:

ScaledExportTest.zip

@emackey emackey added Animation exporter This involves or affects the export process labels Jun 2, 2020
@julienduroure julienduroure added the bug Something isn't working label Jun 3, 2020
@julienduroure
Copy link
Collaborator

Note this is not only animation error. Still rotation are also false:
image

Probably a missing matrix_parent_inverse multiplication somewhere

@scurest
Copy link
Contributor

scurest commented Dec 3, 2020

It is actually impossible to represent this scene in glTF with only two nodes.

The TRS for the blue box must be (world matrix for orange box).inverted() @ (world matrix for blue box) (modulo Zup2Yup conversion). However in this scene, at, say, frame 100

badmat

This matrix is not a TRS matrix (or that dot-product would be zero).

It's not possible to fix this without inserting another node between the two boxes.

@emackey
Copy link
Member Author

emackey commented Dec 3, 2020

Bummer. Thanks for confirming. Should we print a warning, or try to insert the in-between node?

@scurest
Copy link
Contributor

scurest commented Dec 3, 2020

Probably print a warning, but not sure if the current animation code actually knows when it's indecomposable. I think it would be possible to insert a static in-between node in some special cases but not all cases (edit: actually I think all cases are ok), and not sure how "noisy" it would be, or how complex the implementation would be.

btw export->reimport with both .dae and .fbx also show this effect.

@fire
Copy link

fire commented Apr 17, 2023

iimachines/Maya2glTF#67 @ziriax mentioned a way to decompose scaled objects.

@julienduroure
Copy link
Collaborator

@fire Thanks, I will have a look soon.

Another solution is to implement flatten tree, as we did for armatures (See #1683)

@julienduroure
Copy link
Collaborator

Closing this ticket, as we now have an option to export flatten tree (all object at root of scene), avoiding this issue

@VertebreakHER
Copy link

I'm aware this issue has been closed and I may drawing ire by commenting. But after facing this exact problem and stumbling here after extended time searching I have to make it clear that flattening the bone hierarchy of an armature is not an adequate solution. Techniques like inverse kinematics rely heavily on there being a discernible bone chain, which is very often utilized in real-time engines for assisting already rendered animations (such as keeping feet level with the ground.) So presenting a flat hierarchy as a solution does not make sense and would result in choosing between scaling issues or losing major functionality. Ideally, this issue should be revisited.

@emackey
Copy link
Member Author

emackey commented Oct 29, 2024

@IncredibleMeh This issue frustrates me too, but the root cause is fundamental to the way basic transformation math works in its simplest form. Blender avoids it with its magical "Parent Inverse" matrices, which cause a number of side-effects of their own but are believed to be less-bad than allowing objects to become distorted by child rotations. So there's no "bug fix" to be had here. glTF and all of its many clients and implementations across the industry just implement a normal TRS scene hierarchy, and a normal scene hierarchy is susceptible to this problem. There's no quick patch to this exporter that will solve it.

There's a much better workaround than flattening everything, of course. You can "Apply Scale" (in Blender) to any non-uniformly-scaled parent objects that have rotating children below them.

That's the root of this problem: A non-uniform scale (where X, Y, and/or Z are scaled by different amounts) interferes with the normal math for rotating child objects, as the children inherit the scale and rotate through differently-sized axes. So any parents that have non-uniform scale need to be converted to uniformly-scaled objects prior to export. This is needed not just for glTF, but for any rendering engine that uses simple, traditional TRS scene hierarchy. Blender's "Apply Scale" option, used surgically on the offending parent objects, may provide an escape from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Animation bug Something isn't working exporter This involves or affects the export process
Projects
None yet
Development

No branches or pull requests

5 participants