I want to calculate a rotation matrix from two vectors, in order to check the steps are correct I have setup 3 armatures.
- A reference bone (arm_org),
- One that is directly rotated by applying a rotation matrix (arm_rot) and
- Another (arm_mat) that should be rotated by a matrix that has been calculated from the rotational difference of the 1st and 2nd.
Why are the bones tails not updated? Unfortunatly ArmatureEditBones isn't well documented. I also tried to set the active bone. But the changes are not reflected in the 3D view. Only the currently selected bone can manipulated.
def setBone( name, v ): arm = bpy.data.armatures[ name ] print("set arm=" + name + " v=" + str( v )) for bone in arm.edit_bones: print( bone.tail ) bone.tail= v def getBone( name ): #bpy.context.scene.objects.active = bpy.data.objects[ name ] arm = bpy.data.armatures[ name ] print("get arm=" + name + " arm=" + str( arm )) v = None for bone in arm.edit_bones: print( bone.tail ) v = bone.tail return v def vec(): mx = mathutils.Matrix.Rotation(math.radians(15.0), 4, 'X') my = mathutils.Matrix.Rotation(math.radians(30.0), 4, 'Y') mz = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'Z') m = mx * my * mz print( "m : " + str (m )) # get and duplicate original tail pos of reference bone vo = getBone("arm_org") if vo == None: print("arm_org not found") return setBone("arm_mat", vo.copy() ) setBone("arm_rot", vo.copy() ) vr = vo * m setBone("arm_rot", vr ) # recalc and apply matrix from rotational difference q = vo.rotation_difference( vr ) mr = q.to_matrix() mr.resize_4x4() vm = vo * mr setBone( "arm_mat" , vm ) print("mr: " + str(mr)) print( "-" * 20 ) vec()
Blend file (works only in edit mode with arm_org selected)