Just heard of this thread & problem from a friend. I've created an alternative tiler class (based on the one by Marius) which I only recently also extended to support different FOVs and clipping planes. It was meant to be part of toxiclibs for a while now, but I've been holding off it (to avoid the dependencies) and will include it in a Processing adapter bundle for this and various other classes in the collection soon.
Below is a working demo (works in 1.0.6) and the already adapted Tiler class itself.
Hope that helps!
Code:import processing.opengl.*;
import toxi.geom.*;
Tiler tiler;
// camera field of vision and desired clipping planes
float FOV=radians(90);
float CLIP_NEAR=1;
float CLIP_FAR=5000;
int NUM_TILES=3;
void setup() {
size(640,480,OPENGL);
tiler=new Tiler((PGraphics3D)g,NUM_TILES);
}
void draw() {
perspective(FOV,(float)width/height,CLIP_NEAR,CLIP_FAR);
translate(width/2,height/2,0);
background(0);
noStroke();
tiler.pre();
lights();
rotateX(0.3);
rotateY(0.2);
for(int y=0; y<6; y++) {
for(int x=0; x<6; x++) {
pushMatrix();
translate((x-3)*300,(y-3)*300,0);
fill(y*64,x*16,(6-x)*64);
box(200);
popMatrix();
}
}
tiler.post();
}
void keyPressed() {
tiler.initTiles(FOV,CLIP_NEAR,CLIP_FAR);
tiler.save(sketchPath("export"), "tiles-" + (System.currentTimeMillis() / 1000), "tga");
}
/**
* Implements a screen tile exporter with support for FOV,
* clip planes and flexible file formats.
*
* Re-engineered from an older version by Marius Watz:
* http://workshop.evolutionzone.com/unlekkerlib/
*
* @author toxi <info at postspectacular dot com>
*/
class Tiler {
protected PGraphics3D gfx;
protected PImage buffer;
protected Vec2D[] tileOffsets;
protected double top;
protected double bottom;
protected double left;
protected double right;
protected Vec2D tileSize;
protected int numTiles;
protected int tileID;
protected float subTileID;
protected boolean isTiling;
protected String fileName;
protected String format;
protected double cameraFOV;
protected double cameraFar;
protected double cameraNear;
public Tiler(PGraphics3D g, int n) {
gfx = g;
numTiles = n;
}
public void chooseTile(int id) {
Vec2D o = tileOffsets[id];
gfx.frustum(o.x, o.x + tileSize.x, o.y, o.y + tileSize.y,
(float) cameraNear, (float) cameraFar);
}
public void initTiles(float fov, float near, float far) {
tileOffsets = new Vec2D[numTiles * numTiles];
double aspect = (double) gfx.width / gfx.height;
cameraFOV = fov;
cameraNear = near;
cameraFar = far;
top = Math.tan(cameraFOV * 0.5) * cameraNear;
bottom = -top;
left = aspect * bottom;
right = aspect * top;
int idx = 0;
tileSize = new Vec2D((float) (2 * right / numTiles), (float) (2 * top / numTiles));
double y = top - tileSize.y;
while (idx < tileOffsets.length) {
double x = left;
for (int xi = 0; xi < numTiles; xi++) {
tileOffsets[idx++] = new Vec2D((float) x, (float) y);
x += tileSize.x;
}
y -= tileSize.y;
}
}
public void post() {
if (isTiling) {
subTileID += 0.5;
if (subTileID > 1) {
int x = tileID % numTiles;
int y = tileID / numTiles;
gfx.loadPixels();
buffer.set(x * gfx.width, y * gfx.height, gfx);
if (tileID == tileOffsets.length - 1) {
buffer.save(fileName + "_" + buffer.width + "x"
+ buffer.height + "." + format);
buffer = null;
}
subTileID = 0;
isTiling = (++tileID < tileOffsets.length);
}
}
}
public void pre() {
if (isTiling) {
chooseTile(tileID);
}
}
public void save(String path, String baseName, String format) {
(new File(path)).mkdirs();
this.fileName = path + "/" + baseName;
this.format = format;
buffer = new PImage(gfx.width * numTiles, gfx.height * numTiles);
tileID = 0;
subTileID = 0;
isTiling = true;
}
public boolean isTiling() {
return isTiling;
}
}