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

Send2UE - Fixed Texture Filepaths Post Operation #99

Merged
merged 8 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading