0
$\begingroup$

I am attempting to move an armature bone in edit mode by the inverted matrix of another bone in pose mode. My reasoning for doing this is because I have joined two armatures and have lined the bones of the second armature up with the first armature while the first armature was in pose mode (made it much easier). So what I'm attempting to do is keep the same location/rotation offsets between the two, but transform the second armature's bones to be relative to the default position of the first armature. I hope that makes sense. I believe this is possible, but I'm not sure exactly which matrices I need to be applying to get the desired effect as my below script does not provide desired result. I feel like I'm missing some vital key element...might anyone know what that is?

import bpy
from mathutils import Vector, Matrix
import numpy as np


matFilePath = 'Z:\\models\\myfps\\weapons\\pretty\\arms\\script\\mat.txt'


def convert_matrix_to_string(some_matrix):
    # omitted for brevity

def convert_file_to_matrix(some_path):
    # omitted for brevity
        
# select the bone in pose mode and run this to save to matFilePath
#for b in bpy.context.selected_pose_bones:
#    f = open(matFilePath, "w")
#    f.write(convert_matrix_to_string(b.matrix))
#    f.close()

# load in the matrix from file
hand_pose_mat = convert_file_to_matrix(matFilePath)

# apply inversion of matrix to bone
for b in bpy.context.selected_bones:
    b.transform(hand_pose_mat.inverted())

The below images should assist in explaining what I am attempting to accomplish: enter image description here

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

The solution to this was to transform bone2 by the inverse of bone1's pose mode matrix, then transform bone2 again by bone1's matrix in edit mode:

for b in bpy.context.selected_bones:
    b.transform(hand_pose_mat.inverted())
    b.transform(hand_edit_mat)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.