Maniphest T101848

matrix_world.to_quaternion() returns wrong rotation for 0 scaled matrices
Closed, Resolved

Assigned To
Campbell Barton (campbellbarton)
Authored By
Unknown ElementX (UnknownElementX)
Oct 15 2022, 9:37 PM
Tags
  • BF Blender
  • Python API
Subscribers
Julien DUROURE (julien)
Unknown ElementX (UnknownElementX)

Description

System Information
Operating system: win 10-pro 64bit
Graphics card: NVIDIA GeForce RTX 3070

Blender Version
Broken: 3.3.1, b292cfe5a936, master, 2022-10-04
Worked: 3.0

Short description of error
Additional rotation transform is added to .glb export when an object has a 0 scale transform on the first frame of object animation. This was not an issue in prior versions of blender and exported properly. Old files, when opened in newer Blender builds are being exported at an angle for all objects that have a 0 scale first frame transform.

Exact steps for others to reproduce the error
Keyframe a 0 x scale transform on the first frame and 1 for all other frames. .glb is rotated at an angle upon export.

Revisions and Commits

rB Blender

Related Objects

Mentioned Here
rBb292cfe5a936: Bump version cycle for Blender 3.3.1 release.

Event Timeline

Unknown ElementX (UnknownElementX) created this task.Oct 15 2022, 9:37 PM
Julien DUROURE (julien) changed the task status from Needs Triage to Needs Information from Developers.Oct 16 2022, 6:14 AM
Julien DUROURE (julien) added a subscriber: Julien DUROURE (julien).

Not sure how matrix maths works for 0 scaled matrices (and if it can be solved), but

bpy.context.object.matrix_world.to_quaternion()

Return a non default rotation for 0 scaled object with no rotation

Quaternion((0.0, 0.0, 0.0, 1.0))

For 1 scaled object with no rotation:

Quaternion((1.0, 0.0, 0.0, 0.0))

Julien DUROURE (julien) renamed this task from 0 scale transformation on first frame of object animation is causing additional rotation transform upon GLB export since 3.0 to matrix_world.to_quaternion() returns wrong rotation for 0 scaled matrices.Oct 16 2022, 6:14 AM
Julien DUROURE (julien) added a project: Python API.
Julien DUROURE (julien) added a comment.Oct 16 2022, 6:17 AM

Note: glTF exporters use first frame to get rest TRS of objects, so this is not a good idea to have 0 scales objects on first frame. This can lead to wrong export (and sometime can't export correct files if these objects have children, because local matrices can't be correctly set when parent has a 0 scale).

Unknown ElementX (UnknownElementX) added a comment.EditedOct 16 2022, 6:41 PM
In T101848#1432923, @Julien DUROURE (julien) wrote:

Note: glTF exporters use first frame to get rest TRS of objects, so this is not a good idea to have 0 scales objects on first frame. This can lead to wrong export (and sometime can't export correct files if these objects have children, because local matrices can't be correctly set when parent has a 0 scale).

Unfortunately a 0 scale start frame is the only way I’ve been able to bootstrap a GLB animation via planes that pop in and out of visibility in sequence (since opacity cannot be keyframed in that way).

If you have a better way of achieving that in GLB, please let me know.

This still seems to work when exporting from Blender 3.0 and earlier, so if not a true bug, perhaps whatever was changed from 3.0 onward can be an export checkbox option instead?

Julien DUROURE (julien) added a comment.Oct 16 2022, 6:47 PM

Unfortunately, some massive refactoring have been done since 3.0 (in order to fix lots of hierarchy/animation issues), so it's not possible to switch from one code to another with checkbox.
But we have a workaround using "Use Current Frame" option. It will set rest TRS as there are in the current frame when exporting (when not using this option use frame 1).
We have to choose a frame without any 0 scale, and then export with this option.

Unknown ElementX (UnknownElementX) added a comment.EditedOct 16 2022, 6:52 PM

I couldn’t get that to work here. The way this functions is by every other frame object being set to 0 in all other frames. There would never be a frame were all objects started above 0 unless they could be easily occluded by the displayed object (which is typically impossible with transparency’s and how images on the same plane fight one another with tearing)

Campbell Barton (campbellbarton) claimed this task.Nov 8 2022, 10:21 AM
Campbell Barton (campbellbarton) triaged this task as High priority.

Setting high priority as a round-trip object.matrix_world.to_quaternion().to_matrix() flips the X & Y axes.

Campbell Barton (campbellbarton) closed this task as Resolved by committing rB494385a5bcc4: Fix T101848: Zeroed matrix converted to a quaternion results in rotation.Nov 9 2022, 2:24 AM
Campbell Barton (campbellbarton) added a commit: rB494385a5bcc4: Fix T101848: Zeroed matrix converted to a quaternion results in rotation.