def draw(self): from compas_rhino.artists import MeshArtist previous_layer = None if self.layer: if not compas_rhino.rs.IsLayer(self.layer): compas_rhino.create_layers_from_path(self.layer) previous_layer = compas_rhino.rs.CurrentLayer(self.layer) compas_rhino.rs.EnableRedraw(False) for vkey, element in self.assembly.elements(): artist = MeshArtist(element.mesh) artist.draw_mesh() if self.layer and previous_layer: compas_rhino.rs.CurrentLayer(previous_layer) self.redraw()
# update default vertex attributes mesh.update_default_vertex_attributes({'px': 0.0, 'py': 0.0, 'pz': 0.0}) mesh.update_default_edge_attributes({'q': 1.0}) # numerical data xyz = mesh.get_vertices_attributes('xyz') edges = list(mesh.edges()) fixed = list(mesh.vertices_where({'vertex_degree': 2})) q = mesh.get_edges_attribute('q', 1.0) loads = mesh.get_vertices_attributes(('px', 'py', 'pz'), (0.0, 0.0, 0.0)) # call to fd_numpy over proxy server xyz, q, f, l, r = proxy.fd_numpy(xyz, edges, fixed, q, loads) # update the mesh vertices for key, attr in mesh.vertices(True): mesh.set_vertex_attributes(key, 'xyz', xyz[key]) mesh.set_vertex_attributes(key, ('rx', 'ry', 'rz'), r[key]) # update the mesh edges for index, (u, v, attr) in enumerate(mesh.edges(True)): attr['f'] = f[index][0] attr['l'] = l[index][0] # visualise the result artist = MeshArtist(mesh, layer="Mesh::FD") artist.clear_layer() artist.draw_vertices() artist.draw_mesh()
VC, FC = igl.mesh_intersection(VA, FA, VB, FB) c_intersection = Mesh.from_vertices_and_faces(VC, FC) VC, FC = igl.mesh_difference(VA, FA, VB, FB) c_diff = Mesh.from_vertices_and_faces(VC, FC) # ============================================================================== # Visualization # ============================================================================== # the original meshes artist = MeshArtist(a, layer="IGL::A") artist.clear_layer() artist.draw_mesh(color=[255, 0, 0]) artist = MeshArtist(b, layer="IGL::B") artist.clear_layer() artist.draw_mesh(color=[0, 0, 255]) # the boolean meshes c_union.transform(Translation([7.5, 0, 0])) c_intersection.transform(Translation([15, 0, 0])) c_diff.transform(Translation([22.5, 0, 0])) artist = MeshArtist(c_union, layer="IGL::Union") artist.clear_layer() artist.draw_mesh(color=[225, 0, 255])
else: poles = [rs.PointCoordinates(pole) for pole in poles] vertices, faces = RhinoMesh.from_guid(guid).get_vertices_and_faces() mesh = CoarsePseudoQuadMesh.from_vertices_and_faces_with_poles( vertices, faces, poles) mesh.collect_strips() mesh.set_strips_density(1) mesh.densification() count = 100 while count: count -= 1 artist = MeshArtist(mesh.get_quad_mesh()) guid = artist.draw_mesh() operation = rs.GetString('operation?', strings=[ 'global_density_value', 'global_subdivision_target_length', 'strip_density_value', 'strip_subdivision_target_length', 'global_uniform_target_number_faces', 'exit' ]) # stop if asked if operation is None or operation == 'exit': break # get operation parameters
top = [] for point, normal in zip(bottom, normals): x = point[0] + 0.1 * normal[0] y = point[1] + 0.1 * normal[1] z = point[2] + 0.1 * normal[2] top.append([x, y, z]) # vertices and faces of the block vertices = bottom[::-1] + top faces = [[0, 1, 2, 3], [4, 5, 6, 7], [4, 3, 2, 5], [5, 2, 1, 6], [6, 1, 0, 7], [7, 0, 3, 4]] block = Mesh.from_vertices_and_faces(vertices, faces) block.name = "Block.{}".format(fkey) blocks.append(block) # ============================================================================== # Visualize the blocks # ============================================================================== artist = MeshArtist(None, layer="Blocks") artist.clear_layer() b = len(blocks) for i, block in enumerate(blocks): artist.mesh = block artist.draw_mesh(color=i_to_rgb(i / b)) artist.redraw()
# map positions to TPMS (Gyroid) properties = [ math.sin(v[0]) * math.cos(v[1]) + math.sin(v[1]) * math.cos(v[2]) + math.sin(v[2]) * math.cos(v[2]) for v in centers ] fkeys = list(mesh5.faces()) for f, p in zip(fkeys, properties): new_keys = pyramid_face(mesh5, f, p) # spiky ball artist9 = MeshArtist(mesh5, layer="07_3d") artist9.clear_layer() artist9.draw_mesh() # 3d mesh - Custom shapes my_circle = Circle([[0, 0, 0], [0, 0, 1]], 5) my_cone = Cone(my_circle, 5) vs, fs = my_cone.to_vertices_and_faces(u=11, v=11) my_cone_mesh = Mesh.from_vertices_and_faces(vs, fs) point = [21, 0, 0] T = Translation.from_vector(point) my_cone_mesh.transform(T) artist = MeshArtist(my_cone_mesh, layer="08_cone") artist.clear_layer() artist.draw_mesh() mesh = my_cone_mesh
def gh_to_rhino_mesh(mesh): artist = MeshArtist(mesh) mesh_guid = artist.draw_mesh() return mesh_guid
volume = idos.copy() volume.name = 'concrete1' # flip its cycles to make the bottom normals point downwards # set the key offset dkey = volume._max_int_key + 1 # add the vertices of the extrados for key, attr in edos.vertices(True): # add the faces of the extrados for fkey in edos.faces(): vertices = edos.face_vertices(fkey) # construct a polygon of boundary vertices # add the "side" faces # ============================================================================== # Export and visualisation # ============================================================================== # export volume.to_json('concrete1.json') # visualize artist = MeshArtist(volume, layer="Concrete1") artist.clear_layer() artist.draw_mesh(color=(0, 0, 255))
boundary.append(boundary[0]) for a, b in pairwise(boundary): volume.add_face([b, a, a + max_vertex, b + max_vertex]) # ============================================================================== # Export # ============================================================================== session['idos'] = idos session['edos'] = edos session['volume'] = volume compas.json_dump(session, FILE) # ============================================================================== # visualize # ============================================================================== artist = MeshArtist(idos, layer="HiLo::Concrete1::Idos") artist.clear_layer() artist.draw_mesh(disjoint=True, color=(255, 0, 0)) artist = MeshArtist(edos, layer="HiLo::Concrete1::Edos") artist.clear_layer() artist.draw_mesh(disjoint=True, color=(0, 0, 255)) artist = MeshArtist(volume, layer="HiLo::Concrete1::Volume") artist.clear_layer() artist.draw_mesh(disjoint=True)
from shapes import Polyhedron from compas_rhino.artists import MeshArtist from compas.datastructures import Mesh poly = Mesh.from_polyhedron(12) print(poly) artist = MeshArtist(poly, layer='00_my_mesh') artist.clear_layer() artist.draw_faces() artist.draw_mesh(join_faces=True)