diff options
author | Nathan Vegdahl <cessen@cessen.com> | 2011-05-17 00:02:22 +0400 |
---|---|---|
committer | Nathan Vegdahl <cessen@cessen.com> | 2011-05-17 00:02:22 +0400 |
commit | 4339115f5d506487cba2e6400758440c1b464561 (patch) | |
tree | bfbf9f6ed4aaee9f7e611e03eab04f9d1b15986e /rigify | |
parent | 8b339cdad2a63d5f409e794357c939d2e9297763 (diff) |
Rigify: user can disable control and deform rig generation on copy and copy_chain.
Diffstat (limited to 'rigify')
-rw-r--r-- | rigify/rigs/basic/copy.py | 54 | ||||
-rw-r--r-- | rigify/rigs/basic/copy_chain.py | 112 |
2 files changed, 116 insertions, 50 deletions
diff --git a/rigify/rigs/basic/copy.py b/rigify/rigs/basic/copy.py index ed6d7816..22beedf1 100644 --- a/rigify/rigs/basic/copy.py +++ b/rigify/rigs/basic/copy.py @@ -36,6 +36,8 @@ class Rig: self.org_bone = bone self.org_name = strip_org(bone) self.params = params + self.make_control = params.make_control + self.make_deform = params.make_deform def generate(self): """ Generate the rig. @@ -46,31 +48,57 @@ class Rig: bpy.ops.object.mode_set(mode='EDIT') # Make a control bone (copy of original). - bone = copy_bone(self.obj, self.org_bone, self.org_name) + if self.make_control: + bone = copy_bone(self.obj, self.org_bone, self.org_name) # Make a deformation bone (copy of original, child of original). - def_bone = copy_bone(self.obj, self.org_bone, make_deformer_name(self.org_name)) + if self.make_deform: + def_bone = copy_bone(self.obj, self.org_bone, make_deformer_name(self.org_name)) # Get edit bones eb = self.obj.data.edit_bones - bone_e = eb[bone] - def_bone_e = eb[def_bone] + if self.make_control: + bone_e = eb[bone] + if self.make_deform: + def_bone_e = eb[def_bone] # Parent - def_bone_e.use_connect = False - def_bone_e.parent = eb[self.org_bone] + if self.make_deform: + def_bone_e.use_connect = False + def_bone_e.parent = eb[self.org_bone] bpy.ops.object.mode_set(mode='OBJECT') pb = self.obj.pose.bones - # Constrain the original bone. - con = pb[self.org_bone].constraints.new('COPY_TRANSFORMS') - con.name = "copy_transforms" - con.target = self.obj - con.subtarget = bone + if self.make_control: + # Constrain the original bone. + con = pb[self.org_bone].constraints.new('COPY_TRANSFORMS') + con.name = "copy_transforms" + con.target = self.obj + con.subtarget = bone - # Create control widget - create_bone_widget(self.obj, bone) + # Create control widget + create_bone_widget(self.obj, bone) + + @classmethod + def add_parameters(self, group): + """ Add the parameters of this rig type to the + RigifyParameters PropertyGroup + """ + group.make_control = bpy.props.BoolProperty(name="Control", default=True, description="Create a control bone for the copy.") + group.make_deform = bpy.props.BoolProperty(name="Deform", default=True, description="Create a deform bone for the copy.") + + + @classmethod + def parameters_ui(self, layout, obj, bone): + """ Create the ui for the rig parameters. + """ + params = obj.pose.bones[bone].rigify_parameters[0] + + r = layout.row() + r.prop(params, "make_control") + r = layout.row() + r.prop(params, "make_deform") @classmethod def create_sample(self, obj): diff --git a/rigify/rigs/basic/copy_chain.py b/rigify/rigs/basic/copy_chain.py index 930e025b..4910ef82 100644 --- a/rigify/rigs/basic/copy_chain.py +++ b/rigify/rigs/basic/copy_chain.py @@ -36,6 +36,8 @@ class Rig: self.obj = obj self.org_bones = [bone_name] + connected_children_names(obj, bone_name) self.params = params + self.make_controls = params.make_controls + self.make_deforms = params.make_deforms if len(self.org_bones) <= 1: raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones." % (strip_org(bone))) @@ -55,51 +57,87 @@ class Rig: for i in range(len(self.org_bones)): name = self.org_bones[i] - # Create bones - def_bone = copy_bone(self.obj, name) - ctrl_bone = copy_bone(self.obj, name) - - # Get edit bones - eb = self.obj.data.edit_bones - def_bone_e = eb[def_bone] - ctrl_bone_e = eb[ctrl_bone] - - # Set their names - def_bone_e.name = make_deformer_name(strip_org(name)) - ctrl_bone_e.name = strip_org(name) - - # Add them to their respective lists - def_chain += [def_bone_e.name] - ctrl_chain += [ctrl_bone_e.name] - - # Parenting - if i == 0: - # First bone - def_bone_e.parent = eb[self.org_bones[i]].parent - ctrl_bone_e.parent = eb[self.org_bones[i]].parent + # Control bone + if self.make_controls: + # Copy + ctrl_bone = copy_bone(self.obj, name) + eb = self.obj.data.edit_bones + ctrl_bone_e = eb[ctrl_bone] + # Name + ctrl_bone_e.name = strip_org(name) + # Parenting + if i == 0: + # First bone + ctrl_bone_e.parent = eb[self.org_bones[0]].parent + else: + # The rest + ctrl_bone_e.parent = eb[ctrl_chain[-1]] + # Add to list + ctrl_chain += [ctrl_bone_e.name] else: - # The rest - def_bone_e.parent = eb[def_chain[i-1]] - ctrl_bone_e.parent = eb[ctrl_chain[i-1]] + ctrl_chain += [None] + + # Deformation bone + if self.make_deforms: + # Copy + def_bone = copy_bone(self.obj, name) + eb = self.obj.data.edit_bones + def_bone_e = eb[def_bone] + # Name + def_bone_e.name = make_deformer_name(strip_org(name)) + # Parenting + if i == 0: + # First bone + def_bone_e.parent = eb[self.org_bones[0]].parent + else: + # The rest + def_bone_e.parent = eb[def_chain[-1]] + # Add to list + def_chain += [def_bone_e.name] + else: + def_chain += [None] bpy.ops.object.mode_set(mode='OBJECT') pb = self.obj.pose.bones - # Constraint org and def to the control bones + # Constraints for org and def for org, ctrl, defrm in zip(self.org_bones, ctrl_chain, def_chain): - con = pb[org].constraints.new('COPY_TRANSFORMS') - con.name = "copy_transforms" - con.target = self.obj - con.subtarget = ctrl - - con = pb[defrm].constraints.new('COPY_TRANSFORMS') - con.name = "copy_transforms" - con.target = self.obj - con.subtarget = ctrl + if self.make_controls: + con = pb[org].constraints.new('COPY_TRANSFORMS') + con.name = "copy_transforms" + con.target = self.obj + con.subtarget = ctrl + + if self.make_deforms: + con = pb[defrm].constraints.new('COPY_TRANSFORMS') + con.name = "copy_transforms" + con.target = self.obj + con.subtarget = org # Create control widgets - for bone in ctrl_chain: - create_bone_widget(self.obj, bone) + if self.make_controls: + for bone in ctrl_chain: + create_bone_widget(self.obj, bone) + + @classmethod + def add_parameters(self, group): + """ Add the parameters of this rig type to the + RigifyParameters PropertyGroup + """ + group.make_controls = bpy.props.BoolProperty(name="Controls", default=True, description="Create control bones for the copy.") + group.make_deforms = bpy.props.BoolProperty(name="Deform", default=True, description="Create deform bones for the copy.") + + + @classmethod + def parameters_ui(self, layout, obj, bone): + """ Create the ui for the rig parameters. + """ + params = obj.pose.bones[bone].rigify_parameters[0] + + r = layout.row() + r.prop(params, "make_controls") + r = layout.row() + r.prop(params, "make_deforms") @classmethod def create_sample(self, obj): |