From 1be8b1f8350fbbc6a9d38932cd9f5b6c9ca89250 Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 09:09:41 -0500 Subject: [PATCH 01/11] fixed version condition --- ue2rigify/constants.py | 12 +++++++----- ue2rigify/core/scene.py | 10 +++++----- ue2rigify/core/templates.py | 18 +++++++++--------- ue2rigify/core/utilities.py | 32 ++++++++++++++++---------------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/ue2rigify/constants.py b/ue2rigify/constants.py index 19c0c565..9e77c7ed 100644 --- a/ue2rigify/constants.py +++ b/ue2rigify/constants.py @@ -1,8 +1,8 @@ # Copyright Epic Games, Inc. All Rights Reserved. +import bpy import os import tempfile from enum import Enum -from bpy import app class ToolInfo(Enum): @@ -33,10 +33,12 @@ class Nodes: class Template: - if app.version < (4,0,0): - RIG_TEMPLATES_PATH = os.path.join(tempfile.gettempdir(), ToolInfo.NAME.value, 'resources', 'rig_templates\\b3_6') - else: - RIG_TEMPLATES_PATH = os.path.join(tempfile.gettempdir(), ToolInfo.NAME.value, 'resources', 'rig_templates\\b4_0') + @staticmethod + def RIG_TEMPLATES_PATH(): + if bpy.app.version[0] < 4: + return os.path.join(tempfile.gettempdir(), ToolInfo.NAME.value, 'resources', 'rig_templates', 'b3_6') + else: + return os.path.join(tempfile.gettempdir(), ToolInfo.NAME.value, 'resources', 'rig_templates', 'b4_0') DEFAULT_MALE_TEMPLATE = 'male_mannequin_Ue4' DEFAULT_FEMALE_TEMPLATE = 'female_mannequin_Ue4' diff --git a/ue2rigify/core/scene.py b/ue2rigify/core/scene.py index 95ca85aa..616216fc 100644 --- a/ue2rigify/core/scene.py +++ b/ue2rigify/core/scene.py @@ -1344,7 +1344,7 @@ def load_metadata(properties): setattr(rig_object.data, attribute, value) # set the bone groups if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: for bone_group_name, bone_group_data in visual_data.get('bone_groups', {}).items(): bone_group = rig_object.pose.bone_groups.get(bone_group_name) if not bone_group: @@ -1371,7 +1371,7 @@ def load_metadata(properties): bone.use_custom_shape_bone_size = custom_shape_data['use_bone_size'] # set the bone group if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: bone_group = rig_object.pose.bone_groups.get(bone_data.get('bone_group', '')) if bone_group: bone.bone_group = bone_group @@ -1396,7 +1396,7 @@ def save_metadata(properties): }, 'bones': {}, } - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: visual_data['armature']['show_group_colors'] = rig_object.data.show_group_colors visual_data['bone_groups'] = {} else: @@ -1417,7 +1417,7 @@ def save_metadata(properties): 'use_bone_size': bone.use_custom_shape_bone_size } # save bone group if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: if bone.bone_group: bone_data['bone_group'] = bone.bone_group.name @@ -1425,7 +1425,7 @@ def save_metadata(properties): visual_data['bones'][bone.name] = bone_data # save the bone_groups if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: for bone_group in rig_object.pose.bone_groups: visual_data['bone_groups'][bone_group.name] = { 'color_set': bone_group.color_set, diff --git a/ue2rigify/core/templates.py b/ue2rigify/core/templates.py index dff2db43..5043f790 100644 --- a/ue2rigify/core/templates.py +++ b/ue2rigify/core/templates.py @@ -23,10 +23,10 @@ def copy_default_templates(): """ Copies the default addon templates to the user location. """ - template_folder = 'rig_templates/b3_6' if bpy.app.version < (4,0,0) else 'rig_templates/b4_0' - template_location = os.path.join(os.path.dirname(__file__), os.path.pardir, 'resources', template_folder) + sub_folder = 'b3_6' if bpy.app.version[0] < 4 else 'b4_0' + template_location = os.path.join(os.path.dirname(__file__), os.path.pardir, 'resources', 'rig_templates', sub_folder) - shutil.copytree(template_location, Template.RIG_TEMPLATES_PATH, dirs_exist_ok=True) + shutil.copytree(template_location, Template.RIG_TEMPLATES_PATH(), dirs_exist_ok=True) def get_saved_node_data(properties): @@ -189,7 +189,7 @@ def get_rig_templates(self=None, context=None, index_offset=0): :return list: A list of tuples that define the rig template enumeration. """ rig_templates = [] - rig_template_directories = next(os.walk(Template.RIG_TEMPLATES_PATH))[1] + rig_template_directories = next(os.walk(Template.RIG_TEMPLATES_PATH()))[1] # ensure that the male and female template are first rig_templates.append(( @@ -235,7 +235,7 @@ def get_template_file_path(template_file_name, properties): template_name = re.sub(r'\W+', '_', properties.new_template_name).lower() return os.path.join( - Template.RIG_TEMPLATES_PATH, + Template.RIG_TEMPLATES_PATH(), template_name, template_file_name ) @@ -286,7 +286,7 @@ def remove_template_folder(properties, template): properties.selected_mode = Modes.SOURCE.name # delete the selected rig template folder - selected_template_path = os.path.join(Template.RIG_TEMPLATES_PATH, template) + selected_template_path = os.path.join(Template.RIG_TEMPLATES_PATH(), template) import logging logging.info(selected_template_path) @@ -307,7 +307,7 @@ def create_template_folder(template_name, properties): template_name = re.sub(r'\W+', '_', template_name.strip()).lower() # create the template folder - template_path = os.path.join(Template.RIG_TEMPLATES_PATH, template_name) + template_path = os.path.join(Template.RIG_TEMPLATES_PATH(), template_name) if not os.path.exists(template_path): try: original_umask = os.umask(0) @@ -412,7 +412,7 @@ def import_zip(zip_file_path, properties): """ # get the template name and path from the zip file template_name = os.path.basename(zip_file_path).replace('.zip', '') - template_folder_path = os.path.join(Template.RIG_TEMPLATES_PATH, template_name) + template_folder_path = os.path.join((Template.RIG_TEMPLATES_PATH()), template_name) # create the template folder create_template_folder(template_name, properties) @@ -433,7 +433,7 @@ def export_zip(zip_file_path, properties): no_extension_file_path = zip_file_path.replace('.zip', '') # zip up the folder and save it to the given path - template_folder_path = os.path.join(Template.RIG_TEMPLATES_PATH, properties.selected_export_template) + template_folder_path = os.path.join(Template.RIG_TEMPLATES_PATH(), properties.selected_export_template) shutil.make_archive(no_extension_file_path, 'zip', template_folder_path) # diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index 721a43b9..470c9b5a 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -448,7 +448,7 @@ def set_viewport_settings(viewport_settings, properties): previous_settings['red_sphere_bones'] = False if rig_object_settings.get('red_sphere_bones'): # set a give the rig a custom color if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: set_rig_color(rig_object, 'THEME01', True) # create the display object for the bones @@ -469,7 +469,7 @@ def set_viewport_settings(viewport_settings, properties): if rig_object.name != Rigify.CONTROL_RIG_NAME: # remove the custom rig color if b3 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: set_rig_color(rig_object, 'THEME01', False) for bone in rig_object.pose.bones: bone.custom_shape = None @@ -478,7 +478,7 @@ def set_viewport_settings(viewport_settings, properties): else: bone.custom_shape_scale = 1 - if bpy.app.version < (4,0,0): + if bpy.app.version[0] < 4: # set the visible bone layers if b3 if rig_object_settings.get('visible_bone_layers'): visible_bone_layers = [] @@ -698,19 +698,19 @@ def toggle_expand_in_outliner(state=2): :param int state: 1 will expand all collections, 2 will collapse them. """ - area = next(a for a in bpy.context.screen.areas if a.type == 'OUTLINER') - - if bpy.app.version < (4,0,0): - bpy.ops.outliner.show_hierarchy({'area': area}, 'INVOKE_DEFAULT') - for i in range(state): - bpy.ops.outliner.expanded_toggle({'area': area}) - else: - with bpy.context.temp_override(area=area): - bpy.ops.outliner.show_hierarchy('INVOKE_DEFAULT') - for i in range(state): - bpy.ops.outliner.expanded_toggle() - - area.tag_redraw() + try: + for area in bpy.context.screen.areas: + if area.type == 'OUTLINER': + override = {'area': area} + bpy.ops.outliner.show_hierarchy( + override_context=override, + execution_context='INVOKE_DEFAULT' + ) + for i in range(state): + bpy.ops.outliner.expanded_toggle(override_context=override) + area.tag_redraw() + except RuntimeError as error: + print(error) def focus_on_selected(): From 8accd940dd60f004a9ed7032f32f2d69f0228a66 Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 09:31:16 -0500 Subject: [PATCH 02/11] updated template names in test cases --- tests/test_ue2rigify_mannequins.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_ue2rigify_mannequins.py b/tests/test_ue2rigify_mannequins.py index b3612664..3b7bcc7d 100644 --- a/tests/test_ue2rigify_mannequins.py +++ b/tests/test_ue2rigify_mannequins.py @@ -16,7 +16,7 @@ def test_modes(self): """ self.run_modes_tests({ 'male_root': { - 'template': 'male_mannequin', + 'template': 'male_mannequin_UE4', 'modes': [ 'SOURCE', 'FK_TO_SOURCE', @@ -26,7 +26,7 @@ def test_modes(self): ] }, 'female_root': { - 'template': 'female_mannequin', + 'template': 'female_mannequin_UE4', 'modes': [ 'FK_TO_SOURCE', 'SOURCE_TO_DEFORM', @@ -51,7 +51,7 @@ def test_new_template(self): }, 'female_root': { 'new_template_name': 'test_mannequin', - 'starter_template_name': 'female_mannequin', + 'starter_template_name': 'female_mannequin_UE4', 'fk_to_source': {'upper_arm_fk.L': 'upperarm_l'}, 'source_to_deform': {'upperarm_l': 'DEF-upper_arm.L'} } @@ -66,7 +66,7 @@ def test_baking(self): self.run_baking_tests({ # TODO flip animation order and fix failure 'male_root': { - 'template': 'male_mannequin', + 'template': 'male_mannequin_UE4', 'control_rig': 'rig', 'animations': ['third_person_run_01', 'third_person_walk_01'], # 'bones': ['pelvis', 'calf_r', 'foot_l', 'hand_l'], # TODO make this pass with the hands and feet @@ -80,7 +80,7 @@ def test_baking(self): }, # TODO investigate female template fix failure # 'female_root': { - # 'template': 'female_mannequin', + # 'template': 'female_mannequin_UE4', # 'control_rig': 'rig', # 'animations': ['third_person_run_01', 'third_person_walk_01'], # 'bones': ['spine_02', 'calf_l', 'lowerarm_r'], @@ -94,7 +94,7 @@ def test_template_sharing(self): """ self.run_template_sharing_tests({ 'male_root': { - 'template': 'male_mannequin', + 'template': 'male_mannequin_UE4', } }) From c1b51c80a372284b5b29102b143576fd015480e6 Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 10:04:26 -0500 Subject: [PATCH 03/11] updated template names in constants --- ue2rigify/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ue2rigify/constants.py b/ue2rigify/constants.py index 9e77c7ed..5c6f1919 100644 --- a/ue2rigify/constants.py +++ b/ue2rigify/constants.py @@ -40,8 +40,8 @@ def RIG_TEMPLATES_PATH(): else: return os.path.join(tempfile.gettempdir(), ToolInfo.NAME.value, 'resources', 'rig_templates', 'b4_0') - DEFAULT_MALE_TEMPLATE = 'male_mannequin_Ue4' - DEFAULT_FEMALE_TEMPLATE = 'female_mannequin_Ue4' + DEFAULT_MALE_TEMPLATE = 'male_mannequin_UE4' + DEFAULT_FEMALE_TEMPLATE = 'female_mannequin_UE4' class Viewport: From b7fc8aff167cc0d2d7283ef41bffcea6723f209c Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 10:29:51 -0500 Subject: [PATCH 04/11] update the template folder check to account for blender version in test case --- tests/run_tests.py | 1 + tests/utils/base_test_case.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/run_tests.py b/tests/run_tests.py index b16b9267..69a8b764 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -39,6 +39,7 @@ 'UE2RIGIFY_DEV': '1', 'BLENDER_ADDONS': BLENDER_ADDONS, 'BLENDER_PORT': BLENDER_PORT, + 'BLENDER_VERSION': BLENDER_VERSION, 'UNREAL_PORT': UNREAL_PORT, 'HOST_REPO_FOLDER': HOST_REPO_FOLDER, 'CONTAINER_REPO_FOLDER': CONTAINER_REPO_FOLDER, diff --git a/tests/utils/base_test_case.py b/tests/utils/base_test_case.py index 6c3e9691..7fbab7ee 100644 --- a/tests/utils/base_test_case.py +++ b/tests/utils/base_test_case.py @@ -1444,7 +1444,8 @@ def run_template_sharing_tests(self, rigs_and_templates): self.ue2rigify.constants.ToolInfo.NAME.value, 'resources', 'rig_templates', - f'{template_name}_test' + 'b4_0' if int(os.environ.get('BLENDER_VERSION', '4.1').split('.')[0]) >= 4 else 'b3_6' + f'{template_name}_test'.lower() ] template_file_paths = [ From f23cc3f162acd7a87f46f1de4afd65c2eaa7163b Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 12:13:17 -0500 Subject: [PATCH 05/11] forgot comma --- tests/utils/base_test_case.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/base_test_case.py b/tests/utils/base_test_case.py index 7fbab7ee..7694ed54 100644 --- a/tests/utils/base_test_case.py +++ b/tests/utils/base_test_case.py @@ -1444,7 +1444,7 @@ def run_template_sharing_tests(self, rigs_and_templates): self.ue2rigify.constants.ToolInfo.NAME.value, 'resources', 'rig_templates', - 'b4_0' if int(os.environ.get('BLENDER_VERSION', '4.1').split('.')[0]) >= 4 else 'b3_6' + 'b4_0' if int(os.environ.get('BLENDER_VERSION', '4.1').split('.')[0]) >= 4 else 'b3_6', f'{template_name}_test'.lower() ] From b21ef9b96d4534f99e906a01f33287f44717bd27 Mon Sep 17 00:00:00 2001 From: Jack Yao Date: Fri, 14 Jun 2024 13:57:18 -0500 Subject: [PATCH 06/11] fixed case sensitivity with template files --- tests/utils/base_test_case.py | 2 +- ue2rigify/core/templates.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/base_test_case.py b/tests/utils/base_test_case.py index 7694ed54..4df86dc5 100644 --- a/tests/utils/base_test_case.py +++ b/tests/utils/base_test_case.py @@ -1468,7 +1468,7 @@ def run_template_sharing_tests(self, rigs_and_templates): self.addon_name, 'remove_rig_template', None, - {'template': f'{template_name}_test'} + {'template': f'{template_name.lower()}_test'} ) for template_file_path in template_file_paths: self.assertFalse( diff --git a/ue2rigify/core/templates.py b/ue2rigify/core/templates.py index 5043f790..541aa0c1 100644 --- a/ue2rigify/core/templates.py +++ b/ue2rigify/core/templates.py @@ -411,7 +411,7 @@ def import_zip(zip_file_path, properties): :param object properties: The property group that contains variables that maintain the addon's correct state. """ # get the template name and path from the zip file - template_name = os.path.basename(zip_file_path).replace('.zip', '') + template_name = os.path.basename(zip_file_path).replace('.zip', '').lower() template_folder_path = os.path.join((Template.RIG_TEMPLATES_PATH()), template_name) # create the template folder From c9c2ecfd45174846bcfb8e3892c73315f9497a9e Mon Sep 17 00:00:00 2001 From: JoshQuake Date: Fri, 14 Jun 2024 14:57:29 -0700 Subject: [PATCH 07/11] fixed context override solved overriding context. If it can be optimized, feel free. --- ue2rigify/core/utilities.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index 470c9b5a..e6ac803a 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -698,19 +698,15 @@ def toggle_expand_in_outliner(state=2): :param int state: 1 will expand all collections, 2 will collapse them. """ - try: - for area in bpy.context.screen.areas: - if area.type == 'OUTLINER': - override = {'area': area} - bpy.ops.outliner.show_hierarchy( - override_context=override, - execution_context='INVOKE_DEFAULT' - ) + area = next(a for a in bpy.context.screen.areas if a.type == 'OUTLINER') + + for area in bpy.context.screen.areas: + if area.type == 'OUTLINER': + with bpy.context.temp_override(area=area): + bpy.ops.outliner.show_hierarchy('INVOKE_DEFAULT') for i in range(state): - bpy.ops.outliner.expanded_toggle(override_context=override) - area.tag_redraw() - except RuntimeError as error: - print(error) + bpy.ops.outliner.expanded_toggle() + area.tag_redraw() def focus_on_selected(): From a765315caffdfa05536aa9bca70408a82c013237 Mon Sep 17 00:00:00 2001 From: JoshQuake Date: Fri, 14 Jun 2024 16:06:19 -0700 Subject: [PATCH 08/11] removed invoke_default --- ue2rigify/core/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index e6ac803a..7d984192 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -703,7 +703,7 @@ def toggle_expand_in_outliner(state=2): for area in bpy.context.screen.areas: if area.type == 'OUTLINER': with bpy.context.temp_override(area=area): - bpy.ops.outliner.show_hierarchy('INVOKE_DEFAULT') + bpy.ops.outliner.show_hierarchy() for i in range(state): bpy.ops.outliner.expanded_toggle() area.tag_redraw() From 46760763442c1df8733125024106ad97244da1a6 Mon Sep 17 00:00:00 2001 From: JoshQuake Date: Sat, 15 Jun 2024 14:44:05 -0700 Subject: [PATCH 09/11] regions test --- ue2rigify/core/utilities.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index 7d984192..161b7108 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -702,10 +702,14 @@ def toggle_expand_in_outliner(state=2): for area in bpy.context.screen.areas: if area.type == 'OUTLINER': + print(f'Area: ${area.type}') with bpy.context.temp_override(area=area): - bpy.ops.outliner.show_hierarchy() - for i in range(state): - bpy.ops.outliner.expanded_toggle() + for region in area.regions: + print(f'Region: ${region.type}') + if region.type == 'WINDOW': + bpy.ops.outliner.show_hierarchy() + for i in range(state): + bpy.ops.outliner.expanded_toggle() area.tag_redraw() From edf64ff1ad224b032515c6727bf00fcde1f9398a Mon Sep 17 00:00:00 2001 From: JoshQuake Date: Sat, 15 Jun 2024 15:05:05 -0700 Subject: [PATCH 10/11] added region override --- ue2rigify/core/utilities.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index 161b7108..3ebce4c1 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -703,14 +703,14 @@ def toggle_expand_in_outliner(state=2): for area in bpy.context.screen.areas: if area.type == 'OUTLINER': print(f'Area: ${area.type}') - with bpy.context.temp_override(area=area): - for region in area.regions: - print(f'Region: ${region.type}') - if region.type == 'WINDOW': + for region in area.regions: + print(f'Region: ${region.type}') + if region.type == 'WINDOW': + with bpy.context.temp_override(area=area, region=region): bpy.ops.outliner.show_hierarchy() for i in range(state): bpy.ops.outliner.expanded_toggle() - area.tag_redraw() + area.tag_redraw() def focus_on_selected(): From 8025cc0ae9db76b083b3f3c1d54f2d6f81018074 Mon Sep 17 00:00:00 2001 From: JoshQuake Date: Sat, 15 Jun 2024 15:31:42 -0700 Subject: [PATCH 11/11] removed test prints --- ue2rigify/core/utilities.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ue2rigify/core/utilities.py b/ue2rigify/core/utilities.py index 3ebce4c1..998fd756 100644 --- a/ue2rigify/core/utilities.py +++ b/ue2rigify/core/utilities.py @@ -702,9 +702,7 @@ def toggle_expand_in_outliner(state=2): for area in bpy.context.screen.areas: if area.type == 'OUTLINER': - print(f'Area: ${area.type}') for region in area.regions: - print(f'Region: ${region.type}') if region.type == 'WINDOW': with bpy.context.temp_override(area=area, region=region): bpy.ops.outliner.show_hierarchy()