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

utils.py « rigs « rigify - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fd9a2c148e1987b62095212f1e4ee64bcda00e9 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# SPDX-License-Identifier: GPL-2.0-or-later

from ..utils.rig import connected_children_names
from ..utils.naming import strip_mch, strip_org, make_mechanism_name
import re


def get_future_names_arm(bones):
    if len(bones) != 3:
        return

    names = dict()

    uarm = strip_mch(strip_org(bones[0].name))
    farm = strip_mch(strip_org(bones[1].name))
    hand = strip_mch(strip_org(bones[2].name))

    suffix = ''
    if uarm[-2:] == '.L' or uarm[-2:] == '.R':
        suffix = uarm[-2:]
        uarm = uarm.rstrip(suffix)
        farm = farm.rstrip(suffix)
        hand = hand.rstrip(suffix)

    # the following is declared in rig_ui
    # controls = ['upper_arm_ik.L', 'upper_arm_fk.L', 'forearm_fk.L', 'hand_fk.L', 'hand_ik.L', 'MCH-hand_fk.L',
    #             'upper_arm_parent.L']
    # tweaks = ['upper_arm_tweak.L.001', 'forearm_tweak.L', 'forearm_tweak.L.001']
    # ik_ctrl = ['hand_ik.L', 'MCH-upper_arm_ik.L', 'MCH-upper_arm_ik_target.L']
    # fk_ctrl = 'upper_arm_fk.L'
    # parent = 'upper_arm_parent.L'
    # hand_fk = 'hand_fk.L'
    # pole = 'upper_arm_ik_target.L'

    names['controls'] = [uarm + '_ik', uarm + '_fk', farm + '_fk', hand + '_fk', hand + '_ik',
                         make_mechanism_name(hand + '_fk'), uarm + '_parent']
    names['ik_ctrl'] = [hand + '_ik', make_mechanism_name(uarm) + '_ik', make_mechanism_name(uarm) + '_ik_target']
    names['fk_ctrl'] = uarm + '_fk' + suffix
    names['parent'] = uarm + '_parent' + suffix
    names['hand_fk'] = hand + '_fk' + suffix
    names['pole'] = uarm + '_ik_target' + suffix
    names['limb_type'] = 'arm'

    if suffix:
        for i, name in enumerate(names['controls']):
            names['controls'][i] = name + suffix
        for i, name in enumerate(names['ik_ctrl']):
            names['ik_ctrl'][i] = name + suffix

    return names


def get_future_names_leg(bones):
    if len(bones) != 4:
        return

    names = dict()

    thigh = strip_mch(strip_org(bones[0].name))
    shin = strip_mch(strip_org(bones[1].name))
    foot = strip_mch(strip_org(bones[2].name))
    toe = strip_mch(strip_org(bones[3].name))

    suffix = ''
    if thigh[-2:] == '.L' or thigh[-2:] == '.R':
        suffix = thigh[-2:]
        thigh = thigh.rstrip(suffix)
        shin = shin.rstrip(suffix)
        foot = foot.rstrip(suffix)
        toe = toe.rstrip(suffix)

    # the following is declared in rig_ui
    # controls = ['thigh_ik.R', 'thigh_fk.R', 'shin_fk.R', 'foot_fk.R', 'toe.R', 'foot_heel_ik.R', 'foot_ik.R',
    #             'MCH-foot_fk.R', 'thigh_parent.R']
    # tweaks = ['thigh_tweak.R.001', 'shin_tweak.R', 'shin_tweak.R.001']
    # ik_ctrl = ['foot_ik.R', 'MCH-thigh_ik.R', 'MCH-thigh_ik_target.R']
    # fk_ctrl = 'thigh_fk.R'
    # parent = 'thigh_parent.R'
    # foot_fk = 'foot_fk.R'
    # pole = 'thigh_ik_target.R'

    names['controls'] = [thigh + '_ik', thigh + '_fk', shin + '_fk', foot + '_fk', toe, foot + '_heel_ik',
                         foot + '_ik', make_mechanism_name(foot + '_fk'), thigh + '_parent']
    names['ik_ctrl'] = [foot + '_ik', make_mechanism_name(thigh) + '_ik', make_mechanism_name(thigh) + '_ik_target']
    names['fk_ctrl'] = thigh + '_fk' + suffix
    names['parent'] = thigh + '_parent' + suffix
    names['foot_fk'] = foot + '_fk' + suffix
    names['pole'] = thigh + '_ik_target' + suffix

    names['limb_type'] = 'leg'

    if suffix:
        for i, name in enumerate(names['controls']):
            names['controls'][i] = name + suffix
        for i, name in enumerate(names['ik_ctrl']):
            names['ik_ctrl'][i] = name + suffix

    return names


def get_future_names_paw(bones):
    if len(bones) != 4:
        return

    names = dict()

    thigh = strip_mch(strip_org(bones[0].name))
    shin = strip_mch(strip_org(bones[1].name))
    foot = strip_mch(strip_org(bones[2].name))
    toe = strip_mch(strip_org(bones[3].name))

    suffix = ''
    if thigh[-2:] == '.L' or thigh[-2:] == '.R':
        suffix = thigh[-2:]
        thigh = thigh.rstrip(suffix)
        shin = shin.rstrip(suffix)
        foot = foot.rstrip(suffix)
        toe = toe.rstrip(suffix)

    # the following is declared in rig_ui
    # controls = ['thigh_ik.R', 'thigh_fk.R', 'shin_fk.R', 'foot_fk.R', 'toe.R', 'foot_heel_ik.R', 'foot_ik.R',
    #             'MCH-foot_fk.R', 'thigh_parent.R']
    # tweaks = ['thigh_tweak.R.001', 'shin_tweak.R', 'shin_tweak.R.001']
    # ik_ctrl = ['foot_ik.R', 'MCH-thigh_ik.R', 'MCH-thigh_ik_target.R']
    # fk_ctrl = 'thigh_fk.R'
    # parent = 'thigh_parent.R'
    # foot_fk = 'foot_fk.R'
    # pole = 'thigh_ik_target.R'

    names['controls'] = [thigh + '_ik', thigh + '_fk', shin + '_fk', foot + '_fk', toe, foot + '_heel_ik',
                         foot + '_ik', make_mechanism_name(foot + '_fk'), thigh + '_parent']
    names['ik_ctrl'] = [foot + '_ik', make_mechanism_name(thigh) + '_ik', make_mechanism_name(thigh) + '_ik_target']
    names['fk_ctrl'] = thigh + '_fk' + suffix
    names['parent'] = thigh + '_parent' + suffix
    names['foot_fk'] = foot + '_fk' + suffix
    names['pole'] = thigh + '_ik_target' + suffix

    names['limb_type'] = 'paw'

    if suffix:
        for i, name in enumerate(names['controls']):
            names['controls'][i] = name + suffix
        for i, name in enumerate(names['ik_ctrl']):
            names['ik_ctrl'][i] = name + suffix

    return names


def get_future_names(bones):
    if bones[0].rigify_parameters.limb_type == 'arm':
        return get_future_names_arm(bones)
    elif bones[0].rigify_parameters.limb_type == 'leg':
        return get_future_names_leg(bones)
    elif bones[0].rigify_parameters.limb_type == 'paw':
        return get_future_names_paw(bones)


def get_limb_generated_names(rig):

    pose_bones = rig.pose.bones
    names = dict()

    for b in pose_bones:
        super_limb_orgs = []
        if re.match('^ORG', b.name) and b.rigify_type == 'limbs.super_limb':
            super_limb_orgs.append(b)
            children = connected_children_names(rig, b.name)
            for child in children:
                if re.match('^ORG', child) or re.match('^MCH', child):
                    super_limb_orgs.append(pose_bones[child])
            names[b.name] = get_future_names(super_limb_orgs)

    return names