File this under "Old Hacks"...
This'll work with Beta 0148, but not 1.0+ as the stencil buffer has gone away. (probably a good thing for performance reasons, as it was undocumented and likely seldom used)
The P3D renderer has (had) a stencil buffer you can (could) use as shown in sketch below. If rendering with OPENGL, then you'd want to create an offscreen PGraphics3D to serve as proxy stencil buffer, and render your scene twice (once to OPENGL to see, once to P3D to pick)
I've run across other "picking" code out there too, just don't happen to have any links handy, some searching should turn them up if this approach doesn't fit.
Quote:void setup() {
size(400,400,P3D);
}
void draw() {
background(0);
// manually handle the stencil buffer
// it is created but never cleared:
Arrays.fill(g.stencil, 0);
// and the index needs to be reset:
((PGraphics3D)g).shape_index = 0;
// now draw some stuff
translate(width/3f, height/3f);
rotateX(PI/4f);
rotateY(PI/4f);
fill(255,0,0);
box(100); // id = 1
translate(50,50,25);
fill(0,255,0);
box(100); // id = 2
translate(50,50,25);
fill(0,0,255);
box(100); // id = 3
// use the stencil to id what mouse points to:
if ((g.stencil!=null) && (mouseX>=0) && (mouseY>=0) && (mouseX<width) && (mouseY<height)) {
int pixidx = mouseY * width + mouseX;
int shpidx = g.stencil[pixidx];
println("stencil value at " + mouseX + ", " + mouseY + " = " + shpidx);
}
}