Hi Processing Community! I am running into a wall creating the rasterized layer for my rotating PShape 3d models. Here is my current code:
PShape obj, obj2;
PImage txtr;
float theta;
PGraphics canvas;
void setup(){
size(1000,1000,P3D);
txtr = loadImage("grid3.jpg");
}
void draw() {
background(txtr);
objAbstractShape();
objAbstractShape2();
}
void objAbstractShape(){
obj = loadShape("Abstract_Curve.obj");
obj.setFill(color(255)); // Brigthens the texture
obj.setTexture(txtr);
pushMatrix();
translate(width/2, height/2);
shininess(5.0);
lights();
rotateY(theta/2); //mouseY or (radians(frameCount));
rotateX(theta/2); //mouseX or (radians(frameCount));
rotateZ(theta/2);
scale(70);
shape(obj);
popMatrix();
theta+=.1; //.01
}
void objAbstractShape2(){
obj2 = loadShape("Abstract_Curve_2.obj");
obj2.setFill(color(255)); // Brigthens the texture
obj2.setTexture(txtr);
pushMatrix();
translate(width/2, height/2);
shininess(5.0);
lights();
//rotateY(theta/2); //mouseY or (radians(frameCount));
rotateX(radians(frameCount)); //mouseX or
rotateZ(theta/2);
scale(70);
shape(obj);
popMatrix();
theta+=.1; //.01
}
I am trying to combine my 3d PShape objects with Tim Rodenbröeker’s rotating image rasterization as follows…
PGraphics pg1, pg2, canvas;
float wave;
void setup() {
size(900, 900, P2D);
pg1 = createGraphics(900, 900, P3D);
pg2 = createGraphics(900, 900, P2D);
canvas = createGraphics(900, 900, P3D);
}
void draw() {
background(#FFFF00);
wave = map(tan(radians(frameCount)), -1, 1, -50, 50);
drawPg1();
drawPg2();
canvas.beginDraw();
canvas.imageMode(CENTER);
canvas.background(0);
canvas.pushMatrix();
canvas.translate(canvas.width/2, canvas.height/2);
canvas.image(pg1, 0, 0);
canvas.image(pg2, 0, 0);
canvas.popMatrix();
canvas.endDraw();
float tilesX = 100;
float tilesY = 100;
float tileW = width/tilesX;
float tileH = height/tilesY;
fill(0);
noStroke();
PImage buffer = canvas.get();
for (int x = 0; x < tilesX; x++) {
for (int y = 0; y < tilesY; y++) {
int px = int(x * tileW);
int py = int(y * tileH);
color c = buffer.get(px,py);
float b = brightness(c);
float s = map(b,0,255,0,1);
pushMatrix();
translate(px, py);
ellipse(0, 0, tileW * s, tileH * s);
popMatrix();
}
}
}
void drawPg1() {
pg1.beginDraw();
pg1.background(#111111);
pg1.fill(#F1F1F1);
pg1.noStroke();
pg1.pushMatrix();
pg1.translate(pg1.width/2 + wave, pg1.height/2);
pg1.rotateY(radians(frameCount));
pg1.ellipse(0, 0, 700, 700);
pg1.popMatrix();
pg1.endDraw();
}
void drawPg2() {
pg2.beginDraw();
pg2.clear();
pg2.rectMode(CENTER);
pg2.stroke(#aaaaaa);
pg2.strokeWeight(20);
pg2.noFill();
pg2.pushMatrix();
pg2.translate(pg2.width/2, pg2.height/2);
pg2.rotate(radians(frameCount));
pg2.rect(0, 0, 600, 600);
pg2.popMatrix();
pg2.endDraw();
}