-
Notifications
You must be signed in to change notification settings - Fork 18
/
example_3d.py
61 lines (45 loc) · 1.78 KB
/
example_3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
A simple example showing how to use PySLM for generating slices across a 3D model
"""
import pyslm
import pyslm.visualise
from pyslm import hatching as hatching
import numpy as np
# Imports the part and sets the geometry to an STL file (frameGuide.stl)
solidPart = pyslm.Part('inversePyramid')
solidPart.setGeometry('../models/inversePyramid.stl')
solidPart.origin[0] = 5.0
solidPart.origin[1] = 2.5
solidPart.scaleFactor = 1.0
solidPart.rotation = [0, 0.0, 45]
solidPart.dropToPlatform()
# Create a StripeHatcher object for performing any hatching operations
myHatcher = hatching.Hatcher()
# Set the base hatching parameters which are generated within Hatcher
myHatcher.hatchAngle = 10
myHatcher.volumeOffsetHatch = 0.08
myHatcher.spotCompensation = 0.06
myHatcher.numInnerContours = 2
myHatcher.numOuterContours = 1
myHatcher.hatchSortMethod = hatching.AlternateSort()
# Set the layer thickness
layerThickness = 0.04 # [mm]
# Perform the slicing. Return coords paths should be set so they are formatted internally.
#myHatcher.layerAngleIncrement = 66.7
#Perform the hatching operations
print('Hatching Started')
layers = []
for z in np.arange(0, solidPart.boundingBox[5], layerThickness):
# Typically the hatch angle is globally rotated per layer by usually 66.7 degrees per layer
myHatcher.hatchAngle += 66.7
# Slice the boundary
geomSlice = solidPart.getVectorSlice(z)
# Hatch the boundary using myHatcher
layer = myHatcher.hatch(geomSlice)
# The layer height is set in integer increment of microns to ensure no rounding error during manufacturing
layer.z = int(z*1000)
layers.append(layer)
print('Completed Hatching')
# Plot the layer geometries using matplotlib
# Note: the use of python slices to get the arrays
pyslm.visualise.plotLayers(layers[0:-1:10])