Beispiel #1
0
def quats_to_matrix(qx, qy, qz, qw, tx, ty, tz): # pylint: disable=invalid-name
    """
    Converts the quaternions and the translation into a 4-dimensional matrix
    """
    # this is straight up math, nothing to "graps" or "understand". Var names are practical
    # pylint: disable=invalid-name
    mat = Quaternion((qx, qy, qz, qw)).to_matrix().to_4x4()
    mat.translation = Vector((tx, ty, tz))
    return mat
Beispiel #2
0
 def execute(self, context):
     obj = context.active_object
     root = mmd_model.Model.findRoot(obj)
     mmd_root = root.mmd_root
     rig = mmd_model.Model(root)
     armature = rig.armature()
     morph = mmd_root.bone_morphs[mmd_root.active_morph]
     morph_data = morph.data[morph.active_data]
     p_bone = armature.pose.bones[morph_data.bone]
     mtx = Quaternion(
         *morph_data.rotation.to_axis_angle()).to_matrix().to_4x4()
     mtx.translation = morph_data.location
     p_bone.matrix_basis = mtx
     utils.selectSingleBone(context, armature, p_bone.name)
     return {'FINISHED'}
    def execute(self, context):
        preferences = context.preferences.addons[__package__].preferences
        activeObject = context.active_object

        poseBones = activeObject.pose.bones
        for boneName, rotation in APoseBoneRotation.items():
            poseBone = poseBones.get(boneName)
            if poseBone:
                oriMat = poseBone.matrix.copy()
                newMat = Quaternion(rotation).to_matrix().to_4x4()
                newMat.translation = oriMat.to_translation()
                poseBone.matrix = newMat
                bpy.ops.pose.visual_transform_apply()

        return {"FINISHED"}