pose_bone.matrix
is the transform from bone-local-space to armature-space (not world-space). It is the real transform, after constraints, drivers, etc. are applied.
So you can get the transform relative to the bone's parent by first transforming into armature space with pbone.matrix
, then transforming from armature space in pbone.parent
's space with pbone.parent.matrix.inverted()
.
for pbone in ob.pose.bones:
m = pbone.matrix
if pbone.parent:
m = pbone.parent.matrix.inverted() @ m
print(pbone.name, m)
Note that the matrix m
might not be a pure rotation matrix in general (although for your screenshot it looks like it will be).
Also note that this won't work if you have non-invertible matrices. Avoid scaling bones to 0.