Changeset View
Changeset View
Standalone View
Standalone View
rigify/ui.py
| Show All 26 Lines | |||||
| ) | ) | ||||
| from mathutils import Color | from mathutils import Color | ||||
| from .utils import MetarigError | from .utils import MetarigError | ||||
| from .utils import write_metarig, write_widget | from .utils import write_metarig, write_widget | ||||
| from .utils import unique_name | from .utils import unique_name | ||||
| from .utils import upgradeMetarigTypes, outdated_types | from .utils import upgradeMetarigTypes, outdated_types | ||||
| from .utils import get_keyed_frames, bones_in_frame | |||||
| from .utils import overwrite_prop_animation | |||||
| from .rigs.utils import get_limb_generated_names | 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 rig_lists | ||||
| from . import generate | from . import generate | ||||
| from . import rot_mode | from . import rot_mode | ||||
| from . import feature_set_list | from . import feature_set_list | ||||
| def build_type_list(context, rigify_types): | def build_type_list(context, rigify_types): | ||||
| rigify_types.clear() | rigify_types.clear() | ||||
| ▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Lines | def draw(self, context): | ||||
| if rig_name != "": | if rig_name != "": | ||||
| try: | try: | ||||
| rig = rig_lists.rigs[rig_name]['module'] | rig = rig_lists.rigs[rig_name]['module'] | ||||
| except (ImportError, AttributeError): | except (ImportError, AttributeError): | ||||
| row = layout.row() | row = layout.row() | ||||
| box = row.box() | box = row.box() | ||||
| box.label(text="ALERT: type \"%s\" does not exist!" % rig_name) | box.label(text="ALERT: type \"%s\" does not exist!" % rig_name) | ||||
| else: | else: | ||||
| if hasattr(rig.Rig, 'parameters_ui'): | |||||
| rig = rig.Rig | |||||
| try: | try: | ||||
| rig.parameters_ui | rig.parameters_ui | ||||
| except AttributeError: | except AttributeError: | ||||
| col = layout.column() | col = layout.column() | ||||
| col.label(text="No options") | col.label(text="No options") | ||||
| else: | else: | ||||
| col = layout.column() | col = layout.column() | ||||
| col.label(text="Options:") | col.label(text="Options:") | ||||
| Show All 33 Lines | class VIEW3D_PT_rigify_animation_tools(bpy.types.Panel): | ||||
| bl_label = "Rigify Animation Tools" | bl_label = "Rigify Animation Tools" | ||||
| bl_context = "posemode" | bl_context = "posemode" | ||||
| bl_space_type = 'VIEW_3D' | bl_space_type = 'VIEW_3D' | ||||
| bl_region_type = 'UI' | bl_region_type = 'UI' | ||||
| bl_category = 'View' | bl_category = 'View' | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return context.object and context.object.type == 'ARMATURE'\ | obj = context.active_object | ||||
| and context.active_object.data.get("rig_id") is not None | if obj and obj.type == 'ARMATURE': | ||||
| rig_id = obj.data.get("rig_id") | |||||
| if rig_id is not None: | |||||
| has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id) | |||||
| has_leg = hasattr(bpy.types, 'POSE_OT_rigify_leg_ik2fk_' + rig_id) | |||||
| return has_arm or has_leg | |||||
| return False | |||||
| def draw(self, context): | def draw(self, context): | ||||
| obj = context.active_object | obj = context.active_object | ||||
| id_store = context.window_manager | id_store = context.window_manager | ||||
| if obj is not None: | if obj is not None: | ||||
| row = self.layout.row() | row = self.layout.row() | ||||
| if id_store.rigify_transfer_only_selected: | if id_store.rigify_transfer_only_selected: | ||||
| Show All 19 Lines | def draw(self, context): | ||||
| op = row.operator("rigify.rotation_pole", icon='FORCE_HARMONIC', text='Switch to pole') | op = row.operator("rigify.rotation_pole", icon='FORCE_HARMONIC', text='Switch to pole') | ||||
| op.value = True | op.value = True | ||||
| op.toggle = False | op.toggle = False | ||||
| op.bake = True | op.bake = True | ||||
| op = row.operator("rigify.rotation_pole", icon='FORCE_MAGNETIC', text='Switch to rotation') | op = row.operator("rigify.rotation_pole", icon='FORCE_MAGNETIC', text='Switch to rotation') | ||||
| op.value = False | op.value = False | ||||
| op.toggle = False | op.toggle = False | ||||
| op.bake = True | op.bake = True | ||||
| row = self.layout.row(align=True) | RIGIFY_OT_get_frame_range.draw_range_ui(context, self.layout) | ||||
| row.prop(id_store, 'rigify_transfer_start_frame') | |||||
| row.prop(id_store, 'rigify_transfer_end_frame') | |||||
| row.operator("rigify.get_frame_range", icon='TIME', text='') | |||||
| def rigify_report_exception(operator, exception): | def rigify_report_exception(operator, exception): | ||||
| import traceback | import traceback | ||||
| import sys | import sys | ||||
| import os | import os | ||||
| # find the module name where the error happened | # find the non-utils module name where the error happened | ||||
| # hint, this is the metarig type! | # hint, this is the metarig type! | ||||
| exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() | exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() | ||||
| fn = traceback.extract_tb(exceptionTraceback)[-1][0] | fns = [ item.filename for item in traceback.extract_tb(exceptionTraceback) ] | ||||
| fns_rig = [ fn for fn in fns if os.path.basename(os.path.dirname(fn)) != 'utils' ] | |||||
| fn = fns_rig[-1] | |||||
| fn = os.path.basename(fn) | fn = os.path.basename(fn) | ||||
| fn = os.path.splitext(fn)[0] | fn = os.path.splitext(fn)[0] | ||||
| message = [] | message = [] | ||||
| if fn.startswith("__"): | if fn.startswith("__"): | ||||
| message.append("Incorrect armature...") | message.append("Incorrect armature...") | ||||
| else: | else: | ||||
| message.append("Incorrect armature for type '%s'" % fn) | message.append("Incorrect armature for type '%s'" % fn) | ||||
| message.append(exception.message) | message.append(exception.message) | ||||
| Show All 30 Lines | class Generate(bpy.types.Operator): | ||||
| def execute(self, context): | def execute(self, context): | ||||
| import importlib | import importlib | ||||
| importlib.reload(generate) | importlib.reload(generate) | ||||
| try: | try: | ||||
| generate.generate_rig(context, context.object) | generate.generate_rig(context, context.object) | ||||
| except MetarigError as rig_exception: | except MetarigError as rig_exception: | ||||
| import traceback | |||||
| traceback.print_exc() | |||||
| rigify_report_exception(self, rig_exception) | rigify_report_exception(self, rig_exception) | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class UpgradeMetarigTypes(bpy.types.Operator): | class UpgradeMetarigTypes(bpy.types.Operator): | ||||
| """Upgrades metarig bones rigify_types""" | """Upgrades metarig bones rigify_types""" | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| text = write_widget(context.active_object) | text = write_widget(context.active_object) | ||||
| text_block.write(text) | text_block.write(text) | ||||
| bpy.ops.object.mode_set(mode='EDIT') | bpy.ops.object.mode_set(mode='EDIT') | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class OBJECT_OT_GetFrameRange(bpy.types.Operator): | |||||
| """Get start and end frame range""" | |||||
| bl_idname = "rigify.get_frame_range" | |||||
| bl_label = "Get Frame Range" | |||||
| def execute(self, context): | |||||
| scn = context.scene | |||||
| id_store = context.window_manager | |||||
| id_store.rigify_transfer_start_frame = scn.frame_start | |||||
| id_store.rigify_transfer_end_frame = scn.frame_end | |||||
| return {'FINISHED'} | |||||
| def FktoIk(rig, window='ALL'): | def FktoIk(rig, window='ALL'): | ||||
| scn = bpy.context.scene | scn = bpy.context.scene | ||||
| id_store = bpy.context.window_manager | id_store = bpy.context.window_manager | ||||
| rig_id = rig.data['rig_id'] | rig_id = rig.data['rig_id'] | ||||
| leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id) | leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id) | ||||
| arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id) | arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id) | ||||
| limb_generated_names = get_limb_generated_names(rig) | limb_generated_names = get_limb_generated_names(rig) | ||||
| if window == 'ALL': | if window == 'ALL': | ||||
| frames = get_keyed_frames(rig) | frames = get_keyed_frames_in_range(bpy.context, rig) | ||||
| frames = [f for f in frames if f in range(id_store.rigify_transfer_start_frame, id_store.rigify_transfer_end_frame+1)] | |||||
| elif window == 'CURRENT': | elif window == 'CURRENT': | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| else: | else: | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| if not id_store.rigify_transfer_only_selected: | if not id_store.rigify_transfer_only_selected: | ||||
| pbones = rig.pose.bones | pbones = rig.pose.bones | ||||
| bpy.ops.pose.select_all(action='DESELECT') | bpy.ops.pose.select_all(action='DESELECT') | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | def IktoFk(rig, window='ALL'): | ||||
| id_store = bpy.context.window_manager | id_store = bpy.context.window_manager | ||||
| rig_id = rig.data['rig_id'] | rig_id = rig.data['rig_id'] | ||||
| leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id) | leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id) | ||||
| arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id) | arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id) | ||||
| limb_generated_names = get_limb_generated_names(rig) | limb_generated_names = get_limb_generated_names(rig) | ||||
| if window == 'ALL': | if window == 'ALL': | ||||
| frames = get_keyed_frames(rig) | frames = get_keyed_frames_in_range(bpy.context, rig) | ||||
| frames = [f for f in frames if f in range(id_store.rigify_transfer_start_frame, id_store.rigify_transfer_end_frame+1)] | |||||
| elif window == 'CURRENT': | elif window == 'CURRENT': | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| else: | else: | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| if not id_store.rigify_transfer_only_selected: | if not id_store.rigify_transfer_only_selected: | ||||
| bpy.ops.pose.select_all(action='DESELECT') | bpy.ops.pose.select_all(action='DESELECT') | ||||
| pbones = rig.pose.bones | pbones = rig.pose.bones | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | def rotPoleToggle(rig, window='ALL', value=False, toggle=False, bake=False): | ||||
| rig_id = rig.data['rig_id'] | rig_id = rig.data['rig_id'] | ||||
| leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id) | leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id) | ||||
| arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id) | arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id) | ||||
| leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id) | leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id) | ||||
| arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id) | arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id) | ||||
| limb_generated_names = get_limb_generated_names(rig) | limb_generated_names = get_limb_generated_names(rig) | ||||
| if window == 'ALL': | if window == 'ALL': | ||||
| frames = get_keyed_frames(rig) | frames = get_keyed_frames_in_range(bpy.context, rig) | ||||
| frames = [f for f in frames if f in range(id_store.rigify_transfer_start_frame, id_store.rigify_transfer_end_frame+1)] | |||||
| elif window == 'CURRENT': | elif window == 'CURRENT': | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| else: | else: | ||||
| frames = [scn.frame_current] | frames = [scn.frame_current] | ||||
| if not id_store.rigify_transfer_only_selected: | if not id_store.rigify_transfer_only_selected: | ||||
| bpy.ops.pose.select_all(action='DESELECT') | bpy.ops.pose.select_all(action='DESELECT') | ||||
| pbones = rig.pose.bones | pbones = rig.pose.bones | ||||
| ▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | classes = ( | ||||
| LayerInit, | LayerInit, | ||||
| Generate, | Generate, | ||||
| UpgradeMetarigTypes, | UpgradeMetarigTypes, | ||||
| SwitchToLegacy, | SwitchToLegacy, | ||||
| Sample, | Sample, | ||||
| EncodeMetarig, | EncodeMetarig, | ||||
| EncodeMetarigSample, | EncodeMetarigSample, | ||||
| EncodeWidget, | EncodeWidget, | ||||
| OBJECT_OT_GetFrameRange, | |||||
| OBJECT_OT_FK2IK, | OBJECT_OT_FK2IK, | ||||
| OBJECT_OT_IK2FK, | OBJECT_OT_IK2FK, | ||||
| OBJECT_OT_TransferFKtoIK, | OBJECT_OT_TransferFKtoIK, | ||||
| OBJECT_OT_TransferIKtoFK, | OBJECT_OT_TransferIKtoFK, | ||||
| OBJECT_OT_ClearAnimation, | OBJECT_OT_ClearAnimation, | ||||
| OBJECT_OT_Rot2Pole, | OBJECT_OT_Rot2Pole, | ||||
| ) | ) | ||||
| def register(): | def register(): | ||||
| from bpy.utils import register_class | from bpy.utils import register_class | ||||
| animation_register() | |||||
| # Classes. | # Classes. | ||||
| for cls in classes: | for cls in classes: | ||||
| register_class(cls) | register_class(cls) | ||||
| # Sub-modules. | # Sub-modules. | ||||
| rot_mode.register() | rot_mode.register() | ||||
| def unregister(): | def unregister(): | ||||
| from bpy.utils import unregister_class | from bpy.utils import unregister_class | ||||
| # Sub-modules. | # Sub-modules. | ||||
| rot_mode.unregister() | rot_mode.unregister() | ||||
| # Classes. | # Classes. | ||||
| for cls in classes: | for cls in classes: | ||||
| unregister_class(cls) | unregister_class(cls) | ||||
| animation_unregister() | |||||