I’m trying to export armature data from Blender 2.5. I know I can access bones like this:
bpy.data.armatures[i].bones[j]
and that each bone has the following useful properties:
length
head
head_local
tail
tail_local
matrix
matrix_local
However, I wish to represent the bone’s bind-pose rotation as a quaternion in my file format. I know I could convert matrix_local into a quaternion, but I assume there’s a better way. Could anyone offer some insight?
Converting the matrices to quaternions works, but the process is long-winded and it’s very likely that there’s a better way. If anyone knows or finds out, give me a shout.
import time
mat = bpy.context.active_object.matrix_local
print(mat)
q1=(Quaternion(MatrixToQuaternion( mat )))
q2=(mat.to_quat())
print(q1,q2)
print(q1-q2)
oldtime = time.time()
for i in range(100000):
Quaternion(MatrixToQuaternion( mat ))
res=(time.time()-oldtime)
print(res)
oldtime = time.time()
for i in range(100000):
mat.to_quat()
res=(time.time()-oldtime)
print(res)
gives:
1.44799995422
0.137000083923
meaning the builtin conversion is 10 times faster!!!