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();
}





it didnt work for me… maybe i am doing something wrong. im using processing beta and it highlights the line :
for(float i=12; i>-1; iā) {
and says unexpected char: ‘\’
please help!!!!
Yes, I’m getting same yeyo’s issue.
an idea why?
Sorry about that, I think the syntax highlighting plugin I was using is to blame, it had some issues with backspaces etc. I just switched to SyntaxHighlighter, which looks good and also allows you to copy the plaintext without any problem.
I think it should be i–
That’s odd. i minus minus ends up as being i minus
Ouch, I see it now. Wordpress automagically corrects two minus signs into one long hyphen. Will figure out how to turn that off. There should be a tutorial on how to post code on WordPress somewhere..
[...] Luckily I’m not the first to tackle this in the processing community. Marius Watz provides a wonderful library which includes an STL renderer. Totally fantastic. All that I have to do is provide geometry in [...]
Option Explicit
Call Main
Sub Main
Dim point (80)
Dim i, x, y, z
For i = 0 To 80
x = (20 + 20*Cos (i))*Cos (i*Sin(i))
y = (20 + 20*Cos (i))*Sin (Cos(i)*i)
z = y*i/100 * Sin (i)
point(i)=Array (x,y,z)
Next
Call mifunction(point)
End Sub
Function mifunction(point)
Rhino.AddCurve(point)
End Function
Sub Main
Dim Curve
Dim Domain ,Param, Point, i,sections
sections=150
ReDim collection (sections)
curve=Rhino.GetObject(”sel curve”,4)
If IsNull (Curve) Then Exit Sub
Domain = Rhino.CurveDomain(curve)
For i = 0 To 100
Param =i * ((Domain(1)-Domain(0))/100)
point =Rhino.EvaluateCurve(Curve,Param)
Rhino.AddPoint point
collection(i) = point
Next
Dim Newpoint
Dim arrBase, dblMajorRadius, dblMinorRadius, arrDirection
For i = 0 To 100
dblMajorRadius = i/13
dblMinorRadius = dblMajorRadius - 5
arrBase = newpoint
newpoint=collection(i)
Rhino.AddTorus newpoint, dblMajorRadius, dblMinorRadius
Next
End Sub