vertexcolor = { key: (255, 0, 0) for key in shell.vertices_where({'is_anchor': True}) } lines = [] for key in shell.vertices(): a = shell.vertex_coordinates(key) n = shell.vertex_normal(key) b = add_vectors(a, n) lines.append({ 'start': a, 'end': b, 'arrow': 'end', 'color': (0, 255, 0), 'name': "{}.{}.normal".format(shell.name, key) }) # ============================================================================== # Visualise # ============================================================================== artist = ShellArtist(shell, layer="Geometry::Normals") artist.clear_layer() artist.draw_vertices(color=vertexcolor) artist.draw_edges() artist.draw_lines(lines) artist.redraw()
# path = os.path.join(DATA, 'FABRIC', 'unrolled', SIDE, "{}.json".format(mesh.attributes['name'])) # mesh.to_json(path) # for mesh in SW_unrolled: # path = os.path.join(DATA, 'FABRIC', 'unrolled', SIDE, "{}.json".format(mesh.attributes['name'])) # mesh.to_json(path) # for mesh in NW_unrolled: # path = os.path.join(DATA, 'FABRIC', 'unrolled', SIDE, "{}.json".format(mesh.attributes['name'])) # mesh.to_json(path) # ============================================================================== # Visualize # ============================================================================== ARTIST = ShellArtist(None) for mesh in SOUTH_unrolled: points = [ mesh.vertex_coordinates(key) for key in mesh.vertices_on_boundary(ordered=True) ] polygon = offset_polygon(points, SEEM) polygons = [{'points': polygon + polygon[:1]}] ARTIST.mesh = mesh ARTIST.layer = "Unrolled::{}::{}".format(SIDE, mesh.attributes['name']) ARTIST.clear_layer() ARTIST.draw_faces() ARTIST.draw_facelabels(text={ key: "{}".format(attr['count'])
for key in shell.vertices(): normal = shell.vertex_normal(key) xyz = shell.vertex_coordinates(key) up = scale_vector(normal, 0.5 * thickness) down = scale_vector(normal, -0.5 * thickness) xyz_up = add_vectors(xyz, up) xyz_down = add_vectors(xyz, down) edos.set_vertex_attributes(key, 'xyz', xyz_up) idos.set_vertex_attributes(key, 'xyz', xyz_down) # ============================================================================== # Visualise # ============================================================================== artist = ShellArtist(None) artist.mesh = idos artist.layer = "Geometry::Offset::Intrados" artist.clear_layer() artist.draw_mesh(color=(255, 0, 0)) artist.mesh = edos artist.layer = "Geometry::Offset::Extrados" artist.clear_layer() artist.draw_mesh(color=(0, 0, 255)) artist.redraw()
LINES += framelines(origin, xaxis, yaxis, zaxis, 'frame') normal = yaxis origin = add_vectors(origin, scale_vector(normal, OFFSET)) plane = (origin, normal) points = [] for key in keys: a = SHELL.vertex_coordinates(key) r = SHELL.get_vertex_attributes(key, ['rx', 'ry', 'rz']) b = add_vectors(a, r) line = a, b x = intersection_line_plane(line, plane) points.append(x) POINTS.append({ 'pos' : x, 'color' : (0, 0, 255), 'name' : "{}.{}.extensions".format(SHELL.name, key)}) # ============================================================================== # Visualize # ============================================================================== ARTIST = ShellArtist(SHELL, layer="Scaffolding::Clamps") ARTIST.clear_layer() ARTIST.draw_points(POINTS) ARTIST.draw_lines(LINES) ARTIST.redraw()
x = intersection_line_plane(line, plane) points.append(x) rhinopoints.append({ 'pos' : x, 'color' : (0, 0, 255), 'name' : "{}.{}.anchor".format(shell.name, key) }) box = bounding_box(points) lines = [] for i, j in [(0, 1), (1, 5), (5, 4), (4, 0)]: a = box[i] b = box[j] d = distance_point_point(a, b) if d < 0.01: continue lines.append({ 'start' : a, 'end' : b, 'color' : (0, 255, 255), 'name' : "box" }) artist = ShellArtist(shell, layer="Scaffolding::Points") artist.clear_layer() artist.draw_points(rhinopoints) artist.draw_lines(lines) artist.redraw()
# ============================================================================== # Initialise # ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.abspath(os.path.join(HERE, '..', 'data')) FILE_I = os.path.join(DATA, 'data.json') SHELL = Shell.from_json(FILE_I) # ============================================================================== # Visualise # ============================================================================== ARTIST = ShellArtist(SHELL, layer="FoFin") ARTIST.clear_layer() ARTIST.layer = "FoFin::Data" ARTIST.draw_vertices(color={ key: (255, 0, 0) for key in SHELL.vertices_where({'is_anchor': True}) }) ARTIST.draw_edges() ARTIST.draw_faces() ARTIST.layer = "FoFin::Forces" ARTIST.draw_forces(scale=0.025) ARTIST.layer = "FoFin::Reactions" ARTIST.draw_reactions(scale=0.5)
'points': [box1[0], box1[3], box2[3], box2[0], box1[0]], 'color': (0, 0, 0) }) POLYGONS.append({ 'points': [box1[1], box2[1], box2[2], box1[2], box1[1]], 'color': (0, 0, 0) }) FRAMES += framelines(origin, xaxis, yaxis, zaxis, 'box') # ============================================================================== # Visualize # ============================================================================== ARTIST = ShellArtist(SHELL, layer="Scaffolding") ARTIST.clear_layer() ARTIST.layer = "Scaffolding::Anchors" ARTIST.clear_layer() ARTIST.draw_points(POINTS) ARTIST.layer = "Scaffolding::Connectors" ARTIST.clear_layer() ARTIST.draw_lines(LINES) ARTIST.layer = "Scaffolding::Beams" ARTIST.clear_layer() ARTIST.draw_polygons(POLYGONS) ARTIST.layer = "Scaffolding::Frames"
# ============================================================================== # Initialise # ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.abspath(os.path.join(HERE, '..', 'data')) FILE_I = os.path.join(DATA, 'data-extended-strips-split.json') FILE_O = os.path.join(DATA, 'data-extended-strips-split.json') fabric = Shell.from_json(FILE_I) # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(fabric, layer="Fabric::SplitCorners") artist.clear_layer() artist.draw_vertices() artist.draw_faces() artist.draw_edges() artist.redraw() # ============================================================================== # Assign strips # ============================================================================== while True: edge = ShellHelper.select_edge(fabric) if not edge: break u, v = edge
# ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.abspath(os.path.join(HERE, '..', 'data')) FILE_I = os.path.join(DATA, 'data-extended-faces.json') FILE_O = os.path.join(DATA, 'data-extended-faces.json') shell = Shell.from_json(FILE_I) mesh = shell.copy() # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(mesh, layer="Fabric::Extended") artist.clear_layer() artist.draw_vertices() artist.draw_faces() artist.draw_facenormals() artist.redraw() # ============================================================================== # Add faces # ============================================================================== while True: keys = ShellHelper.select_vertices(mesh) if not keys: break mesh.add_face(keys)
for root in sample(list(SHELL.faces()), k=100): children = SHELL.get_face_attribute(root, 'children') u = children[-1] faces = [] for v in children[:-1]: faces.append(SUBD1.halfedge[u][v]) grandchildren = [] for fkey in faces: grandchildren += SUBD1.get_face_attribute(fkey, 'children') descendants[root] = children + grandchildren # ============================================================================== # Visualise # ============================================================================== ARTIST = ShellArtist(None, layer="Pillows") ARTIST.clear_layer() keys = [] for root in descendants: keys += list(SHELL.face_vertices(root)) ARTIST.mesh = SHELL ARTIST.layer = "Pillows::Control" ARTIST.draw_vertices(keys=keys, color={key: (255, 0, 0) for key in keys}) ARTIST.draw_edges() keys = [] for root in descendants: keys += descendants[root]
subd.set_vertex_attribute(key, 'is_anchor', True) # dva = shell.default_vertex_attributes # gkey_key = shell.gkey_key() # # for key, attr in subd.vertices(True): # gkey = geometric_key(subd.vertex_coordinates(key)) # if gkey in gkey_key: # key = gkey_key[gkey] # for name in dva: # subd.set_vertex_attribute(key, name, shell.get_vertex_attribute(key, name)) # subd.set_vertex_attribute(key, 'is_anchor', True) # ============================================================================== # Serialize # ============================================================================== subd.to_json(FILE_O) # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(subd, layer="Geometry::Subd") artist.clear_layer() # artist.draw_vertices(color={key: (255, 0, 0) for key in subd.vertices_where({'is_anchor': True})}) # artist.draw_edges() artist.draw_mesh(color=(0, 255, 0)) artist.redraw()
for fkey in EDOS.faces(): vertices = EDOS.face_vertices(fkey) vertices = [key + max_int_key for key in vertices] VOLUME.add_face(vertices) boundary = EDOS.vertices_on_boundary(ordered=True) boundary.append(boundary[0]) for a, b in pairwise(boundary): VOLUME.add_face([b, a, a + max_int_key, b + max_int_key]) # ============================================================================== # Visualise # ============================================================================== ARTIST = ShellArtist(SHELL, layer="Shell") ARTIST.clear_layer() # ARTIST.layer = "Shell::FoFin" # ARTIST.draw_vertices(color={key: (255, 0, 0) for key in SHELL.vertices_where({'is_anchor': True})}) # ARTIST.draw_edges() # ARTIST.draw_faces() # ARTIST.draw_reactions(scale=0.5) # ARTIST.draw_forces(scale=0.025) # ARTIST.layer = "Shell::Intrados" # ARTIST.mesh = IDOS # ARTIST.draw_mesh(color=(255, 0, 0)) # ARTIST.draw_facenormals(color=(255, 0, 0), scale=0.05) # ARTIST.layer = "Shell::Extrados"
for key, attr in EDOS.vertices(True): index = key_index[key] attr['x'] = xyz[index][0] attr['y'] = xyz[index][1] attr['z'] = xyz[index][2] # ============================================================================== # Volume # ============================================================================== # ============================================================================== # Visualise # ============================================================================== ARTIST = ShellArtist(None, layer='Pillows') ARTIST.clear_layer() anchors = list(EDOS.vertices_where({'is_anchor': True})) ARTIST.mesh = EDOS ARTIST.layer = "Pillows::EDOS" ARTIST.clear_layer() ARTIST.draw_vertices(keys=anchors, color={key: (255, 0, 0) for key in anchors}) ARTIST.draw_mesh() anchors = list(IDOS.vertices_where({'is_anchor': True})) ARTIST.mesh = IDOS ARTIST.layer = "Pillows::IDOS" ARTIST.clear_layer()
lines = [] for key in shell.vertices(): area = shell.vertex_area(key) volume = area * thickness a = shell.vertex_coordinates(key) v = [0.0, 0.0, -volume] b = add_vectors(a, v) lines.append({ 'start' : a, 'end' : b, 'name' : "{}.{}.volume.{:.2f}".format(shell.name, key, volume), 'color' : (0, 0, 255), 'arrow' : 'end' }) # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(shell, layer="Geometry::Area") artist.clear_layer() artist.draw_vertices() artist.draw_edges() artist.draw_lines(lines) artist.redraw()
# add the vertices of the edos for key, attr in edos.vertices(True): volume.add_vertex(key=key + max_int_key, **attr) # add the faces of the edos for fkey in edos.faces(): vertices = edos.face_vertices(fkey) vertices = [key + max_int_key for key in vertices] volume.add_face(vertices) # add the side faces boundary = edos.vertices_on_boundary(ordered=True) boundary.append(boundary[0]) for a, b in pairwise(boundary): volume.add_face([b, a, a + max_int_key, b + max_int_key]) # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(volume, layer="Geometry::Volume") artist.clear_layer() artist.draw_mesh(disjoint=True) artist.redraw()
from compas_fofin.datastructures import Shell from compas_fofin.rhino import ShellArtist # ============================================================================== # Initialise # ============================================================================== HERE = os.path.dirname(__file__) DATA = os.path.abspath(os.path.join(HERE, '..', 'data')) FILE_I = os.path.join(DATA, 'data.json') shell = Shell.from_json(FILE_I) # ============================================================================== # Compute dual # ============================================================================== dual = mesh_dual(shell) dual.name = "Dual" # ============================================================================== # Visualize # ============================================================================== artist = ShellArtist(dual, layer="Geometry::Dual") artist.clear_layer() artist.draw_vertices() artist.draw_edges() artist.redraw()