USD: Add tests for USDZ image processing
More thoroughly test certain image processing behavior of USDZ IO. Namely that regular and UDIM images are imported back when using either the packed or the copy import modes. Along the way ensure that we have coverage for image downscaling on export as well. Pull Request: https://projects.blender.org/blender/blender/pulls/127985
This commit is contained in:
committed by
Jesse Yurkovich
parent
c6f5c89669
commit
295cb653ea
@@ -1144,6 +1144,74 @@ class USDImportTest(AbstractUSDTest):
|
||||
]
|
||||
assert_all_props_present(properties, "")
|
||||
|
||||
def test_import_usdz_image_processing(self):
|
||||
"""Test importing of images from USDZ files in various ways."""
|
||||
|
||||
# USDZ processing needs the destination directory to exist
|
||||
self.tempdir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Use the existing materials test file to create the USD file
|
||||
# for import. It is validated as part of the bl_usd_export test.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "usd_materials_export.blend"))
|
||||
usdz1 = str(self.tempdir / "usd_materials_export.usdz")
|
||||
res = bpy.ops.wm.usd_export(filepath=usdz1, export_materials=True)
|
||||
self.assertEqual({'FINISHED'}, res, f"Unable to export to {usdz1}")
|
||||
|
||||
usdz2 = str(self.tempdir / "usd_materials_export_downscaled.usdz")
|
||||
res = bpy.ops.wm.usd_export(
|
||||
filepath=usdz2,
|
||||
export_materials=True,
|
||||
usdz_downscale_size='CUSTOM',
|
||||
usdz_downscale_custom_size=128)
|
||||
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)
|
||||
|
||||
image = bpy.data.images[name]
|
||||
self.assertEqual(len(image.tiles), tiles_num)
|
||||
self.assertEqual(image.packed_file is not None, is_packed)
|
||||
for tile in range(0, tiles_num):
|
||||
self.assertEqual(image.tiles[tile].size[0], size)
|
||||
self.assertEqual(image.tiles[tile].size[1], size)
|
||||
|
||||
def check_materials():
|
||||
self.assertEqual(len(bpy.data.materials), 7) # +1 because of the "Dots Stroke" material
|
||||
self.assertTrue("Clip_With_LessThanInvert" in bpy.data.materials)
|
||||
self.assertTrue("Clip_With_Round" in bpy.data.materials)
|
||||
self.assertTrue("Material" in bpy.data.materials)
|
||||
self.assertTrue("NormalMap" in bpy.data.materials)
|
||||
self.assertTrue("NormalMap_Scale_Bias" in bpy.data.materials)
|
||||
self.assertTrue("Transforms" in bpy.data.materials)
|
||||
|
||||
# Reload the empty file and import back in using IMPORT_PACK
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "empty.blend"))
|
||||
res = bpy.ops.wm.usd_import(filepath=usdz1, import_textures_mode='IMPORT_PACK')
|
||||
self.assertEqual({'FINISHED'}, res, f"Unable to import USD file {usdz1}")
|
||||
|
||||
self.assertEqual(len(bpy.data.images), 4)
|
||||
check_image("test_grid_<UDIM>.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_materials()
|
||||
|
||||
# Reload the empty file and import back in using IMPORT_COPY
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "empty.blend"))
|
||||
res = bpy.ops.wm.usd_import(
|
||||
filepath=usdz2,
|
||||
import_textures_mode='IMPORT_COPY',
|
||||
import_textures_dir=str(
|
||||
self.tempdir))
|
||||
self.assertEqual({'FINISHED'}, res, f"Unable to import USD file {usdz2}")
|
||||
|
||||
self.assertEqual(len(bpy.data.images), 4)
|
||||
check_image("test_grid_<UDIM>.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_materials()
|
||||
|
||||
|
||||
def main():
|
||||
global args
|
||||
|
||||
Reference in New Issue
Block a user