I am having some problems with blender bones.
In short this is my issue:
- In python I am creating some bones.
- I transform them in edit mode using a specific matrix.
- Now I need to read back the mentioned matrix. How can I do that?
Check the script to clarify may be:
import bmesh import bpy import mathutils # create skin container asset_arm_name = '' + '_sk' bpy.ops.object.armature_add() narmature = bpy.context.scene.objects.active narmature.name = asset_arm_name arm = narmature.data arm.name = asset_arm_name # enter edit mode to start creating bones arm_obj = bpy.data.objects[asset_arm_name] bpy.context.scene.objects.active = None bpy.context.scene.objects.active = arm_obj bpy.ops.object.mode_set(mode='EDIT', toggle=False) edit_bones = arm_obj.data.edit_bones arm.edit_bones.remove(arm.edit_bones) #remove default bone # calc transformations x = [[2.220446049250313e-16, -1.0, 0.0], [1.0, 2.220446049250313e-16, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]] tr=mathutils.Matrix([i+ for i in x]) tr=1.0 bone = edit_bones.new('bone') bone.head=[0,0,0] bone.tail=[0,0,10] bone.transform(tr) print('=====================') print(tr) print(arm_obj.data.bones.matrix) x=arm_obj.data.bones.matrix x.transpose() print(x)
So, given a bone at 0,0,0 with no previous transformations... if I transformed a bone using a tr_matrix. How can I get the transformation matrix that I just applied using the blender api? In the previous example this is the tr_matrix applied to the bone:
tr_matrix = <Matrix 4x4 (0.0000, -1.0000, 0.0000, 0.0000) (1.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 1.0000, 0.0000) (0.0000, 0.0000, 0.0000, 1.0000)>
And this is what I am getting from the bone:
arm_obj.data.bones.matrix = <Matrix 3x3 (1.0000, 0.0000, 0.0000) (0.0000, 0.0000, -1.0000) (0.0000, 1.0000, 0.0000)>
Multiplying by parent transform, transposing or converting to_4x4 doesn't help. I tried through arm_obj.data.bones and arm_obj.pose.bones, using matrix or matrix_local... but I don't manage to get tr_matrix again, and I have been searching for some days already.
May be I am missing something?
Note: In case you are missing the use case, I am evaluating blender to use it in our pipeline. We have a custom mesh format. Importing is fine, all bones, skin, etc.. all ends in the correct places. But exporting that same data without any changes is giving me different results. The problem is in the bones. I don't manage to get their world transform. I can set it (using bone.transform(tr_matrix)) but when asking for the transformation I am getting different data. So, I assume I am doing something wrong, and this example is probably simple enough to find out what. I hope!