46
46
# Get the chain of 3 connected bones
47
47
self.org_bones = [bone] + connected_children_names(self.obj, bone)[:2]
49
49
if len(self.org_bones) != 3:
50
raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 3 bones" % (strip_org(bone)))
52
# Get (optional) parent
53
if self.obj.data.bones[bone].parent is None:
54
self.org_parent = None
56
self.org_parent = self.obj.data.bones[bone].parent.name
58
# Get the rig parameters
50
raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of at least 3 bones" % (strip_org(bone)))
59
53
if "layers" in params:
60
self.layers = get_layers(params["layers"])
54
layers = get_layers(params["layers"])
64
self.primary_rotation_axis = params.primary_rotation_axis
58
primary_rotation_axis = params.primary_rotation_axis
60
# Arm is based on common limb
61
self.fk_limb = limb_common.FKLimb(obj, self.org_bones[0], self.org_bones[1], self.org_bones[2], primary_rotation_axis, layers)
66
63
def generate(self):
67
64
""" Generate the rig.
69
66
The main armature should be selected and active before this is called.
72
bpy.ops.object.mode_set(mode='EDIT')
74
# Create the control bones
75
uarm = copy_bone(self.obj, self.org_bones[0], strip_org(self.org_bones[0]))
76
farm = copy_bone(self.obj, self.org_bones[1], strip_org(self.org_bones[1]))
77
hand = copy_bone(self.obj, self.org_bones[2], strip_org(self.org_bones[2]))
79
# Create the hinge bones
80
if self.org_parent != None:
81
hinge = copy_bone(self.obj, self.org_parent, make_mechanism_name(uarm + ".hinge"))
82
socket1 = copy_bone(self.obj, uarm, make_mechanism_name(uarm + ".socket1"))
83
socket2 = copy_bone(self.obj, uarm, make_mechanism_name(uarm + ".socket2"))
86
eb = self.obj.data.edit_bones
92
if self.org_parent != None:
94
socket1_e = eb[socket1]
95
socket2_e = eb[socket2]
98
farm_e.parent = uarm_e
99
hand_e.parent = farm_e
101
if self.org_parent != None:
102
hinge_e.use_connect = False
103
socket1_e.use_connect = False
104
socket2_e.use_connect = False
106
uarm_e.parent = hinge_e
107
hinge_e.parent = socket2_e
108
socket2_e.parent = None
111
if self.org_parent != None:
112
center = (hinge_e.head + hinge_e.tail) / 2
113
hinge_e.head = center
114
socket1_e.length /= 4
115
socket2_e.length /= 3
117
# Object mode, get pose bones
118
bpy.ops.object.mode_set(mode='OBJECT')
119
pb = self.obj.pose.bones
124
if self.org_parent != None:
127
if self.org_parent != None:
128
# socket1_p = pb[socket1] # UNUSED
129
socket2_p = pb[socket2]
131
# Set the elbow to only bend on the x-axis.
132
farm_p.rotation_mode = 'XYZ'
133
if 'X' in self.primary_rotation_axis:
134
farm_p.lock_rotation = (False, True, True)
135
elif 'Y' in self.primary_rotation_axis:
136
farm_p.lock_rotation = (True, False, True)
138
farm_p.lock_rotation = (True, True, False)
140
# Hinge transforms are locked, for auto-ik
141
if self.org_parent != None:
142
hinge_p.lock_location = True, True, True
143
hinge_p.lock_rotation = True, True, True
144
hinge_p.lock_rotation_w = True
145
hinge_p.lock_scale = True, True, True
147
# Set up custom properties
148
if self.org_parent != None:
149
prop = rna_idprop_ui_prop_get(uarm_p, "isolate", create=True)
150
uarm_p["isolate"] = 0.0
151
prop["soft_min"] = prop["min"] = 0.0
152
prop["soft_max"] = prop["max"] = 1.0
154
# Hinge constraints / drivers
155
if self.org_parent != None:
156
con = socket2_p.constraints.new('COPY_LOCATION')
157
con.name = "copy_location"
158
con.target = self.obj
159
con.subtarget = socket1
161
con = socket2_p.constraints.new('COPY_TRANSFORMS')
162
con.name = "isolate_off"
163
con.target = self.obj
164
con.subtarget = socket1
167
fcurve = con.driver_add("influence")
168
driver = fcurve.driver
169
var = driver.variables.new()
170
driver.type = 'AVERAGE'
172
var.targets[0].id_type = 'OBJECT'
173
var.targets[0].id = self.obj
174
var.targets[0].data_path = uarm_p.path_from_id() + '["isolate"]'
175
mod = fcurve.modifiers[0]
177
mod.coefficients[0] = 1.0
178
mod.coefficients[1] = -1.0
180
# Constrain org bones to controls
181
con = pb[self.org_bones[0]].constraints.new('COPY_TRANSFORMS')
183
con.target = self.obj
186
con = pb[self.org_bones[1]].constraints.new('COPY_TRANSFORMS')
188
con.target = self.obj
191
con = pb[self.org_bones[2]].constraints.new('COPY_TRANSFORMS')
193
con.target = self.obj
196
# Set layers if specified
198
uarm_p.bone.layers = self.layers
199
farm_p.bone.layers = self.layers
200
hand_p.bone.layers = self.layers
202
# Create control widgets
203
create_limb_widget(self.obj, uarm)
204
create_limb_widget(self.obj, farm)
69
bone_list = self.fk_limb.generate()
206
75
ob = create_widget(self.obj, hand)
208
77
verts = [(0.7, 1.5, 0.0), (0.7, -0.25, 0.0), (-0.7, -0.25, 0.0), (-0.7, 1.5, 0.0), (0.7, 0.723, 0.0), (-0.7, 0.723, 0.0), (0.7, 0.0, 0.0), (-0.7, 0.0, 0.0)]