From 3e3ee35e9d7651659e10cce9bf114e65f020b4d8 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Fri, 5 Sep 2025 19:41:20 +0200 Subject: [PATCH] Fix #145711: Packed images may fail to export with USD Certain packed images, like those loaded directly into memory with `BKE_image_packfiles_from_mem`, would cause USD to process the images as "in memory" rather than as "packed" because the API was not removing the IMG_GEN_TILE flag. Additionally, be sure to use the packed filepath whenever possible rather than the name given to the Image datablock as this ensures the correct file names are used inside the USD file and for the resulting file on disk after export. This also fixes 2 render tests which now match when compared to the native renders. Pull Request: https://projects.blender.org/blender/blender/pulls/145749 --- source/blender/blenkernel/intern/image.cc | 4 ++++ source/blender/io/usd/intern/usd_writer_material.cc | 8 ++++++++ .../storm_usd_renders/image_mapping_udim_packed.png | 4 ++-- .../render/shader/storm_usd_renders/glossy_normal_map.png | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 504d5d6722d..12ad4d6fb45 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -1527,6 +1527,10 @@ void BKE_image_packfiles_from_mem(ReportList *reports, imapf->view = 0; imapf->tile_number = 1001; STRNCPY(imapf->filepath, ima->filepath); + + /* The image should not be marked as "generated" since image data was provided. */ + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + base_tile->gen_flag &= ~IMA_GEN_TILE; } } diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 87428b92c15..4d5760aba4c 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -784,6 +784,14 @@ static std::string get_in_memory_texture_filename(Image *ima) BKE_image_release_ibuf(ima, imbuf, nullptr); char file_name[FILE_MAX]; + + /* NOTE: Any changes in packed filepath handling here should be considered alongside potential + * changes in `export_packed_texture`. The file name returned needs to match. */ + if (is_packed && ima->filepath[0] != '\0') { + BLI_path_split_file_part(ima->filepath, file_name, FILE_MAX); + return file_name; + } + /* Use the image name for the file name. */ STRNCPY(file_name, ima->id.name + 2); diff --git a/tests/files/render/image_mapping/storm_usd_renders/image_mapping_udim_packed.png b/tests/files/render/image_mapping/storm_usd_renders/image_mapping_udim_packed.png index e68b554bd32..58d5e8d1fcf 100644 --- a/tests/files/render/image_mapping/storm_usd_renders/image_mapping_udim_packed.png +++ b/tests/files/render/image_mapping/storm_usd_renders/image_mapping_udim_packed.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ad6a9ed944f996c3bfb23c2fc314738161740ff63168948dffd717f89efc082 -size 16965 +oid sha256:e4a3958fbd903f9d19411f2f0da4caf24790254fcd099b571e6e56237b60b33a +size 17543 diff --git a/tests/files/render/shader/storm_usd_renders/glossy_normal_map.png b/tests/files/render/shader/storm_usd_renders/glossy_normal_map.png index c19053ecabc..cc61aa0c436 100644 --- a/tests/files/render/shader/storm_usd_renders/glossy_normal_map.png +++ b/tests/files/render/shader/storm_usd_renders/glossy_normal_map.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a65ffa7fae2deb66b02711fa76a4109c807afb71c79366be7b498372f9fc8960 -size 13978 +oid sha256:954bcf3c7ef28f9783269dcf3e9bf0c4576e8e413cd6a96ce595855d88e7da68 +size 17215