Here is a simple example showing how to use unlekkerLib to output and input 3D geometry in STL format.

// STLBoxes.pde - demonstrates how to use unlekkerLib to
// import / export STL geometry data.
//
// Marius Watz - http://workshop.evolutionzone.com/

import unlekker.data.*;

STL stl;

public void setup() {
  size(400,400, P3D);
  frameRate(25);
  sphereDetail(12);
}

public void draw() {
  translate(width/2,height/2);

  if(frameCount==10) outputSTL();
  else if(frameCount==11) readSTL();
  if(frameCount<12) return;

  background(0);
  noStroke();
  lights();
  rotateY(radians(frameCount));
  rotateX(radians(frameCount*0.25f));
  fill(0,200,255, 128);
  stl.draw();

}

public void readSTL() {
  stl=new STL(this,"Boxes.stl");
  stl.normalize(400); // scale object
  stl.center(); // center it around world origin
}

public void outputSTL() {
  float rad;

  stl=(STL)beginRaw("unlekker.data.STL","Boxes.stl");
  for(int i=0; i<200; i++) {
    pushMatrix();
    translate(random(-200,200),0,-random(400));
    rotateX(((float)(int)random(6))*radians(30));
    rotateY(((float)(int)random(6))*radians(30));

    rad=random(5,25);
    if(random(100)>5) box(rad,random(50,200),rad);
    else sphere(rad);
    popMatrix();
  }
  endRaw();
}

10 Comments »

There are 10 comments to "unlekkerLib: STLBoxes.pde". You may leave your own comment.
1. lenny, September 26th, 2007 at 04:55

now stupid me has a brandnew problem:(

java.lang.UnsupportedClassVersionError: unlekker/data/STL (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

2. marius watz, September 27th, 2007 at 09:16

Oops, I suspect I compiled the library for Java 1.5. I’ll fix it and post a new version.

3. lenny, September 27th, 2007 at 15:38

great, thanks a lot for your efforts marius.

4. Yoda1000, October 15th, 2007 at 19:33

Same problem for me ! where found a new version for Java 1.6 ?

5. Paul Rabattski, October 25th, 2007 at 19:34

Bonjour Monsieur Watz,

The unlekkerLib has disappeared into a 404. What happened to it?

6. marius watz, October 28th, 2007 at 02:31

Hi Paul, I’m sorry the code was incorrect. You’ll find it here, I just posted a minor update as well.

7. Bill Bounds, November 14th, 2007 at 16:03

Very nice an elegant example! Thanks!

8. Paul Rabattski, February 15th, 2008 at 19:20

Awesome Marius! Thank you!

9. hansi, November 8th, 2008 at 00:57

i reall like your lib.

but it looks like this example (or stl import at all) does not work anymore in current processing (0155):

Exception in thread “Animation Thread” java.lang.NoSuchMethodError: processing.core.PGraphics3D.(IILprocessing/core/PApplet;)V
at unlekker.data.STL.(STL.java:69)
at STLBoxes.readSTL(STLBoxes.java:52)
at STLBoxes.draw(STLBoxes.java:38)
at processing.core.PApplet.handleDraw(PApplet.java:1395)
at processing.core.PApplet.run(PApplet.java:1300)
at java.lang.Thread.run(Unknown Source)

i tested the same sketch in 0148 and it works. do you know a solution or workaround?

thank you.

10. marius watz, November 10th, 2008 at 01:39

Thanks for letting me know, I just got the same error with 0155. I will look into it.

Comment on this entry

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">