Last active
March 16, 2016 23:25
-
-
Save madhephaestus/da78cb13a62c1a5c691f to your computer and use it in GitHub Desktop.
This file contains 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 java.awt.Font | |
import java.awt.Shape | |
import java.awt.font.FontRenderContext | |
import java.awt.font.TextLayout | |
import java.awt.geom.AffineTransform | |
import java.awt.geom.PathIterator | |
import java.util.List; | |
import javafx.scene.paint.Color | |
import eu.mihosoft.vrl.v3d.CSG | |
import eu.mihosoft.vrl.v3d.Cube | |
import eu.mihosoft.vrl.v3d.Extrude | |
import eu.mihosoft.vrl.v3d.Sphere | |
import eu.mihosoft.vrl.v3d.Vector3d; | |
Closure textExtrude={Font font,String text-> | |
FontRenderContext frc = new FontRenderContext(null,(boolean)true,(boolean)true); | |
TextLayout textLayout = new TextLayout(text, font, frc); | |
Shape s = textLayout.getOutline(null); | |
PathIterator pi = s.getPathIterator(null); | |
ArrayList<Vector3d> points = new ArrayList<Vector3d>(); | |
CSG stringOut = new Sphere(2).toCSG(); | |
connectorDepth=10; | |
float [] coords = new float[6]; | |
float [] start = new float[6]; | |
ArrayList<CSG> sections = new ArrayList<CSG>(); | |
float tmp=0,tmp1=0; | |
BowlerStudioController.setCsg(null,null); | |
while(pi.isDone() == (boolean)false ) { | |
coords = new float[6]; | |
int type = pi.currentSegment(coords); | |
switch(type) { | |
case PathIterator.SEG_CLOSE: | |
//points.add(new Vector3d(tmp, tmp1 ,0)); | |
points.add(new Vector3d(start[0], start[1],0)); | |
if(points.size()>3){ | |
//println "Adding "+points | |
try{ | |
for(Vector3d v:points){ | |
Cube nl= new Cube(1); | |
nl.setCenter(v); | |
BowlerStudioController.addCsg(nl.toCSG()); | |
ThreadUtil.wait(200) | |
} | |
println "Letter done" | |
CSG newLetter = Extrude.points(new Vector3d(0, 0, connectorDepth), points); | |
ThreadUtil.wait(5000) | |
Color c =new Color(Math.random(),Math.random(),Math.random(),1) | |
println "Setting Color to "+c | |
newLetter.setColor(c) | |
BowlerStudioController.addCsg(newLetter); | |
sections.add(newLetter); | |
//ThreadUtil.wait(1000) | |
//stringOut = new Sphere(2).toCSG(); | |
//return stringOut; | |
}catch(NullPointerException e){ | |
e.printStackTrace() | |
} | |
} | |
points = new ArrayList<Vector3d>(); | |
break; | |
case PathIterator.SEG_QUADTO: | |
//println "SEG_QUADTO from ( "+coords[0]+" , "+coords[1]+" ) to ( "+coords[2]+" , "+coords[3]+" )"; | |
for(float t=0.05f;t<=1.0f;t+=0.05f) { | |
//(1-t)²*P0 + 2t*(1-t)*P1 + t²*P2 | |
float u = (1.0f-t); | |
float tt=u*u; | |
float ttt=2.0f*t*u; | |
float tttt=t*t; | |
float p1 = tmp*tt + (coords[0]*ttt) + (coords[2]*tttt); | |
float p2 = tmp1*tt + (coords[1]*ttt) + (coords[3]*tttt); | |
points.add(new Vector3d(p1, p2,0)); | |
//println "SEG_QUADTO "+p1+" and "+p2 | |
} | |
tmp = coords[2]; | |
tmp1 = coords[3]; | |
points.add(new Vector3d(tmp, tmp1,0)); | |
break; | |
case PathIterator.SEG_LINETO: | |
//println "SEG_LINETO "+coords | |
tmp = coords[0]; | |
tmp1 = coords[1]; | |
points.add(new Vector3d(tmp, tmp1,0)); | |
break; | |
case PathIterator.SEG_MOVETO: | |
// move without drawing | |
start[0] = tmp = coords[0]; | |
start[1] = tmp1 = coords[1]; | |
//println "Moving to "+start | |
points.add(new Vector3d(tmp, tmp1,0)); | |
break; | |
case PathIterator.SEG_CUBICTO: | |
for(float t=0.0f;t<=1.05f;t+=0.1f) { | |
// p = a0 + a1*t + a2 * tt + a3*ttt; | |
float tt=t*t; | |
float ttt=tt*t; | |
float p1 = tmp + (coords[0]*t) + (coords[2]*tt) + (coords[4]*ttt); | |
float p2 = tmp1 + (coords[1]*t) + (coords[3]*tt) + (coords[5]*ttt); | |
points.add(new Vector3d(p1, p2,0)); | |
//println "SEG_CUBICTO "+p1+" and "+p2 | |
} | |
tmp = coords[4]; | |
tmp1 = coords[5]; | |
break; | |
default: | |
throw new RuntimeException("Unknown iterator type: "+type) | |
} | |
pi.next(); | |
//println "pi.isDone() "+pi.isDone() | |
} | |
return sections; | |
} | |
Font font = new Font("Times New Roman", Font.PLAIN, 30); | |
String text = "Hello world!" | |
return textExtrude(font,text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment