from compas.datastructures import Mesh from compas.topology import trimesh_remesh from compas.topology import delaunay_from_points from compas.topology import voronoi_from_delaunay from compas.geometry import pointcloud_xy from compas.plotters import MeshPlotter points = pointcloud_xy(10, (0, 10)) faces = delaunay_from_points(points) delaunay = Mesh.from_vertices_and_faces(points, faces) trimesh_remesh(delaunay, 1.0, allow_boundary_split=True) points = [delaunay.vertex_coordinates(key) for key in delaunay.vertices()] faces = delaunay_from_points(points) delaunay = Mesh.from_vertices_and_faces(points, faces) voronoi = voronoi_from_delaunay(delaunay) lines = [] for u, v in voronoi.edges(): lines.append({ 'start': voronoi.vertex_coordinates(u, 'xy'), 'end': voronoi.vertex_coordinates(v, 'xy'), 'width': 1.0 }) plotter = MeshPlotter(delaunay, figsize=(10, 6))
attr['x'] = x attr['y'] = y attr['z'] = z else: x, y, z = target.closest_point(mesh.vertex_coordinates(key)) attr['x'] = x attr['y'] = y attr['z'] = z conduit.redraw(k) # run the remeshing algorithm # draw the result with conduit.enabled(): trimesh_remesh(mesh, target=length, kmax=kmax, tol=0.1, divergence=0.01, allow_boundary_split=True, allow_boundary_swap=True, allow_boundary_collapse=False, smooth=True, fixed=fixed, callback=callback) artist = MeshArtist(mesh, layer='remeshed') artist.draw_faces(join_faces=True)
# generate a delaunay triangulation # from the points on the boundary faces = delaunay_from_points(points, boundary=points) mesh = Mesh.from_vertices_and_faces(points, faces) # make a conduit for visualization # and a callback for updating the conduit conduit = MeshConduit(mesh, refreshrate=2) def callback(mesh, k, args): conduit.redraw(k) # run the remeshing algorithm # and draw the result with conduit.enabled(): trimesh_remesh(mesh, target=length, kmax=500, allow_boundary_split=True, allow_boundary_swap=True, callback=callback) compas_rhino.mesh_draw( mesh, vertexcolor={key: '#ff0000' for key in mesh.vertices_on_boundary()})
from compas.datastructures import Mesh from compas.datastructures import FaceNetwork from compas.topology import mesh_dual from compas.topology import network_dual from compas.topology import delaunay_from_points from compas.topology import trimesh_remesh from compas.plotters import MeshPlotter points = hstack((10.0 * random.random_sample((10, 2)), zeros( (10, 1)))).tolist() faces = delaunay_from_points(points) mesh = Mesh.from_vertices_and_faces(points, faces) trimesh_remesh(mesh, 1.0, allow_boundary_split=True) points = [mesh.vertex_coordinates(key) for key in mesh.vertices()] faces = delaunay_from_points(points) mesh = Mesh.from_vertices_and_faces(points, faces) dual = mesh_dual(mesh) # network = FaceNetwork.from_vertices_and_faces(points, faces) # network_find_faces(network) # dual = network_dual(network) lines = [] for u, v in mesh.edges(): lines.append({ 'start': mesh.vertex_coordinates(u, 'xy'),
holes = attr['hole_polygons'] #create flat list of all points points = polygon + [item for hole in holes for item in hole] #compute initial delaunay mesh based on all points for the current face faces = delaunay_from_points(points, boundary=polygon, holes=holes) delaunay = Mesh.from_vertices_and_faces(points, faces) rs.Prompt('Computing triangular mesh for face {} of {}'.format( count, mesh.number_of_faces())) #compute the remeshed delaunay for the current face trimesh_remesh(delaunay, target=trg_length, tol=0.05, kmax=300, allow_boundary_split=False, allow_boundary_swap=True, verbose=False) delaunay_meshes.append(delaunay) count += 1 #join all meshes created per face mesh_diagram = join_meshes(delaunay_meshes, cull_duplicates=True, precision=precision) #draw joint mesh artist = MeshArtist(mesh_diagram, layer='form_tri') artist.draw_faces()
from compas.datastructures import Mesh from compas.plotters import MeshPlotter from compas.topology import trimesh_remesh vertices = [(0.0, 0.0, 0.0), (10.0, 0.0, 0.0), (10.0, 10.0, 0.0), (0.0, 10.0, 0.0), (5.0, 5.0, 0.0)] faces = [(0, 1, 4), (1, 2, 4), (2, 3, 4), (3, 0, 4)] mesh = Mesh.from_vertices_and_faces(vertices, faces) trimesh_remesh(mesh, target=0.5, tol=0.05, kmax=300, allow_boundary_split=True, allow_boundary_swap=True, verbose=False) plotter = MeshPlotter(mesh) plotter.draw_vertices(radius=0.03) plotter.draw_faces() plotter.draw_edges() plotter.show()
mesh = Mesh.from_vertices_and_faces(vertices, faces) key = mesh.insert_vertex(0) fixed = [key] plotter = MeshPlotter(mesh, figsize=(10, 7)) plotter.draw_edges(width=0.5) def callback(mesh, k, args): print(k) plotter.update_edges() plotter.update(pause=0.1) trimesh_remesh(mesh, 2.0, kmax=200, allow_boundary_split=True, allow_boundary_swap=True, allow_boundary_collapse=False, fixed=fixed, callback=callback) mesh_smooth_area(mesh, fixed=mesh.vertices_on_boundary()) plotter.update_edges() plotter.update(pause=2.0) plotter.show()