Skip to content

Commit

Permalink
Adding documentation and testing for mesh texture coordinate encoding (
Browse files Browse the repository at this point in the history
…#43)

* Add tex_coord lines to a comment.

* Add tex_coord testing.
  • Loading branch information
hanseuljun authored May 4, 2023
1 parent fb6306f commit 8059fe6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/DracoPy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def encode(
order as the input.
Colors is a numpy array of colors (uint8) with shape (N, K). N is the number of
vertices. K must be >= 1. Use None if mesh does not have colors
Tex coord is a numpy array of texture coordinates (float) with shape (N, 2). N is the number of
vertices. Use None if mesh does not have texture coordinates.
"""
assert 0 <= compression_level <= 10, "Compression level must be in range [0, 10]"

Expand Down Expand Up @@ -193,7 +195,7 @@ def encode(

tex_coord_channel = 0
if tex_coord is not None:
assert np.issubdtype(tex_coord.dtype, np.float), "Tex coord must be float"
assert np.issubdtype(tex_coord.dtype, float), "Tex coord must be float"
assert len(tex_coord.shape) == 2, "Tex coord must be 2D"
tex_coord_channel = tex_coord.shape[1]
assert 1 <= tex_coord_channel <= 127, "Number of tex coord channels must be in range [1, 127]"
Expand Down
4 changes: 3 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_decoding_and_encoding_mesh_file():
assert mesh_decode.colors is None, "colors should not present"

colors = np.random.randint(0, 255, [mesh.points.shape[0], 16]).astype(np.uint8)
tex_coord = np.random.random([mesh.points.shape[0], 2])

# test extreme quantization
encoding_test4 = DracoPy.encode(mesh.points, mesh.faces, compression_level=10,
Expand All @@ -52,9 +53,10 @@ def test_decoding_and_encoding_mesh_file():

# Setting quantization_bits 26 here. Larger value causes MemoryError on 32bit systems.
encoding_test5 = DracoPy.encode(mesh.points, mesh.faces, compression_level=1,
quantization_bits=26, colors=colors)
quantization_bits=26, colors=colors, tex_coord=tex_coord)
mesh_decode = DracoPy.decode(encoding_test5)
assert mesh_decode.colors is not None, "colors should present"
assert mesh_decode.tex_coord is not None, "tex_coord should present"

with open(os.path.join(testdata_directory, "bunny_test.drc"), "wb") as test_file:
test_file.write(encoding_test)
Expand Down

0 comments on commit 8059fe6

Please sign in to comment.