forked from vermontolympian/Baby-Yoda
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LeftEar.groovy
176 lines (154 loc) · 5.31 KB
/
LeftEar.groovy
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//Your code here
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import com.neuronrobotics.bowlerstudio.BowlerStudioController
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins
import eu.mihosoft.vrl.v3d.svg.SVGExporter
import eu.mihosoft.vrl.v3d.svg.SVGLoad
import eu.mihosoft.vrl.v3d.*
def url="https://github.com/Halloween2020TheChild/Baby-Yoda.git"
def branch="master"
double moldY = 90
double moldX = 90
double moldZ = 200
double neckLength =10.5
void ignore(String url, String filename) {
boolean add=false;
File earCoreFile = ScriptingEngine.fileFromGit(url,
".gitignore");
if(earCoreFile.exists()) {
String data = earCoreFile.text
if(!data.contains(filename)) {
ScriptingEngine.pushCodeToGit(url, ScriptingEngine.getBranch(url), ".gitignore", data+"\n"+filename, "updating gitignore ", true)
}
}else {
ScriptingEngine.pushCodeToGit(url, ScriptingEngine.getBranch(url), ".gitignore", filename, "creating gitignore ", true)
}
}
CSG makeCachedFile(String url, String filename, Closure makeit) {
if(!filename.toLowerCase().endsWith(".stl"))
filename=filename+".stl"
File earCoreFile = ScriptingEngine.fileFromGit(url,
filename);
CSG earCore;
if(!earCoreFile.exists()) {
println "Making Cached "+filename
earCore=makeit()
def earCoreToStlString = earCore.toStlString()
if(earCoreToStlString.length()<10000000-1)
ScriptingEngine.pushCodeToGit(url, ScriptingEngine.getBranch(url), filename, earCoreToStlString, "Making Cached "+filename, true)
else {
println "STL too big for git, stored on disk"
ignore( url, filename)
}
}else
println "Loading cached "+filename
earCore=Vitamins.get(earCoreFile)
return earCore
}
List<Polygon> makeCachedSVG(String url, String filename, Closure makeit) {
if(!filename.toLowerCase().endsWith(".svg"))
filename=filename+".svg"
File earCoreFile = ScriptingEngine.fileFromGit(url,
filename);
List<Polygon> polygons;
if(!earCoreFile.exists()) {
println "SVG Making Cached "+filename
polygons=makeit()
println "Exporting to SVG"
SVGExporter svg = new SVGExporter();
for( Polygon p: polygons){
svg.toPolyLine(p);
svg.colorTick();
}
println "Pushing changes"
def svgMake = svg.make()
if(svgMake.length()<10000000-1)
ScriptingEngine.pushCodeToGit(url, ScriptingEngine.getBranch(url), filename, svgMake, "Making Cached SVG "+filename, true)
else {
println "SVG too big for git, stored on disk"
ignore( url, filename)
}
}
println "SVG Loading Cached "+filename
ArrayList<Polygon> list=new ArrayList<Polygon>();
SVGLoad l=new SVGLoad(earCoreFile.toURI())
for(String s:l.getLayers()) {
list.addAll(l.getPolygonByLayers().get(s))
}
return list
}
File earFile = ScriptingEngine.fileFromGit(url,
"Left Ear-DownRes.stl");
Vitamins.clear();
CSG ear = Vitamins.get(earFile)
// .roty(90)
// .toZMin()
//ear=ear.movex(-ear.centerX)
// .movey(-ear.centerY)
CSG.setProgressMoniter(new ICSGProgress() {
@Override
public void progressUpdate(int currentIndex, int finalIndex, String type, CSG intermediateShape) {
System.out.println(type+" "+currentIndex+" of "+finalIndex);
}
})
def earCore=makeCachedFile(url,"LeftEar-DownRes-4mmInset-2.stl",{
return ear.toolOffset(-4)
})
println "Number of polys in first gen: "+ earCore.getPolygons().size()
//earCore=makeCachedFile(url,"LeftEar-DownRes-4mmInset-rev2.stl",{
// return ear.toolOffset(-4)
//})
//
//println "Number of polys in second gen: "+ earCore.getPolygons().size()
File f = ScriptingEngine
.fileFromGit(
"https://github.com/Halloween2020TheChild/Baby-Yoda.git",//git repo URL
"master",//branch
"draftlineEar.SVG"// File from within the Git repo
)
println "Extruding SVG "+f.getAbsolutePath()
SVGLoad s = new SVGLoad(f.toURI())
CSG draftLine = s.extrudeLayerToCSG(moldX*2,"X")
.rotx(-90)
.rotz(-90)
.movex(-moldX)
.rotz(-7)
def slicePlane =new Transform()
.movez(neckLength)
.rotY(-5)
.rotX(1)
CSG boxOfPlug=new Cube(moldX,moldY,neckLength).toCSG().toZMax()
.transformed(slicePlane)
def polys = makeCachedSVG(url, "earCoreSlice.svg",{
println "Slicing ear"
return Slice.slice(earCore,slicePlane,0)
})
println "Extruding neck"
//def earNub = makeCachedFile(url, "earNub.stl",{Extrude.polygons(polys.get(1).transformed(new Transform()
// .movez(neckLength/2) ), polys.get(1).transformed(slicePlane))})
//def Neck = makeCachedFile(url, "neck.stl",{Extrude.polygons(polys.get(0), polys.get(0).transformed(slicePlane))})
def earNub = Extrude.polygons(polys.get(1).transformed(new Transform()
.movez(neckLength/2) ), polys.get(1).transformed(slicePlane)).movez(0.5)
def Neck = Extrude.polygons(polys.get(0), polys.get(0).transformed(slicePlane))
Plane.setDebugger(new IPolygonDebugger() {
void display( List<Polygon> poly) {
BowlerStudioController.getBowlerStudio().addObject(poly, null);
}
})
def newNeck =Neck.difference(earNub)
//CoreWithExtention=makeCachedFile(url,"LeftEarCoreWithExtention.stl",{
// return newNeck.union(earCore)
//})
//def extendedCore = earCore.union(Neck)
CSG post=makeCachedFile(url,"EarPostNeckPart.stl",{
CSG corePlug = earCore.intersect(boxOfPlug)
return corePlug.union(corePlug.movez(-neckLength)).hull().intersect(boxOfPlug)
})
return [
earCore,
newNeck
]