def RunCommand(is_interactive): #load Derivation and delete last step derivation = Derivation.from_json(rhino_UI_utilities.get_json_file_location()) continue_playback = True step_id = 0 while(continue_playback): #ask user for which step they would like to see derivation_last_step_index = derivation.count - 1 step_id = rs.GetInteger("Enter which step to visualize (0 - "+ str(derivation_last_step_index) + " step) (Enter -1 for last step)", step_id, -1, derivation_last_step_index) if (step_id == -1): step_id = derivation_last_step_index if (step_id == None): break # Allow user to quite the command #load the selected model model = derivation.get_step(step_id) step_id = step_id + 1 #Visualization artist = MeshArtist(None, layer ='BEAM::Beams_out') artist.clear_layer() for beam in model.beams: artist = MeshArtist(beam.mesh, layer ='BEAM::Beams_out') artist.draw_faces(join_faces=True) artist.redraw()
def RunCommand(is_interactive): #load Derivation and model derivation = Derivation.from_json( rhino_UI_utilities.get_json_file_location()) model = derivation.get_next_step() #user input rc, corners = Rhino.Input.RhinoGet.GetRectangle() if rc != Rhino.Commands.Result.Success: return rc plane = Rhino.Geometry.Plane(corners[0], corners[1], corners[2]) beam_frame = Frame(plane[0], plane[1], plane[2]) length = rs.GetReal("length", 4000, 300, None) #Generate unique name for the Beam name = create_id() #Create Beam model.rule_create_beam(beam_frame, length, 100, 100, name) #Save Derivation (Model is also saved) derivation.to_json(rhino_UI_utilities.get_json_file_location(), pretty=True) #Visualization artist = MeshArtist(None, layer='BEAM::Beams_out') artist.clear_layer() for beam in model.beams: artist = MeshArtist( beam.mesh, layer='BEAM::Beams_out' ) #.mesh is not ideal fix in beam and assemble class artist.draw_faces(join_faces=True) return 0
def RunCommand(is_interactive): """Interactive Rhino Command Creates 90 Lap joint on a seleceted Beam Return: ------ None """ #load Derivation and model derivation = Derivation.from_json(rhino_UI_utilities.get_json_file_location()) model = derivation.get_next_step() #Select mesh Obj_ref = rs.GetObject(message = "select mesh(es)", filter = 32, preselect = False, subobjects = True) selected_beam_name = (rs.ObjectName(Obj_ref)[:-5]) #Loop through all beams in model to identify the selected beam selected_beam = None for beam in model.beams: if(beam.name == selected_beam_name): selected_beam = beam break assert (selected_beam != None) #list of user inputs(face needs to be implemented through UI) face_id = rs.GetInteger("face_id",None,0,5) helper = UI_helpers() joint_point = helper.Get_SelectPointOnMeshEdge("Select mesh edge","Pick point on edge") ext_start = rs.GetReal("extension start ",200,None,None) ext_end = rs.GetReal("extension end ",200,None,None) name = create_id() #adding joints to selected Beam #joint_distance_from_start = Get_distancefromBeamYZFrame(selected_beam,joint_point) joint_distance_from_start = selected_beam.Get_distancefromBeamYZFrame(joint_point) match_beam_origin = model.rule_90lap(selected_beam,joint_distance_from_start,face_id,ext_start,ext_end,name) #Save Derivation (Model is also saved) derivation.to_json(rhino_UI_utilities.get_json_file_location(), pretty = True) #Visualization viz_point = [] for pt in match_beam_origin: a = (pt[0],pt[1],pt[2]) viz_point.append({ 'pos': a, 'color': (0,255,0) }) #Visualization artist = MeshArtist(None, layer ='BEAM::Beams_out') artist.clear_layer() artist.draw_points(viz_point) for beam in model.beams: artist = MeshArtist(beam.mesh, layer ='BEAM::Beams_out')#.mesh is not ideal fix in beam and assemble class artist.draw_faces(join_faces=True)
def draw_mesh_faces(mesh): fkeys_nodraw = [ fkey for fkey in mesh.faces() if mesh.face_area(fkey) <= 0 ] fkeys = list(set(list(mesh.faces())) - set(fkeys_nodraw)) artist = MeshArtist(mesh) artist.layer = '3GS::Skeleton' artist.draw_faces(faces=fkeys, join_faces=True)
def subdivide(mesh, guid): compas_rhino.delete_object(guid) mesh = mesh_subdivide_catmullclark(mesh, k=1) artist = MeshArtist(mesh) artist.layer = '3GS::Skeleton' guid = artist.draw_faces(join_faces=True) artist.redraw() return mesh, guid[0]
def RunCommand(is_interactive): #load Derivation and delete last step derivation = Derivation.from_json( rhino_UI_utilities.get_json_file_location()) derivation.remove_last_step() print("New Derivation step count:", str(derivation.count)) #load last model model = derivation.get_step(derivation.count - 1) #Visualization artist = MeshArtist(None, layer='BEAM::Beams_out') artist.clear_layer() for beam in model.beams: artist = MeshArtist(beam.mesh, layer='BEAM::Beams_out') artist.draw_faces(join_faces=True) #Save Derivation (Model is also saved) derivation.to_json(rhino_UI_utilities.get_json_file_location(), pretty=True)
def main(): ##################################### ### NOTE: Run this file in Rhino. ### ##################################### ### --- Load stl mesh = Mesh.from_stl(FILE) ### --- Get color list color_list = get_mesh_face_color_overhang(mesh, max_angle=85, mode="adaptive", infill=False) ### --- Create Rhino artist artist = MeshArtist(mesh, layer='COMPAS::MeshArtist') artist.clear_layer() artist.draw_faces( color={key: color_list[i] for i, key in enumerate(mesh.faces())}) artist.redraw()
def create_sk3_exo(lines, branch_radius=1, node_radius_fac=1, segments=4): sk3 = Skeleton3D.from_skeleton_lines(lines) sk3.section_seg = segments sk3.branch_radius = branch_radius sk3.node_radius_fac = node_radius_fac sk3.generate_mesh() sk3.merge_triangles() artist = MeshArtist(sk3) artist.layer = '3GS::Skeleton' guid = artist.draw_faces(join_faces=True) artist.redraw() return sk3, guid[0]
from mysubdivision import * from compas.datastructures import Mesh from compas_rhino.artists import MeshArtist from compas.geometry import Translation from compas_rhino import unload_modules unload_modules('mysubdivision') 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], [0.5, 2.0, 0.0]] faces = [[0, 1, 2], [1, 0, 3, 4]] my_mesh = Mesh.from_vertices_and_faces(vertices, faces) artist = MeshArtist(my_mesh, layer="00_my_base_mesh") artist.draw_faces(join_faces=True) artist.draw_vertexlabels() artist.draw_facelabels() #for meshes point = [2.5, 0, 0] T = Translation.from_vector(point) my_mesh = my_mesh.transformed(T) mesh1 = mesh_subdivide_pyramid(my_mesh, k=1, height=0.5) artist2 = MeshArtist(mesh1, layer="00_my_mesh_pyramid") artist2.draw_faces(join_faces=True) mesh2 = mesh_subdivide_tapered(my_mesh, k=1,
def RunCommand(is_interactive): #load Derivation and model derivation = Derivation.from_json( rhino_UI_utilities.get_json_file_location()) model = derivation.get_next_step() #select beams selection_reference = [] selection_reference.append( rs.GetObject(message="select start Beam", filter=32, preselect=True)) selection_reference.extend( rs.GetObjects(message="select Beams to connect", filter=32, preselect=True)) #load helpers helper = UI_helpers() #name search selected_beams = helper.extract_BeambyName(model, selection_reference) #check for parallel planes, uses the function above start_beam = selected_beams[0] beams_to_connect = selected_beams[1:] parallel_check = check_for_parallel_vectors(start_beam, beams_to_connect) if parallel_check != True: raise IndexError('beams are not parallel') else: print("beams are parallel") #check for coplanarity, uses the function above coplanar_planes = {} face_ids_coplanar_planes = {} for i in range(1, 5): start_beam_plane = start_beam.face_plane(i).copy() start_beam_origin = start_beam_plane.point a = get_coplanar_planes(start_beam_plane, start_beam_origin, beams_to_connect) if a != False: coplanar_planes['' + str(i)] = a[0] face_ids_coplanar_planes['' + str(i)] = a[1] else: pass print("face_dictionary here", face_ids_coplanar_planes) if len(coplanar_planes.keys()) == 2: print("'success", coplanar_planes) else: raise IndexError('beams are not coplanar') #user inputs face_id = rs.GetInteger(("possible face connections " + "face_id " + coplanar_planes.keys()[0] + " or face_id " + coplanar_planes.keys()[1]), None, None, None) start_point = (helper.Get_SelectPointOnMeshEdge("Select mesh edge", "Pick point on edge")) ext_start = rs.GetReal("extension length start", 200, None, None) ext_end = rs.GetReal("extension length end", 200, None, None) #list of coplanar planes extracted from coplanar_planes dict using face_id as key coplanar_planes_along_selected_face = [] coplanar_planes_along_selected_face.append( start_beam.face_plane(face_id).copy()) for key, value in coplanar_planes.items(): if key == "" + str(face_id): coplanar_planes_along_selected_face.extend(value) #list of face_ids of coplanar planes coplanar_face_ids = [] coplanar_face_ids.append(face_id) for key, value in face_ids_coplanar_planes.items(): if key == "" + str(face_id): coplanar_face_ids.extend(value) #intersection points by passing a line from the origin of start beam to the adjacent planes of the coplanar planes of all beams points_to_compare = [] for i in range(len(selected_beams)): beam = selected_beams[i] start_beam_selected_face_frame = selected_beams[0].face_frame(face_id) line_pt_a = start_beam_selected_face_frame.point normal = start_beam_selected_face_frame.normal line_pt_b = add_vectors(line_pt_a, scale_vector(normal, 0.3)) line_to_intersect = Line(line_pt_a, line_pt_b) face_index = coplanar_face_ids[i] adjacent_planes = beam.neighbour_face_plane(face_index) for p in adjacent_planes: intersection_point = intersection_line_plane(line_to_intersect, p) points_to_compare.append(intersection_point) viz_pts = [] #project distance from points_to_compare to the plane of the start Beam distances = [] start_beam_face_frame = start_beam.face_frame(face_id).copy() start_beam_Plane_perpendicular_to_face_id_Plane = Plane( start_beam_face_frame.point, start_beam_face_frame.normal) viz_pts.append(start_beam_Plane_perpendicular_to_face_id_Plane.point) for point in points_to_compare: viz_pts.append(point) vector = subtract_vectors( point, start_beam_Plane_perpendicular_to_face_id_Plane.point) distances.append( dot_vectors( vector, start_beam_Plane_perpendicular_to_face_id_Plane.normal)) #search to find max point maximum_distance = max(distances) minimum_distance = min(distances) beam_length = (maximum_distance - minimum_distance) + ext_start + ext_end ext_len = maximum_distance + ext_start #project selected point to perpendicular planes of the beams to connect if coplanar_planes.keys()[0] == "1" or coplanar_planes.keys()[0] == "3": start_beam_perpendicular_plane = start_beam.face_plane(5).copy() elif coplanar_planes.keys()[0] == "2" or coplanar_planes.keys()[0] == "4": start_beam_perpendicular_plane = start_beam.face_plane(6).copy() tol = 1.0e-5 # tol = 5.0 perpendicular_plane = [] for beam in beams_to_connect: for i in range(5, 7): beam_plane = beam.face_plane(i).copy() print("beam_plane", beam_plane) angle_check = start_beam_perpendicular_plane.normal.angle( beam_plane.normal) print("angle", angle_check) if (abs(angle_check) - 0) < tol or (abs(angle_check) - 180) < tol: perpendicular_plane.append(beam_plane) print(perpendicular_plane) print(len(perpendicular_plane)) #project points projected_point_list = [] new_start_point = project_points_plane([start_point], start_beam_perpendicular_plane) projected_point_list.extend(new_start_point) for plane in perpendicular_plane: new_point = project_points_plane(new_start_point, plane) projected_point_list.extend(new_point) #list of distance to move joints on match beam model.rule_Connect_90lap(selected_beams, projected_point_list, coplanar_face_ids, beam_length, ext_len, create_id()) print(len(projected_point_list)) print(projected_point_list) #Save Derivation (Model is also saved) derivation.to_json(rhino_UI_utilities.get_json_file_location(), pretty=True) # Visualization viz_point = [] for pt in projected_point_list: a = (pt[0], pt[1], pt[2]) viz_point.append({'pos': a, 'color': (0, 255, 0)}) artist = MeshArtist(None, layer='BEAM::Beams_out') artist.clear_layer() artist.draw_points(viz_point) for beam in model.beams: artist = MeshArtist( beam.mesh, layer='BEAM::Beams_out' ) #.mesh is not ideal fix in beam and assemble class artist.draw_faces(join_faces=True)
# ============================================================================== # Visualise # ============================================================================== ARTIST = MeshArtist(FABRIC, layer="Fabric") ARTIST.clear_layer() # INTRADOS ARTIST.mesh = IDOS ARTIST.layer = "Fabric::Intrados" for i, strip in enumerate(STRIPS): guid = ARTIST.draw_faces(keys=strip, join_faces=True) color = (255, 128, 128) if i % 2 else (255, 0, 0) rs.ObjectColor(guid, color) ARTIST.layer = "Fabric::Normals" ARTIST.draw_facenormals(color=(255, 0, 0), scale=0.05) # EXTRADOS ARTIST.mesh = EDOS ARTIST.layer = "Fabric::Extrados" for i, strip in enumerate(STRIPS): guid = ARTIST.draw_faces(keys=strip, join_faces=True) color = (128, 128, 255) if i % 2 else (0, 0, 255)
points = [] fkeys = [] for fkey in faces: origin = IDOS.face_centroid(fkey) normal = IDOS.face_normal(fkey, unitized=True) plane = origin, normal if SHELL.has_vertex(fkey): fkeys.append(fkey) normal = SHELL.vertex_normal(fkey) xyz = SHELL.vertex_coordinates(fkey) xyz_i = add_vectors(xyz, scale_vector(normal, -0.5 * THICKNESS)) line = xyz, xyz_i x = intersection_line_plane(line, plane) points.append({'pos': x, 'color': color}) guid = ARTIST.draw_faces(keys=fkeys, join_faces=True) rs.ObjectColor(guid, color) ARTIST.draw_points(points) # EXTRADOS ARTIST.mesh = EDOS ARTIST.layer = "Fabric::Extrados" for name, panel in [('SOUTH', SOUTH), ('WEST', WEST), ('NORTH', NORTH), ('RING', RING)]: for strip, faces in enumerate(panel): ARTIST.layer = "Fabric::Extrados::{}-{}".format( name, str(strip).zfill(2))
block.attributes['blank'] = blank block.attributes['bottom'] = bottom blocks.append(block) # ============================================================================== # Export # ============================================================================== with open(FILE, 'w') as f: json.dump(blocks, f, cls=DataEncoder) # ============================================================================== # Visualize # ============================================================================== compas_rhino.clear_layers(["ITA20::Assignment1"]) for block in blocks: artist = MeshArtist(block, layer="ITA20::Assignment1::{}::Block".format( block.name)) artist.draw_faces(color={block.attributes['bottom']: (255, 0, 0)}) blank = block.attributes['blank'] artist = BoxArtist(blank, layer="ITA20::Assignment1::{}::Blank".format( block.name)) artist.draw(show_edges=True, show_faces=False)
'x': (0, float('inf')), 'y': (0, float('inf')), 'z': (0, float('inf')) })) block.vertex_attribute(vertex, 'z', 150) blank = Box.from_bounding_box(block.bounding_box()) blank.xsize += 20 blank.ysize += 20 blank.zsize += 20 block.attributes['blank'] = blank # ============================================================================== # Export # ============================================================================== block.to_json(FILE_O) # ============================================================================== # Visualize # ============================================================================== compas_rhino.clear() artist = MeshArtist(block, layer="ITA20::HotWire::Block") artist.draw_faces() artist = BoxArtist(blank, layer="ITA20::HotWire::Blank") artist.draw(show_edges=True, show_faces=False)
def mesh_draw_faces(mesh, keys=None, color=None, layer=None, clear_layer=False, clear_faces=False, redraw=True, join_faces=False): """Draw a selection of faces of the mesh. Parameters ---------- keys : list (None) A list of face keys identifying which faces to draw. Default is to draw all faces. color : str, tuple, dict (None) The color specififcation for the faces. 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 to 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. join_faces : bool (False) Join the faces into a polymesh object. Notes ----- The faces are named using the following template: ``"{}.face.{}".format(self.mesh.attributes['name'], key)``. This name is used afterwards to identify faces of the mesh in the Rhino model. Examples -------- >>> """ artist = MeshArtist(mesh) artist.layer = layer if clear_layer: artist.clear_layer() if clear_faces: artist.clear_faces() guids = artist.draw_faces(color=color) if redraw: artist.redraw() if join_faces: guid = rs.JoinMeshes(guids, delete_input=True) return guid return guids
FILE_O = os.path.join(HERE, 'data', 'form_blocks.json') idos = Mesh.from_json(FILE_I1) edos = Mesh.from_json(FILE_I2) blocks = [] for face in idos.faces(): bottom = idos.face_coordinates(face) top = edos.face_coordinates(face) f = len(bottom) faces = [list(range(f)), list(range(f + f - 1, f - 1, -1))] for i in range(f - 1): faces.append([i, i + f, i + f + 1, i + 1]) faces.append([f - 1, f + f - 1, f, 0]) block = Mesh.from_vertices_and_faces(bottom + top, faces) blocks.append(block) compas.json_dump(blocks, FILE_O) artist = MeshArtist(None, layer="RV2::Blocks") artist.clear_layer() for block in blocks: artist.mesh = block artist.draw_faces(color=(0, 255, 255), join_faces=True)
import os import compas from compas.datastructures import Mesh from compas_rhino.artists import MeshArtist HERE = os.path.dirname(__file__) DATA = os.path.join(HERE, 'data') FILE = os.path.join(DATA, 'faces.obj') mesh = Mesh.from_obj(FILE) artist = MeshArtist(mesh, layer="Mesh") artist.draw_vertices( color={key: (255, 0, 0) for key in mesh.vertices_on_boundary()}) artist.draw_vertexlabels( text={key: str(mesh.vertex_degree(key)) for key in mesh.vertices()}) artist.draw_edges(keys=list(mesh.edges_on_boundary()), color=(255, 0, 0)) artist.draw_faces( color={ key: (150, 255, 150) for key in mesh.faces() if not mesh.is_face_on_boundary(key) })
# ============================================================================== # Process output # ============================================================================== polylines = [] for points in pointsets: points = [Point(*point) for point in points] # otherwise Polygon throws an error polyline = Polyline(points) polylines.append(polyline) # ============================================================================== # Visualize # ============================================================================== meshartist = MeshArtist(bunny, layer="CGAL::Slicer::Bunny") meshartist.clear_layer() meshartist.draw_faces(join_faces=True, color=(255, 200, 200)) meshartist.redraw() # this is very slow polylineartist = PolylineArtist(None, layer="CGAL::Slicer::Slices") polylineartist.clear_layer() for polyline in polylines: polylineartist.primitive = polyline polylineartist.color = (255, 0, 0) polylineartist.draw() polylineartist.redraw()
def draw_faces(self, **kwattr): artist = MeshArtist(self) artist.draw_faces(**kwattr)
mesh = Mesh.from_json(FILE_I) idos = mesh.copy() edos = mesh.copy() for vertex in mesh.vertices(): point = mesh.vertex_coordinates(vertex) normal = mesh.vertex_normal(vertex) thickness = 0.10 idos.vertex_attributes( vertex, 'xyz', add_vectors(point, scale_vector(normal, +0.5 * thickness))) edos.vertex_attributes( vertex, 'xyz', add_vectors(point, scale_vector(normal, -0.5 * thickness))) idos.to_json(FILE_O1) edos.to_json(FILE_O2) artist = MeshArtist(None) artist.mesh = idos artist.layer = "RV2::Idos" artist.clear_layer() artist.draw_faces(color=(255, 0, 0)) artist.mesh = edos artist.layer = "RV2::Edos" artist.clear_layer() artist.draw_faces(color=(0, 0, 255))
c = len(set(key_color.values())) colors = Colormap(list(range(c)), 'rgb') facecolor = {key: colors(key_color[key]) for key in dual.vertices()} # the artist for drawing various versions of the mesh artist = MeshArtist(mesh) # mesh mesh.name = "Mesh" artist.clear() artist.draw_mesh() # edges mesh.name = "Edges" mesh.transform(X) artist.clear() artist.draw_edges() # vertices mesh.name = "Vertices" mesh.transform(X) artist.clear() artist.draw_vertices(color=vertexcolor) artist.draw_edges(color=(255, 255, 255)) # faces mesh.name = "Faces" mesh.transform(X) artist.clear() artist.draw_faces(color=facecolor)
unload_modules('shapes') # 2D Subdivision 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)
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()
from compas.geometry import Transformation from compas.geometry import Box from compas.datastructures import Mesh from compas_rhino.artists import FrameArtist from compas_rhino.artists import MeshArtist # Box in the world coordinate system frame = Frame([1, 0, 0], [-0.45, 0.1, 0.3], [1, 0, 0]) width, length, height = 1, 1, 1 box = Box(frame, width, length, height) # Frame F representing a coordinate system F = Frame([2, 2, 2], [0.978, 0.010, -0.210], [0.090, 0.882, 0.463]) # Get transformation between frames and apply transformation on box. T = Transformation.from_frame_to_frame(Frame.worldXY(), F) box_transformed = box.transformed(T) print("Box frame transformed", box_transformed.frame) # create artists artist1 = FrameArtist(Frame.worldXY()) artist2 = MeshArtist(Mesh.from_shape(box)) artist3 = FrameArtist(F) artist4 = MeshArtist(Mesh.from_shape(box_transformed)) # draw artist1.draw() artist2.draw_faces() artist3.draw() artist4.draw_faces()
polylines = [] for points in pointsets: points = [Point(*point) for point in points] polyline = Polyline(points) polylines.append(polyline) # ============================================================================== # Visualize # ============================================================================== meshartist = MeshArtist(None) meshartist.mesh = Mesh.from_vertices_and_faces(*A) meshartist.layer = "CGAL::Intersections::A" meshartist.clear_layer() meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#222222')) meshartist.mesh = Mesh.from_vertices_and_faces(*B) meshartist.layer = "CGAL::Intersections::B" meshartist.clear_layer() meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#888888')) polylineartist = PolylineArtist(None, layer="CGAL::Intersections::Polylines") polylineartist.clear_layer() pointartist = PointArtist(None, layer='CGAL::Intersections::Points') pointartist.clear_layer() for polyline in polylines: polylineartist.primitive = polyline polylineartist.color = hex_to_rgb('#ffffff') polylineartist.draw()
# park = [key for key in m2fkeys if m2.face_attribute(key, 'ftype')== "park"] # facade = [key for key in m2fkeys if m2.face_attribute(key, 'ftype')== "facade"] # floor = [key for key in m2fkeys if m2.face_attribute(key, 'ftype')== "floor"] # roof = [key for key in m2fkeys if m2.face_attribute(key, 'ftype')== "roof"] # artist3.draw_faces( circulation, color= (255,0,0), join_faces=True) # artist3.draw_faces( park, color= (0,255,0), join_faces=True) # artist3.draw_faces( facade, color= (0,255,255), join_faces=True) # artist3.draw_faces( floor, color= (255,255,0), join_faces=True) # artist3.draw_faces( roof, color= (160,32,255), join_faces=True) m3 = m2.copy() subdivide_by_ftype(m3) artist4 = MeshArtist(m3, layer="level4") m3fkeys = list(m3.faces()) circulation = [ key for key in m3fkeys if m3.face_attribute(key, 'ftype') == "circulation" ] park = [key for key in m3fkeys if m3.face_attribute(key, 'ftype') == "park"] floor = [key for key in m3fkeys if m3.face_attribute(key, 'ftype') == "floor"] roof = [key for key in m3fkeys if m3.face_attribute(key, 'ftype') == "roof"] panel = [key for key in m3fkeys if m3.face_attribute(key, 'ftype') == "panel"] artist4.draw_faces(circulation, color=(255, 0, 0), join_faces=True) artist4.draw_faces(park, color=(0, 255, 0), join_faces=True) artist4.draw_faces(floor, color=(255, 255, 0), join_faces=True) artist4.draw_faces(roof, color=(160, 32, 255), join_faces=True) artist4.draw_faces(panel, color=(255, 160, 16), join_faces=True)
attr['x'] = x attr['y'] = y attr['z'] = z else: x, y, z = target.closest_point(mesh.vertex_coordinates(key)) attr['x'] = x attr['y'] = y attr['z'] = z conduit.redraw(k) # run the remeshing algorithm # draw the result with conduit.enabled(): trimesh_remesh(mesh, target=length, kmax=kmax, tol=0.1, divergence=0.01, allow_boundary_split=True, allow_boundary_swap=True, allow_boundary_collapse=False, smooth=True, fixed=fixed, callback=callback) artist = MeshArtist(mesh, layer='remeshed') artist.draw_faces(join_faces=True)
pt = point_on_plane(point, top_plane, normal) top.append(pt) bottom = offset_polygon_xy(bottom, OFFSET_0) top = offset_polygon_xy(top, OFFSET_1, True) vertices = bottom + top faces = [[0, 3, 2, 1], [4, 5, 6, 7], [3, 0, 4, 7], [2, 3, 7, 6], [1, 2, 6, 5], [0, 1, 5, 4]] block = Mesh.from_vertices_and_faces(vertices, faces) blocks.append(block) # ============================================================================== # Visualize blocks # ============================================================================== artist = MeshArtist(None, layer="Boxes::Test") artist.clear_layer() for block in blocks: artist = MeshArtist(block, layer="Boxes::Test") artist.draw_faces(join_faces=True, color=(0, 255, 255)) # ============================================================================== # Serialize meshes -- trick, not really working... # ============================================================================== meshes_to_json(blocks, HERE + "\\meshes.json", True) # m = Mesh.from_json(HERE + "\\meshes.json") # artist = MeshArtist(m, layer="Boxes::Test") # artist.draw_faces(join_faces=True, color=(0, 255, 255))
# Export # ============================================================================== block.attributes['sides'] = {'left': left, 'right': right} block.attributes['cut1'] = {'left': left_poly, 'right': right_poly} block.to_json(FILE_O) # ============================================================================== # Visualization # ============================================================================== compas_rhino.clear() artist = MeshArtist(block, layer="ITA20::HotWire::Block") artist.draw_faces(color={left: (255, 0, 0), right: (0, 255, 0)}) artist = BoxArtist(blank, layer="ITA20::HotWire::Blank") artist.draw(show_edges=True, show_faces=False) points = [[0, 0, 0], [0, 0, HEIGHT], [0, TABLE, HEIGHT], [0, TABLE, 0]] polygon = Polygon(points) artist = PolygonArtist(polygon, layer="ITA20::HotWire::Left", color=(255, 0, 0)) artist.draw(show_edges=True, show_face=False) points = [[WIRE, 0, 0], [WIRE, 0, HEIGHT], [WIRE, TABLE, HEIGHT], [WIRE, TABLE, 0]] polygon = Polygon(points) artist = PolygonArtist(polygon,
import os import compas from compas.datastructures import Mesh from compas.datastructures import mesh_flatness from compas.utilities import i_to_rgb from compas_rhino.artists import MeshArtist from compas.rpc import Proxy maxdev = 0.005 kmax = 500 igl = Proxy('compas_libigl') # igl.stop_server() # igl.start_server() HERE = os.path.dirname(__file__) FILE = os.path.join(HERE, '..', 'data', 'tubemesh.json') mesh = Mesh.from_json(FILE) vertices, faces = mesh.to_vertices_and_faces() vertices = igl.planarize_quads(vertices, faces, kmax, maxdev) mesh = Mesh.from_vertices_and_faces(vertices, faces) dev = mesh_flatness(mesh, maxdev=maxdev) artist = MeshArtist(mesh, layer="IGL::PlanarizeQuads") artist.clear_layer() artist.draw_faces(color={fkey: i_to_rgb(dev[fkey]) for fkey in mesh.faces()})