Skip to content

Commit

Permalink
Use shorts for triangle indices when possible for isosurface glTF exp…
Browse files Browse the repository at this point in the history
…orts.
  • Loading branch information
Carifio24 committed Dec 16, 2024
1 parent 8f8ec1c commit 0ff00e0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions glue_ar/common/marching_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from glue_ar.common.stl_builder import STLBuilder
from glue_ar.common.usd_builder import USDBuilder
from glue_ar.common.volume_export_options import ARIsosurfaceExportOptions
from glue_ar.gltf_utils import add_points_to_bytearray, add_triangles_to_bytearray, \
from glue_ar.gltf_utils import SHORT_MAX, add_points_to_bytearray, add_triangles_to_bytearray, \
index_mins, index_maxes
from glue_ar.utils import BoundsWithResolution, clip_sides, frb_for_layer, hex_to_components, isomin_for_layer, \
isomax_for_layer, layer_color
Expand Down Expand Up @@ -52,13 +52,15 @@ def add_isosurface_layer_gltf(builder: GLTFBuilder,
add_points_to_bytearray(barr, points)
point_len = len(barr)

add_triangles_to_bytearray(barr, triangles)
triangle_len = len(barr) - point_len

pt_mins = index_mins(points)
pt_maxes = index_maxes(points)
tri_mins = [int(min(idx for tri in triangles for idx in tri))]
tri_maxes = [int(max(idx for tri in triangles for idx in tri))]
max_tri_index = int(max(idx for tri in triangles for idx in tri))
tri_maxes = [max_tri_index]

Check warning on line 59 in glue_ar/common/marching_cubes.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/common/marching_cubes.py#L58-L59

Added lines #L58 - L59 were not covered by tests

use_short = max_tri_index <= SHORT_MAX
add_triangles_to_bytearray(barr, triangles, short=use_short)
triangle_len = len(barr) - point_len

Check warning on line 63 in glue_ar/common/marching_cubes.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/common/marching_cubes.py#L61-L63

Added lines #L61 - L63 were not covered by tests

builder.add_buffer(byte_length=len(barr), uri=level_bin)

Expand All @@ -83,9 +85,10 @@ def add_isosurface_layer_gltf(builder: GLTFBuilder,
byte_offset=point_len,
target=BufferTarget.ELEMENT_ARRAY_BUFFER,
)
component_type = ComponentType.UNSIGNED_SHORT if use_short else ComponentType.UNSIGNED_INT

Check warning on line 88 in glue_ar/common/marching_cubes.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/common/marching_cubes.py#L88

Added line #L88 was not covered by tests
builder.add_accessor(
buffer_view=builder.buffer_view_count-1,
component_type=ComponentType.UNSIGNED_INT,
component_type=component_type,
count=len(triangles)*3,
type=AccessorType.SCALAR,
mins=tri_mins,
Expand Down

0 comments on commit 0ff00e0

Please sign in to comment.