def draw(self, color=None, u=None, v=None): """Draw the capsule associated with the artist. Parameters ---------- color : tuple[int, int, int], optional The RGB color of the capsule. u : int, optional Number of faces in the "u" direction. Default is :attr:`~CapsuleArtist.u`. v : int, optional Number of faces in the "v" direction. Default is :attr:`CapsuleArtist.v`. Returns ------- list[System.Guid] The GUIDs of the objects created in Rhino. """ color = color or self.color u = u or self.u v = v or self.v vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v) vertices = [list(vertex) for vertex in vertices] guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=color, disjoint=True) return [guid]
def draw_mesh(self, color=None, disjoint=False): """Draw the mesh as a consolidated RhinoMesh. Notes ----- The mesh should be a valid Rhino Mesh object, which means it should have only triangular or quadrilateral faces. """ key_index = self.mesh.key_index() vertices = self.mesh.get_vertices_attributes('xyz') faces = [[key_index[key] for key in self.mesh.face_vertices(fkey)] for fkey in self.mesh.faces()] new_faces = [] for face in faces: f = len(face) if f == 3: new_faces.append(face + face[-1:]) elif f == 4: new_faces.append(face) elif f > 4: centroid = len(vertices) vertices.append(centroid_polygon([vertices[index] for index in face])) for a, b in pairwise(face + face[0:1]): new_faces.append([centroid, a, b, b]) else: continue layer = self.layer name = "{}.mesh".format(self.mesh.name) return compas_rhino.draw_mesh(vertices, new_faces, layer=layer, name=name, color=color, disjoint=disjoint)
def draw_mesh(self, color=None, disjoint=False): """Draw the mesh as a consolidated RhinoMesh. Parameters ---------- color : tuple, optional The color of the mesh. Default is the value of ``~MeshArtist.default_color``. disjoint : bool, optional Draw the faces of the mesh with disjoint vertices. Default is ``False``. Returns ------- list The GUIDs of the created Rhino objects. Notes ----- The mesh should be a valid Rhino Mesh object, which means it should have only triangular or quadrilateral faces. Faces with more than 4 vertices will be triangulated on-the-fly. """ color = color or self.default_color vertex_index = self.mesh.vertex_index() vertex_xyz = self.vertex_xyz vertices = [vertex_xyz[vertex] for vertex in self.mesh.vertices()] faces = [[vertex_index[vertex] for vertex in self.mesh.face_vertices(face)] for face in self.mesh.faces()] layer = self.layer name = "{}.mesh".format(self.mesh.name) guid = compas_rhino.draw_mesh(vertices, faces, layer=layer, name=name, color=color, disjoint=disjoint) return [guid]
def draw(self, color=None, u=None): """Draw the cylinder associated with the artist. Parameters ---------- color : tuple of float, optional The RGB color of the cylinder. u : int, optional Number of faces in the "u" direction. Default is ``~CylinderArtist.u``. Returns ------- list The GUIDs of the objects created in Rhino. """ color = color or self.color u = u or self.u vertices, faces = self.shape.to_vertices_and_faces(u=u) vertices = [list(vertex) for vertex in vertices] guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=color, disjoint=True) return [guid]
def draw_mesh(self, color=(0, 0, 0), disjoint=False): """Draw the mesh as a consolidated RhinoMesh. Parameters ---------- color : tuple, optional The color of the mesh. Default is black, ``(0, 0, 0)``. disjoint : bool, optional Draw the faces of the mesh with disjoint vertices. Default is ``False``. Returns ------- list The GUIDs of the created Rhino objects. Notes ----- The mesh should be a valid Rhino Mesh object, which means it should have only triangular or quadrilateral faces. Faces with more than 4 vertices will be triangulated on-the-fly. """ vertex_index = self.mesh.key_index() vertex_xyz = self.vertex_xyz vertices = [vertex_xyz[vertex] for vertex in self.mesh.vertices()] faces = [[ vertex_index[vertex] for vertex in self.mesh.face_vertices(face) ] for face in self.mesh.faces()] new_faces = [] for face in faces: f = len(face) if f == 3: new_faces.append(face + face[-1:]) elif f == 4: new_faces.append(face) elif f > 4: centroid = len(vertices) vertices.append( centroid_polygon([vertices[index] for index in face])) for a, b in pairwise(face + face[0:1]): new_faces.append([centroid, a, b, b]) else: continue layer = self.layer name = "{}".format(self.mesh.name) guid = compas_rhino.draw_mesh(vertices, new_faces, layer=layer, name=name, color=color, disjoint=disjoint) return [guid]
def draw_mesh(self, color=None, disjoint=False): """Draw the mesh as a consolidated RhinoMesh. Parameters ---------- color : 3-tuple, optional RGB color components in integer format (0-255). disjoint : bool, optional Draw the faces of the mesh with disjoint vertices. Default is ``False``. Returns ------- list The GUIDs of the created Rhino objects. Notes ----- The mesh should be a valid Rhino Mesh object, which means it should have only triangular or quadrilateral faces. Faces with more than 4 vertices will be triangulated on-the-fly. """ key_index = self.mesh.key_index() vertices = self.mesh.vertices_attributes('xyz') faces = [[key_index[key] for key in self.mesh.face_vertices(fkey)] for fkey in self.mesh.faces()] new_faces = [] for face in faces: f = len(face) if f == 3: new_faces.append(face + face[-1:]) elif f == 4: new_faces.append(face) elif f > 4: centroid = len(vertices) vertices.append( centroid_polygon([vertices[index] for index in face])) for a, b in pairwise(face + face[0:1]): new_faces.append([centroid, a, b, b]) else: continue layer = self.layer name = "{}.mesh".format(self.mesh.name) guid = compas_rhino.draw_mesh(vertices, new_faces, layer=layer, name=name, color=color, disjoint=disjoint) self.guids += [guid] return [guid]
def draw(self, u=10, v=10, show_vertices=False, show_edges=False, show_faces=True, join_faces=True): """Draw the sphere associated with the artist. Parameters ---------- u : int, optional Number of faces in the "u" direction. Default is ``10``. v : int, optional Number of faces in the "v" direction. Default is ``10``. show_vertices : bool, optional Default is ``False``. show_edges : bool, optional Default is ``False``. show_faces : bool, optional Default is ``True``. join_faces : bool, optional Default is ``True``. Returns ------- list The GUIDs of the objects created in Rhino. """ vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v) vertices = [list(vertex) for vertex in vertices] guids = [] if show_vertices: points = [{'pos': point, 'color': self.color} for point in vertices] guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False) if show_edges: lines = [] seen = set() for face in faces: for u, v in pairwise(face + face[:1]): if (u, v) not in seen: seen.add((u, v)) seen.add((v, u)) lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color}) guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False) if show_faces: if join_faces: guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.name, color=self.color, disjoint=True) guids.append(guid) else: polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces] guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False) self._guids = guids return guids
def draw(self, show_vertices=False, show_edges=False, show_faces=True, join_faces=True): """Draw the polyhedron associated with the artist. Parameters ---------- show_vertices : bool, optional Default is ``False``. show_edges : bool, optional Default is ``False``. show_faces : bool, optional Default is ``True``. join_faces : bool, optional Default is ``True``. Returns ------- list The GUIDs of the objects created in Rhino. """ vertices = [list(vertex) for vertex in self.shape.vertices] guids = [] if show_vertices: points = [{'pos': point, 'color': self.color, 'name': str(index)} for index, point in enumerate(vertices)] guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False) if show_edges: edges = self.shape.edges lines = [{'start': vertices[i], 'end': vertices[j], 'color': self.color} for i, j in edges] guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False) if show_faces: faces = self.shape.faces if join_faces: guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.name, color=self.color, disjoint=True) guids.append(guid) else: polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces] guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False) self._guids = guids return guids
def draw(self, color=None): """Draw the box associated with the artist. Parameters ---------- color : tuple of float, optional The RGB color of the box. Returns ------- list The GUIDs of the objects created in Rhino. """ color = color or self.color vertices = [list(vertex) for vertex in self.shape.vertices] faces = self.shape.faces guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.shape.name, color=color, disjoint=True) return [guid]
key = gkey_key[gkey] mesh.vertex[key]['is_fixed'] = True # find the fixed vertices fixed = set(mesh.vertices_where({'is_fixed': True})) # create a conduit for visualisation conduit = MeshConduit(mesh, color=(255, 255, 255), refreshrate=5) # set the target length target_length = 0.25 # visualise the process with a conduit with conduit.enabled(): optimise_trimesh_topology(mesh, target_length, tol=0.1, divergence=0.01, kmax=500, allow_boundary_split=True, allow_boundary_collapse=True, smooth=False, fixed=fixed, callback=callback, callback_args=(conduit, fixed, target, border)) compas_rhino.draw_mesh(mesh, layer='remeshed', clear_layer=True)
__author__ = ['Tom Van Mele', 'Matthias Rippmann'] __copyright__ = 'Copyright 2017, BRG - ETH Zurich', __license__ = 'MIT' __email__ = '*****@*****.**' def callback(mesh, k, args): conduit = args[0] conduit.redraw(k) boundary = rs.GetObject("Select Boundary Curve", 4) target_length = rs.GetReal("Select Edge Target Length", 2.5) points = rs.DivideCurve(boundary, rs.CurveLength(boundary) / target_length) faces = delaunay_from_points(points, points) mesh = Mesh.from_vertices_and_faces(points, faces) conduit = MeshConduit(mesh, refreshrate=2) with conduit.enabled(): optimise_trimesh_topology(mesh, target_length, kmax=250, callback=callback, callback_args=(conduit, )) compas_rhino.draw_mesh(mesh)
cube = Polyhedron.generate(6) mesh = Mesh.from_vertices_and_faces(cube.vertices, cube.faces) # give it a name # and set default vertex attributes mesh.attributes['name'] = 'Control' mesh.update_default_vertex_attributes({'is_fixed': False}) # draw the control mesh # with showing the faces compas_rhino.draw_mesh(mesh, layer='SubdModeling::Control', clear_layer=True, show_faces=False, show_vertices=True, show_edges=True) # allow the user to change the attributes of the vertices # note: the interaction loop exits # when the user cancels the selection of mesh vertices while True: keys = compas_rhino.select_mesh_vertices(mesh) if not keys: break compas_rhino.update_mesh_vertex_attributes(mesh, keys) # redraw the mesh to reflect the changes by the user
def RunCommand(is_interactive): if '3GS' not in sc.sticky: compas_rhino.display_message('3GS has not been initialised yet.') return scene = sc.sticky['3GS']['scene'] # get ForceVolMeshObject from scene objects = scene.find_by_name('force') if not objects: compas_rhino.display_message("There is no force diagram in the scene.") return force = objects[0] # get ForceVolMeshObject from scene objects = scene.find_by_name('form') if not objects: compas_rhino.display_message("There is no form diagram in the scene.") return form = objects[0] # check global constraints ------------------------------------------------- force.check_eq() form.check_eq() if not force.settings['_is.valid'] or not form.settings['_is.valid']: options = ["Yes", "No"] option = compas_rhino.rs.GetString( "System is not in equilibrium... proceed?", strings=options, defaultString="No") if not option: return if option == "No": return show_loads = form.settings['show.loads'] form.settings['show.loads'] = False # unified diagram ---------------------------------------------------------- while True: rs.EnableRedraw(True) alpha = rs.GetReal('unified diagram scale', minimum=0.01, maximum=1.0) if alpha is None: break if not alpha: break compas_rhino.clear_layer(force.layer) compas_rhino.clear_layer(form.layer) # 1. get colors -------------------------------------------------------- hf_color = (0, 0, 0) uv_c_dict = get_force_colors_uv(force.diagram, form.diagram, gradient=True) # 2. compute unified diagram geometries -------------------------------- cells, prisms = volmesh_ud(force.diagram, form.diagram, scale=alpha) # 3. draw -------------------------------------------------------------- for cell in cells: vertices = cells[cell]['vertices'] faces = cells[cell]['faces'] compas_rhino.draw_mesh(vertices, faces, layer=force.layer, name=str(cell), color=hf_color, redraw=False) for edge in prisms: vertices = prisms[edge]['vertices'] faces = prisms[edge]['faces'] compas_rhino.draw_mesh(vertices, faces, layer=force.layer, name=str(edge), color=uv_c_dict[edge], redraw=False) form.artist.draw_edges(color=uv_c_dict) form.settings['show.loads'] = show_loads scene.save()
uv_c_dict = get_force_colors_uv(forcediagram, formdiagram, gradient=True) hf_c_dict = get_force_colors_hf(forcediagram, formdiagram, uv_c_dict=uv_c_dict) # 2. compute unified diagram geometries ------------------------------------ # halffaces, prism_faces = volmesh_ud(forcediagram, formdiagram, scale=alpha) cells, prisms = volmesh_ud(forcediagram, formdiagram, scale=alpha) # 3. draw ------------------------------------------------------------------ for cell in cells: vertices = cells[cell]['vertices'] faces = cells[cell]['faces'] compas_rhino.draw_mesh(vertices, faces, layer=force_layer, name=str(cell), color=hf_color, redraw=False) # forces = get_force_mags(forcediagram, formdiagram) for edge in prisms: vertices = prisms[edge]['vertices'] faces = prisms[edge]['faces'] compas_rhino.draw_mesh(vertices, faces, layer=force_layer, name=str(edge), color=uv_c_dict[edge], redraw=False)
"""Delaunay triangulation from points""" import compas_rhino as rhino from compas.datastructures.mesh import Mesh from compas.datastructures.mesh.algorithms import delaunay_from_points __author__ = ['Tom Van Mele', 'Matthias Rippmann'] __copyright__ = 'Copyright 2017, BRG - ETH Zurich', __license__ = 'MIT' __email__ = '*****@*****.**' guids = rhino.select_points() vertices = rhino.get_point_coordinates(guids) faces = delaunay_from_points(vertices) mesh = Mesh.from_vertices_and_faces(vertices, faces) rhino.draw_mesh(mesh)