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.get_installed_list()) == 0
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):
if not context.object:
return False
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'}:
armature_id_store = C.object.data
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():
old_bone = b.name
old_rig = b.rigify_type
Alexander Gavrilov
committed
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="("+old_rig+" on bone "+old_bone+")")
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="("+old_rig+" on bone "+old_bone+")")
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
if armature_id_store.rigify_advanced_generation:
Lucio Rossi
committed
icon = 'UNLOCKED'
else:
icon = 'LOCKED'
col = layout.column()
col.enabled = enable_generate_and_advanced
row = col.row()
row.prop(armature_id_store, "rigify_advanced_generation", toggle=True, icon=icon)
if armature_id_store.rigify_advanced_generation:
row = col.row(align=True)
row.prop(armature_id_store, "rigify_generate_mode", expand=True)
Lucio Rossi
committed
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 = (armature_id_store.rigify_generate_mode == "overwrite")
Lucio Rossi
committed
row = col1.row()
row.label(text="Target UI")
row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
row = col2.row(align=True)
row.prop(armature_id_store, "rigify_rig_basename", text="", icon="SORTALPHA")
Lucio Rossi
committed
row = col2.row(align=True)
row.prop(armature_id_store, "rigify_target_rig", text="")
row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
row = col2.row()
row.prop(armature_id_store, "rigify_rig_ui", text="", icon='TEXT')
row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
row = col.row()
row.prop(armature_id_store, "rigify_force_widget_update")
if armature_id_store.rigify_generate_mode == 'new':
Lucio Rossi
committed
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.get_installed_list()) > 0:
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')
props = layout.operator("armature.metarig_sample_add", text="Add sample")
props.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name
Nathan Vegdahl
committed
class DATA_PT_rigify_layer_names(bpy.types.Panel):
bl_label = "Rigify Layer Names"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
Loading
Loading full blame...