Skip to content

Commit db6c9fb

Browse files
committed
Fallback boolean operations to PyVista when trimesh has no backend
Extend the boolean helper to first attempt trimesh-based union/intersection/difference (with engine and then default engine), and on any failure (e.g., no backends available) fall back to PyVista's VTK-backed boolean_* methods on the original PolyData meshes. This resolves ValueError('No backends available for boolean operations!') on environments such as macOS 3.9 where trimesh boolean backends are not installed, while still preferring trimesh when available.
1 parent 7583877 commit db6c9fb

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

svv/domain/routines/boolean.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,32 @@ def _apply(op, eng):
5252
else:
5353
raise ValueError("Unsupported boolean operation.")
5454

55+
result_tm = None
5556
try:
56-
result = _apply(operation, engine)
57-
except KeyError:
58-
# If the requested engine (e.g., 'manifold') is not registered
59-
# in trimesh.boolean._engines, fall back to trimesh's default
60-
# engine selection by omitting the explicit engine argument.
61-
result = _apply(operation, eng=None)
57+
try:
58+
result_tm = _apply(operation, engine)
59+
except KeyError:
60+
# If the requested engine (e.g., 'manifold') is not registered
61+
# in trimesh.boolean._engines, fall back to trimesh's default
62+
# engine selection by omitting the explicit engine argument.
63+
result_tm = _apply(operation, eng=None)
64+
except Exception:
65+
result_tm = None
66+
67+
if result_tm is not None:
68+
result = convert_to_pyvista(result_tm)
69+
else:
70+
# Fallback to PyVista/VTK boolean operations when no trimesh
71+
# boolean backend is available on the current platform.
72+
if operation == 'union':
73+
result = pyvista_object_1.boolean_union(pyvista_object_2)
74+
elif operation == 'intersection':
75+
result = pyvista_object_1.boolean_intersection(pyvista_object_2)
76+
elif operation == 'difference':
77+
result = pyvista_object_1.boolean_difference(pyvista_object_2)
78+
else:
79+
raise ValueError("Unsupported boolean operation.")
6280

63-
result = convert_to_pyvista(result)
6481
if not result.is_manifold and fix_mesh:
6582
fix = pymeshfix.MeshFix(result)
6683
fix.repair(verbose=False)

0 commit comments

Comments
 (0)