1 #====================== BEGIN GPL LICENSE BLOCK ======================
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #======================= END GPL LICENSE BLOCK ========================
24 "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello",
25 "blender": (2, 78, 0),
26 "description": "Automatic rigging from building-block components",
27 "location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu",
28 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
29 "Scripts/Rigging/Rigify",
30 "category": "Rigging"}
35 importlib
.reload(generate
)
37 importlib
.reload(utils
)
38 importlib
.reload(metarig_menu
)
39 importlib
.reload(rig_lists
)
41 from . import utils
, rig_lists
, generate
, ui
, metarig_menu
46 from bpy
.types
import AddonPreferences
47 from bpy
.props
import BoolProperty
50 class RigifyPreferences(AddonPreferences
):
51 # this must match the addon name, use '__package__'
52 # when defining this in a submodule of a python package.
55 def update_legacy(self
, context
):
58 if 'ui' in globals() and 'legacy' in str(globals()['ui']): # already in legacy mode. needed when rigify is reloaded
61 rigify_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
62 if rigify_dir
not in sys
.path
:
63 sys
.path
.append(rigify_dir
)
67 globals().pop('utils')
68 globals().pop('rig_lists')
69 globals().pop('generate')
71 globals().pop('metarig_menu')
74 import legacy
.rig_lists
75 import legacy
.generate
77 import legacy
.metarig_menu
79 print("ENTERING RIGIFY LEGACY\r\n")
81 globals()['utils'] = legacy
.utils
82 globals()['rig_lists'] = legacy
.rig_lists
83 globals()['generate'] = legacy
.generate
84 globals()['ui'] = legacy
.ui
85 globals()['metarig_menu'] = legacy
.metarig_menu
91 rigify_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
93 if rigify_dir
in sys
.path
:
94 id = sys
.path
.index(rigify_dir
)
99 globals().pop('utils')
100 globals().pop('rig_lists')
101 globals().pop('generate')
103 globals().pop('metarig_menu')
106 from . import rig_lists
107 from . import generate
109 from . import metarig_menu
111 print("EXIT RIGIFY LEGACY\r\n")
113 globals()['utils'] = utils
114 globals()['rig_lists'] = rig_lists
115 globals()['generate'] = generate
117 globals()['metarig_menu'] = metarig_menu
121 legacy_mode
= BoolProperty(
122 name
='Rigify Legacy Mode',
123 description
='Select if you want to use Rigify in legacy mode',
128 show_expanded
= BoolProperty()
130 def draw(self
, context
):
132 column
= layout
.column()
136 expand
= getattr(self
, 'show_expanded')
137 icon
= 'TRIA_DOWN' if expand
else 'TRIA_RIGHT'
141 sub
.context_pointer_set('addon_prefs', self
)
142 sub
.alignment
= 'LEFT'
143 op
= sub
.operator('wm.context_toggle', text
='', icon
=icon
,
145 op
.data_path
= 'addon_prefs.show_expanded'
146 sub
.label('{}: {}'.format('Rigify', 'Enable Legacy Mode'))
148 sub
.alignment
= 'RIGHT'
149 sub
.prop(self
, 'legacy_mode')
152 split
= col
.row().split(percentage
=0.15)
153 split
.label('Description:')
154 split
.label(text
='When enabled the add-on will run in legacy mode using the old 2.76b feature set.')
157 row
.label("End of Rigify Preferences")
160 class RigifyName(bpy
.types
.PropertyGroup
):
161 name
= bpy
.props
.StringProperty()
164 class RigifyColorSet(bpy
.types
.PropertyGroup
):
165 name
= bpy
.props
.StringProperty(name
="Color Set", default
=" ")
166 active
= bpy
.props
.FloatVectorProperty(
169 default
=(1.0, 1.0, 1.0),
171 description
="color picker"
173 normal
= bpy
.props
.FloatVectorProperty(
176 default
=(1.0, 1.0, 1.0),
178 description
="color picker"
180 select
= bpy
.props
.FloatVectorProperty(
183 default
=(1.0, 1.0, 1.0),
185 description
="color picker"
187 standard_colors_lock
= bpy
.props
.BoolProperty(default
=True)
190 class RigifySelectionColors(bpy
.types
.PropertyGroup
):
192 select
= bpy
.props
.FloatVectorProperty(
195 default
=(0.314, 0.784, 1.0),
197 description
="color picker"
200 active
= bpy
.props
.FloatVectorProperty(
203 default
=(0.549, 1.0, 1.0),
205 description
="color picker"
209 class RigifyParameters(bpy
.types
.PropertyGroup
):
210 name
= bpy
.props
.StringProperty()
213 class RigifyArmatureLayer(bpy
.types
.PropertyGroup
):
216 if 'group_prop' in self
.keys():
217 return self
['group_prop']
221 def set_group(self
, value
):
222 arm
= bpy
.context
.object.data
223 if value
> len(arm
.rigify_colors
):
224 self
['group_prop'] = len(arm
.rigify_colors
)
226 self
['group_prop'] = value
228 name
= bpy
.props
.StringProperty(name
="Layer Name", default
=" ")
229 row
= bpy
.props
.IntProperty(name
="Layer Row", default
=1, min=1, max=32, description
='UI row for this layer')
230 set = bpy
.props
.BoolProperty(name
="Selection Set", default
=False, description
='Add Selection Set for this layer')
231 group
= bpy
.props
.IntProperty(name
="Bone Group", default
=0, min=0, max=32,
232 get
=get_group
, set=set_group
, description
='Assign Bone Group to this layer')
238 metarig_menu
.register()
240 bpy
.utils
.register_class(RigifyName
)
241 bpy
.utils
.register_class(RigifyParameters
)
243 bpy
.utils
.register_class(RigifyColorSet
)
244 bpy
.utils
.register_class(RigifySelectionColors
)
245 bpy
.utils
.register_class(RigifyArmatureLayer
)
246 bpy
.utils
.register_class(RigifyPreferences
)
247 bpy
.types
.Armature
.rigify_layers
= bpy
.props
.CollectionProperty(type=RigifyArmatureLayer
)
249 bpy
.types
.PoseBone
.rigify_type
= bpy
.props
.StringProperty(name
="Rigify Type", description
="Rig type for this bone")
250 bpy
.types
.PoseBone
.rigify_parameters
= bpy
.props
.PointerProperty(type=RigifyParameters
)
252 bpy
.types
.Armature
.rigify_colors
= bpy
.props
.CollectionProperty(type=RigifyColorSet
)
254 bpy
.types
.Armature
.rigify_selection_colors
= bpy
.props
.PointerProperty(type=RigifySelectionColors
)
256 bpy
.types
.Armature
.rigify_colors_index
= bpy
.props
.IntProperty(default
=-1)
257 bpy
.types
.Armature
.rigify_colors_lock
= bpy
.props
.BoolProperty(default
=True)
258 bpy
.types
.Armature
.rigify_theme_to_add
= bpy
.props
.EnumProperty(items
=(('THEME01', 'THEME01', ''),
259 ('THEME02', 'THEME02', ''),
260 ('THEME03', 'THEME03', ''),
261 ('THEME04', 'THEME04', ''),
262 ('THEME05', 'THEME05', ''),
263 ('THEME06', 'THEME06', ''),
264 ('THEME07', 'THEME07', ''),
265 ('THEME08', 'THEME08', ''),
266 ('THEME09', 'THEME09', ''),
267 ('THEME10', 'THEME10', ''),
268 ('THEME11', 'THEME11', ''),
269 ('THEME12', 'THEME12', ''),
270 ('THEME13', 'THEME13', ''),
271 ('THEME14', 'THEME14', ''),
272 ('THEME15', 'THEME15', ''),
273 ('THEME16', 'THEME16', ''),
274 ('THEME17', 'THEME17', ''),
275 ('THEME18', 'THEME18', ''),
276 ('THEME19', 'THEME19', ''),
277 ('THEME20', 'THEME20', '')
280 IDStore
= bpy
.types
.WindowManager
281 IDStore
.rigify_collection
= bpy
.props
.EnumProperty(items
=rig_lists
.col_enum_list
, default
="All",
282 name
="Rigify Active Collection",
283 description
="The selected rig collection")
285 IDStore
.rigify_types
= bpy
.props
.CollectionProperty(type=RigifyName
)
286 IDStore
.rigify_active_type
= bpy
.props
.IntProperty(name
="Rigify Active Type", description
="The selected rig type")
288 IDStore
.rigify_advanced_generation
= bpy
.props
.BoolProperty(name
="Advanced Options",
289 description
="Enables/disables advanced options for Rigify rig generation",
292 def update_mode(self
, context
):
293 if self
.rigify_generate_mode
== 'new':
294 self
.rigify_force_widget_update
= False
296 IDStore
.rigify_generate_mode
= bpy
.props
.EnumProperty(name
="Rigify Generate Rig Mode",
297 description
="'Generate Rig' mode. In 'overwrite' mode the features of the target rig will be updated as defined by the metarig. In 'new' mode a new rig will be created as defined by the metarig. Current mode",
299 items
=(('overwrite', 'overwrite', ''),
302 IDStore
.rigify_force_widget_update
= bpy
.props
.BoolProperty(name
="Force Widget Update",
303 description
="Forces Rigify to delete and rebuild all the rig widgets. if unset, only missing widgets will be created",
306 IDStore
.rigify_target_rigs
= bpy
.props
.CollectionProperty(type=RigifyName
)
307 IDStore
.rigify_target_rig
= bpy
.props
.StringProperty(name
="Rigify Target Rig",
308 description
="Defines which rig to overwrite. If unset, a new one called 'rig' will be created",
311 IDStore
.rigify_rig_uis
= bpy
.props
.CollectionProperty(type=RigifyName
)
312 IDStore
.rigify_rig_ui
= bpy
.props
.StringProperty(name
="Rigify Target Rig UI",
313 description
="Defines the UI to overwrite. It should always be the same as the target rig. If unset, 'rig_ui.py' will be used",
316 IDStore
.rigify_rig_basename
= bpy
.props
.StringProperty(name
="Rigify Rig Name",
317 description
="Defines the name of the Rig. If unset, in 'new' mode 'rig' will be used, in 'overwrite' mode the target rig name will be used",
320 IDStore
.rigify_transfer_only_selected
= bpy
.props
.BoolProperty(name
="Transfer Only Selected", description
="Transfer selected bones only", default
=True)
321 IDStore
.rigify_transfer_start_frame
= bpy
.props
.IntProperty(name
="Start Frame", description
="First Frame to Transfer", default
=0, min= 0)
322 IDStore
.rigify_transfer_end_frame
= bpy
.props
.IntProperty(name
="End Frame", description
="Last Frame to Transfer", default
=0, min= 0)
324 if (ui
and 'legacy' in str(ui
)) or bpy
.context
.user_preferences
.addons
['rigify'].preferences
.legacy_mode
:
325 # update legacy on restart or reload
326 bpy
.context
.user_preferences
.addons
['rigify'].preferences
.legacy_mode
= True
329 for rig
in rig_lists
.rig_list
:
330 r
= utils
.get_rig_type(rig
)
332 r
.add_parameters(RigifyParameters
)
333 except AttributeError:
338 del bpy
.types
.PoseBone
.rigify_type
339 del bpy
.types
.PoseBone
.rigify_parameters
341 IDStore
= bpy
.types
.WindowManager
342 del IDStore
.rigify_collection
343 del IDStore
.rigify_types
344 del IDStore
.rigify_active_type
345 del IDStore
.rigify_advanced_generation
346 del IDStore
.rigify_generate_mode
347 del IDStore
.rigify_force_widget_update
348 del IDStore
.rigify_target_rig
349 del IDStore
.rigify_target_rigs
350 del IDStore
.rigify_rig_uis
351 del IDStore
.rigify_rig_ui
352 del IDStore
.rigify_rig_basename
353 del IDStore
.rigify_transfer_only_selected
354 del IDStore
.rigify_transfer_start_frame
355 del IDStore
.rigify_transfer_end_frame
357 bpy
.utils
.unregister_class(RigifyName
)
358 bpy
.utils
.unregister_class(RigifyParameters
)
360 bpy
.utils
.unregister_class(RigifyColorSet
)
361 bpy
.utils
.unregister_class(RigifySelectionColors
)
363 bpy
.utils
.unregister_class(RigifyArmatureLayer
)
364 bpy
.utils
.unregister_class(RigifyPreferences
)
366 metarig_menu
.unregister()