pixels[] array works in 2D but not 3D?
in
Core Library Questions
•
8 months ago
I've been pulling out my hair all day trying to understand why the pixels[] array for a PImage was not being updated correctly.
sketch in 2D (line 16 changed to "size(1280,720)"), movie frame correctly reproduced in the grid of squares:
It seems that the PImage pixels[] array is updated correctly when my sketch is 2D, but not 3D (not P3D nor OPENGL; both renders fail).
What I'm trying to do is to divide each frame of a movie into a grid of squares, and then arbitrarily move the squares in a 3D space.
When my sketch is 3D, it seems like only the lower right corner of the movie frame is replicated on all of the squares in the grid. But if the sketch is 2D, then each square is a corresponding portion of the movie frame, as expected, and the entire movie frame is reproduced in the grid of squares.
I've tried this on 2.0b5 and 2.0b7 (Note that PeasyCam will make the sketch crash in 2.0b7 if you move the mouse). I'm running Processing on a Mac, 10.7.5
Thoughts?
- import processing.video.*;
- import peasy.*;
- PeasyCam cam;
- Movie myMovie;
- int stepsW ;
- int stepsH ;
- int stepSize = 80;
- PImage textureImage = new PImage();
- void setup()
- {
- size(1280, 720, OPENGL);
- smooth();
- perspective(radians(12), float(width)/float(height), 1, 500000);
- cam = new PeasyCam(this, 5500);
- cam.setMinimumDistance(1);
- cam.setMaximumDistance(50000000);
- textureImage = createImage(stepSize, stepSize, RGB);
- stepsW = width/stepSize;
- stepsH = height/stepSize;
- println("stepSize: " + stepSize + " | stepsW: " + stepsW + " | stepsH: " + stepsH);
- myMovie = new Movie(this, "test4.mov");
- myMovie.loop();
- }
- void draw() {
- background(0);
- myMovie.read();
- myMovie.loadPixels();
- meshUpdate();
- }
- void meshUpdate() {
- pushStyle();
- pushMatrix();
- stroke(255);
- int movieImagePixelIndex = 0;
- for (int y=0; y<stepsH; y++) {
- for (int x=0; x<stepsW; x++) {
- int pixelIndex = 0;
- for (int j=0; j < stepSize; j++) {
- for (int i=0; i < stepSize; i++) {
- movieImagePixelIndex = (y*stepSize*width) + (x*stepSize) + j*width + i;
- textureImage.pixels[pixelIndex] = myMovie.pixels[movieImagePixelIndex];
- pixelIndex++;
- }
- }
- textureImage.updatePixels();
- image(textureImage, x*stepSize-width/2, y*stepSize-height/2);
- }
- }
- popStyle();
- popMatrix();
- }
sketch in 3D (the image is offset by width/2, height/2). each square is a replication of the lower right corner of the movie frame:
1