latest v0.2.4 04/21/2013
This is a library to export meshes from Processing as OBJ or X3D files. It can export color meshes with triangle and quad shaped faces as an OBJ or X3D with a PNG texture map. It can also export meshes with faces with an arbitrary number of sides (without color support). The OBJExport library is used the same way the PDF library is used.
OBJExport works with beginRecord(), beginRaw(), and createGraphics(). The OBJ format and the exporter work with arbitrarily sided polygon, not just triangles. This allows for the versatility to export quad or hex based meshes not just triangles. If you require triangles but are drawing with polygons instead, you can use beginRaw() to get the tesselated output of Processing rather than the original polygons.
The library also supports color mesh export creating a .png texture and a .mtl material file to go along with the obj. Color mode is not enabled by default. Use setColor(true) on the OBJExport object before beginDraw() to turn on color export.
The library does not support stroke(), texture() or normal() in the export. If you're interested in that functionality, let me know or contribute!
Tested on Windows 7, Processing 2.0b8
This library is brand spanking new and probably has bugs!
To install simply download the zip file, and extract the contents to your Processing libraries folder. Or you can use Add Library in the Processing IDE.
import nervoussystem.obj.*; boolean record = false; void setup() { size(400, 400,P3D); } void draw() { if (record) { beginRecord("nervoussystem.obj.OBJExport", "filename.obj"); } box(100,100,100); if (record) { endRecord(); record = false; } } void mousePressed() { record = true; }
Color Example
import nervoussystem.obj.*; boolean record = false; float noiseScale = .05; void setup() { size(400,400,P3D); } void draw() { background(255); if(record) { //X3DExport x3d = (X3DExport) createGraphics(10,10,"nervoussystem.obj.X3DExport","colored.x3d"); OBJExport obj = (OBJExport) createGraphics(10,10,"nervoussystem.obj.OBJExport","colored.obj"); obj.setColor(true); obj.beginDraw(); drawNoise(obj); obj.endDraw(); obj.dispose(); record = false; } noStroke(); translate(width/2,height/2,-50); rotateX(PI/6.0); rotateZ(frameCount*PI/360.0); translate(-100,-100,0); scale(4); drawNoise(this.g); } void drawNoise(PGraphics pg) { pg.beginShape(TRIANGLES); for(int i=0;i<50;i++) { for(int j=0;j<50;j++) { float z = noise(i*noiseScale,j*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i,j,z*50); z = noise((i+1)*noiseScale,j*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i+1,j,z*50); z = noise((i+1)*noiseScale,(j+1)*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i+1,j+1,z*50); z = noise((i+1)*noiseScale,(j+1)*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i+1,j+1,z*50); z = noise(i*noiseScale,(j+1)*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i,j+1,z*50); z = noise(i*noiseScale,j*noiseScale); pg.fill( lerpColor( color(255,0,0),color(0,0,255),z )); pg.vertex(i,j,z*50); } } pg.endShape(); } void keyPressed() { if (key == 'r') { record = true; } }
jesse@n-e-r-v-o-u-s.com