I need to export skeletons from blender to my own file format. The problem is that I get bad quaternions.
I have this in my export script. The function SHOULD return the quaternion that translates from parent space to bone’s space.
# global-global=local, right?
def get_local_quat( bone ):
mat = bone.matrix["BONESPACE"].copy()
if bone.parent != None:
pmat = bone.parent.matrix["BONESPACE"].copy()
pmat.invert()
mat = mat * pmat
# swap Y and Z
mat = mat * Matrix( [1,0,0], [0,0,1], [0,1,0] ).rotationPart()
quat = mat.toQuat()
print bone.name, "
", mat, "
", quat
return quat
But the skeleton gets somehow distorted:
The skeleton gets even more distorted and twisted if I use this:
def get_local_quat2( bone ):
mat = bone.matrix["ARMATURESPACE"].copy()
# swap Y and Z
mat = mat * Matrix( [1,0,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1] )
quat = mat.toQuat()
print bone.name, "
", mat, "
", quat
return quat
I think this has something to do with roll and bonespace/armaturespace.
The problem isn’t in my program, because it looks correct if I manually write the skeleton.txt file.
Also, I use OpenGL for rendering the skeleton, which is why I need to swap Y and Z axes.
So, what am I doing wrong? Can you help me out?
Thanks for your replies.