From 2822b3badfb9cabb976fb3cb42e2f557e1f9eda0 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Thu, 7 Aug 2025 20:54:22 +0200 Subject: [PATCH] Fix: USD: Use exr instead of hdr for world light texture The spec for .usdz permits only a small handful of file formats to be contained in the archive, and HDR is not among those supported[1]. This also causes validation errors with the `usdchecker` tool (will be properly tested in a follow up change). Ignoring the potential for a user to export a .usdz file with materials referencing unsupported file formats, Blender itself should use only the supported formats for its business. [1] https://openusd.org/release/spec_usdz.html#usdz-specification Pull Request: https://projects.blender.org/blender/blender/pulls/144101 --- source/blender/io/usd/intern/usd_capi_export.cc | 15 +++++++-------- tests/python/bl_usd_import_test.py | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 5cdb68022f3..d0bd06c0584 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -359,20 +359,19 @@ std::string get_image_cache_file(const std::string &file_name, bool mkdir) std::string cache_image_color(const float color[4]) { - char name[128]; - SNPRINTF(name, - "color_%02d%02d%02d.hdr", - int(color[0] * 255), - int(color[1] * 255), - int(color[2] * 255)); + std::string name = fmt::format("color_{:02X}{:02X}{:02X}.exr", + int(color[0] * 255), + int(color[1] * 255), + int(color[2] * 255)); std::string file_path = get_image_cache_file(name); if (BLI_exists(file_path.c_str())) { return file_path; } - ImBuf *ibuf = IMB_allocImBuf(4, 4, 32, IB_float_data); + ImBuf *ibuf = IMB_allocImBuf(1, 1, 32, IB_float_data); IMB_rectfill(ibuf, color); - ibuf->ftype = IMB_FTYPE_RADHDR; + ibuf->ftype = IMB_FTYPE_OPENEXR; + ibuf->foptions.flag = R_IMF_EXR_CODEC_RLE; if (IMB_save_image(ibuf, file_path.c_str(), IB_float_data)) { CLOG_INFO(&LOG, "%s", file_path.c_str()); diff --git a/tests/python/bl_usd_import_test.py b/tests/python/bl_usd_import_test.py index 32fabe58e1b..af8838d2997 100644 --- a/tests/python/bl_usd_import_test.py +++ b/tests/python/bl_usd_import_test.py @@ -1789,7 +1789,7 @@ class USDImportTest(AbstractUSDTest): self.assertEqual({'FINISHED'}, res, f"Unable to export to {usdz2}") def check_image(name, tiles_num, size, is_packed): - self.assertTrue(name in bpy.data.images) + self.assertTrue(name in bpy.data.images, f"Could not find '{name}'") image = bpy.data.images[name] self.assertEqual(len(image.tiles), tiles_num) @@ -1816,7 +1816,7 @@ class USDImportTest(AbstractUSDTest): check_image("test_grid_.png", 2, 1024, True) check_image("test_normal.exr", 1, 128, True) check_image("test_normal_invertY.exr", 1, 128, True) - check_image("color_121212.hdr", 1, 4, True) + check_image("color_0C0C0C.exr", 1, 1, True) check_materials() # Reload the empty file and import back in using IMPORT_COPY @@ -1832,7 +1832,7 @@ class USDImportTest(AbstractUSDTest): check_image("test_grid_.png", 2, 128, False) check_image("test_normal.exr", 1, 128, False) check_image("test_normal_invertY.exr", 1, 128, False) - check_image("color_121212.hdr", 1, 4, False) + check_image("color_0C0C0C.exr", 1, 1, False) check_materials() def test_get_prim_map_parent_xform_not_merged(self):