Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bpy.types.Bone.convert_local_to_pose.py « examples « python_api « doc - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3cc95dec614773f9e6df179fe515702f6b998bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This method enables conversions between Local and Pose space for bones in
the middle of updating the armature without having to update dependencies
after each change, by manually carrying updated matrices in a recursive walk.
"""

def set_pose_matrices(obj, matrix_map):
    "Assign pose space matrices of all bones at once, ignoring constraints."

    def rec(pbone, parent_matrix):
        matrix = matrix_map[pbone.name]

        ## Instead of:
        # pbone.matrix = matrix
        # bpy.context.view_layer.update()

        # Compute and assign local matrix, using the new parent matrix
        if pbone.parent:
            pbone.matrix_basis = pbone.bone.convert_local_to_pose(
                matrix,
                pbone.bone.matrix_local,
                parent_matrix=parent_matrix,
                parent_matrix_local=pbone.parent.bone.matrix_local,
                invert=True
            )
        else:
            pbone.matrix_basis = pbone.bone.convert_local_to_pose(
                matrix,
                pbone.bone.matrix_local,
                invert=True
            )

        # Recursively process children, passing the new matrix through
        for child in pbone.children:
            rec(child, matrix)

    # Scan all bone trees from their roots
    for pbone in obj.pose.bones:
        if not pbone.parent:
            rec(pbone, None)