I have a script in which I compute a custom matrix for each bone of a skeleton. I know I have switch to edit mode but then I read that the property edit_bone.matrix
is read-only for bones. Now, because I know how matrices work, I thought, I would just set the bones matrix to Identity() (edit_bone.head
to (0, 0, 0)
and edit_bone.tail
to (0, 1, 0)
). But when I then do transform the bone the outcome is not what I expected. The script-snippet is the following:
for bone in self._data.edit_bones:
ebone = armature.edit_bones.new(bone.name)
# ebone.head = (0.0, 0.0, 0.0) # already default
ebone.tail = (0.0, 1.0, 0.0)
t_matrix = Matrix(bone.transform) # use blender-intern Matrix
# the following call should set ebone.matrix to t_matrix
# cannot do that directly, is currently wrong
ebone.transform(t_matrix)
print(t_matrix, ebone.matrix, sep='\n')
This gives the following output:
<Matrix 4x4 (-0.9665, -0.2564, -0.0119, 17.7405)
( 0.0171, -0.0183, -0.9997, 0.0280)
( 0.2561, -0.9664, 0.0221, -0.0120)
( 0.0000, 0.0000, 0.0000, 1.0000)>
<Matrix 4x4 (-0.0530, -0.0119, 0.9985, 17.7405)
( 0.0227, -0.9997, -0.0107, 0.0280)
( 0.9983, 0.0221, 0.0533, -0.0120)
( 0.0000, 0.0000, 0.0000, 1.0000)>
Notice how the translation is correct but I don't understand why the other part isn't. Can anyone give an insight what is going on and provide a solution to my problem?
bone.matrix == Matrix.Identity(4)
$\endgroup$.matrix
can't be set, you need to set.roll
and the both endpoints instead. There are 2 utility function: blender.org/documentation/blender_python_api_2_70a_release/… $\endgroup$