@@ -28,15 +28,28 @@ def create_mch(self):
28
28
29
29
org_chain = self .get_chain_bones (self .base_bone )
30
30
31
- if edit_bones [org_chain [- 1 ]].children :
32
- bone_to_copy = edit_bones [org_chain [- 1 ]].children [ 0 ] .name
31
+ if edit_bones [org_chain [0 ]].parent :
32
+ bone_to_copy = edit_bones [org_chain [0 ]].parent .name
33
33
else :
34
34
bone_to_copy = self .orientation_bone
35
+
35
36
mch_rot_tail = make_mechanism_name ('ROT-' + strip_org (self .base_bone ))
36
37
mch_rot_tail = copy_bone (self .obj , bone_to_copy , assign_name = mch_rot_tail )
37
38
self .bones ['tail_mch' ]['rot_tail_mch' ] = mch_rot_tail
38
39
main_chain = self .get_chain_bones (self .base_bone )
39
- put_bone (self .obj , mch_rot_tail , edit_bones [main_chain [- 1 ]].tail )
40
+ flip_bone (self .obj , mch_rot_tail )
41
+ edit_bones [mch_rot_tail ].parent = None
42
+ put_bone (self .obj , mch_rot_tail , edit_bones [main_chain [0 ]].head )
43
+
44
+ def create_def (self ):
45
+ super ().create_def ()
46
+
47
+ chain = strip_org (self .base_bone )
48
+
49
+ for def_bone in self .bones ['def' ][chain ]:
50
+ flip_bone (self .obj , def_bone )
51
+
52
+ self .bones ['def' ][chain ].reverse ()
40
53
41
54
def create_controls (self ):
42
55
@@ -45,8 +58,6 @@ def create_controls(self):
45
58
46
59
super ().create_controls ()
47
60
48
- edit_bones = self .obj .data .edit_bones
49
-
50
61
self .bones ['tweaks' ] = {}
51
62
self .bones ['tail_ctrl' ] = {}
52
63
@@ -58,30 +69,24 @@ def create_controls(self):
58
69
for org_bone , ctrl in zip (orgs , ctrl_chain ):
59
70
edit_bones [ctrl ].length = edit_bones [org_bone ].length
60
71
align_bone_y_axis (self .obj , ctrl , edit_bones [org_bone ].y_axis )
61
- flip_bone (self .obj , ctrl )
62
72
tweak_name = 'tweak_' + ctrl
63
73
tweak_name = copy_bone (self .obj , org_bone , assign_name = tweak_name )
64
- flip_bone (self .obj , tweak_name )
65
- put_bone (self .obj , tweak_name , edit_bones [org_bone ].head )
66
74
edit_bones [tweak_name ].length = edit_bones [self .orientation_bone ].length * self .TWEAK_SCALE
67
75
self .bones ['tweaks' ][chain ].append (tweak_name )
68
76
69
77
tweak_name = 'tweak_' + ctrl_chain [- 1 ]
70
78
tweak_name = copy_bone (self .obj , orgs [- 1 ], assign_name = tweak_name )
71
79
edit_bones [tweak_name ].parent = None
72
- flip_bone (self .obj , tweak_name )
73
80
put_bone (self .obj , tweak_name , edit_bones [orgs [- 1 ]].tail )
74
81
edit_bones [tweak_name ].length = edit_bones [self .orientation_bone ].length * self .TWEAK_SCALE
75
82
self .bones ['tweaks' ][chain ].append (tweak_name )
76
83
77
- ctrl_chain = self .bones ['ctrl' ][strip_org (self .base_bone )]
78
- flip_bone (self .obj , ctrl_chain [- 1 ])
79
- edit_bones [ctrl_chain [- 1 ]].head = edit_bones [orgs [- 1 ]].tail
80
- edit_bones [ctrl_chain [- 1 ]].tail = edit_bones [orgs [- 1 ]].head
84
+ edit_bones [ctrl_chain [- 1 ]].head = edit_bones [orgs [0 ]].head
85
+ edit_bones [ctrl_chain [- 1 ]].tail = edit_bones [orgs [0 ]].tail
81
86
tail_master = strip_org (self .base_bone ) + '_master'
82
87
edit_bones [ctrl_chain [- 1 ]].name = tail_master
83
88
self .bones ['tail_ctrl' ]['tail_master' ] = tail_master
84
- self . bones [ 'ctrl' ][ strip_org ( self . base_bone )] [- 1 ] = tail_master
89
+ ctrl_chain [- 1 ] = tail_master
85
90
86
91
def parent_bones (self ):
87
92
@@ -93,24 +98,26 @@ def parent_bones(self):
93
98
ctrl_chain = self .bones ['ctrl' ][strip_org (self .base_bone )]
94
99
tweak_chain = self .bones ['tweaks' ][strip_org (self .base_bone )]
95
100
def_chain = self .bones ['def' ][strip_org (self .base_bone )]
96
- org_bones = self .bones ['org' ]
97
101
98
- edit_bones [tweak_chain [0 ]].parent = edit_bones [ ctrl_chain [ 0 ]]
102
+ edit_bones [tweak_chain [0 ]].parent = None
99
103
100
- for ctrl , tweak in zip (ctrl_chain , tweak_chain [1 :- 1 ]):
104
+ for ctrl , tweak in zip (ctrl_chain [ 1 : - 1 ] , tweak_chain [1 :- 1 ]):
101
105
edit_bones [tweak ].use_connect = False
102
106
edit_bones [tweak ].parent = edit_bones [ctrl ]
103
107
108
+ edit_bones [tweak_chain [- 1 ]].use_connect = False
109
+ edit_bones [tweak_chain [- 1 ]].parent = edit_bones [ctrl_chain [- 2 ]]
110
+
104
111
for i , def_bone in enumerate (def_chain [1 :]):
105
112
edit_bones [def_bone ].use_connect = True
106
113
edit_bones [def_bone ].parent = edit_bones [def_chain [i ]]
107
114
108
- for i , ctrl in enumerate (ctrl_chain [0 : - 2 ]):
109
- edit_bones [ctrl ].parent = edit_bones [ctrl_chain [i + 1 ]]
115
+ for i , ctrl in enumerate (ctrl_chain [1 : - 1 ]):
116
+ edit_bones [ctrl ].parent = edit_bones [ctrl_chain [i ]]
110
117
111
- edit_bones [ctrl_chain [- 2 ]].parent = edit_bones [self .bones ['tail_mch' ]['rot_tail_mch' ]]
118
+ edit_bones [ctrl_chain [0 ]].parent = edit_bones [self .bones ['tail_mch' ]['rot_tail_mch' ]]
112
119
113
- edit_bones [self .bones ['tail_mch' ]['rot_tail_mch' ]].parent = edit_bones [tweak_chain [- 1 ]]
120
+ edit_bones [self .bones ['tail_mch' ]['rot_tail_mch' ]].parent = edit_bones [tweak_chain [0 ]]
114
121
115
122
def assign_layers (self ):
116
123
@@ -135,21 +142,24 @@ def make_constraints(self):
135
142
ctrl_chain = self .bones ['ctrl' ][strip_org (self .base_bone )]
136
143
137
144
for i , def_bone in enumerate (def_chain ):
138
- pose_bones [def_bone ].constraints [0 ].subtarget = tweak_chain [i ]
139
- pose_bones [def_bone ].constraints [1 ].subtarget = tweak_chain [i + 1 ]
140
- pose_bones [def_bone ].constraints [2 ].subtarget = tweak_chain [i + 1 ]
145
+ pose_bones [def_bone ].constraints [0 ].subtarget = tweak_chain [- i - 1 ]
146
+ pose_bones [def_bone ].constraints [1 ].subtarget = tweak_chain [- i - 2 ]
147
+ pose_bones [def_bone ].constraints [2 ].subtarget = tweak_chain [- i - 2 ]
141
148
142
149
for i , ctrl in enumerate (ctrl_chain ):
143
150
if ctrl != ctrl_chain [- 1 ]:
144
151
owner = pose_bones [ctrl ]
145
- subtarget = ctrl_chain [i + 1 ]
152
+ if i == 0 :
153
+ subtarget = ctrl_chain [- 1 ]
154
+ else :
155
+ subtarget = ctrl_chain [i - 1 ]
146
156
make_constraints_from_string (owner , self .obj , subtarget , "CR1.0LLO" )
147
157
owner .constraints [- 1 ].use_y = False
148
158
149
- last_connected_org = self .get_chain_bones (self .base_bone )[- 1 ]
150
- if pose_bones [last_connected_org ]. children :
159
+ first_org = self .get_chain_bones (self .base_bone )[0 ]
160
+ if pose_bones [first_org ]. parent :
151
161
owner = pose_bones [self .bones ['tail_mch' ]['rot_tail_mch' ]]
152
- subtarget = pose_bones [last_connected_org ]. children [ 0 ] .name
162
+ subtarget = pose_bones [first_org ]. parent .name
153
163
make_constraints_from_string (owner , self .obj , subtarget , "CR1.0WW" )
154
164
155
165
def create_widgets (self ):
@@ -168,7 +178,7 @@ def create_widgets(self):
168
178
create_sphere_widget (self .obj , bone )
169
179
170
180
pose_bones [ctrl_chain [- 1 ]].custom_shape_transform = \
171
- pose_bones [self .bones ['tweaks' ][strip_org (self .base_bone )][0 ]]
181
+ pose_bones [self .bones ['tweaks' ][strip_org (self .base_bone )][- 1 ]]
172
182
173
183
super ().create_widgets ()
174
184
0 commit comments