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 draw_facelabels(self, **kwattr): artist = MeshArtist(self) artist.draw_facelabels(**kwattr)
vertices = [[0.5, 0.0, 0.0], [0.0, 1.0, 0.0], [-0.5, 0.0, 0.0], [1.0, 1.0, 0.0]] faces = [[0, 1, 2], [1, 0, 3]] my_mesh = Mesh.from_vertices_and_faces(vertices, faces) artist = MeshArtist(my_mesh, layer="00_my_first mesh") artist.clear_layer() artist.draw_vertices() artist.draw_faces() artist.draw_edges() artist.draw_vertexlabels() artist.draw_facelabels() artist.draw_edgelabels() # iterate through the mesh # for key,attr in my_mesh.vertices(True): # print (key, attr['x'], attr['y'], attr['z']) # for key in my_mesh.faces(): # print(key) # for key in my_mesh.edges(): # print(key) # get topology information vertex = 0 #print (my_mesh.vertex_neighbors(vertex , ordered=False))
from compas_rhino.artists import MeshArtist poly = Polyhedron.generate(12) mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces) artist = MeshArtist(mesh) artist.clear() artist.draw_vertices() artist.redraw(0.0) artist.draw_vertexlabels() artist.redraw(1.0) artist.draw_faces() artist.redraw(1.0) artist.draw_facelabels() artist.redraw(1.0) artist.draw_edges() artist.redraw(1.0) artist.draw_edgelabels() artist.redraw(1.0) print(artist.save(os.path.join(compas.TEMP, 'test4.png')))
while True: pick = rs.GetString('Set target area', strings=['pick_face', 'exit']) if pick == 'pick_face': fkey = mesh_select_face(cell) target_area = rs.GetReal('set target area', 1, 0.1, 1000.0) target_areas[fkey] = target_area elif pick == 'exit': break artist = MeshArtist(cell) artist.draw_facelabels(text=target_areas) rs.EnableRedraw(True) # arearisation options ------------------------------------------------- fix_normal = rs.GetBoolean('Fix face normals?', items=[('fix_normals', 'no', 'yes')], defaults=[False]) target_normals = {} if fix_normal: for fkey in cell.faces(): target_normals[fkey] = cell.face_normal(fkey) # arearise -------------------------------------------------------------