I used to use Nervous System to export to OBJ, but it does not work for Processing 3, I even installed Processing 2 and won’t work there either. If there’s no similar library now I’ll try to code it directly in python/blender
Exporting OBJ or STL with ToxicLibs is very easy, just mesh.saveAsOBJ(...)
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
PImage img;
ToxiclibsSupport gfx;
TriangleMesh mesh;
void setup() {
size(600, 700, P3D);
img = loadImage("adventuretime.jpg");
img.loadPixels();
noStroke();
gfx = new ToxiclibsSupport(this);
mesh = new TriangleMesh("shape");
for (int x=0; x<100; x++) {
for (int y=0; y<100; y++) {
int imgx = (int)map(x, 0, 100, 0, img.width);
int imgy = (int)map(y, 0, 100, 0, img.height);
float bri = brightness(img.get(imgx, imgy));
// Axis Aligned Bounding Box
AABB box = new AABB(0.5 * bri/256.0);
TriangleMesh m = (TriangleMesh) box.toMesh();
m.translate(x, y, 0);
// Add all cubes to one big mesh
mesh.addMesh(m);
}
}
}
void draw() {
background(255);
lights();
gfx.mesh(mesh); // draw the mesh
}
void keyPressed() {
if (key == 's') {
mesh.saveAsOBJ(sketchPath("mesh.obj"));
}
}
The only issue is that the faces are sharing vertices so the shading is smooth and may look wrong. You should set Flat Shading for this shape in Blender or wherever you plan to use it.
Otherwise, construct a box without using AABB, but with 6 planes instead.
Here a close up of the Processing logo using the technique above, but all cubes with the same size and setting a random rotation for bright pixels only.
Thanks a bunch, this really helped me! I was not aware of the toxic lib
I changed the script a little bit to only create cubes on the black pixels found.
So, what I did is the following:
I rotoscoped manually a sequence of a dancer, I’m not running every frame with this script to create cubes where I drew the dancer and now I’ll import that sequence of OBJs to Blender and create a sequence out of it. I’ll share the results when decent.