Hi, I've tried to make a program that shows a 2D image in 3D, using the brightness of each pixel. So I draw a box at each x and y, the z is the birghtness. Unfortunately, the only way I've found to see the image is to draw boxes in draw(), but it gets really slow for images bigger than 400*400. I think that there are ways to make that better, so how can I do it ?
Code :
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;
PImage img;
void setup() {
size(800, 800, P3D);
ambientLight(255, 255, 255, 0, 0, 0);
img = loadImage("download.jpg");
camera = new PeasyCam(this, img.width/2, img.height/2, 0, 1000);
img.loadPixels();
}
void draw() {
background(0);
for (int i=0; i<img.pixels.length; i++) {
color c = img.pixels[i];
float b = map(brightness(c), 0, 255, -100, 100);
fill(c);
noStroke();
int x = i%(img.width);
int y = (i-x)/img.width;
translate(x, y, b);
box(1);
translate(-x, -y, -b);
}
}