frompathlibimportPathimportnumpyasnpfromcompas.colorsimportColorfromcompas.datastructuresimportMeshfromcompas.geometryimportPlanefromcompas.geometryimportPointfromcompas.geometryimportPolylinefromcompas.geometryimportVectorfromcompas_cgal.slicerimportslice_mesh_planesfromcompas_viewerimportViewerFILE=Path(__file__).parent.parent.parent/"data"/"3DBenchy.stl"# ==============================================================================# Get benchy and construct a mesh# ==============================================================================benchy=Mesh.from_stl(FILE)# ==============================================================================# Create planes# ==============================================================================# replace by planes along a curvebbox=benchy.aabb()normal=Vector(0,0,1)planes=[]foriinnp.linspace(bbox.zmin,bbox.zmax,50):plane=Plane(Point(0,0,i),normal)planes.append(plane)# ==============================================================================# Slice# ==============================================================================M=benchy.to_vertices_and_faces()pointsets=slice_mesh_planes(M,planes)# ==============================================================================# Process output# ==============================================================================polylines=[]forpointsinpointsets:points=[Point(*point)forpointinpoints]polyline=Polyline(points)polylines.append(polyline)# ==============================================================================# Visualize# ==============================================================================viewer=Viewer(width=1600,height=900)viewer.renderer.camera.target=[0,0,20]viewer.renderer.camera.position=[-40,-70,40]viewer.scene.add(benchy,show_lines=False,show_points=False,opacity=0.5)forpolylineinpolylines:viewer.scene.add(polyline,linecolor=Color.grey(),lineswidth=2,show_points=False)viewer.show()