diff options
18 files changed, 508 insertions, 508 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 83065b47f3e..540a76df105 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -29,7 +29,7 @@ LAYER_TYPES = "main", "extra", "ik", "fk" ORG_LAYERS = [n==31 for n in range(0,32)] MCH_LAYERS = [n==30 for n in range(0,32)] DEF_LAYERS = [n==29 for n in range(0,32)] -ROOT_LAYERS = [n==28 for n in range(0,32)] +ROOT_LAYERS = [n==28 for n in range(0,32)] ORG_PREFIX = "ORG-" MCH_PREFIX = "MCH-" @@ -154,7 +154,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): from collections import OrderedDict import rigify_utils reload(rigify_utils) - + print("Begin...") # Not needed but catches any errors before duplicating @@ -178,63 +178,63 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): name = obj_orig["rig_object_name"] except KeyError: name = "rig" - + try: obj = scene.objects[name] except KeyError: obj = bpy.data.objects.new(name, type='ARMATURE') obj.data = bpy.data.armatures.new(name) scene.objects.link(obj) - + obj.data.pose_position = 'POSE' - + # Get rid of anim data in case the rig already existed print("Clear rig animation data.") obj.animation_data_clear() - + # Select generated rig object obj_orig.selected = False obj.selected = True scene.objects.active = obj - + # Remove all bones from the generated rig armature. bpy.ops.object.mode_set(mode='EDIT') for bone in obj.data.edit_bones: obj.data.edit_bones.remove(bone) bpy.ops.object.mode_set(mode='OBJECT') - + # Create temporary duplicates for merging temp_rig_1 = obj_orig.copy() temp_rig_1.data = obj_orig.data.copy() scene.objects.link(temp_rig_1) - + temp_rig_2 = obj_orig.copy() temp_rig_2.data = obj.data scene.objects.link(temp_rig_2) - + # Select the temp rigs for merging for objt in scene.objects: objt.selected = False # deselect all objects temp_rig_1.selected = True temp_rig_2.selected = True scene.objects.active = temp_rig_2 - + # Merge the temporary rigs bpy.ops.object.join(context) - + # Delete the second temp rig bpy.ops.object.delete() - + # Select the generated rig for objt in scene.objects: objt.selected = False # deselect all objects obj.selected = True scene.objects.active = obj - + # Copy over the pose_bone properties for bone in obj_orig.pose.bones: bone_gen = obj.pose.bones[bone.name] - + # Rotation mode and transform locks bone_gen.rotation_mode = bone.rotation_mode bone_gen.lock_rotation = tuple(bone.lock_rotation) @@ -242,28 +242,28 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): bone_gen.lock_rotations_4d = bone.lock_rotations_4d bone_gen.lock_location = tuple(bone.lock_location) bone_gen.lock_scale = tuple(bone.lock_scale) - + # Custom properties for prop in bone.keys(): bone_gen[prop] = bone[prop] - + # Copy over bone properties for bone in obj_orig.data.bones: bone_gen = obj.data.bones[bone.name] - + # B-bone stuff bone_gen.bbone_segments = bone.bbone_segments bone_gen.bbone_in = bone.bbone_in bone_gen.bbone_out = bone.bbone_out - - + + # Create proxy deformation rig # TODO: remove this if META_DEF: obj_def = obj_orig.copy() obj_def.data = obj_orig.data.copy() scene.objects.link(obj_def) - + scene.update() print("On to the real work.") @@ -474,7 +474,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): obj.data.pose_position = 'POSE' obj_orig.data.pose_position = 'POSE' context.user_preferences.edit.global_undo = global_undo - + print("Done.\n") return obj diff --git a/release/scripts/modules/rigify/arm_biped.py b/release/scripts/modules/rigify/arm_biped.py index 56a7fca25a4..935e5bb4e33 100644 --- a/release/scripts/modules/rigify/arm_biped.py +++ b/release/scripts/modules/rigify/arm_biped.py @@ -277,14 +277,14 @@ def fk(obj, definitions, base_names, options): fk_chain.arm_b.layer = layer fk_chain.forearm_b.layer = layer fk_chain.hand_b.layer = layer - + # Forearm was getting wrong roll somehow. Hack to fix that. bpy.ops.object.mode_set(mode='EDIT') fk_chain.update() mt.update() fk_chain.forearm_e.roll = mt.forearm_e.roll bpy.ops.object.mode_set(mode='OBJECT') - + bpy.ops.object.mode_set(mode='EDIT') return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand @@ -301,7 +301,7 @@ def deform(obj, definitions, base_names, options): center = uarm1.center uarm1.tail = center uarm2.head = center - + # Create forearm bones: two bones, each half of the forearm. farm1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True) farm2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True) @@ -311,16 +311,16 @@ def deform(obj, definitions, base_names, options): center = farm1.center farm1.tail = center farm2.head = center - + # Create twist bone twist = copy_bone_simple(obj.data, definitions[2], "MCH-arm_twist") twist.connected = False twist.parent = obj.data.edit_bones[definitions[3]] twist.length /= 2 - + # Create hand bone hand = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True) - + # Store names before leaving edit mode uarm1_name = uarm1.name uarm2_name = uarm2.name @@ -328,10 +328,10 @@ def deform(obj, definitions, base_names, options): farm2_name = farm2.name twist_name = twist.name hand_name = hand.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bones uarm1 = obj.pose.bones[uarm1_name] uarm2 = obj.pose.bones[uarm2_name] @@ -339,50 +339,50 @@ def deform(obj, definitions, base_names, options): farm2 = obj.pose.bones[farm2_name] twist = obj.pose.bones[twist_name] hand = obj.pose.bones[hand_name] - + # Upper arm constraints con = uarm1.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[2] - + con = uarm1.constraints.new('COPY_SCALE') con.name = "trackto" con.target = obj con.subtarget = definitions[1] - + con = uarm2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[1] - + # Forearm constraints con = farm1.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[2] - + con = farm1.constraints.new('COPY_SCALE') con.name = "copy_rot" con.target = obj con.subtarget = definitions[2] - + con = farm2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = twist.name - + con = farm2.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[3] - + # Hand constraint con = hand.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[3] - + bpy.ops.object.mode_set(mode='EDIT') return (uarm1_name, uarm2_name, farm1_name, farm2_name, hand_name) diff --git a/release/scripts/modules/rigify/copy.py b/release/scripts/modules/rigify/copy.py index c0192af7d18..2d4a3da8c44 100644 --- a/release/scripts/modules/rigify/copy.py +++ b/release/scripts/modules/rigify/copy.py @@ -50,28 +50,28 @@ def deform(obj, definitions, base_names, options): # Create deform bone. bone = copy_bone_simple(obj.data, definitions[0], "DEF-%s" % base_names[definitions[0]], parent=True) - + # Store name before leaving edit mode bone_name = bone.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bone bone = obj.pose.bones[bone_name] - + # Constrain to the original bone con = bone.constraints.new('COPY_TRANSFORMS') con.name = "copy_loc" con.target = obj con.subtarget = definitions[0] - + return (bone_name,) def control(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + arm = obj.data mt = bone_class_instance(obj, METARIG_NAMES) mt.cpy = definitions[0] @@ -97,10 +97,10 @@ def control(obj, definitions, base_names, options): cp.cpy_p.lock_rotation = tuple(mt.cpy_p.lock_rotation) cp.cpy_p.lock_rotation_w = mt.cpy_p.lock_rotation_w cp.cpy_p.lock_scale = tuple(mt.cpy_p.lock_scale) - + # Layers cp.cpy_b.layer = list(mt.cpy_b.layer) - + return (mt.cpy,) diff --git a/release/scripts/modules/rigify/eye_balls.py b/release/scripts/modules/rigify/eye_balls.py index 927235517b3..995cd555c55 100644 --- a/release/scripts/modules/rigify/eye_balls.py +++ b/release/scripts/modules/rigify/eye_balls.py @@ -37,7 +37,7 @@ def get_unmarked_action(): if action.tag != True: return action return None - + def add_action(name=None): mark_actions() bpy.ops.action.new() @@ -66,46 +66,46 @@ def metarig_template(): def metarig_definition(obj, orig_bone_name): bone = obj.data.bones[orig_bone_name] chain = [] - + try: chain += [bone.parent.name, bone.name] except AttributeError: raise RigifyError("'%s' rig type requires a parent (bone: %s)" % (RIG_TYPE, base_names[0])) - + return chain def deform(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones pb = obj.pose.bones - + # Get list of eyes if "eyes" in options: eye_base_names = options["eyes"].replace(" ", "").split(",") else: eye_base_names = [] - + # Get their ORG- names eyes = [] for name in eye_base_names: eyes += ["ORG-"+name] - + # Duplicate the eyes to make deformation bones def_eyes = [] # def/org pairs for eye in eyes: def_eyes += [(copy_bone_simple(obj.data, eye, "DEF-"+base_names[eye], parent=True).name, eye)] - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Constraints for eye in def_eyes: con = pb[eye[0]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = eye[1] - + return (None,) @@ -113,32 +113,32 @@ def deform(obj, definitions, base_names, options): def control(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + head = definitions[0] eye_target = definitions[1] - + # Get list of eyes if "eyes" in options: eye_base_names = options["eyes"].replace(" ", "").split(",") else: eye_base_names = [] - + # Get their ORG- names eyes = [] for name in eye_base_names: eyes += ["ORG-"+name] - + # Get the average position of the eyes center = Vector(0,0,0) for eye in eyes: center += eb[eye].head if len(eyes) != 0: center /= len(eyes) - + # Get the average length of the eyes length = 0.0 for eye in eyes: @@ -147,48 +147,48 @@ def control(obj, definitions, base_names, options): length = 1.0 else: length /= len(eyes) - - + + # Make the mind's eye minds_eye = copy_bone_simple(obj.data, eye_target, "MCH-"+base_names[eye_target]+".mind", parent=True).name eb[minds_eye].head = center eb[minds_eye].tail = eb[eye_target].head eb[minds_eye].roll = 0.0 eb[minds_eye].length = length - + # Create org/copy/control eye sets eye_sets = [] for eye in eyes: copy = copy_bone_simple(obj.data, minds_eye, "MCH-"+base_names[eye]+".cpy", parent=True).name eb[copy].translate(eb[eye].head - eb[copy].head) eb[copy].parent = eb[eye].parent - + control = copy_bone_simple(obj.data, eye, base_names[eye], parent=True).name eb[control].parent = eb[copy] - + eye_sets += [(eye, copy, control)] - + # Bones for parent/free switch for eye target target_ctrl = copy_bone_simple(obj.data, eye_target, base_names[eye_target], parent=True).name parent = copy_bone_simple(obj.data, head, "MCH-eye_target_parent", parent=False).name - + eb[target_ctrl].parent = eb[parent] - - - - + + + + bpy.ops.object.mode_set(mode='OBJECT') - + # Axis locks pb[target_ctrl].lock_scale = False, True, True - + # Add eye_spread action if it doesn't already exist action_name = "eye_spread" if action_name in bpy.data.actions: spread_action = bpy.data.actions[action_name] else: spread_action = add_action(name=action_name) - + # Add free property prop_name = "free" prop = rna_idprop_ui_prop_get(pb[target_ctrl], prop_name, create=True) @@ -197,45 +197,45 @@ def control(obj, definitions, base_names, options): prop["soft_max"] = 1.0 prop["min"] = 0.0 prop["max"] = 1.0 - + free_driver_path = pb[target_ctrl].path_to_id() + '["free"]' - + # Constraints # Mind's eye tracks eye target control con = pb[minds_eye].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = target_ctrl - + # Parent copies transforms of head con = pb[parent].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = head - + fcurve = con.driver_add("influence", 0) driver = fcurve.driver driver.type = 'AVERAGE' mod = fcurve.modifiers[0] mod.coefficients[0] = 1.0 mod.coefficients[1] = -1.0 - + var = driver.variables.new() var.name = "free" var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = free_driver_path - + # Eye set's constraints for eye in eye_sets: # Org copies transforms of control con = pb[eye[0]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = eye[2] - + # Copy copies rotation of mind's eye con = pb[eye[1]].constraints.new('COPY_ROTATION') con.target = obj con.subtarget = minds_eye - + # Control gets action constraint for eye spread con = pb[eye[2]].constraints.new('ACTION') con.target = obj @@ -247,9 +247,9 @@ def control(obj, definitions, base_names, options): con.minimum = 0.0 con.maximum = 2.0 con.target_space = 'LOCAL' - - - + + + # Set layers #layer = list(bb[definitions[2]].layer) #bb[lid1].layer = layer @@ -260,8 +260,8 @@ def control(obj, definitions, base_names, options): #bb[lid6].layer = layer #bb[lid7].layer = layer #bb[lid8].layer = layer - - + + return (None,) diff --git a/release/scripts/modules/rigify/eye_lid.py b/release/scripts/modules/rigify/eye_lid.py index 1955b3e459b..9824b6eeb16 100644 --- a/release/scripts/modules/rigify/eye_lid.py +++ b/release/scripts/modules/rigify/eye_lid.py @@ -37,7 +37,7 @@ def get_unmarked_action(): if action.tag != True: return action return None - + def add_action(name=None): mark_actions() bpy.ops.action.new() @@ -67,35 +67,35 @@ def metarig_definition(obj, orig_bone_name): bb = obj.data.bones bone = bb[orig_bone_name] chain = [] - + try: chain += [bone.parent.parent.name, bone.parent.name, bone.name] except AttributeError: raise RigifyError("'%s' rig type requires a chain of two parents (bone: %s)" % (RIG_TYPE, base_names[0])) - + chain += [child.name for child in bone.children_recursive_basename] - + if len(chain) < 10: raise RigifyError("'%s' rig type requires a chain of 10 bones (bone: %s)" % (RIG_TYPE, base_names[0])) - + chain = chain[:10] - + try: chain += [bb[chain[9]].children[0].name] chain += [bb[chain[10]].children[0].name] except IndexError: raise RigifyError("'%s' rig type requires a chain of 10 bones (bone: %s)" % (RIG_TYPE, base_names[0])) - + return chain def deform(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones pb = obj.pose.bones - - + + # Upper lid MCH lid1 = make_lid_stretch_bone(obj, "MCH-lid", definitions[2], definitions[3], 1.0) lid2 = make_lid_stretch_bone(obj, "MCH-lid", definitions[3], definitions[4], 1.0) @@ -103,19 +103,19 @@ def deform(obj, definitions, base_names, options): lid33 = make_lid_stretch_bone(obj, "MCH-lid", definitions[4], definitions[3], 1.0) lid3 = make_lid_stretch_bone(obj, "MCH-lid", definitions[5], definitions[4], 1.0) lid4 = make_lid_stretch_bone(obj, "MCH-lid", definitions[6], definitions[5], 1.0) - + dlid22 = copy_bone_simple(obj.data, lid22, "MCH-lid", parent=True).name dlid33 = copy_bone_simple(obj.data, lid33, "MCH-lid", parent=True).name eb[dlid22].bbone_segments = 8 eb[dlid33].bbone_segments = 8 - + eb[lid1].parent = eb[definitions[2]] eb[lid2].parent = eb[definitions[3]] eb[lid22].parent = eb[definitions[4]] eb[lid33].parent = eb[definitions[4]] eb[lid3].parent = eb[definitions[5]] eb[lid4].parent = eb[definitions[6]] - + # Lower lid MCH lid5 = make_lid_stretch_bone(obj, "MCH-lid", definitions[6], definitions[7], 1.0) lid6 = make_lid_stretch_bone(obj, "MCH-lid", definitions[7], definitions[8], 1.0) @@ -123,115 +123,115 @@ def deform(obj, definitions, base_names, options): lid77 = make_lid_stretch_bone(obj, "MCH-lid", definitions[8], definitions[7], 1.0) lid7 = make_lid_stretch_bone(obj, "MCH-lid", definitions[9], definitions[8], 1.0) lid8 = make_lid_stretch_bone(obj, "MCH-lid", definitions[2], definitions[9], 1.0) - + dlid66 = copy_bone_simple(obj.data, lid66, "MCH-lid", parent=True).name dlid77 = copy_bone_simple(obj.data, lid77, "MCH-lid", parent=True).name eb[dlid66].bbone_segments = 8 eb[dlid77].bbone_segments = 8 - + eb[lid5].parent = eb[definitions[6]] eb[lid6].parent = eb[definitions[7]] eb[lid66].parent = eb[definitions[8]] eb[lid77].parent = eb[definitions[8]] eb[lid7].parent = eb[definitions[9]] eb[lid8].parent = eb[definitions[2]] - + # Upper lid DEF dlid1 = copy_bone_simple(obj.data, lid1, "DEF-" + base_names[definitions[2]], parent=True).name dlid2 = copy_bone_simple(obj.data, lid2, "DEF-" + base_names[definitions[3]], parent=True).name dlid3 = copy_bone_simple(obj.data, lid3, "DEF-" + base_names[definitions[4]], parent=True).name dlid4 = copy_bone_simple(obj.data, lid4, "DEF-" + base_names[definitions[5]], parent=True).name - + eb[dlid2].parent = eb[dlid1] eb[dlid22].parent = eb[dlid2] - + eb[dlid3].parent = eb[dlid4] eb[dlid33].parent = eb[dlid3] - + eb[dlid2].connected = True eb[dlid22].connected = True eb[dlid3].connected = True eb[dlid33].connected = True - + eb[dlid1].bbone_segments = 8 eb[dlid2].bbone_segments = 8 eb[dlid3].bbone_segments = 8 eb[dlid4].bbone_segments = 8 - + # Lower lid DEF dlid5 = copy_bone_simple(obj.data, lid5, "DEF-" + base_names[definitions[6]], parent=True).name dlid6 = copy_bone_simple(obj.data, lid6, "DEF-" + base_names[definitions[7]], parent=True).name dlid7 = copy_bone_simple(obj.data, lid7, "DEF-" + base_names[definitions[8]], parent=True).name dlid8 = copy_bone_simple(obj.data, lid8, "DEF-" + base_names[definitions[9]], parent=True).name - + eb[dlid6].parent = eb[dlid5] eb[dlid66].parent = eb[dlid6] - + eb[dlid7].parent = eb[dlid8] eb[dlid77].parent = eb[dlid7] - + eb[dlid6].connected = True eb[dlid66].connected = True eb[dlid7].connected = True eb[dlid77].connected = True - + eb[dlid5].bbone_segments = 8 eb[dlid6].bbone_segments = 8 eb[dlid7].bbone_segments = 8 eb[dlid8].bbone_segments = 8 - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Constraints con = pb[dlid1].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid1 - + con = pb[dlid22].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid22 - + con = pb[dlid33].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid33 - + con = pb[dlid2].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid2 - + con = pb[dlid3].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid3 - + con = pb[dlid4].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid4 - + con = pb[dlid5].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid5 - + con = pb[dlid6].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid6 - + con = pb[dlid66].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid66 - + con = pb[dlid77].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid77 - + con = pb[dlid7].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid7 - + con = pb[dlid8].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lid8 - + return (None,) @@ -239,15 +239,15 @@ def deform(obj, definitions, base_names, options): def control(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + head_e = eb[definitions[0]] eye_e = eb[definitions[1]] - - + + # Make eye "flower" flo1 = copy_bone_simple(obj.data, definitions[1], "MCH-"+base_names[definitions[2]]+".flower", parent=True).name flo2 = copy_bone_simple(obj.data, definitions[1], "MCH-"+base_names[definitions[3]]+".flower", parent=True).name @@ -257,7 +257,7 @@ def control(obj, definitions, base_names, options): flo6 = copy_bone_simple(obj.data, definitions[1], "MCH-"+base_names[definitions[7]]+".flower", parent=True).name flo7 = copy_bone_simple(obj.data, definitions[1], "MCH-"+base_names[definitions[8]]+".flower", parent=True).name flo8 = copy_bone_simple(obj.data, definitions[1], "MCH-"+base_names[definitions[9]]+".flower", parent=True).name - + eb[flo1].tail = eb[definitions[2]].head eb[flo2].tail = eb[definitions[3]].head eb[flo3].tail = eb[definitions[4]].head @@ -266,8 +266,8 @@ def control(obj, definitions, base_names, options): eb[flo6].tail = eb[definitions[7]].head eb[flo7].tail = eb[definitions[8]].head eb[flo8].tail = eb[definitions[9]].head - - + + # Make eye lids on tips of flowers flid1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]).name flid2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]).name @@ -277,7 +277,7 @@ def control(obj, definitions, base_names, options): flid6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]).name flid7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]).name flid8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]).name - + eb[flid1].parent = eb[flo1] eb[flid2].parent = eb[flo2] eb[flid3].parent = eb[flo3] @@ -286,8 +286,8 @@ def control(obj, definitions, base_names, options): eb[flid6].parent = eb[flo6] eb[flid7].parent = eb[flo7] eb[flid8].parent = eb[flo8] - - + + # Make eye lid controls lid1 = copy_bone_simple(obj.data, definitions[2], base_names[definitions[2]]).name lid2 = copy_bone_simple(obj.data, definitions[3], base_names[definitions[3]]).name @@ -297,7 +297,7 @@ def control(obj, definitions, base_names, options): lid6 = copy_bone_simple(obj.data, definitions[7], base_names[definitions[7]]).name lid7 = copy_bone_simple(obj.data, definitions[8], base_names[definitions[8]]).name lid8 = copy_bone_simple(obj.data, definitions[9], base_names[definitions[9]]).name - + size = eb[lid1].length eb[lid1].tail = eb[lid1].head + Vector(0,size,0) eb[lid2].tail = eb[lid2].head + Vector(0,size,0) @@ -307,7 +307,7 @@ def control(obj, definitions, base_names, options): eb[lid6].tail = eb[lid6].head + Vector(0,size,0) eb[lid7].tail = eb[lid7].head + Vector(0,size,0) eb[lid8].tail = eb[lid8].head + Vector(0,size,0) - + eb[lid1].roll = 0 eb[lid2].roll = 0 eb[lid3].roll = 0 @@ -316,7 +316,7 @@ def control(obj, definitions, base_names, options): eb[lid6].roll = 0 eb[lid7].roll = 0 eb[lid8].roll = 0 - + eb[lid1].parent = head_e eb[lid2].parent = head_e eb[lid3].parent = head_e @@ -325,27 +325,27 @@ def control(obj, definitions, base_names, options): eb[lid6].parent = head_e eb[lid7].parent = head_e eb[lid8].parent = head_e - + lower_lid_ctrl = copy_bone_simple(obj.data, definitions[10], base_names[definitions[10]]).name upper_lid_ctrl = copy_bone_simple(obj.data, definitions[11], base_names[definitions[11]]).name eb[lower_lid_ctrl].parent = head_e eb[upper_lid_ctrl].parent = head_e distance = (eb[lower_lid_ctrl].head - eb[upper_lid_ctrl].head).length - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Axis locks pb[lower_lid_ctrl].lock_location = True, False, True pb[upper_lid_ctrl].lock_location = True, False, True - + # Add eye close action if it doesn't already exist action_name = "eye_close" if action_name in bpy.data.actions: close_action = bpy.data.actions[action_name] else: close_action = add_action(name=action_name) - + # Add close property (useful when making the animation in the action) prop_name = "close_action" prop = rna_idprop_ui_prop_get(pb[upper_lid_ctrl], prop_name, create=True) @@ -354,79 +354,79 @@ def control(obj, definitions, base_names, options): prop["soft_max"] = 1.0 prop["min"] = 0.0 prop["max"] = 1.0 - + close_driver_path = pb[upper_lid_ctrl].path_to_id() + '["close_action"]' - + # Constraints - + # Flowers track lid controls con = pb[flo1].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid1 - + con = pb[flo2].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid2 - + con = pb[flo3].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid3 - + con = pb[flo4].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid4 - + con = pb[flo5].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid5 - + con = pb[flo6].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid6 - + con = pb[flo7].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid7 - + con = pb[flo8].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = lid8 - - + + # ORG bones to flower lids con = pb[definitions[2]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid1 - + con = pb[definitions[3]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid2 - + con = pb[definitions[4]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid3 - + con = pb[definitions[5]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid4 - + con = pb[definitions[6]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid5 - + con = pb[definitions[7]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid6 - + con = pb[definitions[8]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid7 - + con = pb[definitions[9]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = flid8 - - + + # Action constraints, upper lid con = pb[lid1].constraints.new('ACTION') con.target = obj @@ -445,8 +445,8 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - - + + con = pb[lid2].constraints.new('ACTION') con.target = obj con.subtarget = upper_lid_ctrl @@ -464,7 +464,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid3].constraints.new('ACTION') con.target = obj con.subtarget = upper_lid_ctrl @@ -482,7 +482,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid4].constraints.new('ACTION') con.target = obj con.subtarget = upper_lid_ctrl @@ -500,7 +500,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid5].constraints.new('ACTION') con.target = obj con.subtarget = upper_lid_ctrl @@ -518,7 +518,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + # Action constraints, lower lid con = pb[lid5].constraints.new('ACTION') con.target = obj @@ -537,7 +537,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid6].constraints.new('ACTION') con.target = obj con.subtarget = lower_lid_ctrl @@ -555,7 +555,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid7].constraints.new('ACTION') con.target = obj con.subtarget = lower_lid_ctrl @@ -573,7 +573,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid8].constraints.new('ACTION') con.target = obj con.subtarget = lower_lid_ctrl @@ -591,7 +591,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - + con = pb[lid1].constraints.new('ACTION') con.target = obj con.subtarget = lower_lid_ctrl @@ -609,10 +609,10 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = close_driver_path - - - - + + + + # Set layers layer = list(bb[definitions[2]].layer) bb[lid1].layer = layer @@ -623,8 +623,8 @@ def control(obj, definitions, base_names, options): bb[lid6].layer = layer bb[lid7].layer = layer bb[lid8].layer = layer - - + + return (None,) @@ -644,34 +644,34 @@ def main(obj, bone_definition, base_names, options): def make_lid_stretch_bone(obj, name, bone1, bone2, roll_alpha): eb = obj.data.edit_bones pb = obj.pose.bones - + # Create the bone, pointing from bone1 to bone2 bone_e = copy_bone_simple(obj.data, bone1, name, parent=True) bone_e.connected = False bone_e.tail = eb[bone2].head bone = bone_e.name - + # Align the bone roll with the average direction of bone1 and bone2 vec = bone_e.y_axis.cross(((1.0-roll_alpha)*eb[bone1].y_axis) + (roll_alpha*eb[bone2].y_axis)).normalize() - + ang = acos(vec * bone_e.x_axis) - + bone_e.roll += ang c1 = vec * bone_e.x_axis bone_e.roll -= (ang*2) c2 = vec * bone_e.x_axis - + if c1 > c2: bone_e.roll += (ang*2) - + bpy.ops.object.mode_set(mode='OBJECT') bone_p = pb[bone] - + # Constrains con = bone_p.constraints.new('COPY_LOCATION') con.target = obj con.subtarget = bone1 - + con = bone_p.constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = bone2 diff --git a/release/scripts/modules/rigify/finger_curl.py b/release/scripts/modules/rigify/finger_curl.py index 997ed889bb2..760ef10607b 100644 --- a/release/scripts/modules/rigify/finger_curl.py +++ b/release/scripts/modules/rigify/finger_curl.py @@ -100,48 +100,48 @@ def deform(obj, definitions, base_names, options): center = f1a.center f1a.tail = center f1b.head = center - + # Create the other deform bones. f2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s" % base_names[definitions[1]], parent=True) f3 = copy_bone_simple(obj.data, definitions[2], "DEF-%s" % base_names[definitions[2]], parent=True) - + # Store names before leaving edit mode f1a_name = f1a.name f1b_name = f1b.name f2_name = f2.name f3_name = f3.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bones f1a = obj.pose.bones[f1a_name] f1b = obj.pose.bones[f1b_name] f2 = obj.pose.bones[f2_name] f3 = obj.pose.bones[f3_name] - + # Constrain the base digit's bones con = f1a.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[1] - + con = f1a.constraints.new('COPY_SCALE') con.name = "copy_scale" con.target = obj con.subtarget = definitions[0] - + con = f1b.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[0] - + # Constrain the other digit's bones con = f2.constraints.new('COPY_TRANSFORMS') con.name = "copy_transforms" con.target = obj con.subtarget = definitions[1] - + con = f3.constraints.new('COPY_TRANSFORMS') con.name = "copy_transforms" con.target = obj @@ -151,32 +151,32 @@ def deform(obj, definitions, base_names, options): def main(obj, bone_definition, base_names, options): # *** EDITMODE bpy.ops.object.mode_set(mode='EDIT') - + # get assosiated data arm = obj.data bb = obj.data.bones eb = obj.data.edit_bones pb = obj.pose.bones - + org_f1 = bone_definition[0] # Original finger bone 01 org_f2 = bone_definition[1] # Original finger bone 02 org_f3 = bone_definition[2] # Original finger bone 03 - + # Check options if "bend_ratio" in options: bend_ratio = options["bend_ratio"] else: bend_ratio = 0.4 - + yes = [1, 1.0, True, "True", "true", "Yes", "yes"] make_hinge = False if ("hinge" in options) and (eb[org_f1].parent is not None): if options["hinge"] in yes: make_hinge = True - + # Needed if its a new armature with no keys - obj.animation_data_create() + obj.animation_data_create() # Create the control bone base_name = base_names[bone_definition[0]].split(".", 1)[0] @@ -185,12 +185,12 @@ def main(obj, bone_definition, base_names, options): eb[control].connected = eb[org_f1].connected eb[control].parent = eb[org_f1].parent eb[control].length = tot_len - + # Create secondary control bones f1 = copy_bone_simple(arm, bone_definition[0], base_names[bone_definition[0]]).name f2 = copy_bone_simple(arm, bone_definition[1], base_names[bone_definition[1]]).name f3 = copy_bone_simple(arm, bone_definition[2], base_names[bone_definition[2]]).name - + # Create driver bones df1 = copy_bone_simple(arm, bone_definition[0], "MCH-" + base_names[bone_definition[0]]).name eb[df1].length /= 2 @@ -198,7 +198,7 @@ def main(obj, bone_definition, base_names, options): eb[df2].length /= 2 df3 = copy_bone_simple(arm, bone_definition[2], "MCH-" + base_names[bone_definition[2]]).name eb[df3].length /= 2 - + # Set parents of the bones, interleaving the driver bones with the secondary control bones eb[f3].connected = False eb[df3].connected = False @@ -206,29 +206,29 @@ def main(obj, bone_definition, base_names, options): eb[df2].connected = False eb[f1].connected = False eb[df1].connected = eb[org_f1].connected - + eb[f3].parent = eb[df3] eb[df3].parent = eb[f2] eb[f2].parent = eb[df2] eb[df2].parent = eb[f1] eb[f1].parent = eb[df1] eb[df1].parent = eb[org_f1].parent - + # Set up bones for hinge if make_hinge: socket = copy_bone_simple(arm, org_f1, "MCH-socket_"+control, parent=True).name hinge = copy_bone_simple(arm, eb[org_f1].parent.name, "MCH-hinge_"+control).name - + eb[control].connected = False eb[control].parent = eb[hinge] - + # Create the deform rig while we're still in edit mode deform(obj, bone_definition, base_names, options) - - + + # *** POSEMODE bpy.ops.object.mode_set(mode='OBJECT') - + # Set rotation modes and axis locks pb[control].rotation_mode = obj.pose.bones[bone_definition[0]].rotation_mode pb[control].lock_location = True, True, True @@ -241,20 +241,20 @@ def main(obj, bone_definition, base_names, options): pb[f3].lock_location = True, True, True pb[df2].rotation_mode = 'YZX' pb[df3].rotation_mode = 'YZX' - + # Add the bend_ratio property to the control bone pb[control]["bend_ratio"] = bend_ratio prop = rna_idprop_ui_prop_get(pb[control], "bend_ratio", create=True) prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 - + # Add hinge property to the control bone if make_hinge: pb[control]["hinge"] = 0.0 prop = rna_idprop_ui_prop_get(pb[control], "hinge", create=True) prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 - + # Constraints con = pb[df1].constraints.new('COPY_LOCATION') con.target = obj @@ -263,24 +263,24 @@ def main(obj, bone_definition, base_names, options): con = pb[df1].constraints.new('COPY_ROTATION') con.target = obj con.subtarget = control - + con = pb[org_f1].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = f1 - + con = pb[org_f2].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = f2 - + con = pb[org_f3].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = f3 - + if make_hinge: con = pb[hinge].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = bb[org_f1].parent.name - + hinge_driver_path = pb[control].path_to_id() + '["hinge"]' fcurve = con.driver_add("influence", 0) @@ -296,11 +296,11 @@ def main(obj, bone_definition, base_names, options): mod.poly_order = 1 mod.coefficients[0] = 1.0 mod.coefficients[1] = -1.0 - + con = pb[control].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = socket - + # Create the drivers for the driver bones (control bone scale rotates driver bones) controller_path = pb[control].path_to_id() # 'pose.bones["%s"]' % control_bone_name @@ -349,7 +349,7 @@ def main(obj, bone_definition, base_names, options): layer = list(arm.bones[bone_definition[0]].layer) for bone_name in [f1, f2, f3]: arm.bones[bone_name].layer = layer - + layer = list(arm.bones[bone_definition[0]].layer) bb[control].layer = layer diff --git a/release/scripts/modules/rigify/leg_biped.py b/release/scripts/modules/rigify/leg_biped.py index 5c243727516..be7b103bc8c 100644 --- a/release/scripts/modules/rigify/leg_biped.py +++ b/release/scripts/modules/rigify/leg_biped.py @@ -306,7 +306,7 @@ def fk(obj, bone_definition, base_names, options): fk_chain = mt_chain.copy(base_names=base_names) # fk has no prefix! fk_chain.foot_e.name = "MCH-" + fk_chain.foot fk_chain.foot = fk_chain.foot_e.name - + # Set up fk foot control foot_e = copy_bone_simple(arm, mt.heel, base_names[mt_chain.foot]) foot = foot_e.name @@ -396,7 +396,7 @@ def deform(obj, definitions, base_names, options): center = uleg1.center uleg1.tail = center uleg2.head = center - + # Create lower leg bones: two bones, each half of the lower leg. lleg1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True) lleg2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True) @@ -406,19 +406,19 @@ def deform(obj, definitions, base_names, options): center = lleg1.center lleg1.tail = center lleg2.head = center - + # Create a bone for the second lower leg deform bone to twist with twist = copy_bone_simple(obj.data, lleg2.name, "MCH-leg_twist") twist.length /= 4 twist.connected = False twist.parent = obj.data.edit_bones[definitions[3]] - + # Create foot bone foot = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True) - + # Create toe bone toe = copy_bone_simple(obj.data, definitions[4], "DEF-%s" % base_names[definitions[4]], parent=True) - + # Store names before leaving edit mode uleg1_name = uleg1.name uleg2_name = uleg2.name @@ -427,10 +427,10 @@ def deform(obj, definitions, base_names, options): twist_name = twist.name foot_name = foot.name toe_name = toe.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bones uleg1 = obj.pose.bones[uleg1_name] uleg2 = obj.pose.bones[uleg2_name] @@ -438,56 +438,56 @@ def deform(obj, definitions, base_names, options): lleg2 = obj.pose.bones[lleg2_name] foot = obj.pose.bones[foot_name] toe = obj.pose.bones[toe_name] - + # Upper leg constraints con = uleg1.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[2] - + con = uleg1.constraints.new('COPY_SCALE') con.name = "scale" con.target = obj con.subtarget = definitions[1] - + con = uleg2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[1] - + # Lower leg constraints con = lleg1.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[2] - + con = lleg1.constraints.new('COPY_SCALE') con.name = "copy_rot" con.target = obj con.subtarget = definitions[2] - + con = lleg2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = twist_name - + con = lleg2.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[3] - + # Foot constraint con = foot.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[3] - + # Toe constraint con = toe.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[4] - + bpy.ops.object.mode_set(mode='EDIT') return (uleg1_name, uleg2_name, lleg1_name, lleg2_name, foot_name, toe_name, None) @@ -499,4 +499,4 @@ def main(obj, bone_definition, base_names, options): bpy.ops.object.mode_set(mode='OBJECT') blend_bone_list(obj, bone_definition + [None], bones_fk, bones_ik, target_bone=bones_ik[6], target_prop="ik", blend_default=1.0) - + diff --git a/release/scripts/modules/rigify/leg_quadruped.py b/release/scripts/modules/rigify/leg_quadruped.py index 524450d0d24..ef82380dfef 100644 --- a/release/scripts/modules/rigify/leg_quadruped.py +++ b/release/scripts/modules/rigify/leg_quadruped.py @@ -144,7 +144,7 @@ def ik(obj, bone_definition, base_names, options): eb[knee_rotator].tail = eb[knee_rotator].head + eb[mt_chain.toe].vector eb[knee_rotator].length = eb[ik_chain.thigh].length / 2 eb[knee_rotator].roll += pi/2 - + # parent ik leg to the knee rotator eb[ik_chain.thigh].parent = eb[knee_rotator] @@ -186,7 +186,7 @@ def ik(obj, bone_definition, base_names, options): mt_chain.update() ik.update() ik_chain.update() - + # Set rotation modes and axis locks #pb[knee_rotator].rotation_mode = 'YXZ' #pb[knee_rotator].lock_rotation = False, True, False @@ -195,7 +195,7 @@ def ik(obj, bone_definition, base_names, options): pb[ik.foot_roll].lock_rotation = False, True, True pb[ik_chain.toe].rotation_mode = 'XYZ' pb[ik_chain.toe].lock_rotation = False, True, True - + # IK switch property prop = rna_idprop_ui_prop_get(pb[ik_chain.foot], "ik", create=True) pb[ik_chain.foot]["ik"] = 1.0 @@ -203,7 +203,7 @@ def ik(obj, bone_definition, base_names, options): prop["soft_max"] = 1.0 prop["min"] = 0.0 prop["max"] = 1.0 - + ik_driver_path = pb[ik_chain.foot].path_to_id() + '["ik"]' # simple constraining of orig bones @@ -290,9 +290,9 @@ def ik(obj, bone_definition, base_names, options): for attr in ik.attr_names: obj.data.bones[getattr(ik, attr)].layer = layer obj.data.bones[knee_rotator].layer = layer - + return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe - + def fk(obj, bone_definition, base_names, options): @@ -307,34 +307,34 @@ def fk(obj, bone_definition, base_names, options): mt.attr_initialize(METARIG_NAMES, bone_definition) mt_chain.attr_initialize(METARIG_NAMES, bone_definition) - + fk_chain = mt_chain.copy(to_fmt="%s", base_names=base_names) - + # Create the socket socket = copy_bone_simple(arm, mt_chain.thigh, "MCH-leg_socket").name eb[socket].parent = eb[mt.hips] eb[socket].length = eb[mt_chain.thigh].length / 4 - + # Create the hinge hinge = copy_bone_simple(arm, mt.hips, "MCH-leg_hinge").name eb[hinge].length = eb[mt.hips].length / 2 - + # Make leg child of hinge eb[fk_chain.thigh].connected = False eb[fk_chain.thigh].parent = eb[hinge] - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Set rotation modes and axis locks pb[fk_chain.shin].rotation_mode = 'XYZ' pb[fk_chain.shin].lock_rotation = False, True, True - + # Constrain original bones to control bones con = mt_chain.thigh_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = fk_chain.thigh - + con = mt_chain.shin_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = fk_chain.shin @@ -346,24 +346,24 @@ def fk(obj, bone_definition, base_names, options): con = mt_chain.toe_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = fk_chain.toe - + # Socket constraint con = pb[fk_chain.thigh].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = socket - + # Hinge constraint con = pb[hinge].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = mt.hips - + prop = rna_idprop_ui_prop_get(pb[fk_chain.thigh], "hinge", create=True) pb[fk_chain.thigh]["hinge"] = 0.0 prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 prop["min"] = 0.0 prop["max"] = 1.0 - + hinge_driver_path = pb[fk_chain.thigh].path_to_id() + '["hinge"]' fcurve = con.driver_add("influence", 0) @@ -379,7 +379,7 @@ def fk(obj, bone_definition, base_names, options): mod.poly_order = 1 mod.coefficients[0] = 1.0 mod.coefficients[1] = -1.0 - + return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe @@ -397,7 +397,7 @@ def deform(obj, definitions, base_names, options): center = uleg1.center uleg1.tail = center uleg2.head = center - + # Create lower leg bones: two bones, each half of the lower leg. lleg1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True) lleg2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True) @@ -407,19 +407,19 @@ def deform(obj, definitions, base_names, options): center = lleg1.center lleg1.tail = center lleg2.head = center - + # Create a bone for the second lower leg deform bone to twist with twist = copy_bone_simple(obj.data, lleg2.name, "MCH-leg_twist") twist.length /= 4 twist.connected = False twist.parent = obj.data.edit_bones[definitions[3]] - + # Create foot bone foot = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True) - + # Create toe bone toe = copy_bone_simple(obj.data, definitions[4], "DEF-%s" % base_names[definitions[4]], parent=True) - + # Store names before leaving edit mode uleg1_name = uleg1.name uleg2_name = uleg2.name @@ -428,10 +428,10 @@ def deform(obj, definitions, base_names, options): twist_name = twist.name foot_name = foot.name toe_name = toe.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bones uleg1 = obj.pose.bones[uleg1_name] uleg2 = obj.pose.bones[uleg2_name] @@ -439,49 +439,49 @@ def deform(obj, definitions, base_names, options): lleg2 = obj.pose.bones[lleg2_name] foot = obj.pose.bones[foot_name] toe = obj.pose.bones[toe_name] - + # Upper leg constraints con = uleg1.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[2] - + con = uleg2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[1] - + # Lower leg constraints con = lleg1.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[2] - + con = lleg2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = twist_name - + con = lleg2.constraints.new('DAMPED_TRACK') con.name = "trackto" con.target = obj con.subtarget = definitions[3] - + # Foot constraint con = foot.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[3] - + # Toe constraint con = toe.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj con.subtarget = definitions[4] - + bpy.ops.object.mode_set(mode='EDIT') return (uleg1_name, uleg2_name, lleg1_name, lleg2_name, foot_name, toe_name, None) - + diff --git a/release/scripts/modules/rigify/mouth.py b/release/scripts/modules/rigify/mouth.py index dbda25d399b..5ccb8917f47 100644 --- a/release/scripts/modules/rigify/mouth.py +++ b/release/scripts/modules/rigify/mouth.py @@ -38,7 +38,7 @@ def get_unmarked_action(): if action.tag != True: return action return None - + def add_action(name=None): mark_actions() bpy.ops.action.new() @@ -46,7 +46,7 @@ def add_action(name=None): if name is not None: action.name = name return action - + def addget_shape_key(obj, name="Key"): """ Fetches a shape key, or creates it if it doesn't exist """ @@ -54,16 +54,16 @@ def addget_shape_key(obj, name="Key"): if obj.data.shape_keys is None: shape = obj.add_shape_key(name="Basis", from_mix=False) obj.active_shape_key_index = 0 - + # Get the shapekey, or create it if it doesn't already exist if name in obj.data.shape_keys.keys: shape_key = obj.data.shape_keys.keys[name] else: shape_key = obj.add_shape_key(name=name, from_mix=False) - + return shape_key - - + + def addget_shape_key_driver(obj, name="Key"): """ Fetches the driver for the shape key, or creates it if it doesn't already exist. @@ -78,9 +78,9 @@ def addget_shape_key_driver(obj, name="Key"): if fcurve == None: fcurve = obj.data.shape_keys.keys[name].driver_add("value", 0) fcurve.driver.type = 'AVERAGE' - + return fcurve - + def metarig_template(): # generated by rigify.write_meta_rig @@ -101,37 +101,37 @@ def metarig_template(): def metarig_definition(obj, orig_bone_name): bone = obj.data.bones[orig_bone_name] chain = [] - + try: chain += [bone.parent.parent.name, bone.parent.name, bone.name] except AttributeError: raise RigifyError("'%s' rig type requires a chain of two parents (bone: %s)" % (RIG_TYPE, base_names[0])) - + chain += [child.name for child in bone.children_recursive_basename] - + if len(chain) < 10: raise RigifyError("'%s' rig type requires a chain of 8 bones (bone: %s)" % (RIG_TYPE, base_names[0])) - + return chain[:10] def deform(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + jaw = definitions[1] - + # Options req_options = ["mesh"] for option in req_options: if option not in options: raise RigifyError("'%s' rig type requires a '%s' option (bone: %s)" % (RIG_TYPE, option, base_names[definitions[0]])) - + meshes = options["mesh"].replace(" ", "").split(",") - + # Upper lip MCH lip1 = make_lip_stretch_bone(obj, "MCH-lip", definitions[3], definitions[2], 0.0) lip2 = make_lip_stretch_bone(obj, "MCH-lip", definitions[4], definitions[3], 0.0) @@ -139,17 +139,17 @@ def deform(obj, definitions, base_names, options): lip33 = make_lip_stretch_bone(obj, "MCH-lip", definitions[3], definitions[4], 0.0) lip3 = make_lip_stretch_bone(obj, "MCH-lip", definitions[4], definitions[5], 0.0) lip4 = make_lip_stretch_bone(obj, "MCH-lip", definitions[5], definitions[6], 0.0) - + eb[lip1].parent = eb[definitions[3]] eb[lip2].parent = eb[definitions[4]] eb[lip22].parent = eb[definitions[5]] eb[lip33].parent = eb[definitions[3]] eb[lip3].parent = eb[definitions[4]] eb[lip4].parent = eb[definitions[5]] - + eb[lip22].bbone_segments = 8 eb[lip33].bbone_segments = 8 - + # Lower lip MCH lip5 = make_lip_stretch_bone(obj, "MCH-lip", definitions[7], definitions[6], 0.0) lip6 = make_lip_stretch_bone(obj, "MCH-lip", definitions[8], definitions[7], 0.0) @@ -157,129 +157,129 @@ def deform(obj, definitions, base_names, options): lip77 = make_lip_stretch_bone(obj, "MCH-lip", definitions[7], definitions[8], 0.0) lip7 = make_lip_stretch_bone(obj, "MCH-lip", definitions[8], definitions[9], 0.0) lip8 = make_lip_stretch_bone(obj, "MCH-lip", definitions[9], definitions[2], 0.0) - + eb[lip5].parent = eb[definitions[7]] eb[lip6].parent = eb[definitions[8]] eb[lip66].parent = eb[definitions[9]] eb[lip77].parent = eb[definitions[7]] eb[lip7].parent = eb[definitions[8]] eb[lip8].parent = eb[definitions[9]] - + eb[lip66].bbone_segments = 8 eb[lip77].bbone_segments = 8 - + # Upper lip DEF dlip1 = copy_bone_simple(obj.data, lip1, "DEF-" + base_names[definitions[4]] + ".01.R", parent=True).name dlip2 = copy_bone_simple(obj.data, lip2, "DEF-" + base_names[definitions[4]] + ".02.R", parent=True).name dlip3 = copy_bone_simple(obj.data, lip3, "DEF-" + base_names[definitions[4]] + ".02.L", parent=True).name dlip4 = copy_bone_simple(obj.data, lip4, "DEF-" + base_names[definitions[4]] + ".01.L", parent=True).name - + eb[dlip1].parent = eb[dlip2] eb[dlip2].parent = eb[lip22] - + eb[dlip4].parent = eb[dlip3] eb[dlip3].parent = eb[lip33] - + eb[dlip1].connected = True eb[dlip2].connected = True eb[dlip4].connected = True eb[dlip3].connected = True - + eb[dlip1].bbone_segments = 8 eb[dlip2].bbone_segments = 8 eb[dlip3].bbone_segments = 8 eb[dlip4].bbone_segments = 8 - + # Lower lip DEF dlip8 = copy_bone_simple(obj.data, lip8, "DEF-" + base_names[definitions[8]] + ".01.R", parent=True).name dlip7 = copy_bone_simple(obj.data, lip7, "DEF-" + base_names[definitions[8]] + ".02.R", parent=True).name dlip6 = copy_bone_simple(obj.data, lip6, "DEF-" + base_names[definitions[8]] + ".02.L", parent=True).name dlip5 = copy_bone_simple(obj.data, lip5, "DEF-" + base_names[definitions[8]] + ".01.L", parent=True).name - - + + eb[dlip5].parent = eb[dlip6] eb[dlip6].parent = eb[lip66] - + eb[dlip8].parent = eb[dlip7] eb[dlip7].parent = eb[lip77] - + eb[dlip5].connected = True eb[dlip6].connected = True eb[dlip8].connected = True eb[dlip7].connected = True - + eb[dlip5].bbone_segments = 8 eb[dlip6].bbone_segments = 8 eb[dlip7].bbone_segments = 8 eb[dlip8].bbone_segments = 8 - + # Jaw open bones jopen1 = copy_bone_simple(obj.data, jaw, "MCH-"+base_names[jaw]+".track1", parent=True).name eb[jopen1].connected = False eb[jopen1].head = eb[jaw].tail eb[jopen1].tail = eb[jopen1].head + Vector(0, 0, eb[jaw].length/4) - + jopen2 = copy_bone_simple(obj.data, jopen1, "MCH-"+base_names[jaw]+".track2").name eb[jopen2].parent = eb[jaw] - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Constraints con = pb[dlip1].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip1 - + con = pb[dlip2].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip2 - + con = pb[dlip3].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip3 - + con = pb[dlip4].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip4 - + con = pb[dlip5].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip5 - + con = pb[dlip6].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip6 - + con = pb[dlip7].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip7 - + con = pb[dlip8].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = lip8 - + # Corrective shape keys for the corners of the mouth. bpy.ops.object.mode_set(mode='EDIT') - + # Calculate the rotation difference between the bones rotdiff_r = acos(eb[lip1].matrix.to_quat() * eb[lip8].matrix.to_quat()) * 2 rotdiff_l = acos(eb[lip4].matrix.to_quat() * eb[lip5].matrix.to_quat()) * 2 - + bpy.ops.object.mode_set(mode='OBJECT') - - + + # Left side shape key for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] shape_key_name = "COR-" + base_names[definitions[4]] + ".L.spread" - + # Add/get the shape key shape_key = addget_shape_key(mesh_obj, name=shape_key_name) - + # Add/get the shape key driver fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name) driver = fcurve.driver - + # Get the variable, or create it if it doesn't already exist var_name = base_names[definitions[6]] if var_name in driver.variables: @@ -287,32 +287,32 @@ def deform(obj, definitions, base_names, options): else: var = driver.variables.new() var.name = var_name - + # Set up the variable var.type = "ROTATION_DIFF" var.targets[0].id = obj var.targets[0].bone_target = lip4 var.targets[1].id = obj var.targets[1].bone_target = lip5 - + # Set fcurve offset mod = fcurve.modifiers[0] if rotdiff_l != pi: mod.coefficients[0] = -rotdiff_l / (pi-rotdiff_l) mod.coefficients[1] = 1 / (pi-rotdiff_l) - + # Right side shape key for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] shape_key_name = "COR-" + base_names[definitions[4]] + ".R.spread" - + # Add/get the shape key shape_key = addget_shape_key(mesh_obj, name=shape_key_name) - + # Add/get the shape key driver fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name) driver = fcurve.driver - + # Get the variable, or create it if it doesn't already exist var_name = base_names[definitions[2]] if var_name in driver.variables: @@ -320,32 +320,32 @@ def deform(obj, definitions, base_names, options): else: var = driver.variables.new() var.name = var_name - + # Set up the variable var.type = "ROTATION_DIFF" var.targets[0].id = obj var.targets[0].bone_target = lip1 var.targets[1].id = obj var.targets[1].bone_target = lip8 - + # Set fcurve offset mod = fcurve.modifiers[0] if rotdiff_r != pi: mod.coefficients[0] = -rotdiff_r / (pi-rotdiff_r) mod.coefficients[1] = 1 / (pi-rotdiff_r) - + # Jaw open corrective shape key for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] shape_key_name = "COR-" + base_names[definitions[4]] + ".jaw_open" - + # Add/get the shape key shape_key = addget_shape_key(mesh_obj, name=shape_key_name) - + # Add/get the shape key driver fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name) driver = fcurve.driver - + # Get the variable, or create it if it doesn't already exist var_name = base_names[definitions[4]] if var_name in driver.variables: @@ -353,19 +353,19 @@ def deform(obj, definitions, base_names, options): else: var = driver.variables.new() var.name = var_name - + # Set up the variable var.type = "LOC_DIFF" var.targets[0].id = obj var.targets[0].bone_target = jopen1 var.targets[1].id = obj var.targets[1].bone_target = jopen2 - + # Set fcurve offset mod = fcurve.modifiers[0] mod.coefficients[0] = 0.0 mod.coefficients[1] = 1.0 / bb[jaw].length - + return (None,) @@ -373,15 +373,15 @@ def deform(obj, definitions, base_names, options): def control(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + head_e = eb[definitions[0]] jaw_e = eb[definitions[1]] jaw = definitions[1] - + # Head lips hlip1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]+".head").name hlip2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]+".head").name @@ -391,7 +391,7 @@ def control(obj, definitions, base_names, options): hlip6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]+".head").name hlip7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]+".head").name hlip8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]+".head").name - + eb[hlip1].parent = head_e eb[hlip2].parent = head_e eb[hlip3].parent = head_e @@ -400,7 +400,7 @@ def control(obj, definitions, base_names, options): eb[hlip6].parent = head_e eb[hlip7].parent = head_e eb[hlip8].parent = head_e - + # Jaw lips jlip1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]+".jaw").name jlip2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]+".jaw").name @@ -410,7 +410,7 @@ def control(obj, definitions, base_names, options): jlip6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]+".jaw").name jlip7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]+".jaw").name jlip8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]+".jaw").name - + eb[jlip1].parent = jaw_e eb[jlip2].parent = jaw_e eb[jlip3].parent = jaw_e @@ -419,7 +419,7 @@ def control(obj, definitions, base_names, options): eb[jlip6].parent = jaw_e eb[jlip7].parent = jaw_e eb[jlip8].parent = jaw_e - + # Control lips lip1 = copy_bone_simple(obj.data, definitions[2], base_names[definitions[2]]).name lip2 = copy_bone_simple(obj.data, definitions[3], base_names[definitions[3]]).name @@ -429,7 +429,7 @@ def control(obj, definitions, base_names, options): lip6 = copy_bone_simple(obj.data, definitions[7], base_names[definitions[7]]).name lip7 = copy_bone_simple(obj.data, definitions[8], base_names[definitions[8]]).name lip8 = copy_bone_simple(obj.data, definitions[9], base_names[definitions[9]]).name - + size = eb[lip1].length eb[lip1].tail = eb[lip1].head + Vector(0,size,0) eb[lip2].tail = eb[lip2].head + Vector(0,size,0) @@ -439,7 +439,7 @@ def control(obj, definitions, base_names, options): eb[lip6].tail = eb[lip6].head + Vector(0,size,0) eb[lip7].tail = eb[lip7].head + Vector(0,size,0) eb[lip8].tail = eb[lip8].head + Vector(0,size,0) - + eb[lip1].roll = 0 eb[lip2].roll = 0 eb[lip3].roll = 0 @@ -448,7 +448,7 @@ def control(obj, definitions, base_names, options): eb[lip6].roll = 0 eb[lip7].roll = 0 eb[lip8].roll = 0 - + eb[lip1].parent = eb[hlip1] eb[lip2].parent = eb[hlip2] eb[lip3].parent = eb[hlip3] @@ -457,7 +457,7 @@ def control(obj, definitions, base_names, options): eb[lip6].parent = eb[hlip6] eb[lip7].parent = eb[hlip7] eb[lip8].parent = eb[hlip8] - + # Link lips llip1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]+".link").name llip2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]+".link").name @@ -467,7 +467,7 @@ def control(obj, definitions, base_names, options): llip6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]+".link").name llip7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]+".link").name llip8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]+".link").name - + eb[llip1].parent = eb[lip1] eb[llip2].parent = eb[lip2] eb[llip3].parent = eb[lip3] @@ -476,22 +476,22 @@ def control(obj, definitions, base_names, options): eb[llip6].parent = eb[lip6] eb[llip7].parent = eb[lip7] eb[llip8].parent = eb[lip8] - + # Jaw open tracker jopent = copy_bone_simple(obj.data, jaw_e.name, "MCH-"+base_names[jaw_e.name]+".track", parent=True).name eb[jopent].connected = False eb[jopent].tail = jaw_e.tail + Vector(0,0,jaw_e.length) eb[jopent].head = jaw_e.tail - + bpy.ops.object.mode_set(mode='OBJECT') - + # Add mouth open action if it doesn't already exist action_name = "mouth_open" if action_name in bpy.data.actions: open_action = bpy.data.actions[action_name] else: open_action = add_action(name=action_name) - + # Add close property (useful when making the animation in the action) prop_name = "open_action" prop = rna_idprop_ui_prop_get(pb[lip1], prop_name, create=True) @@ -500,12 +500,12 @@ def control(obj, definitions, base_names, options): prop["soft_max"] = 1.0 prop["min"] = 0.0 prop["max"] = 1.0 - + open_driver_path = pb[lip1].path_to_id() + '["open_action"]' - - + + # Constraints - + # Jaw open tracker stretches to jaw tip con = pb[jopent].constraints.new('STRETCH_TO') con.target = obj @@ -513,83 +513,83 @@ def control(obj, definitions, base_names, options): con.head_tail = 1.0 con.original_length = bb[jopent].length con.volume = 'NO_VOLUME' - + # Head lips to jaw lips influence = [0.02, 0.15, 0.5, 0.25, 0.0] - + con = pb[hlip1].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip1 con.influence = influence[2] - + con = pb[hlip2].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip2 con.influence = influence[1] - + con = pb[hlip3].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip3 con.influence = influence[0] - + con = pb[hlip4].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip4 con.influence = influence[1] - + con = pb[hlip5].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip5 con.influence = influence[2] - + con = pb[hlip6].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip6 con.influence = 1.0 - influence[3] - + con = pb[hlip7].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip7 con.influence = 1.0 - influence[4] - + con = pb[hlip8].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = jlip8 con.influence = 1.0 - influence[3] - + # ORG bones to link lips con = pb[definitions[2]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip1 - + con = pb[definitions[3]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip2 - + con = pb[definitions[4]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip3 - + con = pb[definitions[5]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip4 - + con = pb[definitions[6]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip5 - + con = pb[definitions[7]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip6 - + con = pb[definitions[8]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip7 - + con = pb[definitions[9]].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = llip8 - + # Action constraints for open mouth con = pb[lip1].constraints.new('ACTION') con.target = obj @@ -608,7 +608,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip2].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -626,7 +626,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip3].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -644,7 +644,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip4].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -662,7 +662,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip5].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -680,7 +680,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip6].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -698,7 +698,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip7].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -716,7 +716,7 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - + con = pb[lip8].constraints.new('ACTION') con.target = obj con.subtarget = jopent @@ -734,8 +734,8 @@ def control(obj, definitions, base_names, options): var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = open_driver_path - - + + # Set layers layer = list(bb[definitions[2]].layer) bb[lip1].layer = layer @@ -746,8 +746,8 @@ def control(obj, definitions, base_names, options): bb[lip6].layer = layer bb[lip7].layer = layer bb[lip8].layer = layer - - + + return (None,) @@ -767,34 +767,34 @@ def main(obj, bone_definition, base_names, options): def make_lip_stretch_bone(obj, name, bone1, bone2, roll_alpha): eb = obj.data.edit_bones pb = obj.pose.bones - + # Create the bone, pointing from bone1 to bone2 bone_e = copy_bone_simple(obj.data, bone1, name, parent=True) bone_e.connected = False bone_e.tail = eb[bone2].head bone = bone_e.name - + # Align the bone roll with the average direction of bone1 and bone2 vec = bone_e.y_axis.cross(((1.0-roll_alpha)*eb[bone1].y_axis) + (roll_alpha*eb[bone2].y_axis)).normalize() - + ang = acos(vec * bone_e.x_axis) - + bone_e.roll += ang c1 = vec * bone_e.x_axis bone_e.roll -= (ang*2) c2 = vec * bone_e.x_axis - + if c1 > c2: bone_e.roll += (ang*2) - + bpy.ops.object.mode_set(mode='OBJECT') bone_p = pb[bone] - + # Constrains con = bone_p.constraints.new('COPY_LOCATION') con.target = obj con.subtarget = bone1 - + con = bone_p.constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = bone2 diff --git a/release/scripts/modules/rigify/neck_flex.py b/release/scripts/modules/rigify/neck_flex.py index d26510f49b2..343d18bda82 100644 --- a/release/scripts/modules/rigify/neck_flex.py +++ b/release/scripts/modules/rigify/neck_flex.py @@ -106,16 +106,16 @@ def deform(obj, definitions, base_names, options): # Create deform bone. bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) - + # Store name before leaving edit mode bone_name = bone.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bone bone = obj.pose.bones[bone_name] - + # Constrain to the original bone # XXX. Todo, is this needed if the bone is connected to its parent? con = bone.constraints.new('COPY_TRANSFORMS') @@ -323,8 +323,8 @@ def main(obj, bone_definition, base_names, options): con = orig_neck_p.constraints.new('COPY_ROTATION') con.target = obj con.subtarget = neck_p.name - - + + # Set the head control's custom shape to use the last # org neck bone for its transform ex.head_ctrl_p.custom_shape_transform = obj.pose.bones[bone_definition[len(bone_definition)-1]] @@ -339,11 +339,11 @@ def main(obj, bone_definition, base_names, options): getattr(ex_chain, attr + "_b").layer = layer for attr in ex.attr_names: getattr(ex, attr + "_b").layer = layer - + layer = list(arm.bones[bone_definition[1]].layer) ex.head_ctrl_b.layer = layer # no blending the result of this return None - + diff --git a/release/scripts/modules/rigify/palm_curl.py b/release/scripts/modules/rigify/palm_curl.py index 82010552ea7..b0a1348c938 100644 --- a/release/scripts/modules/rigify/palm_curl.py +++ b/release/scripts/modules/rigify/palm_curl.py @@ -104,16 +104,16 @@ def deform(obj, definitions, base_names, options): # Create deform bone. bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) - + # Store name before leaving edit mode bone_name = bone.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bone bone = obj.pose.bones[bone_name] - + # Constrain to the original bone # XXX. Todo, is this needed if the bone is connected to its parent? con = bone.constraints.new('COPY_TRANSFORMS') @@ -141,7 +141,7 @@ def main(obj, bone_definition, base_names, options): offset = (pinky_ebone.head - ring_ebone.head) control_ebone.translate(offset) - + deform(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') diff --git a/release/scripts/modules/rigify/shape_key_distance.py b/release/scripts/modules/rigify/shape_key_distance.py index 7701e725ea9..54d5f302bba 100644 --- a/release/scripts/modules/rigify/shape_key_distance.py +++ b/release/scripts/modules/rigify/shape_key_distance.py @@ -36,16 +36,16 @@ def addget_shape_key(obj, name="Key"): if obj.data.shape_keys is None: shape = obj.add_shape_key(name="Basis", from_mix=False) obj.active_shape_key_index = 0 - + # Get the shapekey, or create it if it doesn't already exist if name in obj.data.shape_keys.keys: shape_key = obj.data.shape_keys.keys[name] else: shape_key = obj.add_shape_key(name=name, from_mix=False) - + return shape_key - - + + def addget_shape_key_driver(obj, name="Key"): """ Fetches the driver for the shape key, or creates it if it doesn't already exist. @@ -60,7 +60,7 @@ def addget_shape_key_driver(obj, name="Key"): if fcurve == None: fcurve = obj.data.shape_keys.keys[name].driver_add("value", 0) fcurve.driver.type = 'AVERAGE' - + return fcurve @@ -90,42 +90,42 @@ def metarig_definition(obj, orig_bone_name): def deform(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') eb = obj.data.edit_bones - + bone_from = definitions[0] - - + + # Options req_options = ["to", "mesh", "shape_key"] for option in req_options: if option not in options: raise RigifyError("'%s' rig type requires a '%s' option (bone: %s)" % (RIG_TYPE, option, base_names[definitions[0]])) - + bone_to = "ORG-" + options["to"] meshes = options["mesh"].replace(" ", "").split(",") shape_key_name = options["shape_key"] - + if "dmul" in options: shape_blend_fac = options["dmul"] else: shape_blend_fac = 1.0 - - + + # Calculate the distance between the bones distance = (eb[bone_from].head - eb[bone_to].head).length - + bpy.ops.object.mode_set(mode='OBJECT') - + # For every listed mesh object for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] - + # Add/get the shape key shape_key = addget_shape_key(mesh_obj, name=shape_key_name) - + # Add/get the shape key driver fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name) driver = fcurve.driver - + # Get the variable, or create it if it doesn't already exist var_name = base_names[bone_from] if var_name in driver.variables: @@ -133,7 +133,7 @@ def deform(obj, definitions, base_names, options): else: var = driver.variables.new() var.name = var_name - + # Set up the variable var.type = "LOC_DIFF" var.targets[0].id_type = 'OBJECT' @@ -142,14 +142,14 @@ def deform(obj, definitions, base_names, options): var.targets[1].id_type = 'OBJECT' var.targets[1].id = obj var.targets[1].bone_target = bone_to - + # Set fcurve offset, so zero is at the rest distance - + mod = fcurve.modifiers[0] if distance > 0.00001: mod.coefficients[0] = -shape_blend_fac mod.coefficients[1] = shape_blend_fac / distance - + return (None,) diff --git a/release/scripts/modules/rigify/shape_key_rotdiff.py b/release/scripts/modules/rigify/shape_key_rotdiff.py index 265a2fe368a..0c83bda36fd 100644 --- a/release/scripts/modules/rigify/shape_key_rotdiff.py +++ b/release/scripts/modules/rigify/shape_key_rotdiff.py @@ -36,16 +36,16 @@ def addget_shape_key(obj, name="Key"): if obj.data.shape_keys is None: shape = obj.add_shape_key(name="Basis", from_mix=False) obj.active_shape_key_index = 0 - + # Get the shapekey, or create it if it doesn't already exist if name in obj.data.shape_keys.keys: shape_key = obj.data.shape_keys.keys[name] else: shape_key = obj.add_shape_key(name=name, from_mix=False) - + return shape_key - - + + def addget_shape_key_driver(obj, name="Key"): """ Fetches the driver for the shape key, or creates it if it doesn't already exist. @@ -60,7 +60,7 @@ def addget_shape_key_driver(obj, name="Key"): if fcurve == None: fcurve = obj.data.shape_keys.keys[name].driver_add("value", 0) fcurve.driver.type = 'AVERAGE' - + return fcurve @@ -90,42 +90,42 @@ def metarig_definition(obj, orig_bone_name): def deform(obj, definitions, base_names, options): bpy.ops.object.mode_set(mode='EDIT') eb = obj.data.edit_bones - + bone_from = definitions[0] - - + + # Options req_options = ["to", "mesh", "shape_key"] for option in req_options: if option not in options: raise RigifyError("'%s' rig type requires a '%s' option (bone: %s)" % (RIG_TYPE, option, base_names[definitions[0]])) - + bone_to = "ORG-" + options["to"] meshes = options["mesh"].replace(" ", "").split(",") shape_key_name = options["shape_key"] - + if "dmul" in options: shape_blend_fac = options["dmul"] else: shape_blend_fac = 1.0 - - + + # Calculate the rotation difference between the bones rotdiff = (eb[bone_from].matrix.to_quat() * eb[bone_to].matrix.to_quat()) * 2 - + bpy.ops.object.mode_set(mode='OBJECT') - + # For every listed mesh object for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] - + # Add/get the shape key shape_key = addget_shape_key(mesh_obj, name=shape_key_name) - + # Add/get the shape key driver fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name) driver = fcurve.driver - + # Get the variable, or create it if it doesn't already exist var_name = base_names[bone_from] if var_name in driver.variables: @@ -133,7 +133,7 @@ def deform(obj, definitions, base_names, options): else: var = driver.variables.new() var.name = var_name - + # Set up the variable var.type = "ROTATION_DIFF" var.targets[0].id_type = 'OBJECT' @@ -142,14 +142,14 @@ def deform(obj, definitions, base_names, options): var.targets[1].id_type = 'OBJECT' var.targets[1].id = obj var.targets[1].bone_target = bone_to - + # Set fcurve offset, so zero is at the rest distance - + mod = fcurve.modifiers[0] if rotdiff > 0.00001: mod.coefficients[0] = -shape_blend_fac mod.coefficients[1] = shape_blend_fac / rotdiff - + return (None,) diff --git a/release/scripts/modules/rigify/spine_pivot_flex.py b/release/scripts/modules/rigify/spine_pivot_flex.py index 5bf5b3bf484..287a7d0f9d1 100644 --- a/release/scripts/modules/rigify/spine_pivot_flex.py +++ b/release/scripts/modules/rigify/spine_pivot_flex.py @@ -128,16 +128,16 @@ def deform(obj, definitions, base_names, options): # Create deform bone. bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) - + # Store name before leaving edit mode bone_name = bone.name - + # Leave edit mode bpy.ops.object.mode_set(mode='OBJECT') - + # Get the pose bone bone = obj.pose.bones[bone_name] - + # Constrain to the original bone # XXX. Todo, is this needed if the bone is connected to its parent? con = bone.constraints.new('COPY_TRANSFORMS') @@ -284,7 +284,7 @@ def main(obj, bone_definition, base_names, options): mt_chain.update() ex_chain.update() rv_chain.update() - + # Axis locks ex.ribcage_copy_p.lock_location = True, True, True @@ -453,8 +453,8 @@ def main(obj, bone_definition, base_names, options): mod.poly_order = 1 mod.coefficients[0] = - (i - 1) mod.coefficients[1] = spine_chain_len - - + + # Set pelvis and ribcage controls to use the first and last bone in the # spine respectively for their custom shape transform ex.ribcage_copy_p.custom_shape_transform = obj.pose.bones[bone_definition[len(bone_definition)-1]] @@ -472,7 +472,7 @@ def main(obj, bone_definition, base_names, options): getattr(ex_chain, attr + "_b").layer = layer for attr in rv_chain.attr_names: getattr(rv_chain, attr + "_b").layer = layer - + layer = list(arm.bones[bone_definition[1]].layer) arm.bones[ex.pelvis_copy].layer = layer arm.bones[ex.ribcage_copy].layer = layer diff --git a/release/scripts/modules/rigify/stretch.py b/release/scripts/modules/rigify/stretch.py index 373a934ac74..7f24951bdef 100644 --- a/release/scripts/modules/rigify/stretch.py +++ b/release/scripts/modules/rigify/stretch.py @@ -65,7 +65,7 @@ def main(obj, bone_definition, base_names, options): raise RigifyError("'%s' rig type 'to' parameter must be a string (bone: %s)" % (RIG_TYPE, base_names[bone_definition[0]])) if ("ORG-" + options["to"]) not in obj.data.bones: raise RigifyError("'%s' rig type 'to' parameter must name a bone in the metarig (bone: %s)" % (RIG_TYPE, base_names[bone_definition[0]])) - + preserve_volume = None # Check optional parameter if "preserve_volume" in options: @@ -73,14 +73,14 @@ def main(obj, bone_definition, base_names, options): preserve_volume = bool_map[options["preserve_volume"]] except KeyError: preserve_volume = False - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + bpy.ops.object.mode_set(mode='EDIT') arm = obj.data - + mbone1 = bone_definition[0] mbone2 = "ORG-" + options["to"] @@ -90,14 +90,14 @@ def main(obj, bone_definition, base_names, options): bone_e.tail = eb[mbone2].head bone = bone_e.name - + bpy.ops.object.mode_set(mode='OBJECT') # Constraints con = pb[bone].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = mbone2 - + con = pb[bone].constraints.new('STRETCH_TO') con.target = obj con.subtarget = mbone2 diff --git a/release/scripts/modules/rigify/stretch_twist.py b/release/scripts/modules/rigify/stretch_twist.py index 6e5891b5e0a..2a7953133f9 100644 --- a/release/scripts/modules/rigify/stretch_twist.py +++ b/release/scripts/modules/rigify/stretch_twist.py @@ -66,7 +66,7 @@ def main(obj, bone_definition, base_names, options): raise RigifyError("'%s' rig type 'to' parameter must be a string (bone: %s)" % (RIG_TYPE, base_names[0])) if ("ORG-" + options["to"]) not in obj.data.bones: raise RigifyError("'%s' rig type 'to' parameter must name a bone in the metarig (bone: %s)" % (RIG_TYPE, base_names[0])) - + preserve_volume = None # Check optional parameter if "preserve_volume" in options: @@ -74,30 +74,30 @@ def main(obj, bone_definition, base_names, options): preserve_volume = bool_map[options["preserve_volume"]] except KeyError: preserve_volume = False - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + bpy.ops.object.mode_set(mode='EDIT') arm = obj.data - + mbone1 = bone_definition[0] mbone2 = "ORG-" + options["to"] - + bone_e = copy_bone_simple(obj.data, mbone1, "MCH-%s" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = None bone_e.head = (eb[mbone1].head + eb[mbone2].head) / 2 bone_e.tail = (bone_e.head[0], bone_e.head[1], bone_e.head[2]+0.1) mid_bone = bone_e.name - + bone_e = copy_bone_simple(obj.data, mbone1, "DEF-%s.01" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = eb[mbone1] bone_e.tail = eb[mid_bone].head bone1 = bone_e.name - + bone_e = copy_bone_simple(obj.data, mbone2, "DEF-%s.02" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = eb[mbone2] @@ -105,26 +105,26 @@ def main(obj, bone_definition, base_names, options): bone2 = bone_e.name - + bpy.ops.object.mode_set(mode='OBJECT') # Constraints - + # Mid bone con = pb[mid_bone].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = mbone1 - + con = pb[mid_bone].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = mbone2 con.influence = 0.5 - + # Bone 1 con = pb[bone1].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = mid_bone - + con = pb[bone1].constraints.new('STRETCH_TO') con.target = obj con.subtarget = mid_bone @@ -133,12 +133,12 @@ def main(obj, bone_definition, base_names, options): con.volume = 'VOLUME_XZX' else: con.volume = 'NO_VOLUME' - + # Bone 2 con = pb[bone2].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = mid_bone - + con = pb[bone2].constraints.new('STRETCH_TO') con.target = obj con.subtarget = mid_bone diff --git a/release/scripts/modules/rigify/track_dual.py b/release/scripts/modules/rigify/track_dual.py index 3a1197b95bf..59a83d9d5f2 100644 --- a/release/scripts/modules/rigify/track_dual.py +++ b/release/scripts/modules/rigify/track_dual.py @@ -65,23 +65,23 @@ def main(obj, bone_definition, base_names, options): raise RigifyError("'%s' rig type 'to' parameter must be a string (bone: %s)" % (RIG_TYPE, base_names[0])) if ("ORG-" + options["to"]) not in obj.data.bones: raise RigifyError("'%s' rig type 'to' parameter must name a bone in the metarig (bone: %s)" % (RIG_TYPE, base_names[0])) - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + bpy.ops.object.mode_set(mode='EDIT') arm = obj.data - + mbone1 = bone_definition[0] mbone2 = "ORG-" + options["to"] - + bone_e = copy_bone_simple(obj.data, mbone1, "DEF-%s.01" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = eb[mbone1] bone_e.tail = (eb[mbone1].head + eb[mbone2].head) / 2 bone1 = bone_e.name - + bone_e = copy_bone_simple(obj.data, mbone2, "DEF-%s.02" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = eb[mbone1] @@ -89,7 +89,7 @@ def main(obj, bone_definition, base_names, options): bone2 = bone_e.name - + bpy.ops.object.mode_set(mode='OBJECT') # Constraints @@ -98,12 +98,12 @@ def main(obj, bone_definition, base_names, options): con.target = obj con.subtarget = mbone2 - + # Bone 2 con = pb[bone2].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = mbone2 - + con = pb[bone2].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = mbone1 diff --git a/release/scripts/modules/rigify/track_reverse.py b/release/scripts/modules/rigify/track_reverse.py index 38f7b6182f9..c74211f41ef 100644 --- a/release/scripts/modules/rigify/track_reverse.py +++ b/release/scripts/modules/rigify/track_reverse.py @@ -66,17 +66,17 @@ def main(obj, bone_definition, base_names, options): raise RigifyError("'%s' rig type 'to' parameter must be a string (bone: %s)" % (RIG_TYPE, base_names[0])) if ("ORG-" + options["to"]) not in obj.data.bones: raise RigifyError("'%s' rig type 'to' parameter must name a bone in the metarig (bone: %s)" % (RIG_TYPE, base_names[0])) - + eb = obj.data.edit_bones bb = obj.data.bones pb = obj.pose.bones - + bpy.ops.object.mode_set(mode='EDIT') arm = obj.data - + mbone1 = bone_definition[0] mbone2 = "ORG-" + options["to"] - + bone_e = copy_bone_simple(obj.data, mbone2, "DEF-%s.02" % base_names[bone_definition[0]]) bone_e.connected = False bone_e.parent = eb[mbone1] @@ -84,14 +84,14 @@ def main(obj, bone_definition, base_names, options): bone = bone_e.name - + bpy.ops.object.mode_set(mode='OBJECT') # Constraints con = pb[bone].constraints.new('COPY_LOCATION') con.target = obj con.subtarget = mbone2 - + con = pb[bone].constraints.new('DAMPED_TRACK') con.target = obj con.subtarget = mbone1 |