import os from compas.datastructures import Mesh from compas.rpc import Proxy from compas_rhino.artists import MeshArtist cgal = Proxy('compas_cgal.meshing') # cgal.restart_server() HERE = os.path.dirname(__file__) FILE_I = os.path.join(HERE, 'data', 'form_trimesh.json') FILE_O = os.path.join(HERE, 'data', 'form_remeshed.json') mesh = Mesh.from_json(FILE_I) lengths = [mesh.edge_length(*edge) for edge in mesh.edges()] length = sum(lengths) / mesh.number_of_edges() V, F = cgal.remesh(mesh.to_vertices_and_faces(), 0.75 * length) mesh = Mesh.from_vertices_and_faces(V, F) mesh.to_json(FILE_O) artist = MeshArtist(mesh, layer="RV2::Remeshed") artist.clear_layer() artist.draw_faces(join_faces=True)
A = box.to_vertices_and_faces() sphere = Sphere(Point(1, 1, 1), 1) sphere = Mesh.from_shape(sphere, u=30, v=30) sphere.quads_to_triangles() B = sphere.to_vertices_and_faces() # ============================================================================== # Remesh the sphere # ============================================================================== proxy.package = 'compas_cgal.meshing' B = proxy.remesh(B, 0.3, 10) # ============================================================================== # Compute the intersections # ============================================================================== proxy.package = 'compas_cgal.intersections' pointsets = proxy.intersection_mesh_mesh(A, B) # ============================================================================== # Process output # ============================================================================== polylines = [] for points in pointsets:
# ============================================================================== # Move the bunny to the origin and rotate it upright. # ============================================================================== vector = scale_vector(bunny.centroid(), -1) T = Translation.from_vector(vector) S = Scale.from_factors([100, 100, 100]) R = Rotation.from_axis_and_angle(Vector(1, 0, 0), math.radians(90)) bunny.transform(R * S * T) # ============================================================================== # Remesh # ============================================================================== num_edges = bunny.number_of_edges() length = sum(bunny.edge_length(*edge) for edge in bunny.edges()) / num_edges V, F = meshing.remesh(bunny.to_vertices_and_faces(), 2 * length, 10) bunny = Mesh.from_vertices_and_faces(V, F) # ============================================================================== # Visualize # ============================================================================== artist = MeshArtist(bunny, layer="CGAL::Remesh::Bunny") artist.clear_layer() artist.draw_faces(join_faces=True) artist.redraw()