PoseBone local rotation values to global with axis changed 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[0]
            result = (bone.id_data.matrix_world.to_3x3().inverted()
                      @ m.inverted()
                      @ v_axis)

            result.normalize()
            
            result = result * axis_angle[1]
            pose_np[bone_idx*3] = result[0]
            pose_np[bone_idx*3+1] = result[1]
            pose_np[bone_idx*3+2] = result[2]

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?
Thanks!
Not sure what you need. Try this for rotation between local space and world space
for pbone in context.object.pose.bones:
    # This is the transform from bone local space to world space
    world = context.object.matrix_world @ pbone.matrix

    # If there are non-uniform scalings or shears in `world`, this won't work...
    _loc, rot, _scale = world.decompose()
    
    print(rot.to_axis_angle())

If you want the relative rotation from the rest pose to the current pose in world space, maybe this
for pbone in context.object.pose.bones:
    world = context.object.matrix_world @ pbone.matrix
    world_rest = context.object.matrix_world @ pbone.bone.matrix_local

    _loc, rot, _scale = world.decompose()
    _loc, rot_rest, _scale = world_rest.decompose()
    
    print(rot.rotation_difference(rot_rest).to_axis_angle())