Help with Shapes3D - Alphas, VBOs and optimization

edited February 2015 in Library Questions

I decided to use Shapes3D since I could have custom shapes and different colors for each face of my cubes, which is one of my basic requirements. I am having a few issues that I am hoping someone might be able to help me with:

1- towards the end, I have a line with picked.fill(0x88). I would like to change the alpha on a cube as I hover over it or if need be, when it is clicked, but then as soon as I click it again, it goes back to normal, or better yet, when I move the mouse, any suggestions?

2- The main cpu-cycle eater is the line "for (int i = 0; i < box.length; i++) box[i].draw();" It pushes every box from memory back to the GPU. I have been unable to find a good sample of how to use the VBO with Shapes3D and make it all speed up.

3- I understand that there are some libraries(??) that I could pre-process my view with in order to only pass the information I really need to peasy, without sending it the entire matrix. Can anybody suggest any of these pre-processors that work with peasy?

To see the full effect of the slowness, change the CellsPerSide value at the top to 50 or even 100 and everything with slow down to a crawl. On my 64GB machine with 3GPUs, I am only using 5% of my GPU, so I know I could speed things up considerably. Any and all suggestion would be GREATLY APPRECIATED. Thank you for your time and effort.

import peasy.*;
import shapes3d.*;

int ScreenSize=600; 
int d = int(ScreenSize *.476);  // dimensions
int CellsPerSide = 30;
int gridsize = int(d/(CellsPerSide+1)*2);  //gridline spacing
int bsize = int(d/CellsPerSide);  //box size

int TotalCells = CellsPerSide * CellsPerSide * CellsPerSide; 
Box[] box = new Box[TotalCells];
Shape3D picked = null;
boolean clicked = false;
PeasyCam pcam;


void setup() {
  size(ScreenSize, ScreenSize, P3D);
  cursor(CROSS);
  for (int k = 0; k < CellsPerSide; k++) {
    for (int j = 0; j < CellsPerSide; j++) {
      for (int i = 0; i < CellsPerSide; i++) {
        int x=int((i*gridsize + gridsize)-d);
        int y=int((j*gridsize + gridsize)-d);
        int z=int((k*gridsize + gridsize)-d);
        int cellnum = (k*CellsPerSide*CellsPerSide)+(j*CellsPerSide)+i;
        box[cellnum] = new Box(this, bsize, bsize, bsize);
        box[cellnum].moveTo(x,y,z);
        box[cellnum].fill(0xFFFF0000,1);  //Front   RED
        box[cellnum].fill(0xFF00FF00,2);  //Back    GREEN
        box[cellnum].fill(0xFF0000FF,4);  //Left    BLUE
        box[cellnum].fill(0xFFFFFF00,8);  //Right   YELLOW
        box[cellnum].fill(0xFF00FFFF,16); //Bottom  CYAN
        box[cellnum].fill(0xFFFF00FF,32); //Top     MAGENTA
        box[cellnum].stroke(color(64, 0, 64));
        box[cellnum].strokeWeight(0.6);
        box[cellnum].drawMode(S3D.SOLID | S3D.WIRE);
        box[cellnum].tag = "Box " + cellnum;
        }}}  //end for i,j,k
   pcam = new PeasyCam(this, ScreenSize*1.5);
}  // end etup

void draw() {
  pushMatrix();
  if (clicked) {
    clicked = false;
    picked = Shape3D.pickShape(this, mouseX, mouseY);
    if (picked != null) picked.fill(0x88);
    println("Cell # "+picked.tag);
  }  // end clicked
  for (int i = 0; i < box.length; i++) box[i].draw();
  popMatrix(); 
  }  // end draw

void mouseClicked() {  clicked = true;  }
Sign In or Register to comment.