Page MenuHome

Matrix multiplications/ to_quat/ to_euler outputs incorrect rotation in some cases
Closed, ResolvedPublic

Description

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 446.14

Blender Version
Broken: version: 2.91.0, branch: master, commit date: 2020-11-25 08:34, hash: rB0f45cab862b8
Worked: /

Short description of error
The matrix multiplication function is buggy, or the matrix > to_quat/to_euler conversion is buggy. This issue propagate in python addons that uses such functions, including the Fbx export where bones rotation are calculated in bone parent space:
https://developer.blender.org/T77811
It happens when a child bone has a nearly 180° angle or 0° with its parent bone, and possibly related to scale value being non equal to 1.

Exact steps for others to reproduce the error

  • Open this blend file:

  • It contains two bones on the right: the longest one, named "2" is the child of "1". "2" is animated, making a simple rotation.
  • The bone on the left named "3" is used to testify the issue, as well as the mesh object on the left "Cube" to testify it doesn't happen with bones only
  • Click "Run Script". The script does the following > get the matrix in local space (parent space) of bone "2" > apply this matrix either by extracting the quaternion rotation from the matrix and set this rotation to bone "3", or by setting directly the matrix_local of "Cube"
  • Notice that rotations are incorrect, they jitter, while the rotation of bone "2" is pretty linear.
  • Now select bone "1" in Edit Mode, scale it bigger and rotate it upside down > No more jitters

Event Timeline

Perhaps there is a change that is not expected in Blenderbold text

lucas veber (lucky3) renamed this task from Matrix > to_quaternion outputs incorrect rotation in some cases to Matrix multiplications outputs incorrect rotation in some cases.Nov 30 2020, 1:29 PM
lucas veber (lucky3) updated the task description. (Show Details)
lucas veber (lucky3) updated the task description. (Show Details)
lucas veber (lucky3) updated the task description. (Show Details)
lucas veber (lucky3) renamed this task from Matrix multiplications outputs incorrect rotation in some cases to Matrix multiplications/ to_quat/ to_euler outputs incorrect rotation in some cases.Nov 30 2020, 2:29 PM
lucas veber (lucky3) updated the task description. (Show Details)
lucas veber (lucky3) updated the task description. (Show Details)

This looks like a numerical precision bug in matrix to quaternion conversion - if you convert matrix to euler directly, the problem seems to disappear.

Thanks for looking into this @Alexander Gavrilov (angavrilov) ! Well if this can be fixed as simply as that this is reassuring. Will test it thoroughly.