I think this question has been ask a few times but haven't been able to produce an answer.
So for an addon I'm building I need to send the bone rotations of an armature. Those rotations are expected to be in global coordinates. So after doing to bone rotations that I need, I collect the rotations like so:
for bone in context.object.pose.bones: bone_idx: int = get_bone_index(skeleton_info, bone) idx = list(context.object.pose.bones).index(bone) m = matrices[idx] axis_angle = bone.rotation_quaternion.to_axis_angle() v_axis = axis_angle result = (bone.id_data.matrix_world.to_3x3().inverted() @ m.inverted() @ v_axis) result.normalize() result = result * axis_angle pose_np[bone_idx*3] = result pose_np[bone_idx*3+1] = result pose_np[bone_idx*3+2] = result
As you can see I get the quaternion local value, get the axis angle and perform some transformations on the vector representing that axis in order to get to the system of coordinates I want.
The thing is the matrices I expect contain weird values. I don't really understand how to use the matrices inside the PoseBone class to achieve what I want to do... The usage of matrix, matrix_local and matrix_channel confuses me especially to see how each bone accumulates transformations and whether if I need to call the inverse of the parent's object matrix world... Could you please give me some hints on what I might be doing wrong?