Processing + 3D Printing

3d

This is going to be a long post, my hat’s off to you if you get to the end…

Method #1:

Use library unlekker library from Marius Watz, it allows your to export stl files

Example from

/* Convexhull to stl export
* by Ben Leduc-Mills
* 10.5.10
*/

import unlekker.util.*;
import unlekker.geom.*;
import unlekker.data.*;
import ec.util.*;
import quickhull3d.*;

//init STL object
STL stl;
//init quickhull
QuickHull3D hull = new QuickHull3D();
//init Point3d array
Point3d[] points;
//number of points
int numPoints = 20;

void setup() {

size(400, 400, P3D);

//populate point3d array with random xyz coordinates
Point3d[] points = new Point3d[numPoints];
for(int i = 0; i < numPoints; i++) {
points[i] = new Point3d (random(50), random(50), random(50));
}
hull.build (points);
}

void draw() {
background(255);
translate(width/2, height/2 -50, 200);
lights();
rotateY(frameCount * 0.01);

Point3d[] vertices = hull.getVertices();

beginShape();
//println ("Faces:");
int[][] faceIndices = hull.getFaces();
//print(faceIndices.length);
for (int i = 0; i < faceIndices.length; i++) {
for (int k = 0; k < faceIndices[i].length; k++) {

//print (faceIndices[i][k] + " ");

//get points that correspond to each face
Point3d pnt2 = vertices[faceIndices[i][k]];
//print(pnt2);
float x = (float)pnt2.x;
float y = (float)pnt2.y;
float z = (float)pnt2.z;
vertex(x,y,z);
}
//println ("");
}

endShape();
}

//if any key is pressed, output the STL file
void keyPressed() {
outputSTL();
}

//function to output STL file
void outputSTL() {

stl=(STL)beginRaw("unlekker.data.STL","convexhull.stl");

Point3d[] vertices = hull.getVertices();

beginShape(QUADS);
//println ("Faces:");
int[][] faceIndices = hull.getFaces();
//print(faceIndices.length);
for (int i = 0; i < faceIndices.length; i++) {
for (int k = 0; k < faceIndices[i].length; k++) {

//print (faceIndices[i][k] + " ");

Point3d pnt2 = vertices[faceIndices[i][k]];
print(pnt2);
float x = (float)pnt2.x;
float y = (float)pnt2.y;
float z = (float)pnt2.z;
vertex(x,y,z);
}
//println ("");
}

endShape(CLOSE);
endRaw();
}

Problems: Marius Watz created a new library Model Builder that replaces UnlekkerLib and Processing will not allow for both to exist within your library folder. UnlekkerLib has been discontinued. Model builder was designed for 3D printing.

When you copy and paste the code above and test it using UnlekkerLib, you get this error message

“The type processing.core.PGraphics3D cannot be resolved. It is indirectly referenced from required .class file”

So let’s apply this method to our own simple sphere

import unlekker.util.*;
import unlekker.geom.*;
import unlekker.data.*;
import ec.util.*;

import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;

import processing.opengl.*;

//init STL object
STL stl;

int x;
int y;

void setup(){
size(800,400,OPENGL);
x= 50;
y= 2;
}

void draw(){

background(255);

stroke(255, 153, 0);

//Only for display
translate(width/2,height/2);
rotateZ(mouseX/100f);
rotateX(mouseY/100f);

//Your Object
pushMatrix();
scale(2,y,2);
sphere(50);
popMatrix();

// if (keyPressed == true) {
// if (key == ' ') { // ' ' means spacebar
// x++;
// }
// }
//}

if (keyPressed == true) {
if (key == CODED) {
if (keyCode == UP) {
x++;
} else if (keyCode == DOWN) {
x–;
}
} else {
x = 50;
}
}

if (mousePressed == true) {
if (y == 2) {
y–;
} else {
y = 2;
}
}

}

//if any key is pressed, output the STL file
void keyPressed() {
outputSTL();
}

//function to output STL file
void outputSTL() {

stl=(STL)beginRaw("unlekker.data.STL","moving_ellisode.stl");

pushMatrix();
scale(2,y,2);
sphere(50);
popMatrix();
endRaw();
}

Result: You get the same error message

Method #2

Using Model Builder:

Check out

ed_record.html
for examples and her how-to-print guide

“Eventually Processing will tell you that it is writing your STL file and when it is done it will say “Closing ‘name_of_your_file.stl’ and tell you haw many faces are in the file. You can find the finished file in the Processing3DPrintedRecord folder.

So let’s try the example from Code & Form, Marcius Watz website

import unlekker.mb2.geo.*;
import unlekker.mb2.util.*;
import ec.util.*;

UGeo geo;

void setup() {
size(600,600,OPENGL);
UMbMk2.setPApplet(this); // set base PApplet reference

UVertexList vl,vl2;

// create list of vertices arranged radially but with random radii
vl=new UVertexList();
for(int i=0; i<12; i++) {
float deg=map(i, 0,12, 0,TWO_PI);
vl.add(new UVertex(random(100,200), 0, 0).rotY(deg));
}

// copy and offset vl
vl2=vl.copy().translate(0,600,0);

// initialize UGeo and add a quad strip connecting vl and vl2
geo=new UGeo().quadstrip(vl,vl2);

// center mesh around origin and scale by 50%
geo.center().scale(0.5);

}

void draw() {
background(0);

translate(width/2,height/2);
geo.draw();
}

Result: error message

No library found for unlekker.mb2.geo
No library found for unlekker.mb2.util

Let’s try an example from the Model Builder Library

— computer gets stuck in “rainbow wheel of death” model after pressing run

— lets increase the memory

— This still happens

Method #3:

Source:

This only works on Windows

This tutorial will show you how to take a 3D scene from Processing (or any app compatible withOGLE and turn it into a physical 3D model using the Stratasys BST 3D Printer. Right now this only works on Windows due to the reliance on GLIntercept (sorry) though since Processing is cross-platform you could load your sketch on a Windows machine to generate the OBJ.
Steps:
• Download and install Processing
• Download and install GLIntercept
• Download and install OGLE
o Download and install OGLE
o Copy the GLIntercept opengl32.dll into your processing/java/bin directory
o Copy the OGLE gliConfig_OGLE.txt to gliConfig.txt in your processing/java/bin directory
o For some reason Processing doesn’t like the default GLIntercept capture keystroke (CTRL-SHIFT-F) so we need to change it
• Edit the gliConfig.txt in the Processing directory and search for “(ctrl,shift,f)” and replace it with “(f6)”
• Write code in Processing (todo)
o You need to open your window in OpenGL mode by adding import processing.opengl.* at the top of you code and giving OPENGL as the last argument to size in your setup function (e.g. size(200, 200, OPENGL);)
o Run your sketch. You should see the file glIntercept.log appear in your Processing /java/bin directory
• Capture scene by pressing F6 from inside Processing. You should see ogle.obj appear in yourdirectory
• Convert OBJ captured from OGLE into STL
o Using Blender
• Get and install Blender
• Import using File->Import->Wavefront (.obj)
• Export using File->Export->STL
• Inside Catalyst you may need to select STL->Reverse Normals if things look weird. Also, Blender seems to choke on large files that Maya can handle without problems
o Using Maya
• Download and install the mayaExportSTL script
• Open your file in Maya, select the desired geometry, and type “mayaExportSTL” on the MEL command-line
• Preview STL in Catalyst (todo)
• Print it!
• Remove supports from model (todo)

Final:
After doing hours of research and failures I think I might have solved the problem by using Model builder to save a stl file. I am using OPENGL instead of PS3 because I found that it runs sketches much faster on my computer

import unlekker.util.*;
import unlekker.modelbuilder.*;
import ec.util.*;

/*
reference to

Modelbuilder library by Marcius Watz

&

Convexhull to stl export
* by Ben Leduc-Mills
* 10.5.10

*/

import quickhull3d.*;

UGeometry model;

//init quickhull
QuickHull3D hull = new QuickHull3D();
//init Point3d array
Point3d[] points;
//number of points

int numPoints = 150;

float x;
float r;

void setup() {

size(600, 600, OPENGL);

x = .01;
r = 95;
//populate point3d array with random xyz coordinates
Point3d[] points = new Point3d[numPoints];
for(int i = 0; i < numPoints; i++) {
points[i] = new Point3d (random(70), random(100), random(70));
}
hull.build (points);
}

void draw() {
background(255);
translate(width/2, height/2 -50, 300);
lights();
rotateY(frameCount * x);

Point3d[] vertices = hull.getVertices();

stroke(95, 229, 250);
fill(r,250,214,100);
beginShape();
//println ("Faces:");
int[][] faceIndices = hull.getFaces();
//print(faceIndices.length);
for (int i = 0; i < faceIndices.length; i++) {
for (int k = 0; k < faceIndices[i].length; k++) {

//print (faceIndices[i][k] + " ");

//get points that correspond to each face
Point3d pnt2 = vertices[faceIndices[i][k]];
//print(pnt2);
float x = (float)pnt2.x;
float y = (float)pnt2.y;
float z = (float)pnt2.z;
vertex(x,y,z);
}
//println ("");
}

endShape();
}

void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
x++;
} else if (keyCode == DOWN) {
x–;
}
} else {
x=.01;
}

if (keyPressed) {
if (key == 'r' || key == 'R') {
r++;
}
} else {
r=95;
}

if(key=='s') {
model.writeSTL(this, "random_points_3d.stl");
}

}

Yet still after, increasing Processing’s available memory to 500 MB I get the rainbow wheel of death in JAVA mode.

Conclusion:

There is still work to be done.
I have to sign up for the tutorial at Parson’s 3D printing labs in order to be able to use the labs and print my project.

Here is a link to my project

http://www.openprocessing.org/sketch/117387

24 thoughts on “Processing + 3D Printing

  1. josephine

    Hey Nelle, Continuing form what you are saying at your presentation today, what kind of 3D printer are you thinking of trying out? The lab orinetation that you are talking about is for Makerbots, a desktop 3D printer. There are 2 other professional 3D printers at Parsons that are better for your lampshade.

    email me at rahaj466@newschool.edu if you want to know more.

    Laser lab and 3D printer tech,
    Josephine 😀

Leave a Reply

Your email address will not be published.