Skip to content

Commit

Permalink
Send2UE - Fixed Texture Filepaths Post Operation (#99)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
JoshQuake and jack-yao91 authored Nov 6, 2024
1 parent 8647f53 commit 33550b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/addons/send2ue/release_notes.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
25 changes: 24 additions & 1 deletion src/addons/send2ue/resources/extensions/affixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -245,6 +263,7 @@ class AffixesExtension(ExtensionBase):
AddAssetAffixes,
RemoveAssetAffixes
]
images_original_paths = []

show_name_affix_settings: bpy.props.BoolProperty(default=False)
# ---------------------------- name affix settings --------------------------------
Expand Down Expand Up @@ -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()

Expand All @@ -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):
"""
Expand Down

0 comments on commit 33550b8

Please sign in to comment.