def mesh_draw(mesh, color=None): """ Draw a mesh object in Rhino. Parameters ---------- mesh : compas.datastructures.Mesh The mesh object. color : str, tuple, list, dict (None) The vertex color specification. Defaults to None. 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) return artist.draw(color)
def load_slicer(path, folder_name, json_name): """ Loads slicer data. """ data = load_json_file(path, folder_name, json_name) mesh = None paths_nested_list = [] are_closed = [] all_points = [] if data: if 'mesh' in data: compas_mesh = Mesh.from_data(data['mesh']) artist = MeshArtist(compas_mesh) mesh = artist.draw() else: print('No mesh has been saved in the json file.') if 'layers' in data: layers_data = data['layers'] for i in range(len(layers_data)): paths_nested_list.append( []) # save each layer on a different list layer_data = layers_data[str(i)] paths_data = layer_data['paths'] for j in range(len(paths_data)): path_data = paths_data[str(j)] pts = [] are_closed.append(path_data['is_closed']) if len(path_data['points'] ) > 2: # ignore smaller curves that throw errors for k in range(len(path_data['points'])): pt = path_data['points'][str(k)] pt = rs.AddPoint(pt[0], pt[1], pt[2]) # re-create points pts.append(pt) all_points.extend(pts) path = rs.AddPolyline(pts) paths_nested_list[-1].append(path) else: print( 'No layers have been saved in the json file. Is this the correct json?' ) print('The slicer contains %d layers. ' % len(paths_nested_list)) paths_nested_list = list_to_ghtree(paths_nested_list) return mesh, paths_nested_list, are_closed, all_points
def load_multiple_meshes(starts_with, ends_with, path, folder_name): """ Load all the meshes that have the specified name, and print them in different colors. """ filenames = get_files_with_name(starts_with, ends_with, os.path.join(path, folder_name, 'output')) meshes = [ Mesh.from_obj(os.path.join(path, folder_name, 'output', filename)) for filename in filenames ] loaded_meshes = [] for i, m in enumerate(meshes): artist = MeshArtist(m) color = get_color(i, total=len(meshes)) mesh = artist.draw(color) loaded_meshes.append(mesh) return loaded_meshes
def receive_mesh(message): mesh_message = Mesh.from_msg(message) artist = MeshArtist(mesh_message.mesh) sc.doc = Rhino.RhinoDoc.ActiveDoc sc.doc.Objects.AddMesh(artist.draw()) sc.doc = ghdoc
# Ghpython import compas from compas.datastructures import Mesh from compas_ghpython.artists import MeshArtist mesh = Mesh.from_obj(compas.get('hypar.obj')) artist = MeshArtist(mesh) a = artist.draw()