1
$\begingroup$

I have a pose bone whose rotation is affected by a Damped Track bone constraint. I would like to determine the exact rotation of that bone (via Python) when it is affected by the constraint.

In other words, I want to:

  1. Get the posed rotation of the bone in quaternions on a particular frame.
  2. De-activate or remove the Damped Track bone constraint.
  3. Put the quaternion rotation values in for that bone, and have it rotated at the exact same angle as it was when the Damped Track bone constraint was active during that frame.

I've found several code examples of how to do this. However, when I implement them, the quaternion values don't turn out correctly. After converting the final matrix back to a quaternion, usually I get quaternions that look like (1,0,0,0), (0,1,0,0), (0,0,1,0), and (0,0,0,1).

I'm using Blender 2.93.1. I'm wondering if perhaps if something has changed in the API with respect to what the matrix values return, so the code examples I've been using are no longer valid. Below are links to some of the approaches I've tried.

Any ideas?

https://blenderartists.org/t/reading-current-rotation-of-a-bone/539394/4

https://blenderartists.org/t/how-to-get-a-animated-bones-rotation/559434/7

https://stackoverflow.com/questions/12034813/what-space-is-this-matrix-in

http://graemehill.ca/exporting-armature-animation-with-the-blender-25-python-api/

$\endgroup$

1 Answer 1

0
$\begingroup$

Never mind – I figured it out and got everything working.

It turns out that the old code that I had found in the links above were using an asterisk to multiply matrices. I’m not totally clear on what changed with Python or its libraries, but apparently the correct way to multiply matrices (using Blender’s implementation of Python, anyway) is with the @ symbol. Otherwise, when you convert those matrices to quaternions, you get the weird results that I was seeing (like (1,0,0,0)).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.