Last active
July 2, 2024 19:35
-
-
Save madhephaestus/f01548f0e4f85bd3f08fdfdd503510b4 to your computer and use it in GitHub Desktop.
Demonstrate the new bezier extrude API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/.project | |
/.classpath | |
/.cproject | |
/cache/ | |
/*.class | |
/.settings | |
/.project | |
/.classpath | |
/.cproject | |
/cache/ | |
/*.class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.vecmath.Vector3d | |
import eu.mihosoft.vrl.v3d.CSG | |
import eu.mihosoft.vrl.v3d.Cube | |
import eu.mihosoft.vrl.v3d.Extrude; | |
import eu.mihosoft.vrl.v3d.Transform | |
CSG part = new Cube(10).toCSG() | |
ArrayList<CSG> parts = new ArrayList<CSG>() | |
int numParts = 10 | |
for(int i=0;i<numParts;i++){ | |
//println scale | |
parts.add(part.clone()) | |
} | |
// A full bezier extrud with the gaps between the parts filled with a convex hull of the part | |
def fullBezier = Extrude.bezier( parts, | |
[(double)0.0,(double)0.0,(double)300.0], // Control point one | |
[(double)200.0,(double)200.0,(double)-150.0], // Control point two | |
[(double)200.0,(double)200.0,(double)300.0]// Endpoint | |
) | |
// thake the parts and just move to locations along the bezier curve | |
def movedCubesBezier = Extrude.moveBezier( parts, | |
[(double)0,(double)0,(double)300], // Control point one | |
[(double)200,(double)200,(double)-150], // Control point two | |
[(double)200,(double)200,(double)300] // Endpoint | |
).collect{ | |
it.movey(200) | |
} | |
// This is for creating a set of frame transformations from the bezier parameters | |
// this can be used for complex part creation or for path planning | |
ArrayList<Transform> transforms = Extrude.bezierToTransforms( new Vector3d(0,(double)0,(double)300), // Control point one | |
new Vector3d((double)200,(double)200,(double)-150), // Control point two | |
new Vector3d((double)200,(double)200,(double)300), // Endpoint | |
numParts// Iterations | |
) | |
fullBezier.addAll(movedCubesBezier) | |
return fullBezier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bezier": { | |
"start point": [ | |
0.0, | |
0.0, | |
0.0 | |
], | |
"control two": [ | |
-155.55354452521874, | |
-290.4216376424305, | |
-50.0 | |
], | |
"end point": [ | |
-55.55354452521874, | |
-240.42163764243048, | |
100.0 | |
], | |
"control one": [ | |
-133.4232176770754, | |
11.675261825503682, | |
-102.80981309357492 | |
], | |
"number of points": [ | |
20.0 | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eu.mihosoft.vrl.v3d.svg.*; | |
import com.neuronrobotics.bowlerkernel.Bezier3d.BezierEditor | |
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine | |
import eu.mihosoft.vrl.v3d.CSG | |
import eu.mihosoft.vrl.v3d.Cube | |
import eu.mihosoft.vrl.v3d.Extrude; | |
import eu.mihosoft.vrl.v3d.Transform | |
def URL = "https://gist.github.com/1606010b686494cea33527b71c98570a.git" | |
File f = ScriptingEngine | |
.fileFromGit( | |
URL,//git repo URL | |
"master",//branch | |
"airFoil.svg"// File from within the Git repo | |
) | |
def file="bez.json" | |
//Git stored file loaded but not saved | |
BezierEditor editor = new BezierEditor(ScriptingEngine.fileFromGit("https://gist.github.com/f01548f0e4f85bd3f08fdfdd503510b4.git", file),20) | |
//Git file loaded and saved. THis will do a git call on each event of change | |
//BezierEditor editor = new BezierEditor(URL, file,10) | |
ArrayList<Transform> transforms = editor.transforms() | |
//def modelParts = CSG.unionAll(Extrude.hull(new Cube(20).toCSG(), transforms)) | |
//return [editor.get(),modelParts] | |
SVGLoad s = new SVGLoad(f.toURI()) | |
ArrayList<CSG>foil = s.extrude(0.01,0.01) | |
CSG part = foil.get(0) | |
.union(foil) | |
.roty(90) | |
.rotx(180) | |
.toZMin() | |
.toYMin() | |
ArrayList<CSG> parts = new ArrayList<CSG>() | |
int numParts = editor.getNumParts() | |
for(int i=0;i<numParts;i++){ | |
double scale = (5+4*Math.cos(Math.PI*1*i/numParts) | |
+0.1*Math.sin(Math.PI*30*i/numParts) | |
) | |
double twistAngle = Math.toDegrees(Math.cos(Math.PI*2*i/numParts)) | |
//println scale | |
parts.add( | |
part.scale(scale) | |
.rotx(twistAngle) | |
) | |
} | |
def modelParts = Extrude.hull(parts, transforms) | |
return [editor.get(),modelParts] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment