diff options
Diffstat (limited to 'rigify/rigs/biped/limb_common.py')
-rw-r--r-- | rigify/rigs/biped/limb_common.py | 124 |
1 files changed, 112 insertions, 12 deletions
diff --git a/rigify/rigs/biped/limb_common.py b/rigify/rigs/biped/limb_common.py index 96033b61..8cd5ad1c 100644 --- a/rigify/rigs/biped/limb_common.py +++ b/rigify/rigs/biped/limb_common.py @@ -59,13 +59,15 @@ class FKLimb: flimb = copy_bone(self.obj, self.org_bones[1], strip_org(insert_before_lr(self.org_bones[1], ".fk"))) elimb = copy_bone(self.obj, self.org_bones[2], strip_org(insert_before_lr(self.org_bones[2], ".fk"))) + # Create the end-limb mechanism bone + elimb_mch = copy_bone(self.obj, self.org_bones[2], make_mechanism_name(strip_org(self.org_bones[2]))) + # Create the anti-stretch bones + # These sit between a parent and its child, and counteract the + # stretching of the parent so that the child is unaffected fantistr = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[0], "_antistr.fk")))) eantistr = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[1], "_antistr.fk")))) - # Create the end-limb mechanism bone - elimb_mch = copy_bone(self.obj, self.org_bones[2], make_mechanism_name(strip_org(self.org_bones[2]))) - # Create the hinge bones if parent != None: socket1 = copy_bone(self.obj, ulimb, make_mechanism_name(ulimb + ".socket1")) @@ -297,7 +299,7 @@ class IKLimb: """ An IK limb rig, with an optional ik/fk switch. """ - def __init__(self, obj, bone1, bone2, bone3, pole_target_base_name, primary_rotation_axis, bend_hint, layers, ikfk_switch=False): + def __init__(self, obj, bone1, bone2, bone3, pole_parent, pole_target_base_name, primary_rotation_axis, bend_hint, layers, ikfk_switch=False): self.obj = obj self.switch = ikfk_switch @@ -310,6 +312,8 @@ class IKLimb: else: self.org_parent = self.obj.data.bones[bone1].parent.name + self.pole_parent = pole_parent + # Get the rig parameters self.pole_target_base_name = pole_target_base_name self.layers = layers @@ -323,6 +327,8 @@ class IKLimb: if self.org_parent != None: loc = Vector(self.obj.data.edit_bones[self.org_bones[0]].head) parent = make_nonscaling_child(self.obj, self.org_parent, loc, "_ik") + if self.pole_parent == None: + self.pole_parent = parent else: parent = None @@ -340,6 +346,10 @@ class IKLimb: pole_target_name = self.pole_target_base_name + "." + insert_before_lr(self.org_bones[0], ".ik").split(".", 1)[1] pole = copy_bone(self.obj, self.org_bones[0], pole_target_name) + if self.pole_parent == self.org_bones[2]: + self.pole_parent = elimb_mch + if self.pole_parent != None: + pole_par = copy_bone(self.obj, self.pole_parent, make_mechanism_name(insert_before_lr(pole_target_name, "_parent"))) viselimb = copy_bone(self.obj, self.org_bones[2], "VIS-" + strip_org(insert_before_lr(self.org_bones[2], ".ik"))) vispole = copy_bone(self.obj, self.org_bones[1], "VIS-" + strip_org(insert_before_lr(self.org_bones[0], "_pole.ik"))) @@ -358,6 +368,8 @@ class IKLimb: ulimb_str_e = eb[ulimb_str] flimb_str_e = eb[flimb_str] pole_e = eb[pole] + if self.pole_parent != None: + pole_par_e = eb[pole_par] viselimb_e = eb[viselimb] vispole_e = eb[vispole] @@ -384,8 +396,9 @@ class IKLimb: flimb_str_e.parent = ulimb_e.parent pole_e.use_connect = False - if parent != None: - pole_e.parent = parent_e + if self.pole_parent != None: + pole_par_e.parent = None + pole_e.parent = pole_par_e viselimb_e.use_connect = False viselimb_e.parent = None @@ -418,6 +431,8 @@ class IKLimb: pole_e.head = flimb_e.head + v2 pole_e.tail = pole_e.head + (Vector((0, 1, 0)) * (v1.length / 8)) pole_e.roll = 0.0 + if parent != None: + pole_par_e.length *= 0.75 viselimb_e.tail = viselimb_e.head + Vector((0, 0, v1.length / 32)) vispole_e.tail = vispole_e.head + Vector((0, 0, v1.length / 32)) @@ -440,6 +455,8 @@ class IKLimb: ulimb_str_p = pb[ulimb_str] flimb_str_p = pb[flimb_str] pole_p = pb[pole] + if self.pole_parent != None: + pole_par_p = pb[pole_par] viselimb_p = pb[viselimb] vispole_p = pb[vispole] @@ -489,6 +506,12 @@ class IKLimb: prop["soft_min"] = prop["min"] = 0.0 prop["soft_max"] = prop["max"] = 1.0 + if self.pole_parent != None: + prop = rna_idprop_ui_prop_get(pole_p, "follow", create=True) + pole_p["follow"] = 1.0 + prop["soft_min"] = prop["min"] = 0.0 + prop["soft_max"] = prop["max"] = 1.0 + prop = rna_idprop_ui_prop_get(elimb_p, "stretch_length", create=True) elimb_p["stretch_length"] = 1.0 prop["min"] = 0.05 @@ -618,6 +641,21 @@ class IKLimb: con.name = "stretch" con.owner_space = 'LOCAL' + # Pole target parent + if self.pole_parent != None: + con = pole_par_p.constraints.new('COPY_TRANSFORMS') + con.name = "parent" + con.target = self.obj + con.subtarget = self.pole_parent + + driver = con.driver_add("influence").driver + var = driver.variables.new() + var.name = "follow" + var.targets[0].id_type = 'OBJECT' + var.targets[0].id = self.obj + var.targets[0].data_path = pole_p.path_from_id() + '["follow"]' + driver.type = 'SUM' + # Constrain org bones con = pb[self.org_bones[0]].constraints.new('COPY_TRANSFORMS') con.name = "ik" @@ -807,25 +845,34 @@ class RubberHoseLimb: lr = lr[1] # Create bones + # Deformation bones ulimb1 = copy_bone(self.obj, self.org_bones[0], make_deformer_name(strip_org(insert_before_lr(self.org_bones[0], ".01")))) ulimb2 = copy_bone(self.obj, self.org_bones[0], make_deformer_name(strip_org(insert_before_lr(self.org_bones[0], ".02")))) flimb1 = copy_bone(self.obj, self.org_bones[1], make_deformer_name(strip_org(insert_before_lr(self.org_bones[1], ".01")))) flimb2 = copy_bone(self.obj, self.org_bones[1], make_deformer_name(strip_org(insert_before_lr(self.org_bones[1], ".02")))) elimb = copy_bone(self.obj, self.org_bones[2], make_deformer_name(strip_org(self.org_bones[2]))) + # Bones for switchable smooth bbone transition at elbow/knee ulimb2_smoother = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[0], "_smth.02")))) flimb1_smoother = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[1], "_smth.01")))) flimb1_pos = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[1], ".01")))) + # Elbow/knee junction bone junc = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[1], ".junc")))) + # Hose controls + uhoseend = new_bone(self.obj, strip_org(insert_before_lr(self.org_bones[0], "_hose_end"))) uhose = new_bone(self.obj, strip_org(insert_before_lr(self.org_bones[0], "_hose"))) jhose = new_bone(self.obj, self.junc_base_name + "_hose." + lr) fhose = new_bone(self.obj, strip_org(insert_before_lr(self.org_bones[1], "_hose"))) + fhoseend = new_bone(self.obj, strip_org(insert_before_lr(self.org_bones[1], "_hose_end"))) - uhose_par = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(uhose, "_parent")))) - jhose_par = copy_bone(self.obj, junc, make_mechanism_name(strip_org(insert_before_lr(jhose, "_parent")))) - fhose_par = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(fhose, "_parent")))) + # Hose control parents + uhoseend_par = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(uhoseend, "_p")))) + uhose_par = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(uhose, "_p")))) + jhose_par = copy_bone(self.obj, junc, make_mechanism_name(strip_org(insert_before_lr(jhose, "_p")))) + fhose_par = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(fhose, "_p")))) + fhoseend_par = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(fhoseend, "_p")))) # Get edit bones eb = self.obj.data.edit_bones @@ -847,13 +894,17 @@ class RubberHoseLimb: junc_e = eb[junc] + uhoseend_e = eb[uhoseend] uhose_e = eb[uhose] jhose_e = eb[jhose] fhose_e = eb[fhose] + fhoseend_e = eb[fhoseend] + uhoseend_par_e = eb[uhoseend_par] uhose_par_e = eb[uhose_par] jhose_par_e = eb[jhose_par] fhose_par_e = eb[fhose_par] + fhoseend_par_e = eb[fhoseend_par] # Parenting if parent != None: @@ -884,6 +935,9 @@ class RubberHoseLimb: junc_e.use_connect = False junc_e.parent = eb[self.org_bones[0]] + uhoseend_e.use_connect = False + uhoseend_e.parent = uhoseend_par_e + uhose_e.use_connect = False uhose_e.parent = uhose_par_e @@ -893,6 +947,12 @@ class RubberHoseLimb: fhose_e.use_connect = False fhose_e.parent = fhose_par_e + fhoseend_e.use_connect = False + fhoseend_e.parent = fhoseend_par_e + + uhoseend_par_e.use_connect = False + uhoseend_par_e.parent = parent_e + uhose_par_e.use_connect = False uhose_par_e.parent = parent_e @@ -902,6 +962,9 @@ class RubberHoseLimb: fhose_par_e.use_connect = False fhose_par_e.parent = parent_e + fhoseend_par_e.use_connect = False + fhoseend_par_e.parent = parent_e + # Positioning ulimb1_e.length *= 0.5 ulimb2_e.head = Vector(ulimb1_e.tail) @@ -917,16 +980,22 @@ class RubberHoseLimb: junc_e.length *= 0.2 + uhoseend_par_e.length *= 0.25 uhose_par_e.length *= 0.25 jhose_par_e.length *= 0.15 fhose_par_e.length *= 0.25 + fhoseend_par_e.length *= 0.25 + put_bone(self.obj, uhoseend_par, Vector(ulimb1_e.head)) put_bone(self.obj, uhose_par, Vector(ulimb1_e.tail)) put_bone(self.obj, jhose_par, Vector(ulimb2_e.tail)) put_bone(self.obj, fhose_par, Vector(flimb1_e.tail)) + put_bone(self.obj, fhoseend_par, Vector(flimb2_e.tail)) + put_bone(self.obj, uhoseend, Vector(ulimb1_e.head)) put_bone(self.obj, uhose, Vector(ulimb1_e.tail)) put_bone(self.obj, jhose, Vector(ulimb2_e.tail)) put_bone(self.obj, fhose, Vector(flimb1_e.tail)) + put_bone(self.obj, fhoseend, Vector(flimb2_e.tail)) if 'X' in self.primary_rotation_axis: upoint = Vector(ulimb1_e.z_axis) @@ -949,18 +1018,24 @@ class RubberHoseLimb: uside = Vector(ulimb1_e.y_axis) * -1 fside = Vector(flimb1_e.y_axis) * -1 + uhoseend_e.tail = uhoseend_e.head + upoint uhose_e.tail = uhose_e.head + upoint jhose_e.tail = fhose_e.head + upoint + fpoint fhose_e.tail = fhose_e.head + fpoint + fhoseend_e.tail = fhoseend_e.head + fpoint + align_bone_z_axis(self.obj, uhoseend, uside) align_bone_z_axis(self.obj, uhose, uside) align_bone_z_axis(self.obj, jhose, uside + fside) align_bone_z_axis(self.obj, fhose, fside) + align_bone_z_axis(self.obj, fhoseend, fside) l = 0.125 * (ulimb1_e.length + ulimb2_e.length + flimb1_e.length + flimb2_e.length) + uhoseend_e.length = l uhose_e.length = l jhose_e.length = l fhose_e.length = l + fhoseend_e.length = l # Object mode, get pose bones bpy.ops.object.mode_set(mode='OBJECT') @@ -978,13 +1053,17 @@ class RubberHoseLimb: junc_p = pb[junc] + uhoseend_p = pb[uhoseend] uhose_p = pb[uhose] jhose_p = pb[jhose] fhose_p = pb[fhose] + fhoseend_p = pb[fhoseend] + #uhoseend_par_p = pb[uhoseend_par] uhose_par_p = pb[uhose_par] jhose_par_p = pb[jhose_par] fhose_par_p = pb[fhose_par] + fhoseend_par_p = pb[fhoseend_par] # Lock axes uhose_p.lock_rotation = (True, True, True) @@ -1023,6 +1102,10 @@ class RubberHoseLimb: prop["soft_max"] = prop["max"] = 1.0 # Constraints + con = ulimb1_p.constraints.new('COPY_LOCATION') + con.name = "anchor" + con.target = self.obj + con.subtarget = uhoseend con = ulimb1_p.constraints.new('COPY_SCALE') con.name = "anchor" con.target = self.obj @@ -1112,11 +1195,11 @@ class RubberHoseLimb: con = flimb2_p.constraints.new('DAMPED_TRACK') con.name = "track" con.target = self.obj - con.subtarget = self.org_bones[2] + con.subtarget = fhoseend con = flimb2_p.constraints.new('STRETCH_TO') con.name = "track" con.target = self.obj - con.subtarget = self.org_bones[2] + con.subtarget = fhoseend con.volume = 'NO_VOLUME' con = junc_p.constraints.new('COPY_TRANSFORMS') @@ -1168,20 +1251,37 @@ class RubberHoseLimb: con.subtarget = self.org_bones[2] con.influence = 0.5 + con = fhoseend_par_p.constraints.new('COPY_ROTATION') + con.name = "follow" + con.target = self.obj + con.subtarget = self.org_bones[1] + con.influence = 1.0 + con = fhoseend_par_p.constraints.new('COPY_LOCATION') + con.name = "anchor" + con.target = self.obj + con.subtarget = self.org_bones[2] + con.influence = 1.0 + # Layers if self.layers: + uhoseend_p.bone.layers = self.layers uhose_p.bone.layers = self.layers jhose_p.bone.layers = self.layers fhose_p.bone.layers = self.layers + fhoseend_p.bone.layers = self.layers else: layers = list(pb[self.org_bones[0]].bone.layers) + uhoseend_p.bone.layers = layers uhose_p.bone.layers = layers jhose_p.bone.layers = layers fhose_p.bone.layers = layers + fhoseend_p.bone.layers = layers # Create widgets + create_sphere_widget(self.obj, uhoseend) create_sphere_widget(self.obj, uhose) create_sphere_widget(self.obj, jhose) create_sphere_widget(self.obj, fhose) + create_sphere_widget(self.obj, fhoseend) - return [uhose, jhose, fhose] + return [uhoseend, uhose, jhose, fhose, fhoseend] |