def mesh_draw_vertices(mesh, keys=None, color=None, layer=None, clear_layer=False, clear_vertices=False, redraw=True): """Draw a selection of vertices of the mesh. Parameters ---------- mesh : compas.datastructures.Mesh A mesh object. keys : list (None) A list of vertex keys identifying which vertices to draw. Default is to draw all vertices. color : str, tuple, dict (None) The color specififcation for the vertices. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all vertices, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default vertex color (``self.defaults['vertex.color']``). Default is use the color of the parent layer. layer : str (None) The layer in which the vertices are drawn. Default is to draw in the current layer. clear_layer : bool (False) Clear the drawing layer. redraw : bool (True) Redraw the view after adding the vertices. Notes ----- The vertices are named using the following template: ``"{}.vertex.{}".format(self.mesh.attributes['name'], key)``. This name is used afterwards to identify vertices of the meshin the Rhino model. Examples -------- >>> """ artist = MeshArtist(mesh) artist.layer = layer if clear_layer: artist.clear_layer() if clear_vertices: artist.clear_vertices() guids = artist.draw_vertices(color=color) if redraw: artist.redraw() return guids
def mesh_draw_edges(mesh, keys=None, color=None, layer=None, clear_layer=False, redraw=True): """Draw a selection of edges of the mesh. Parameters ---------- keys : list A list of edge keys (as uv pairs) identifying which edges to draw. Default is to draw all edges. color : str, tuple, dict The color specififcation for the edges. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all faces, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default face color (``self.defaults['face.color']``). Default is use the color of the parent layer. layer : str (None) The layer in which the edges are drawn. Default is to draw in the current layer. clear_layer : bool (False) Clear the drawing layer. redraw : bool (True) Redraw the view after adding the edges. Notes ----- All edges are named using the following template: ``"{}.edge.{}-{}".fromat(self.mesh.attributes['name'], u, v)``. This name is used afterwards to identify edges of the mesh in the Rhino model. Examples -------- >>> mesh_draw_edges(mesh) >>> mesh_draw_edges(mesh, color='#ff0000') >>> mesh_draw_edges(mesh, color=(255, 0, 0)) >>> mesh_draw_edges(mesh, keys=mesh.edges_on_boundary()) >>> mesh_draw_edges(mesh, color={(u, v): '#00ff00' for u, v in mesh.edges_on_boundary()}) """ artist = MeshArtist(mesh) artist.layer = layer if clear_layer: artist.clear_layer() artist.clear_edges() guids = artist.draw_edges(color=color) if redraw: artist.redraw() return guids
def mesh_draw_face_labels(mesh, attr_name=None, layer=None, color=None, formatter=None): """Display labels for the faces of a mesh. Parameters ---------- mesh : compas.datastructures.Mesh A mesh object. attr_name : str (None) The name of the attribute value to display in the label. Default is is to display the face key. layer : str (None) The layer to draw in. Default is to draw in the current layer. color : str, tuple, list, dict (None) The color specififcation for the labels. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all face labels, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default face color (``self.defaults['face.color']``). Default is to inherit color from the parent layer. formatter : callable (None) A formatting function. Defaults to the built-in ``str`` function. Notes ----- The labels are named using the following template: ``"{}.face.label.{}".format(self.mesh.name, key)``. This name is used afterwards to identify faces of the meshin the Rhino model. Examples -------- >>> """ if not attr_name: attr_name = 'key' if formatter: assert callable(formatter), 'The provided formatter is not callable.' else: formatter = str text = {} for index, (key, attr) in enumerate(mesh.faces(True)): if 'key' == attr_name: value = key elif 'index' == attr_name: value = index else: value = attr[attr_name] text[key] = formatter(value) artist = MeshArtist(mesh) artist.layer = layer artist.clear_facelabels() artist.draw_facelabels(text=text, color=color) artist.redraw()
def mesh_draw(mesh, layer=None, clear_layer=False, clear_vertices=False, clear_faces=False, clear_edges=False, show_faces=True, show_vertices=False, show_edges=False, vertexcolor=None, edgecolor=None, facecolor=None): """ Draw a mesh object in Rhino. Parameters ---------- mesh : compas.datastructures.Mesh The mesh object. layer : str (None) The layer to draw in. Default is to draw in the current layer. clear_layer : bool (False) Clear the drawing layer. show_faces : bool (True) Draw the faces. show_vertices : bool (False) Draw the vertices. show_edges : bool (False) Draw the edges. vertexcolor : str, tuple, list, dict (None) The vertex color specification. Default is to use the color of the parent layer. edgecolor : str, tuple, list, dict (None) The edge color specification. Default is to use the color of the parent layer. facecolor : str, tuple, list, dict (None) The face color specification. Default is to use the color of the parent layer. Notes ----- Colors can be specifiedin different ways: * str: A hexadecimal color that will be applied to all elements subject to the specification. * tuple, list: RGB color that will be applied to all elements subject to the specification. * dict: RGB or hex color dict with a specification for some or all of the related elements. Notes ----- RGB colors specified as values between 0 and 255, should be integers. RGB colors specified as values between 0.0 and 1.0, should be floats. """ artist = MeshArtist(mesh) artist.layer = layer if clear_layer: artist.clear_layer() if clear_vertices: artist.clear_vertices() if clear_edges: artist.clear_edges() if clear_faces: artist.clear_faces() if show_faces: artist.draw_faces(color=facecolor) if show_edges: artist.draw_edges(color=edgecolor) if show_vertices: artist.draw_vertices(color=vertexcolor) artist.redraw()