Skip to content

Commit

Permalink
Showing 4 changed files with 37 additions and 35 deletions.
12 changes: 7 additions & 5 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):
@@ -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'
10 changes: 5 additions & 5 deletions ue2rigify/core/scene.py
Original file line number Diff line number Diff line change
@@ -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,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,
18 changes: 9 additions & 9 deletions ue2rigify/core/templates.py
Original file line number Diff line number Diff line change
@@ -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)

#
32 changes: 16 additions & 16 deletions ue2rigify/core/utilities.py
Original file line number Diff line number Diff line change
@@ -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():

0 comments on commit 1be8b1f

Please sign in to comment.