def main(): start_time = time.time() ### --- Load stl compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL)) ### --- Move to origin move_mesh_to_point(compas_mesh, Point(0, 0, 0)) ### --- Slicer # options: 'default' : Both for open and closed paths. But slow # 'cgal' : Very fast. Only for closed paths. Requires additional installation (compas_cgal). slicer = PlanarSlicer(compas_mesh, slicer_type="cgal", layer_height=1.5) slicer.slice_model() ### --- Generate brim generate_brim(slicer, layer_width=3.0, number_of_brim_paths=3) ### --- Simplify the paths by removing points with a certain threshold # change the threshold value to remove more or less points simplify_paths_rdp(slicer, threshold=0.7) ### --- Smooth the seams between layers # change the smooth_distance value to achieve smoother, or more abrupt seams seams_smooth(slicer, smooth_distance=10) ### --- Prints out the info of the slicer slicer.printout_info() viewer = ObjectViewer() viewer.view.use_shaders = False slicer.visualize_on_viewer(viewer) utils.save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json') ### --- Fabrication - related information print_organizer = PrintOrganizer(slicer) print_organizer.create_printpoints(compas_mesh) print_organizer.set_extruder_toggle() print_organizer.add_safety_printpoints(z_hop=20) print_organizer.set_linear_velocity("constant", v=25) ### --- Save printpoints dictionary to json file printpoints_data = print_organizer.output_printpoints_dict() utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json') print_organizer.visualize_on_viewer(viewer, visualize_polyline=True, visualize_printpoints=False) viewer.update() viewer.show() end_time = time.time() print("Total elapsed time", round(end_time - start_time, 2), "seconds")
def main(): ### --- Data paths DATA = os.path.join(os.path.dirname(__file__), 'data') INPUT_FILE = 'paths_from_gh.json' slicer = PlanarSlicer.from_data(load_from_json(DATA, INPUT_FILE)) ### --- Visualize using the compas_viewer viewer = ObjectViewer() viewer.view.use_shaders = False slicer.visualize_on_viewer(viewer, visualize_mesh=False, visualize_paths=True) viewer.update() viewer.show()
def main(): start_time = time.time() ### --- Load stl compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL)) ### --- Move to origin move_mesh_to_point(compas_mesh, Point(0, 0, 0)) ### --- Slicer # try out different slicers by changing the slicer_type # options: 'default', 'meshcut', 'cgal' slicer = PlanarSlicer(compas_mesh, slicer_type="default", layer_height=1.5) slicer.slice_model() ### --- Generate brim generate_brim(slicer, layer_width=3.0, number_of_brim_paths=3) ### --- Simplify the printpaths by removing points with a certain threshold # change the threshold value to remove more or less points simplify_paths_rdp(slicer, threshold=0.9) ### --- Prints out the info of the slicer slicer.printout_info() viewer = ObjectViewer() viewer.view.use_shaders = False slicer.visualize_on_viewer(viewer) utils.save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json') ### --- Fabrication - related information print_organizer = PrintOrganizer(slicer) print_organizer.create_printpoints(compas_mesh) print_organizer.set_extruder_toggle() print_organizer.add_safety_printpoints(z_hop=20) print_organizer.set_linear_velocity("constant", v=25) ### --- Save printpoints dictionary to json file printpoints_data = print_organizer.output_printpoints_dict() utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json') # # print_organizer.visualize_on_viewer(viewer, visualize_polyline=True, visualize_printpoints=False) viewer.update() viewer.show() end_time = time.time() print("Total elapsed time", round(end_time - start_time, 2), "seconds")
mesh.transform(S * Rz * Rx) # ============================================================================== # Isolines # ============================================================================== scalars = mesh.vertices_attribute('z') vertices, edges = igl.trimesh_isolines(mesh.to_vertices_and_faces(), scalars, 10) isolines = igl.groupsort_isolines(vertices, edges) # ============================================================================== # Visualisation # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#ffffff', 'vertices.on': False, 'edges.on': False }) cmap = Colormap(scalars, 'rgb') for value, paths in isolines: for path in paths: points = [vertices[path[0][0]]] for i, j in path: points.append(vertices[j]) viewer.add(Polyline(points),
# ========================================================================== # Set fabrication-related parameters # ========================================================================== set_extruder_toggle(print_organizer, slicer) add_safety_printpoints(print_organizer, z_hop=10.0) set_linear_velocity(print_organizer, "constant", v=25.0) set_blend_radius(print_organizer, d_fillet=10.0) # ========================================================================== # Prints out the info of the PrintOrganizer # ========================================================================== print_organizer.printout_info() # ========================================================================== # Converts the PrintPoints to data and saves to JSON # ========================================================================= printpoints_data = print_organizer.output_printpoints_dict() utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json') # ========================================================================== # Initializes the compas_viewer and visualizes results # ========================================================================== viewer = ObjectViewer() print_organizer.visualize_on_viewer(viewer, visualize_polyline=True, visualize_printpoints=False) viewer.view.use_shaders = False viewer.update() viewer.show()
if (i2 - i1).length < 0.01: x = intersection_line_plane((i1, r1), ground) r1 = Point(*x) reflections.append((i1, r1)) else: reflections.append((i1, i2)) else: x = intersection_line_plane((i1, r1), ground) r1 = Point(*x) reflections.append((i1, r1)) # ============================================================================== # Visualisation # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#cccccc', 'opacity': 0.5, 'edges.on': False }) for intersection in intersections: viewer.add(Line(base, intersection), settings={ 'edges.color': '#ff0000', 'edges.width': 3 })
# ============================================================================== mesh = Mesh.from_off(igl.get('tubemesh.off')) mesh.quads_to_triangles() # ============================================================================== # curvature # ============================================================================== curvature = igl.trimesh_gaussian_curvature(mesh) # ============================================================================== # Visualisation # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#cccccc', 'vertices.on': True, 'edges.on': False, 'opacity': 0.7, 'vertices.size': 5 }) for vertex in mesh.vertices(): if mesh.is_vertex_on_boundary(vertex): continue point = Point(*mesh.vertex_coordinates(vertex))
import random from compas.utilities import rgb_to_hex from compas.geometry import Point from compas.geometry import Line from compas.geometry import Polyline from compas.geometry import Plane from compas.geometry import Circle from compas_viewers.objectviewer import ObjectViewer viewer = ObjectViewer() for i in range(10): line = Line( Point(random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10)), Point(random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10))) viewer.add(line) point = Point(0, 0, 0) viewer.add(point, settings={'vertices.size': 10}) polyline = Polyline([[2, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 1]]) viewer.add(polyline, settings={'vertices.size': 10}) plane = Plane([0, 0, 2], [1, 1, 1]) viewer.add(plane) circle = Circle(Plane([0, 0, 3], [1, 1, 1]), 1)
from random import randint as rdi from math import radians from compas.geometry import Box from compas.datastructures import Mesh from compas.datastructures import mesh_transform_numpy from compas.utilities import rgb_to_hex from compas.geometry import Translation from compas.geometry import Rotation from compas_viewers.objectviewer import ObjectViewer viewer = ObjectViewer(activate_selection=True) # make 10 random meshes # with random position and orientation for i in range(10): T = Translation.from_vector([rdi(0, 10), rdi(0, 10), rdi(0, 5)]) R = Rotation.from_axis_and_angle([0, 0, 1.0], radians(rdi(0, 180))) X = T * R box = Box.from_width_height_depth(rdi(1, 3), rdi(1, 3), rdi(1, 3)) mesh = Mesh.from_shape(box) mesh_transform_numpy(mesh, X) viewer.add(mesh, name="Mesh.%s" % i, settings={ 'color': rgb_to_hex((rdi(0, 255), rdi(0, 255), rdi(0, 255))), 'edges.width': 2, 'opacity': 0.7,
Rz = Rotation.from_axis_and_angle([0, 0, 1], math.radians(90)) S = Scale.from_factors([10, 10, 10]) mesh.transform(S * Rz * Rx) # ============================================================================== # Boundaries # ============================================================================== boundaries = igl.trimesh_boundaries(mesh.to_vertices_and_faces()) # ============================================================================== # Visualize # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#00ff00', 'opacity': 0.7, 'edges.on': False, 'vertices.on': False }) for indices in boundaries: points = mesh.vertices_attributes('xyz', keys=indices) polyline = Polyline(points) viewer.add(polyline, settings={ 'edges.color': '#ff0000',
import random from compas.geometry import Plane from compas.geometry import Circle from compas.geometry import Cone from compas.geometry import Polyhedron from compas_viewers.objectviewer import Arrow from compas_viewers.objectviewer import ObjectViewer viewer = ObjectViewer() plane = Plane([2, 0, 0], [0, 0, 1]) circle = Circle(plane, 0.5) cone = Cone(circle, 1) viewer.add(cone) polyhedron = Polyhedron(4) viewer.add(polyhedron) arrow = Arrow([-2, 0, 0], [0, 1, 1]) viewer.add(arrow) viewer.show()
n = scale_vector(mesh.face_normal(i), -1) x = add_vectors(base, scale_vector(vector, d)) p = Point(*x) r = base.transformed(Reflection.from_plane((p, n))) n = add_vectors(n, x) n = Point(*n) intersections.append(p) reflections.append(r) normals.append(n) centers.append(mesh.face_centroid(i)) # ============================================================================== # Visualisation # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#cccccc', 'opacity': 0.7, 'vertices.on': False }) for i in range(len(intersections) - 132): p = intersections[i] r = reflections[i] n = normals[i] c = centers[i] viewer.add(Line(base, p), settings={