diff --git a/lecture_11/assignment_07/frederick_kim/my_slicing_texture_kim.py b/lecture_11/assignment_07/frederick_kim/my_slicing_texture_kim.py new file mode 100644 index 0000000..ba8f54e --- /dev/null +++ b/lecture_11/assignment_07/frederick_kim/my_slicing_texture_kim.py @@ -0,0 +1,46 @@ +from compas_slicer.geometry import Path +from compas_slicer.utilities.utils import get_normal_of_path_on_xy_plane +from compas.geometry import Point +from compas.geometry import scale_vector, add_vectors + +def create_overhang_texture(slicer, overhang_distance): + """Creates a cool overhang texture""" + + print("Creating cool texture") + + for i, layer in enumerate(slicer.layers): + if i % 7 == 0 and i > 0: + # for every 5th layer, except for the first layer + # print(layer) + for j, path in enumerate(layer.paths): + # print(path) + # create an empty layer in which we can store our modified points + new_path = [] + for k, pt in enumerate(path.points): + # for every second point (only even points) + if k % 5 == 0: + # get the normal of the point in relation to the mesh + normal = get_normal_of_path_on_xy_plane(k, pt, path, mesh=None) + # scale the vector by a number to move the point + normal_scaled = scale_vector(normal, overhang_distance) + # create a new point by adding the point and the normal vector + new_pt = add_vectors(pt, normal_scaled) + # recreate the new_pt values as compas_points + pt = Point(new_pt[0], new_pt[1], new_pt[2]) + if k % 2 == 0: + # get the normal of the point in relation to the mesh + normal = get_normal_of_path_on_xy_plane(k, pt, path, mesh=None) + # scale the vector by a number to move the point + normal_scaled = scale_vector(normal, overhang_distance) + # create a new point by adding the point and the normal vector + new_pt = add_vectors(pt, normal_scaled) + # recreate the new_pt values as compas_points + pt = Point(new_pt[0], new_pt[1], new_pt[2]) + + + # append the points to the new path + new_path.append(pt) + + # replace the current path with the new path that we just created + layer.paths[j] = Path(new_path, is_closed=path.is_closed) + diff --git a/lecture_11/assignment_07/frederick_kim/own_function_kim.py b/lecture_11/assignment_07/frederick_kim/own_function_kim.py new file mode 100644 index 0000000..e3cdccf --- /dev/null +++ b/lecture_11/assignment_07/frederick_kim/own_function_kim.py @@ -0,0 +1,130 @@ +import time +import os +import logging + +import compas_slicer.utilities as utils +from compas_slicer.pre_processing import move_mesh_to_point +from compas_slicer.slicers import PlanarSlicer +from compas_slicer.post_processing import generate_brim +from compas_slicer.post_processing import generate_raft +from compas_slicer.post_processing import simplify_paths_rdp +from compas_slicer.post_processing import seams_smooth +from compas_slicer.print_organization import PlanarPrintOrganizer +from compas_slicer.print_organization import set_extruder_toggle +from compas_slicer.print_organization import add_safety_printpoints +from compas_slicer.print_organization import set_linear_velocity_constant +from compas_slicer.print_organization import set_blend_radius +from compas_slicer.utilities import save_to_json + +from compas.datastructures import Mesh +from compas.geometry import Point + +# own function +from my_slicing_texture import create_overhang_texture + +# ============================================================================== +# Logging +# ============================================================================== +logger = logging.getLogger('logger') +logging.basicConfig(format='%(levelname)s-%(message)s', level=logging.INFO) + +# ============================================================================== +# Select location of data folder and specify model to slice +# ============================================================================== +DATA = os.path.join(os.path.dirname(__file__), 'data') +OUTPUT_DIR = utils.get_output_directory(DATA) # creates 'output' folder if it doesn't already exist +MODEL = 'simple_vase_open_low_res.obj' + + +def main(): + start_time = time.time() + + # ========================================================================== + # Load mesh + # ========================================================================== + compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL)) + + # ========================================================================== + # Move to origin + # ========================================================================== + move_mesh_to_point(compas_mesh, Point(0, 0, 0)) + + # ========================================================================== + # Slicing + # 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=5) + slicer.slice_model() + + # ========================================================================== + # Generate brim / raft + # ========================================================================== + # NOTE: Typically you would want to use either a brim OR a raft, + # however, in this example both are used to explain the functionality + # generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=4) + # generate_raft(slicer, + # raft_offset=20, + # distance_between_paths=5, + # direction="xy_diagonal", + # raft_layers=1) + + # ========================================================================== + # 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) + + ############################################################################ + # INSERT OWN TEXTURE HERE + ############################################################################ + create_overhang_texture(slicer, overhang_distance=20) + + # ========================================================================== + # 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() + + # ========================================================================== + # Save slicer data to JSON + # ========================================================================== + save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json') + + # ========================================================================== + # Initializes the PlanarPrintOrganizer and creates PrintPoints + # ========================================================================== + print_organizer = PlanarPrintOrganizer(slicer) + print_organizer.create_printpoints() + + # ========================================================================== + # Set fabrication-related parameters + # ========================================================================== + # set_extruder_toggle(print_organizer, slicer) + # add_safety_printpoints(print_organizer, z_hop=10.0) + # set_linear_velocity_constant(print_organizer, v=100.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') + + end_time = time.time() + print("Total elapsed time", round(end_time - start_time, 2), "seconds") + + +if __name__ == "__main__": + main() diff --git a/lecture_11/assignment_07/frederick_kim/screenshot_1.png b/lecture_11/assignment_07/frederick_kim/screenshot_1.png new file mode 100644 index 0000000..3a2b0f5 Binary files /dev/null and b/lecture_11/assignment_07/frederick_kim/screenshot_1.png differ diff --git a/lecture_11/assignment_07/frederick_kim/screenshot_2.png b/lecture_11/assignment_07/frederick_kim/screenshot_2.png new file mode 100644 index 0000000..e5ebdc5 Binary files /dev/null and b/lecture_11/assignment_07/frederick_kim/screenshot_2.png differ