Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lecture_02/assignment_01/ana-ascic/assignment_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from compas.artists import Artist
from compas.datastructures import Mesh
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Plane
from compas.geometry import Projection
from compas.geometry import Vector

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame.from_points([1, 1, 0], [1, 0, -0.1], [2, 1, 0.1])

# Create a Box with that frame
box = Box(frame, 1, 1, 1) # xsize, ysize, zsize

# Create a Projection (can be orthogonal, parallel or perspective)
projection_plane = Plane([0, 0, 0], [0, 0, 1])
P = Projection.from_plane_and_direction(projection_plane, [0, 0, 1])

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)
print(mesh_projected)

# Create artists
artist1 = Artist(box)
artist2 = Artist(mesh_projected)

# Draw and all to a list
artist1.draw()
artist2.draw_edges(color="#00ff00")
6,532 changes: 6,532 additions & 0 deletions lecture_04/assignment_03/ana_ascic/Assignment_03_Ana_Ascic.ghx

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
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_view2.app import App

from compas.datastructures import Mesh
from compas.geometry import Point

from overhang_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=1)
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
# the higher the threshold the more point will be removed
# ==========================================================================
simplify_paths_rdp(slicer, threshold=0)

# ==========================================================================
# Smooth the seams between layers
# change the smooth_distance value to achieve smoother, or more abrupt seams
# ==========================================================================
# seams_smooth(slicer, smooth_distance=1)

### =======================================================================
### -----------------------------------------------------------------------
### INSERT YOUR CUSTOM FUNCTION BELOW
### -----------------------------------------------------------------------
### =======================================================================
create_overhang_texture(slicer, 2)

# ==========================================================================
# 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=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")

# ===========================================================================
# Viewer
# ===========================================================================
viewer = App(width=1600, height=900)
slicer.visualize_on_viewer(viewer)
viewer.show()

if __name__ == "__main__":
main()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions lecture_09/assignment_04/ana_ascic/overhang_texture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from compas_slicer.utilities.utils import get_normal_of_path_on_xy_plane
from compas.geometry import scale_vector, add_vectors, Point, Vector
from compas_slicer.geometry import Path
from random import randint
import math

def create_overhang_texture(slicer, overhang_distance):
"""Create a overhang texture
"""

for i, layer in enumerate(slicer.layers):
if i % 2 == 0 and i > 0:
if i%4 == 0:
tag = 0
fac = i/5
else:
tag = 0
fac = 1
for j, path in enumerate(layer.paths):
new_path1 = []
for k, point1 in enumerate(path.points):
k = k-tag
if k % 2 == 0:
# get normal of point on polyline
normal = get_normal_of_path_on_xy_plane(k, point1, path, mesh=None)
normal_scaled = scale_vector(normal, -overhang_distance*fac)
new_pt1 = add_vectors(point1, normal_scaled)
# recreate point as compas point
point1 = Point(new_pt1[0], new_pt1[1], new_pt1[2])
# append point to new path
new_path1.append(point1)
layer.paths[j] = Path(new_path1, is_closed=path.is_closed)
Loading