From 33550b8e8268f5786766d02d4b59f8f21dab7654 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 5 Nov 2024 17:52:17 -0800 Subject: [PATCH] Send2UE - Fixed Texture Filepaths Post Operation (#99) * added restore_texture_paths() fixed issue with texture filepaths pointing to wrong location * Update release_notes.md * Update affixes.py * Update affixes.py * Update affixes.py * Update affixes.py * guarded restore textures logic to only when auto_add_asset_name_affixes is true --------- Co-authored-by: Jack Yao --- src/addons/send2ue/release_notes.md | 10 +++----- .../send2ue/resources/extensions/affixes.py | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/addons/send2ue/release_notes.md b/src/addons/send2ue/release_notes.md index 44ebd4f2..dfbf69fc 100644 --- a/src/addons/send2ue/release_notes.md +++ b/src/addons/send2ue/release_notes.md @@ -1,14 +1,10 @@ -## Minor Changes -* Added custom root bone name setting - * [88](https://github.com/poly-hammer/BlenderTools/pull/88) - ## Patch Changes -* Fixed collision merging into LOD meshes - * [93](https://github.com/poly-hammer/BlenderTools/pull/93) +* Fixed Texture filepaths post operation + * [99](https://github.com/poly-hammer/BlenderTools/pull/99) ## Special Thanks -@vaeryn-uk (88), @souvey (93) + ## Tests Passing On * Blender `3.6`, `4.2` (installed from blender.org) diff --git a/src/addons/send2ue/resources/extensions/affixes.py b/src/addons/send2ue/resources/extensions/affixes.py index 311c60d9..085e2d51 100644 --- a/src/addons/send2ue/resources/extensions/affixes.py +++ b/src/addons/send2ue/resources/extensions/affixes.py @@ -15,7 +15,7 @@ def add_affixes(): properties = bpy.context.scene.send2ue mesh_objects = utilities.get_from_collection(BlenderTypes.MESH) rig_objects = utilities.get_from_collection(BlenderTypes.SKELETON) - + for mesh_object in mesh_objects: if mesh_object.modifiers: is_armature = False @@ -42,6 +42,8 @@ def add_affixes(): append_affix(slot.material, properties.extensions.affixes.material_name_affix) texture_images = get_texture_images(mesh_object) + for image in texture_images: + save_image_filepath(image) rename_all_textures(texture_images, append_affix, properties) for rig_object in rig_objects: @@ -86,6 +88,9 @@ def remove_affixes(): for action in actions: discard_affix(action, properties.extensions.affixes.animation_sequence_name_affix) +def save_image_filepath(image): + path, filename = os.path.split(image.filepath_from_user()) + AffixesExtension.images_original_paths.append(path) def append_affix(scene_object, affix, is_image=False): """ @@ -210,6 +215,19 @@ def rename_texture(image, new_name): if os.path.exists(new_path): image.filepath = new_path +def restore_texture_paths(): + mesh_objects = utilities.get_from_collection(BlenderTypes.MESH) + for mesh_object in mesh_objects: + texture_images = get_texture_images(mesh_object) + + for image_index, image in enumerate(texture_images): + if image.source == 'FILE': + original_path = os.path.join( AffixesExtension.images_original_paths[image_index], image.name ) + + if not os.path.exists(original_path): + shutil.copy(image.filepath_from_user(), original_path) + + image.filepath = original_path def check_asset_affixes(self, context=None): """ @@ -245,6 +263,7 @@ class AffixesExtension(ExtensionBase): AddAssetAffixes, RemoveAssetAffixes ] + images_original_paths = [] show_name_affix_settings: bpy.props.BoolProperty(default=False) # ---------------------------- name affix settings -------------------------------- @@ -322,6 +341,7 @@ def pre_operation(self, properties): """ Defines the pre operation logic that will be run before the operation. """ + AffixesExtension.images_original_paths.clear() if self.auto_add_asset_name_affixes: add_affixes() @@ -331,6 +351,9 @@ def post_operation(self, properties): """ if self.auto_remove_asset_name_affixes: remove_affixes() + + if self.auto_add_asset_name_affixes: + restore_texture_paths() def pre_validations(self, properties): """