Skip to content

Commit

Permalink
ManifoldEngine PR Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Vin committed Jan 11, 2024
1 parent 85e33f1 commit b472b3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/scenic/core/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3564,8 +3564,8 @@ class ViewRegion(MeshVolumeRegion):
* Case 1: viewAngles[1] = 180 degrees
* Case 2.a viewAngles[0] = 360 degrees => Sphere
* Case 2.b viewAngles[0] < 360 degrees => Sphere & CylinderSectionRegion
* Case 1.a viewAngles[0] = 360 degrees => Sphere
* Case 1.b viewAngles[0] < 360 degrees => Sphere & CylinderSectionRegion
* Case 2: viewAngles[1] < 180 degrees => Sphere & ViewSectionRegion
Expand Down
16 changes: 14 additions & 2 deletions src/scenic/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def loadMesh(path, filetype, compressed, binary):


def unifyMesh(mesh, verbose=False):
"""Attempt to merge mesh bodies, raising an error if something fails.
"""Attempt to merge mesh bodies, raising a `ValueError` if something fails.
Should only be used with meshes that are volumes.
Expand Down Expand Up @@ -197,15 +197,27 @@ def unifyMesh(mesh, verbose=False):
assert m.is_volume
holes.append(m)

# For each volume, subtract all holes fully contained in the volume.
# For each volume, subtract all holes fully contained in the volume,
# keeping track of which holes are fully contained in at least one solid.
differenced_volumes = []
contained_holes = set()

for v in volumes:
for h in filter(lambda h: h.volume < v.volume, holes):
if h.difference(v).is_empty:
contained_holes.add(h)
v = v.difference(h)
differenced_volumes.append(v)

# If one or more holes was not fully contained (and thus ignored),
# raise a warning.
if verbose:
if contained_holes != set(holes):
warnings.warn(
"One or more holes in the provided mesh was not fully contained"
" in any solid (and was ignored)."
)

# Union all the differenced volumes together.
unified_mesh = trimesh.boolean.union(differenced_volumes)

Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ def test_unify_mesh():
nested_sphere, trimesh.creation.box(bounds=((0, 0, 0), (3, 5, 3)))
)

unifyMesh(bad_mesh)
fixed_mesh = unifyMesh(bad_mesh)
assert fixed_mesh.is_volume
assert fixed_mesh.body_count == 1

0 comments on commit b472b3a

Please sign in to comment.