Simple example of how to generate meshes with Processing and then output them to STL using unlekkerLib.
import unlekker.util.*;
import unlekker.geom.*;
import unlekker.data.*;
import processing.opengl.*;
boolean doSTL=false;
void setup() {
size(400,400, OPENGL);
}
void draw() {
background(100);
if(doSTL) {
beginRaw("unlekker.data.STL","cyl.stl");
}
translate(width/2, height/2, 0);
rotateY(radians(frameCount));
rotateX(radians(frameCount));
fill(255,255,255);
for(int i=0; i<100; i++) {
pushMatrix();
translate(random(-300,300),random(-300,300),random(-300,300));
rotateY(random(PI*2));
rotateX(random(PI*2));
cylinder(50,random(50,200));
popMatrix();
}
if(doSTL) {
endRaw();
doSTL=false;
}
}
void keyPressed() {
if(key=='s') doSTL=true;
}
void cylinder(float w,float h) {
float px,pz;
beginShape(QUAD_STRIP);
for(float i=0; i<13; i++) {
px=cos(radians(i*30))*w;
pz=sin(radians(i*30))*w;
vertex(px,-h,pz);
vertex(px,h,pz);
}
endShape();
beginShape(TRIANGLE_FAN);
vertex(0,-h,0);
for(float i=12; i>-1; i–) {
px=cos(radians(i*30))*w;
pz=sin(radians(i*30))*w;
vertex(px,-h,pz);
}
endShape();
beginShape(TRIANGLE_FAN);
vertex(0,h,0);
for(float i=0; i<13; i++) {
px=cos(radians(i*30))*w;
pz=sin(radians(i*30))*w;
vertex(px,h,pz);
}
endShape();
}




