Skip to content
Snippets Groups Projects
ui.py 50.1 KiB
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 ========================

# <pep8 compliant>

import bpy
from bpy.props import (
    BoolProperty,
    IntProperty,
    EnumProperty,
    StringProperty
)

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


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


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
        if obj.mode in {'POSE', 'OBJECT'}:
            armature_id_store = C.object.data
            WARNING = "Warning: Some features may change after generation"
            show_warning = False
            show_update_metarig = False

            check_props = ['IK_follow', 'root/parent', 'FK_limb_follow', 'IK_Stretch']
            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
                    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()
            # 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')
            row.enabled = enable_generate_and_advanced

            if armature_id_store.rigify_advanced_generation:

            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.prop(armature_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()
                col1.label(text="Rig Name")
                row = col1.row()
                row.label(text="Target Rig")
                row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
                row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
                row.prop(armature_id_store, "rigify_rig_basename", text="", icon="SORTALPHA")
                row.prop(armature_id_store, "rigify_target_rig", text="")
                row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
                row.prop(armature_id_store, "rigify_rig_ui", text="", icon='TEXT')
                row.enabled = (armature_id_store.rigify_generate_mode == "overwrite")
                row.prop(armature_id_store, "rigify_force_widget_update")
                if armature_id_store.rigify_generate_mode == 'new':
        elif obj.mode == 'EDIT':
            # Build types list
            build_type_list(context, id_store.rigify_types)
            if id_store.rigify_active_type > len(id_store.rigify_types):
                id_store.rigify_active_type = 0

            # Rig type list
            if len(feature_set_list.get_installed_list()) > 0:
                row = layout.row()
                row.prop(context.object.data, "active_feature_set")
            row = layout.row()
            row.template_list("UI_UL_list", "rigify_types", id_store, "rigify_types", id_store, 'rigify_active_type')
Campbell Barton's avatar
Campbell Barton committed
            props = layout.operator("armature.metarig_sample_add", text="Add sample")
            props.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name
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...