Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UE to Rigify version condition #17

Merged
merged 11 commits into from
Jun 16, 2024
1 change: 1 addition & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_ue2rigify_mannequins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -26,7 +26,7 @@ def test_modes(self):
]
},
'female_root': {
'template': 'female_mannequin',
'template': 'female_mannequin_UE4',
'modes': [
'FK_TO_SOURCE',
'SOURCE_TO_DEFORM',
Expand All @@ -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'}
}
Expand All @@ -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
Expand All @@ -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'],
Expand All @@ -94,7 +94,7 @@ def test_template_sharing(self):
"""
self.run_template_sharing_tests({
'male_root': {
'template': 'male_mannequin',
'template': 'male_mannequin_UE4',
}
})

5 changes: 3 additions & 2 deletions tests/utils/base_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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(
Expand Down
18 changes: 10 additions & 8 deletions ue2rigify/constants.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions ue2rigify/core/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -1417,15 +1417,15 @@ 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

if bone_data:
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,
Expand Down
20 changes: 10 additions & 10 deletions ue2rigify/core/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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((
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

#
Expand Down
26 changes: 12 additions & 14 deletions ue2rigify/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -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():
Expand Down
Loading