Changeset View
Changeset View
Standalone View
Standalone View
rigify/rigs/basic/super_copy.py
| Show All 14 Lines | |||||
| # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| # | # | ||||
| #======================= END GPL LICENSE BLOCK ======================== | #======================= END GPL LICENSE BLOCK ======================== | ||||
| # <pep8 compliant> | # <pep8 compliant> | ||||
| import bpy | import bpy | ||||
| from ...utils import copy_bone | from ...base_rig import BaseRig | ||||
| from ...utils import strip_org, make_deformer_name | |||||
| from ...utils import create_bone_widget, create_circle_widget | |||||
| from ...utils.naming import strip_org, make_deformer_name | |||||
| from ...utils.widgets_basic import create_bone_widget, create_circle_widget | |||||
| class Rig: | |||||
| class Rig(BaseRig): | |||||
| """ A "copy" rig. All it does is duplicate the original bone and | """ A "copy" rig. All it does is duplicate the original bone and | ||||
| constrain it. | constrain it. | ||||
| This is a control and deformation rig. | This is a control and deformation rig. | ||||
| """ | """ | ||||
| def __init__(self, obj, bone, params): | def find_org_bones(self, pose_bone): | ||||
| return pose_bone.name | |||||
| def initialize(self): | |||||
| """ Gather and validate data about the rig. | """ Gather and validate data about the rig. | ||||
| """ | """ | ||||
| self.obj = obj | self.org_name = strip_org(self.bones.org) | ||||
| self.org_bone = bone | |||||
| self.org_name = strip_org(bone) | |||||
| self.params = params | |||||
| self.make_control = params.make_control | |||||
| self.make_widget = params.make_widget | |||||
| self.make_deform = params.make_deform | |||||
| def generate(self): | |||||
| """ Generate the rig. | |||||
| Do NOT modify any of the original bones, except for adding constraints. | |||||
| The main armature should be selected and active before this is called. | |||||
| """ | self.make_control = self.params.make_control | ||||
| bpy.ops.object.mode_set(mode='EDIT') | self.make_widget = self.params.make_widget | ||||
| self.make_deform = self.params.make_deform | |||||
| def generate_bones(self): | |||||
| bones = self.bones | |||||
| # Make a control bone (copy of original). | # Make a control bone (copy of original). | ||||
| if self.make_control: | if self.make_control: | ||||
| bone = copy_bone(self.obj, self.org_bone, self.org_name) | bones.ctrl = self.copy_bone(bones.org, self.org_name, parent=True) | ||||
| # Make a deformation bone (copy of original, child of original). | # Make a deformation bone (copy of original, child of original). | ||||
| if self.make_deform: | if self.make_deform: | ||||
| def_bone = copy_bone(self.obj, self.org_bone, make_deformer_name(self.org_name)) | bones.deform = self.copy_bone(bones.org, make_deformer_name(self.org_name), bbone=True) | ||||
| # Get edit bones | |||||
| eb = self.obj.data.edit_bones | |||||
| # UNUSED | |||||
| # if self.make_control: | |||||
| # bone_e = eb[bone] | |||||
| if self.make_deform: | |||||
| def_bone_e = eb[def_bone] | |||||
| # Parent | def parent_bones(self): | ||||
| bones = self.bones | |||||
| if self.make_deform: | if self.make_deform: | ||||
| def_bone_e.use_connect = False | self.set_bone_parent(bones.deform, bones.org, use_connect=False) | ||||
| def_bone_e.parent = eb[self.org_bone] | |||||
| bpy.ops.object.mode_set(mode='OBJECT') | |||||
| pb = self.obj.pose.bones | def configure_bones(self): | ||||
| bones = self.bones | |||||
| if self.make_control: | |||||
| self.copy_bone_properties(bones.org, bones.ctrl) | |||||
| def rig_bones(self): | |||||
| bones = self.bones | |||||
| if self.make_control: | if self.make_control: | ||||
| # Constrain the original bone. | # Constrain the original bone. | ||||
| con = pb[self.org_bone].constraints.new('COPY_TRANSFORMS') | self.make_constraint(bones.org, 'COPY_TRANSFORMS', bones.ctrl) | ||||
| con.name = "copy_transforms" | |||||
| con.target = self.obj | |||||
| con.subtarget = bone | |||||
| def generate_widgets(self): | |||||
| bones = self.bones | |||||
| if self.make_control: | |||||
| # Create control widget | # Create control widget | ||||
| if self.make_widget: | if self.make_widget: | ||||
| create_circle_widget(self.obj, bone, radius=0.5) | create_circle_widget(self.obj, bones.ctrl, radius=0.5) | ||||
| else: | else: | ||||
| create_bone_widget(self.obj, bone) | create_bone_widget(self.obj, bones.ctrl) | ||||
| def add_parameters(params): | @classmethod | ||||
| def add_parameters(self, params): | |||||
| """ Add the parameters of this rig type to the | """ Add the parameters of this rig type to the | ||||
| RigifyParameters PropertyGroup | RigifyParameters PropertyGroup | ||||
| """ | """ | ||||
| params.make_control = bpy.props.BoolProperty( | params.make_control = bpy.props.BoolProperty( | ||||
| name = "Control", | name = "Control", | ||||
| default = True, | default = True, | ||||
| description = "Create a control bone for the copy" | description = "Create a control bone for the copy" | ||||
| ) | ) | ||||
| params.make_widget = bpy.props.BoolProperty( | params.make_widget = bpy.props.BoolProperty( | ||||
| name = "Widget", | name = "Widget", | ||||
| default = True, | default = True, | ||||
| description = "Choose a widget for the bone control" | description = "Choose a widget for the bone control" | ||||
| ) | ) | ||||
| params.make_deform = bpy.props.BoolProperty( | params.make_deform = bpy.props.BoolProperty( | ||||
| name = "Deform", | name = "Deform", | ||||
| default = True, | default = True, | ||||
| description = "Create a deform bone for the copy" | description = "Create a deform bone for the copy" | ||||
| ) | ) | ||||
| def parameters_ui(layout, params): | @classmethod | ||||
| def parameters_ui(self, layout, params): | |||||
| """ Create the ui for the rig parameters. | """ Create the ui for the rig parameters. | ||||
| """ | """ | ||||
| r = layout.row() | r = layout.row() | ||||
| r.prop(params, "make_control") | r.prop(params, "make_control") | ||||
| r = layout.row() | r = layout.row() | ||||
| r.prop(params, "make_widget") | r.prop(params, "make_widget") | ||||
| r.enabled = params.make_control | r.enabled = params.make_control | ||||
| r = layout.row() | r = layout.row() | ||||
| r.prop(params, "make_deform") | r.prop(params, "make_deform") | ||||
| def create_sample(obj): | def create_sample(obj): | ||||
| """ Create a sample metarig for this rig type. | """ Create a sample metarig for this rig type. | ||||
| """ | """ | ||||
| # generated by rigify.utils.write_metarig | # generated by rigify.utils.write_metarig | ||||
| bpy.ops.object.mode_set(mode='EDIT') | bpy.ops.object.mode_set(mode='EDIT') | ||||
| arm = obj.data | arm = obj.data | ||||
| Show All 30 Lines | |||||