def RunCommand(is_interactive): if 'AGS' not in sc.sticky: compas_rhino.display_message('AGS has not been initialised yet.') return scene = sc.sticky['AGS']['scene'] guids = compas_rhino.select_lines(message='Select Form Diagram Lines') if not guids: return compas_rhino.rs.HideObjects(guids) lines = compas_rhino.get_line_coordinates(guids) graph = FormGraph.from_lines(lines) if not graph.is_planar_embedding(): compas_rhino.display_message('The graph is not planar. Therefore, a form diagram cannot be created.') return form = FormDiagram.from_graph(graph) scene.purge() scene.add(form, name='Form', layer='AGS::FormDiagram') scene.update() scene.save()
def create_cablenet_from_lines(settings): guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) cablenet = Cablenet.from_lines(lines) return cablenet
def from_lines(root): guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) form = FormDiagram.from_lines(lines) return form
def select_edges(self): """Select edges of the network. Returns ------- list A list of edge identifiers. """ guids = compas_rhino.select_lines() edges = [self.artist.guid_edge[guid] for guid in guids if guid in self.artist.guid_edge] return edges
def select_edges(self, message="Select edges."): """Select edges of the mesh. Returns ------- list A list of edge identifiers. """ guids = compas_rhino.select_lines(message=message) edges = [self.guid_edge[guid] for guid in guids if guid in self.guid_edge] return edges
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] settings = TNA['settings'] options = ['obj', 'json', 'lines', 'mesh'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'obj': filepath = compas_rhino.select_file(folder=compas_tna.DATA, filter='OBJ files (*.obj)|*.obj||') if not filepath: return form = FormDiagram.from_obj(filepath) elif option == 'json': filepath = compas_rhino.select_file( folder=compas_tna.DATA, filter='JSON files (*.json)|*.json||') if not filepath: return form = FormDiagram.from_json(filepath) elif option == 'lines': guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) form = FormDiagram.from_lines(lines) elif option == 'mesh': guid = compas_rhino.select_mesh() if not guid: return form = FormDiagram.from_rhinomesh(guid) else: raise NotImplementedError del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = None compas_rhino.clear_layer(settings['layer.force']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings)
def RunCommand(is_interactive): scene = get_scene() if not scene: return guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) pattern = Pattern.from_lines(lines, delete_boundary_face=True) if not pattern.face: print("No faces found! Pattern object was not created.") return compas_rhino.rs.HideObjects(guids) scene.clear() scene.add(pattern, name='pattern') scene.update() print("Pattern object successfully created.")
Parameters ---------- form : compas_tna.diagrams.FormDiagram The form diagram. zmax : float The maximum z-coordinate of all vertices of the equilibrium network. """ formdata, scale = tna.vertical_from_zmax_proxy(form.to_data(), zmax) form.data = formdata return scale # 1. make the form diagram from selected line elements guids = compas_rhino.select_lines() rs.HideObjects(guids) form = FormDiagram.from_rhinolines(guids) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 2. identify the supports keys = DiagramHelper.select_vertices(form) if keys: form.set_vertices_attributes(['is_anchor', 'is_fixed'], [True, True], keys=keys) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 3. update the boundaries
class SkeletonVol(Mesh): """ SkeletonVol is typologically constructed low poly mesh. It construct a branch like volumetric mesh from input lines. """ def __init__(self): super(SkeletonVol, self).__init__() @classmethod def from_skeleton_lines(cls, lines=[]): skeleton_vol = cls() network = Network.from_lines(lines) convex_hull_mesh = get_convex_hull_mesh(points) def get_convex_hull_mesh(points): faces = convex_hull(points) vertices = list(set(flatten(faces))) i_index = {i: index for index, i in enumerate(vertices)} vertices = [points[index] for index in vertices] faces = [[i_index[i] for i in face] for face in faces] faces = unify_cycles(vertices, faces) mesh = Mesh.from_vertices_and_faces(vertices, faces) return mesh guids = compas_rhino.select_lines() lines = compas_rhino.get_line_coordinates(guids) network = Network.from_lines(lines) leafs = [] joints = [] for key in network.node: if network.is_leaf(key): leafs.append(key) else: joints.append(key) pt_center = network.node_coordinates(joints[0]) pts = [network.node_coordinates(key) for key in leafs] convex_hull_mesh = get_convex_hull_mesh(pts) mesh = Mesh() # for key in convex_hull_mesh.vertices(): # mesh.add_vertex(key) # mesh.vertex[key].update(convex_hull_mesh.vertex[key]) descdent_tree = copy.deepcopy(convex_hull_mesh.halfedge) for u, v in convex_hull_mesh.edges(): descdent_tree[u][v] = {'jp': None, 'lp': None} descdent_tree[v][u] = {'jp': None, 'lp': None} # current_key = convex_hull_mesh.number_of_vertices() current_key = 0 for fkey in convex_hull_mesh.faces(): f_centroid = convex_hull_mesh.face_centroid(fkey) vec = Vector.from_start_end(pt_center, f_centroid) # if the branches has a 'convex' corner, # flip the vec to the corresponding face. f_normal = convex_hull_mesh.face_normal(fkey) angle = angle_vectors(f_normal, vec, False) if angle > math.pi * 0.5: pln = Plane(pt_center, f_normal) pt_mirror = mirror_point_plane(f_centroid, pln) vec = Vector.from_start_end(pt_center, pt_mirror) vec.unitize() vec.scale(joint_width) pt = add_vectors(pt_center, vec) face = convex_hull_mesh.face[fkey] v_keys = face + [face[0]] for u, v in pairwise(v_keys): descdent_tree[u][v].update({'jp': current_key}) mesh.add_vertex(current_key) mesh.vertex[current_key].update({'x': pt[0], 'y': pt[1], 'z': pt[2]}) current_key += 1 for key in convex_hull_mesh.vertices(): nbrs = convex_hull_mesh.vertex_neighbors(key) for nbr in nbrs: halfedge = (key, nbr) pt_joint_descendent = mesh.vertex_coordinates( descdent_tree[key][nbr]['jp']) vec_edge = Vector.from_start_end( pt_center, convex_hull_mesh.vertex_coordinates(key)) pln_end = Plane(convex_hull_mesh.vertex_coordinates(key), vec_edge) pt = project_point_plane(pt_joint_descendent, pln_end) vec_leaf = Vector.from_start_end( convex_hull_mesh.vertex_coordinates(key), pt) vec_leaf.unitize() vec_leaf.scale(leaf_width) pt = add_vectors(convex_hull_mesh.vertex_coordinates(key), vec_leaf) descdent_tree[key][nbr].update({'lp': current_key}) mesh.add_vertex(current_key) mesh.vertex[current_key].update({ 'x': pt[0], 'y': pt[1], 'z': pt[2] }) current_key += 1 for key in convex_hull_mesh.vertices(): nbrs = convex_hull_mesh.vertex_neighbors(key, ordered=True) v_keys = nbrs + [nbrs[0]] for a, b in pairwise(v_keys): face = [ descdent_tree[key][a]['lp'], descdent_tree[key][a]['jp'], descdent_tree[key][b]['jp'], descdent_tree[key][b]['lp'] ] mesh.add_face(face) fixed = list(mesh.vertices_where({'vertex_degree': 3})) fixed = list(mesh.vertices()) mesh = mesh_subdivide_catmullclark(mesh, k=1, fixed=fixed) # mesh = mesh_subdivide_quad(mesh, k=1) mesh_smooth_centroid(mesh, fixed=fixed) artist = MeshArtist(mesh) artist.draw_mesh()