diff --git a/src/readyplayerme/meshops/mesh.py b/src/readyplayerme/meshops/mesh.py index bca8c0f..d16f8a8 100644 --- a/src/readyplayerme/meshops/mesh.py +++ b/src/readyplayerme/meshops/mesh.py @@ -114,10 +114,11 @@ def uv_to_texture_space( return np.empty((0, 2), dtype=np.uint16) try: - selected_uvs = uvs if indices is None else uvs[indices] + selected_uvs = uvs[indices] except IndexError as error: msg = f"Index {np.where(indices>=len(uvs))[0]} is out of bounds for UVs with shape {uvs.shape}." raise IndexError(msg) from error + # Wrap UV coordinates within the range [0, 1] wrapped_uvs = np.mod(selected_uvs, 1) diff --git a/tests/readyplayerme/meshops/unit/test_mesh.py b/tests/readyplayerme/meshops/unit/test_mesh.py index 1809435..1fd0e60 100644 --- a/tests/readyplayerme/meshops/unit/test_mesh.py +++ b/tests/readyplayerme/meshops/unit/test_mesh.py @@ -146,6 +146,8 @@ def test_get_overlapping_vertices_error_handling(indices): (np.array([[0.5, 0.5], [0.25, 0.75]]), 124, 10024, np.array([0]), np.array([[61, 5011]])), # 1px image (np.array([[0.5, 0.5], [-1, 1], [0, 0]]), 1, 1, np.array([0, 1, 2]), np.array([[0, 0], [0, 0], [0, 0]])), + # 0 px image + (np.array([[0.5, 0.5], [0.25, 0.75]]), 0, 0, np.array([0]), np.array([[0, 0]])), ], ) def test_uv_to_texture_space(uvs: UVs, width: int, height: int, indices: Indices, expected: PixelCoord): @@ -158,6 +160,8 @@ def test_uv_to_texture_space(uvs: UVs, width: int, height: int, indices: Indices "uvs, width, height, indices", [ (np.array([[0.5, 0.5], [0.25, 0.75]]), 100, 100, np.array([0, 1, 2])), + # No UV coord + (np.array([]), 1, 1, np.array([0, 1, 2])), ], ) def test_uv_to_texture_space_exceptions(uvs: UVs, width: int, height: int, indices: Indices):