diff options
author | Nathan Vegdahl <cessen@cessen.com> | 2011-06-19 00:41:43 +0400 |
---|---|---|
committer | Nathan Vegdahl <cessen@cessen.com> | 2011-06-19 00:41:43 +0400 |
commit | 1a3f4c4c6af16a3214c9dd3847590b87c580c11a (patch) | |
tree | 546eadd221be849884ac0adb00829f70fa71272c | |
parent | 83840e5713eaeaf3b8ec0c779d0dffe8666cd85c (diff) |
Rigify: users can now specify layer names in the metarig armature properties.
The layer names are then used in creating the custom rig layer UI. This is
useful for users that do not want to--or do not have the knowledge to--edit
the generated python script by hand. It is also handy even for more advanced
users when regerating the rig over and over (which over-writes the script
and any hand-made edits).
Also misc bug fixes in some of the rig types.
-rw-r--r-- | rigify/__init__.py | 36 | ||||
-rw-r--r-- | rigify/generate.py | 9 | ||||
-rw-r--r-- | rigify/metarigs/human.py | 14 | ||||
-rw-r--r-- | rigify/rig_ui_template.py | 6 | ||||
-rw-r--r-- | rigify/rigs/biped/arm/fk.py | 9 | ||||
-rw-r--r-- | rigify/rigs/biped/leg/fk.py | 11 | ||||
-rw-r--r-- | rigify/rigs/spine.py | 3 | ||||
-rw-r--r-- | rigify/ui.py | 42 |
8 files changed, 125 insertions, 5 deletions
diff --git a/rigify/__init__.py b/rigify/__init__.py index 68d22245..fe9511cf 100644 --- a/rigify/__init__.py +++ b/rigify/__init__.py @@ -115,6 +115,37 @@ class RigifyParameters(bpy.types.PropertyGroup): name = bpy.props.StringProperty() +class RigifyArmatureProps(bpy.types.PropertyGroup): + layer_name_01 = bpy.props.StringProperty(name="Layer 1 Name", default="1") + layer_name_02 = bpy.props.StringProperty(name="Layer 2 Name", default="2") + layer_name_03 = bpy.props.StringProperty(name="Layer 3 Name", default="3") + layer_name_04 = bpy.props.StringProperty(name="Layer 4 Name", default="4") + layer_name_05 = bpy.props.StringProperty(name="Layer 5 Name", default="5") + layer_name_06 = bpy.props.StringProperty(name="Layer 6 Name", default="6") + layer_name_07 = bpy.props.StringProperty(name="Layer 7 Name", default="7") + layer_name_08 = bpy.props.StringProperty(name="Layer 8 Name", default="8") + layer_name_09 = bpy.props.StringProperty(name="Layer 9 Name", default="9") + layer_name_10 = bpy.props.StringProperty(name="Layer 10 Name", default="10") + layer_name_11 = bpy.props.StringProperty(name="Layer 11 Name", default="11") + layer_name_12 = bpy.props.StringProperty(name="Layer 12 Name", default="12") + layer_name_13 = bpy.props.StringProperty(name="Layer 13 Name", default="13") + layer_name_14 = bpy.props.StringProperty(name="Layer 14 Name", default="14") + layer_name_15 = bpy.props.StringProperty(name="Layer 15 Name", default="15") + layer_name_16 = bpy.props.StringProperty(name="Layer 16 Name", default="16") + layer_name_17 = bpy.props.StringProperty(name="Layer 17 Name", default="17") + layer_name_18 = bpy.props.StringProperty(name="Layer 18 Name", default="18") + layer_name_19 = bpy.props.StringProperty(name="Layer 19 Name", default="19") + layer_name_20 = bpy.props.StringProperty(name="Layer 20 Name", default="20") + layer_name_21 = bpy.props.StringProperty(name="Layer 21 Name", default="21") + layer_name_22 = bpy.props.StringProperty(name="Layer 22 Name", default="22") + layer_name_23 = bpy.props.StringProperty(name="Layer 23 Name", default="23") + layer_name_24 = bpy.props.StringProperty(name="Layer 24 Name", default="24") + layer_name_25 = bpy.props.StringProperty(name="Layer 25 Name", default="25") + layer_name_26 = bpy.props.StringProperty(name="Layer 26 Name", default="26") + layer_name_27 = bpy.props.StringProperty(name="Layer 27 Name", default="27") + layer_name_28 = bpy.props.StringProperty(name="Layer 28 Name", default="28") + + ##### REGISTER ##### def register(): @@ -123,10 +154,13 @@ def register(): bpy.utils.register_class(RigifyName) bpy.utils.register_class(RigifyParameters) + bpy.utils.register_class(RigifyArmatureProps) bpy.types.PoseBone.rigify_type = bpy.props.StringProperty(name="Rigify Type", description="Rig type for this bone.") bpy.types.PoseBone.rigify_parameters = bpy.props.CollectionProperty(type=RigifyParameters) + bpy.types.Armature.rigify_props = bpy.props.CollectionProperty(type=RigifyArmatureProps) + IDStore = bpy.types.WindowManager IDStore.rigify_collection = bpy.props.EnumProperty(items=col_enum_list, default="All", name="Rigify Active Collection", description="The selected rig collection") IDStore.rigify_types = bpy.props.CollectionProperty(type=RigifyName) @@ -144,6 +178,7 @@ def register(): def unregister(): del bpy.types.PoseBone.rigify_type del bpy.types.PoseBone.rigify_parameters + del bpy.types.Armature.rigify_props IDStore = bpy.types.WindowManager del IDStore.rigify_collection @@ -152,6 +187,7 @@ def unregister(): bpy.utils.unregister_class(RigifyName) bpy.utils.unregister_class(RigifyParameters) + bpy.utils.unregister_class(RigifyArmatureProps) metarig_menu.unregister() ui.unregister() diff --git a/rigify/generate.py b/rigify/generate.py index 4809e290..3de8fe23 100644 --- a/rigify/generate.py +++ b/rigify/generate.py @@ -282,6 +282,13 @@ def generate_rig(context, metarig): vis_layers[i] = vis_layers[i] and not (ORG_LAYER[i] or MCH_LAYER[i] or DEF_LAYER[i]) obj.data.layers = vis_layers + # Create list of layer names + if len(metarig.data.rigify_props) < 1: + metarig.data.rigify_props.add() + layer_names = [] + for i in range(28): + layer_names += [getattr(metarig.data.rigify_props[0], "layer_name_%s" % str(i+1).rjust(2, "0"))] + # Generate the UI script if "rig_ui.py" in bpy.data.texts: script = bpy.data.texts["rig_ui.py"] @@ -291,7 +298,7 @@ def generate_rig(context, metarig): script.write(UI_SLIDERS % rig_id) for s in ui_scripts: script.write("\n " + s.replace("\n", "\n ") + "\n") - script.write(layers_ui(vis_layers)) + script.write(layers_ui(vis_layers, layer_names)) script.write(UI_REGISTER) script.use_module = True diff --git a/rigify/metarigs/human.py b/rigify/metarigs/human.py index e4eb9f2b..d0744066 100644 --- a/rigify/metarigs/human.py +++ b/rigify/metarigs/human.py @@ -24,6 +24,20 @@ def create(obj): bpy.ops.object.mode_set(mode='EDIT') arm = obj.data + props = arm.rigify_props.add() + props.layer_name_01 = "Torso" + props.layer_name_03 = "Head" + props.layer_name_05 = "Fingers" + props.layer_name_06 = "Fingers (tweak)" + props.layer_name_07 = "Arm.L (FK)" + props.layer_name_08 = "Arm.L (IK)" + props.layer_name_09 = "Arm.R (FK)" + props.layer_name_10 = "Arm.R (IK)" + props.layer_name_11 = "Leg.L (FK)" + props.layer_name_12 = "Leg.L (IK)" + props.layer_name_13 = "Leg.R (FK)" + props.layer_name_14 = "Leg.R (IK)" + bones = {} bone = arm.edit_bones.new('hips') diff --git a/rigify/rig_ui_template.py b/rigify/rig_ui_template.py index db3bb6cb..35df1ec2 100644 --- a/rigify/rig_ui_template.py +++ b/rigify/rig_ui_template.py @@ -493,8 +493,8 @@ class RigUI(bpy.types.Panel): ''' -def layers_ui(layers): - """ Turn a list of booleans into a layer UI. +def layers_ui(layers, names): + """ Turn a list of booleans + a list of names into a layer UI. """ code = ''' @@ -522,7 +522,7 @@ class RigLayers(bpy.types.Panel): if i == 28: code += " row.prop(context.active_object.data, 'layers', index=%s, toggle=True, text='Root')\n" % (str(i)) else: - code += " row.prop(context.active_object.data, 'layers', index=%s, toggle=True, text='%s')\n" % (str(i), str(i + 1)) + code += " row.prop(context.active_object.data, 'layers', index=%s, toggle=True, text='%s')\n" % (str(i), names[i]) i += 1 return code diff --git a/rigify/rigs/biped/arm/fk.py b/rigify/rigs/biped/arm/fk.py index 77dcc6a6..2c634b86 100644 --- a/rigify/rigs/biped/arm/fk.py +++ b/rigify/rigs/biped/arm/fk.py @@ -120,6 +120,8 @@ class Rig: uarm_p = pb[uarm] farm_p = pb[farm] hand_p = pb[hand] + if self.org_parent != None: + hinge_p = pb[hinge] if self.org_parent != None: socket1_p = pb[socket1] @@ -134,6 +136,13 @@ class Rig: else: farm_p.lock_rotation = (True, True, False) + # Hinge transforms are locked, for auto-ik + if self.org_parent != None: + hinge_p.lock_location = True, True, True + hinge_p.lock_rotation = True, True, True + hinge_p.lock_rotation_w = True + hinge_p.lock_scale = True, True, True + # Set up custom properties if self.org_parent != None: prop = rna_idprop_ui_prop_get(uarm_p, "isolate", create=True) diff --git a/rigify/rigs/biped/leg/fk.py b/rigify/rigs/biped/leg/fk.py index e231fa8e..f2ce6653 100644 --- a/rigify/rigs/biped/leg/fk.py +++ b/rigify/rigs/biped/leg/fk.py @@ -158,12 +158,14 @@ class Rig: thigh_p = pb[thigh] shin_p = pb[shin] foot_p = pb[foot] + if self.org_parent != None: + hinge_p = pb[hinge] if self.org_parent != None: socket1_p = pb[socket1] socket2_p = pb[socket2] - # Set the elbow to only bend on the x-axis. + # Set the knee to only bend on the x-axis. shin_p.rotation_mode = 'XYZ' if 'X' in self.primary_rotation_axis: shin_p.lock_rotation = (False, True, True) @@ -172,6 +174,13 @@ class Rig: else: shin_p.lock_rotation = (True, True, False) + # Hinge transforms are locked, for auto-ik + if self.org_parent != None: + hinge_p.lock_location = True, True, True + hinge_p.lock_rotation = True, True, True + hinge_p.lock_rotation_w = True + hinge_p.lock_scale = True, True, True + # Set up custom properties if self.org_parent != None: prop = rna_idprop_ui_prop_get(thigh_p, "isolate", create=True) diff --git a/rigify/rigs/spine.py b/rigify/rigs/spine.py index 2b4558f4..a6bbc747 100644 --- a/rigify/rigs/spine.py +++ b/rigify/rigs/spine.py @@ -508,6 +508,9 @@ class Rig: if w != None: obj_to_bone(w, self.obj, self.org_bones[-1]) + # Layers + pb[main_control].bone.layers = pb[self.org_bones[0]].bone.layers + return [main_control] + controls def generate(self): diff --git a/rigify/ui.py b/rigify/ui.py index a751cfe9..eafa9679 100644 --- a/rigify/ui.py +++ b/rigify/ui.py @@ -81,6 +81,46 @@ class DATA_PT_rigify_buttons(bpy.types.Panel): op.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name +class DATA_PT_rigify_layer_names(bpy.types.Panel): + bl_label = "Rigify Layer Names" + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = "data" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + if not context.armature: + return False + #obj = context.object + #if obj: + # return (obj.mode in ('POSE', 'OBJECT', 'EDIT')) + #return False + return True + + def draw(self, context): + C = context + layout = self.layout + obj = context.object + + if len(obj.data.rigify_props) < 1: + obj.data.rigify_props.add() + + for i in range(28): + if (i % 16) == 0: + col = layout.column() + if i == 0: + col.label(text="Top Row:") + else: + col.label(text="Bottom Row:") + if (i % 8) == 0: + col = layout.column(align=True) + row = col.row() + row.prop(obj.data, "layers", index=i, text="", toggle=True) + row.prop(obj.data.rigify_props[0], "layer_name_%s" % str(i+1).rjust(2, "0"), text="Layer %d" % (i + 1)) + + + class BONE_PT_rigify_buttons(bpy.types.Panel): bl_label = "Rigify Type" bl_space_type = 'PROPERTIES' @@ -243,6 +283,7 @@ class Sample(bpy.types.Operator): #from bl_ui import space_info # ensure the menu is loaded first def register(): + bpy.utils.register_class(DATA_PT_rigify_layer_names) bpy.utils.register_class(DATA_PT_rigify_buttons) bpy.utils.register_class(BONE_PT_rigify_buttons) bpy.utils.register_class(Generate) @@ -252,6 +293,7 @@ def register(): def unregister(): + bpy.utils.unregister_class(DATA_PT_rigify_layer_names) bpy.utils.unregister_class(DATA_PT_rigify_buttons) bpy.utils.unregister_class(BONE_PT_rigify_buttons) bpy.utils.unregister_class(Generate) |