diff --git a/src/readyplayerme/meshops/draw/image.py b/src/readyplayerme/meshops/draw/image.py index dd58eb0..d95c62b 100644 --- a/src/readyplayerme/meshops/draw/image.py +++ b/src/readyplayerme/meshops/draw/image.py @@ -68,4 +68,4 @@ def blend_uv_seams(mesh: mops.Mesh, image: Image) -> Image: blurred_mask = np.power(blurred_mask, 1.5) # Blend in average vertex color at the UV seams. - return blend_images(image, raster_image, blurred_mask) + return blend_images(image, raster_image, blurred_mask).astype(np.uint8) diff --git a/tests/mocks/input-img-blended.png b/tests/mocks/input-img-blended.png new file mode 100644 index 0000000..aad4f3a Binary files /dev/null and b/tests/mocks/input-img-blended.png differ diff --git a/tests/readyplayerme/meshops/conftest.py b/tests/readyplayerme/meshops/conftest.py index 1d1fc70..5d15bae 100644 --- a/tests/readyplayerme/meshops/conftest.py +++ b/tests/readyplayerme/meshops/conftest.py @@ -32,3 +32,14 @@ def mock_image(): filepath = files(tests.mocks).joinpath("input-img.png") return ski.io.imread(filepath) + + +@pytest.fixture +def mock_image_blended(): + """Return an image as a numpy array.""" + from importlib.resources import files + + import tests.mocks + + filepath = files(tests.mocks).joinpath("input-img-blended.png") + return ski.io.imread(filepath) diff --git a/tests/readyplayerme/meshops/integration/test_integration.py b/tests/readyplayerme/meshops/integration/test_integration.py index 61720ab..dff19ef 100644 --- a/tests/readyplayerme/meshops/integration/test_integration.py +++ b/tests/readyplayerme/meshops/integration/test_integration.py @@ -4,6 +4,7 @@ import numpy as np import numpy.typing as npt +import readyplayerme.meshops.draw.image as img import readyplayerme.meshops.mesh as mops @@ -28,3 +29,11 @@ def test_access_material_should_fail(gltf_simple_file: str | Path): """Test the simple gltf does not have a material.""" mesh = mops.read_mesh(gltf_simple_file) assert mesh.material is None, "Mesh should not have a material." + + +def test_seam_blend(gltf_file_with_basecolor_texture: str | Path, mock_image_blended: npt.NDArray[Any]): + """Test the seam blending.""" + local_mesh = mops.read_mesh(gltf_file_with_basecolor_texture) + extracted_image = local_mesh.material.baseColorTexture + blended_image = img.blend_uv_seams(local_mesh, extracted_image) + assert np.array_equal(blended_image, mock_image_blended), "The blended image should match the mock-up"