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/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', } }) diff --git a/tests/utils/base_test_case.py b/tests/utils/base_test_case.py index 6c3e9691..4df86dc5 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 = [ @@ -1467,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/constants.py b/ue2rigify/constants.py index 19c0c565..5c6f1919 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,13 +33,15 @@ 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') - - DEFAULT_MALE_TEMPLATE = 'male_mannequin_Ue4' - DEFAULT_FEMALE_TEMPLATE = 'female_mannequin_Ue4' + @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' class Viewport: 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..541aa0c1 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) @@ -411,8 +411,8 @@ 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_folder_path = os.path.join(Template.RIG_TEMPLATES_PATH, template_name) + 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 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..998fd756 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 = [] @@ -700,17 +700,15 @@ def toggle_expand_in_outliner(state=2): """ 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() + for area in bpy.context.screen.areas: + if area.type == 'OUTLINER': + for region in area.regions: + 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() def focus_on_selected():