|
20 | 20 |
|
21 | 21 | import bpy
|
22 | 22 |
|
23 |
| -from ...utils import MetarigError |
24 |
| -from ...utils import copy_bone |
25 |
| -from ...utils import connected_children_names |
26 |
| -from ...utils import strip_org, make_deformer_name |
27 |
| -from ...utils import create_bone_widget |
| 23 | +from ..chain_rigs import SimpleChainRig |
28 | 24 |
|
| 25 | +from ...utils.errors import MetarigError |
| 26 | +from ...utils.rig import connected_children_names |
| 27 | +from ...utils.naming import strip_org, make_deformer_name |
| 28 | +from ...utils.widgets_basic import create_bone_widget |
| 29 | +from ...utils.misc import map_list, map_apply |
29 | 30 |
|
30 |
| -class Rig: |
| 31 | +from ...base_rig import * |
| 32 | + |
| 33 | + |
| 34 | +class Rig(SimpleChainRig): |
31 | 35 | """ A "copy_chain" rig. All it does is duplicate the original bone chain
|
32 | 36 | and constrain it.
|
33 | 37 | This is a control and deformation rig.
|
34 |
| -
|
35 | 38 | """
|
36 |
| - def __init__(self, obj, bone_name, params): |
| 39 | + def initialize(self): |
| 40 | + super(Rig,self).initialize() |
| 41 | + |
37 | 42 | """ Gather and validate data about the rig.
|
38 | 43 | """
|
39 |
| - self.obj = obj |
40 |
| - self.org_bones = [bone_name] + connected_children_names(obj, bone_name) |
41 |
| - self.params = params |
42 |
| - self.make_controls = params.make_controls |
43 |
| - self.make_deforms = params.make_deforms |
| 44 | + self.make_controls = self.params.make_controls |
| 45 | + self.make_deforms = self.params.make_deforms |
44 | 46 |
|
45 |
| - if len(self.org_bones) <= 1: |
46 |
| - raise MetarigError("RIGIFY ERROR: Bone '%s': input to rig type must be a chain of 2 or more bones" % (strip_org(bone_name))) |
| 47 | + ############################## |
| 48 | + # Control chain |
47 | 49 |
|
48 |
| - def generate(self): |
49 |
| - """ Generate the rig. |
50 |
| - Do NOT modify any of the original bones, except for adding constraints. |
51 |
| - The main armature should be selected and active before this is called. |
| 50 | + @stage_generate_bones |
| 51 | + def make_control_chain(self): |
| 52 | + if self.make_controls: |
| 53 | + super(Rig,self).make_control_chain() |
52 | 54 |
|
53 |
| - """ |
54 |
| - bpy.ops.object.mode_set(mode='EDIT') |
55 |
| - |
56 |
| - # Create the deformation and control bone chains. |
57 |
| - # Just copies of the original chain. |
58 |
| - def_chain = [] |
59 |
| - ctrl_chain = [] |
60 |
| - for i in range(len(self.org_bones)): |
61 |
| - name = self.org_bones[i] |
62 |
| - |
63 |
| - # Control bone |
64 |
| - if self.make_controls: |
65 |
| - # Copy |
66 |
| - ctrl_bone = copy_bone(self.obj, name) |
67 |
| - eb = self.obj.data.edit_bones |
68 |
| - ctrl_bone_e = eb[ctrl_bone] |
69 |
| - # Name |
70 |
| - ctrl_bone_e.name = strip_org(name) |
71 |
| - # Parenting |
72 |
| - if i == 0: |
73 |
| - # First bone |
74 |
| - ctrl_bone_e.parent = eb[self.org_bones[0]].parent |
75 |
| - else: |
76 |
| - # The rest |
77 |
| - ctrl_bone_e.parent = eb[ctrl_chain[-1]] |
78 |
| - # Add to list |
79 |
| - ctrl_chain += [ctrl_bone_e.name] |
80 |
| - else: |
81 |
| - ctrl_chain += [None] |
82 |
| - |
83 |
| - # Deformation bone |
84 |
| - if self.make_deforms: |
85 |
| - # Copy |
86 |
| - def_bone = copy_bone(self.obj, name) |
87 |
| - eb = self.obj.data.edit_bones |
88 |
| - def_bone_e = eb[def_bone] |
89 |
| - # Name |
90 |
| - def_bone_e.name = make_deformer_name(strip_org(name)) |
91 |
| - # Parenting |
92 |
| - if i == 0: |
93 |
| - # First bone |
94 |
| - def_bone_e.parent = eb[self.org_bones[0]].parent |
95 |
| - else: |
96 |
| - # The rest |
97 |
| - def_bone_e.parent = eb[def_chain[-1]] |
98 |
| - # Add to list |
99 |
| - def_chain += [def_bone_e.name] |
100 |
| - else: |
101 |
| - def_chain += [None] |
102 |
| - |
103 |
| - bpy.ops.object.mode_set(mode='OBJECT') |
104 |
| - pb = self.obj.pose.bones |
105 |
| - |
106 |
| - # Constraints for org and def |
107 |
| - for org, ctrl, defrm in zip(self.org_bones, ctrl_chain, def_chain): |
108 |
| - if self.make_controls: |
109 |
| - con = pb[org].constraints.new('COPY_TRANSFORMS') |
110 |
| - con.name = "copy_transforms" |
111 |
| - con.target = self.obj |
112 |
| - con.subtarget = ctrl |
113 |
| - |
114 |
| - if self.make_deforms: |
115 |
| - con = pb[defrm].constraints.new('COPY_TRANSFORMS') |
116 |
| - con.name = "copy_transforms" |
117 |
| - con.target = self.obj |
118 |
| - con.subtarget = org |
119 |
| - |
120 |
| - # Create control widgets |
| 55 | + @stage_parent_bones |
| 56 | + def parent_control_chain(self): |
121 | 57 | if self.make_controls:
|
122 |
| - for bone in ctrl_chain: |
123 |
| - create_bone_widget(self.obj, bone) |
| 58 | + super(Rig,self).parent_control_chain() |
124 | 59 |
|
| 60 | + @stage_configure_bones |
| 61 | + def configure_control_chain(self): |
| 62 | + if self.make_controls: |
| 63 | + super(Rig,self).configure_control_chain() |
125 | 64 |
|
126 |
| -def add_parameters(params): |
127 |
| - """ Add the parameters of this rig type to the |
128 |
| - RigifyParameters PropertyGroup |
129 |
| - """ |
130 |
| - params.make_controls = bpy.props.BoolProperty(name="Controls", default=True, description="Create control bones for the copy") |
131 |
| - params.make_deforms = bpy.props.BoolProperty(name="Deform", default=True, description="Create deform bones for the copy") |
| 65 | + @stage_generate_widgets |
| 66 | + def make_control_widgets(self): |
| 67 | + if self.make_controls: |
| 68 | + super(Rig,self).make_control_widgets() |
132 | 69 |
|
| 70 | + ############################## |
| 71 | + # ORG chain |
133 | 72 |
|
134 |
| -def parameters_ui(layout, params): |
135 |
| - """ Create the ui for the rig parameters. |
136 |
| - """ |
137 |
| - r = layout.row() |
138 |
| - r.prop(params, "make_controls") |
139 |
| - r = layout.row() |
140 |
| - r.prop(params, "make_deforms") |
| 73 | + @stage_rig_bones |
| 74 | + def rig_org_chain(self): |
| 75 | + if self.make_controls: |
| 76 | + super(Rig,self).rig_org_chain() |
| 77 | + |
| 78 | + ############################## |
| 79 | + # Deform chain |
| 80 | + |
| 81 | + @stage_generate_bones |
| 82 | + def make_deform_chain(self): |
| 83 | + if self.make_deforms: |
| 84 | + super(Rig,self).make_deform_chain() |
| 85 | + |
| 86 | + @stage_parent_bones |
| 87 | + def parent_deform_chain(self): |
| 88 | + if self.make_deforms: |
| 89 | + super(Rig,self).parent_deform_chain() |
| 90 | + |
| 91 | + @stage_rig_bones |
| 92 | + def rig_deform_chain(self): |
| 93 | + if self.make_deforms: |
| 94 | + super(Rig,self).rig_deform_chain() |
| 95 | + |
| 96 | + |
| 97 | + @classmethod |
| 98 | + def add_parameters(self, params): |
| 99 | + """ Add the parameters of this rig type to the |
| 100 | + RigifyParameters PropertyGroup |
| 101 | + """ |
| 102 | + params.make_controls = bpy.props.BoolProperty(name="Controls", default=True, description="Create control bones for the copy") |
| 103 | + params.make_deforms = bpy.props.BoolProperty(name="Deform", default=True, description="Create deform bones for the copy") |
| 104 | + |
| 105 | + |
| 106 | + @classmethod |
| 107 | + def parameters_ui(self, layout, params): |
| 108 | + """ Create the ui for the rig parameters. |
| 109 | + """ |
| 110 | + r = layout.row() |
| 111 | + r.prop(params, "make_controls") |
| 112 | + r = layout.row() |
| 113 | + r.prop(params, "make_deforms") |
141 | 114 |
|
142 | 115 |
|
143 | 116 | def create_sample(obj):
|
|
0 commit comments