diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-03-30 22:00:55 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-14 09:29:26 +0300 |
commit | 3423174b37a0784dc12035ff3f2fb536835099e1 (patch) | |
tree | 3a54580902cdebdef5ebacd6099e86cc79ba75b3 /rigify/rigs/basic/super_copy.py | |
parent | 12af8a28c14b608e9b9b08568d981273c86590c1 (diff) |
Rigify: redesign generate.py and introduce a base rig class.
The main goals are to provide an official way for rigs to
interact in a structured way, and to remove mode switching
within rigs.
This involves introducing a base class for rigs that holds
rig-to-rig and rig-to-bone references, converting the main
generator into a class and passing it to rigs, and splitting
the single generate method into multiple passes.
For backward compatibility, old rigs are automatically handled
via a wrapper that translates between old and new API.
In addition, a way to create objects that receive the generate
callbacks that aren't rigs is introduced via the GeneratorPlugin
class. The UI script generation code is converted into a plugin.
Making generic rig 'template' classes that are intended to be
subclassed in specific rigs involves splitting operations done
in each stage into multiple methods that can be overridden
separately. The main callback thus ends up simply calling a
sequence of other methods.
To make such code cleaner it's better to allow registering
those methods as new callbacks that would be automatically
called by the system. This can be done via decorators.
A new metaclass used for all rig and generate plugin classes
builds and validates a table of all decorated methods, and
allows calling them all together with the main callback.
A new way to switch parents for IK bones based on the new
features is introduced, and used in the existing limb rigs.
Reviewers: icappiello campbellbarton
Differential Revision: https://developer.blender.org/D4624
Diffstat (limited to 'rigify/rigs/basic/super_copy.py')
-rw-r--r-- | rigify/rigs/basic/super_copy.py | 151 |
1 files changed, 79 insertions, 72 deletions
diff --git a/rigify/rigs/basic/super_copy.py b/rigify/rigs/basic/super_copy.py index b2045346..5abbf22e 100644 --- a/rigify/rigs/basic/super_copy.py +++ b/rigify/rigs/basic/super_copy.py @@ -20,107 +20,112 @@ import bpy -from ...utils import copy_bone -from ...utils import strip_org, make_deformer_name -from ...utils import create_bone_widget, create_circle_widget +from ...base_rig import BaseRig +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 constrain it. 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. """ - self.obj = obj - 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.org_name = strip_org(self.bones.org) - """ - bpy.ops.object.mode_set(mode='EDIT') + self.make_control = self.params.make_control + 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). 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). 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: - def_bone_e.use_connect = False - def_bone_e.parent = eb[self.org_bone] + self.set_bone_parent(bones.deform, bones.org, use_connect=False) + - 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: # Constrain the original bone. - con = pb[self.org_bone].constraints.new('COPY_TRANSFORMS') - con.name = "copy_transforms" - con.target = self.obj - con.subtarget = bone + self.make_constraint(bones.org, 'COPY_TRANSFORMS', bones.ctrl) + + def generate_widgets(self): + bones = self.bones + + if self.make_control: # Create control 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: - create_bone_widget(self.obj, bone) + create_bone_widget(self.obj, bones.ctrl) -def add_parameters(params): - """ Add the parameters of this rig type to the - RigifyParameters PropertyGroup - """ - params.make_control = bpy.props.BoolProperty( - name = "Control", - default = True, - description = "Create a control bone for the copy" - ) - - params.make_widget = bpy.props.BoolProperty( - name = "Widget", - default = True, - description = "Choose a widget for the bone control" - ) - - params.make_deform = bpy.props.BoolProperty( - name = "Deform", - default = True, - description = "Create a deform bone for the copy" - ) - - -def parameters_ui(layout, params): - """ Create the ui for the rig parameters. - """ - r = layout.row() - r.prop(params, "make_control") - r = layout.row() - r.prop(params, "make_widget") - r.enabled = params.make_control - r = layout.row() - r.prop(params, "make_deform") + @classmethod + def add_parameters(self, params): + """ Add the parameters of this rig type to the + RigifyParameters PropertyGroup + """ + params.make_control = bpy.props.BoolProperty( + name = "Control", + default = True, + description = "Create a control bone for the copy" + ) + + params.make_widget = bpy.props.BoolProperty( + name = "Widget", + default = True, + description = "Choose a widget for the bone control" + ) + + params.make_deform = bpy.props.BoolProperty( + name = "Deform", + default = True, + description = "Create a deform bone for the copy" + ) + + + @classmethod + def parameters_ui(self, layout, params): + """ Create the ui for the rig parameters. + """ + r = layout.row() + r.prop(params, "make_control") + r = layout.row() + r.prop(params, "make_widget") + r.enabled = params.make_control + r = layout.row() + r.prop(params, "make_deform") def create_sample(obj): @@ -159,3 +164,5 @@ def create_sample(obj): bone.select_head = True bone.select_tail = True arm.edit_bones.active = bone + + return bones |