|
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 | + |
| 32 | +class Rig(SimpleChainRig): |
31 | 33 | """ A "copy_chain" rig. All it does is duplicate the original bone chain
|
32 | 34 | and constrain it.
|
33 | 35 | This is a control and deformation rig.
|
34 |
| -
|
35 | 36 | """
|
36 |
| - def __init__(self, obj, bone_name, params): |
| 37 | + def initialize(self): |
| 38 | + super(Rig,self).initialize() |
| 39 | + |
37 | 40 | """ Gather and validate data about the rig.
|
38 | 41 | """
|
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 |
| 42 | + self.make_controls = self.params.make_controls |
| 43 | + self.make_deforms = self.params.make_deforms |
44 | 44 |
|
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 | 45 |
|
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. |
| 46 | + def generate_bones(self): |
| 47 | + # Create the deformation and control bone chains. |
| 48 | + if self.make_controls: |
| 49 | + self.make_control_chain() |
52 | 50 |
|
53 |
| - """ |
54 |
| - bpy.ops.object.mode_set(mode='EDIT') |
| 51 | + if self.make_deforms: |
| 52 | + self.make_deform_chain() |
| 53 | + |
| 54 | + |
| 55 | + def parent_bones(self): |
| 56 | + if self.make_controls: |
| 57 | + self.parent_control_chain() |
| 58 | + |
| 59 | + if self.make_deforms: |
| 60 | + self.parent_deform_chain() |
55 | 61 |
|
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 | 62 |
|
| 63 | + def configure_bones(self): |
| 64 | + if self.make_controls: |
| 65 | + self.configure_control_chain() |
| 66 | + |
| 67 | + |
| 68 | + def rig_bones(self): |
| 69 | + # Create the deformation and control bone chain constraints. |
| 70 | + if self.make_controls: |
| 71 | + self.rig_org_chain() |
| 72 | + |
| 73 | + if self.make_deforms: |
| 74 | + self.rig_deform_chain() |
| 75 | + |
| 76 | + |
| 77 | + def generate_widgets(self): |
120 | 78 | # Create control widgets
|
121 | 79 | if self.make_controls:
|
122 |
| - for bone in ctrl_chain: |
123 |
| - create_bone_widget(self.obj, bone) |
| 80 | + self.make_control_widgets() |
124 | 81 |
|
125 | 82 |
|
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") |
| 83 | + @classmethod |
| 84 | + def add_parameters(self, params): |
| 85 | + """ Add the parameters of this rig type to the |
| 86 | + RigifyParameters PropertyGroup |
| 87 | + """ |
| 88 | + params.make_controls = bpy.props.BoolProperty(name="Controls", default=True, description="Create control bones for the copy") |
| 89 | + params.make_deforms = bpy.props.BoolProperty(name="Deform", default=True, description="Create deform bones for the copy") |
132 | 90 |
|
133 | 91 |
|
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") |
| 92 | + @classmethod |
| 93 | + def parameters_ui(self, layout, params): |
| 94 | + """ Create the ui for the rig parameters. |
| 95 | + """ |
| 96 | + r = layout.row() |
| 97 | + r.prop(params, "make_controls") |
| 98 | + r = layout.row() |
| 99 | + r.prop(params, "make_deforms") |
141 | 100 |
|
142 | 101 |
|
143 | 102 | def create_sample(obj):
|
|
0 commit comments