diff options
Diffstat (limited to 'release/scripts/modules/rigify/eye_balls.py')
-rw-r--r-- | release/scripts/modules/rigify/eye_balls.py | 88 |
1 files changed, 44 insertions, 44 deletions
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,) |