77from compas_viewer import Viewer
88
99from compas_cgal .booleans import boolean_chain_with_face_source
10+ from compas_cgal .booleans import split_by_source
1011
1112
1213# =============================================================================
@@ -52,15 +53,16 @@ def cylinder_along(axis, radius=0.8):
5253 exact = False ,
5354)
5455
55- mesh = Mesh .from_vertices_and_faces (V , F )
56-
5756# =============================================================================
5857# Color the output by source mesh:
5958# mesh_id == 0 -> cube (red)
6059# mesh_id == 1 -> sphere (blue) — rounded corners/edges
6160# mesh_id == 2 -> cyl_x (green) — X-axis through-hole walls
6261# mesh_id == 3 -> cyl_y (yellow) — Y-axis through-hole walls
6362# mesh_id == 4 -> cyl_z (magenta) — Z-axis through-hole walls
63+ #
64+ # Two equivalent visualization paths are shown below. Pick whichever fits
65+ # your downstream code; the C++ output is identical in both cases.
6466# =============================================================================
6567
6668palette = {
@@ -71,12 +73,36 @@ def cylinder_along(axis, radius=0.8):
7173 4 : Color (0.80 , 0.40 , 0.85 ),
7274}
7375
76+ # Option A — single connected mesh + per-face color dict (keeps shared
77+ # vertices intact at source boundaries; best for further processing).
78+ mesh = Mesh .from_vertices_and_faces (V , F )
7479facecolor = {fkey : palette [mesh_id ] for fkey , (mesh_id , _ ) in zip (mesh .faces (), S .tolist ())}
7580
81+ # Option B — split into one mesh per source via split_by_source. Each
82+ # submesh is independent (boundary vertices are duplicated across submeshes)
83+ # and gets its own scene object with a single color. Convenient for viewers
84+ # that prefer one material/layer per object.
85+ submeshes = {
86+ mesh_id : Mesh .from_vertices_and_faces (Vs , Fs )
87+ for mesh_id , (Vs , Fs ) in split_by_source (V , F , S ).items ()
88+ }
89+
7690# =============================================================================
77- # Visualize
91+ # Visualize — toggle USE_SPLIT to compare the two paths.
7892# =============================================================================
7993
94+ USE_SPLIT = True
95+
8096viewer = Viewer ()
81- viewer .scene .add (mesh , facecolor = facecolor , lineswidth = 1 , show_points = False , show_lines = True )
97+ if USE_SPLIT :
98+ for mesh_id , submesh in submeshes .items ():
99+ viewer .scene .add (
100+ submesh ,
101+ facecolor = palette [mesh_id ],
102+ lineswidth = 1 ,
103+ show_points = False ,
104+ show_lines = True ,
105+ )
106+ else :
107+ viewer .scene .add (mesh , facecolor = facecolor , lineswidth = 1 , show_points = False , show_lines = True )
82108viewer .show ()
0 commit comments