Newer
Older
#====================== BEGIN GPL LICENSE BLOCK ======================
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#======================= END GPL LICENSE BLOCK ========================
from bpy.props import (
BoolProperty,
IntProperty,
EnumProperty,
StringProperty
)
from mathutils import Color
Alexander Gavrilov
committed
from .utils.errors import MetarigError
from .utils.rig import write_metarig
from .utils.widgets import write_widget
from .utils.naming import unique_name
from .utils.rig import upgradeMetarigTypes, outdated_types
from .rigs.utils import get_limb_generated_names
from .utils.animation import get_keyed_frames_in_range, bones_in_frame, overwrite_prop_animation
from .utils.animation import RIGIFY_OT_get_frame_range
from .utils.animation import register as animation_register
from .utils.animation import unregister as animation_unregister
from . import base_rig
from . import rig_lists
from . import generate
from . import rot_mode
from . import feature_set_list
Alexander Gavrilov
committed
def build_type_list(context, rigify_types):
rigify_types.clear()
for r in sorted(rig_lists.rigs):
if (context.object.data.active_feature_set in ('all', rig_lists.rigs[r]['feature_set'])
or len(feature_set_list.feature_set_items(context.scene, context)) == 2
Alexander Gavrilov
committed
):
a = rigify_types.add()
a.name = r
class DATA_PT_rigify_buttons(bpy.types.Panel):
bl_label = "Rigify Buttons"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE' and context.active_object.data.get("rig_id") is None
def draw(self, context):
C = context
layout = self.layout
obj = context.object
Campbell Barton
committed
id_store = C.window_manager
if obj.mode in {'POSE', 'OBJECT'}:
WARNING = "Warning: Some features may change after generation"
show_warning = False
show_not_updatable = False
check_props = ['IK_follow', 'root/parent', 'FK_limb_follow', 'IK_Stretch']
Alexander Gavrilov
committed
for bone in obj.pose.bones:
if bone.bone.layers[30] and (list(set(bone.keys()) & set(check_props))):
show_warning = True
break
for b in obj.pose.bones:
if b.rigify_type in outdated_types.keys():
if outdated_types[b.rigify_type]:
show_update_metarig = True
else:
show_update_metarig = False
show_not_updatable = True
break
if show_warning:
layout.label(text=WARNING, icon='ERROR')
if show_not_updatable:
layout.label(text="WARNING: This metarig contains deprecated rigify rig-types and cannot be upgraded automatically.", icon='ERROR')
layout.label(text="If you want to use it anyway try enabling the legacy mode before generating again.")
layout.operator("pose.rigify_switch_to_legacy", text="Switch to Legacy")
enable_generate_and_advanced = not (show_not_updatable or show_update_metarig)
if show_update_metarig:
layout.label(text="This metarig contains old rig-types that can be automatically upgraded to benefit of rigify's new features.", icon='ERROR')
layout.label(text="To use it as-is you need to enable legacy mode.",)
layout.operator("pose.rigify_upgrade_types", text="Upgrade Metarig")
row = layout.row()
Alexander Gavrilov
committed
# Rig type field
col = layout.column(align=True)
col.active = (not 'rig_id' in C.object.data)
col.separator()
row = col.row()
row.operator("pose.rigify_generate", text="Generate Rig", icon='POSE_HLT')
Alexander Gavrilov
committed
row.enabled = enable_generate_and_advanced
Lucio Rossi
committed
if id_store.rigify_advanced_generation:
icon = 'UNLOCKED'
else:
icon = 'LOCKED'
col = layout.column()
col.enabled = enable_generate_and_advanced
row = col.row()
row.prop(id_store, "rigify_advanced_generation", toggle=True, icon=icon)
if id_store.rigify_advanced_generation:
row = col.row(align=True)
Lucio Rossi
committed
row.prop(id_store, "rigify_generate_mode", expand=True)
main_row = col.row(align=True).split(factor=0.3)
col1 = main_row.column()
col2 = main_row.column()
Lucio Rossi
committed
col1.label(text="Rig Name")
row = col1.row()
row.label(text="Target Rig")
row.enabled = (id_store.rigify_generate_mode == "overwrite")
row = col1.row()
row.label(text="Target UI")
row.enabled = (id_store.rigify_generate_mode == "overwrite")
row = col2.row(align=True)
Lucio Rossi
committed
row.prop(id_store, "rigify_rig_basename", text="", icon="SORTALPHA")
Lucio Rossi
committed
row = col2.row(align=True)
for i in range(0, len(id_store.rigify_target_rigs)):
id_store.rigify_target_rigs.remove(0)
for ob in context.scene.objects:
if type(ob.data) == bpy.types.Armature and "rig_id" in ob.data:
id_store.rigify_target_rigs.add()
id_store.rigify_target_rigs[-1].name = ob.name
row.prop_search(id_store, "rigify_target_rig", id_store, "rigify_target_rigs", text="",
icon='OUTLINER_OB_ARMATURE')
Lucio Rossi
committed
row.enabled = (id_store.rigify_generate_mode == "overwrite")
for i in range(0, len(id_store.rigify_rig_uis)):
id_store.rigify_rig_uis.remove(0)
for t in bpy.data.texts:
id_store.rigify_rig_uis.add()
id_store.rigify_rig_uis[-1].name = t.name
row = col2.row()
row.prop_search(id_store, "rigify_rig_ui", id_store, "rigify_rig_uis", text="", icon='TEXT')
Lucio Rossi
committed
row.enabled = (id_store.rigify_generate_mode == "overwrite")
row = col.row()
Lucio Rossi
committed
row.prop(id_store, "rigify_force_widget_update")
if id_store.rigify_generate_mode == 'new':
row.enabled = False
elif obj.mode == 'EDIT':
# Build types list
Alexander Gavrilov
committed
build_type_list(context, id_store.rigify_types)
Alexander Gavrilov
committed
if id_store.rigify_active_type > len(id_store.rigify_types):
id_store.rigify_active_type = 0
if len(feature_set_list.feature_set_items(context.scene, context)) > 2:
Alexander Gavrilov
committed
row = layout.row()
row.prop(context.object.data, "active_feature_set")
row.template_list("UI_UL_list", "rigify_types", id_store, "rigify_types", id_store, 'rigify_active_type')
Loading
Loading full blame...