We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have posted this in the Libraries section but i received no solution, so I am trying it here in the open area.
I have the following program creates cubes and changes them. I am trying to make the cubes invisible until they are activated in updatecells, but I need them part of my overall VBO that is created during setup to help performance. I have tried putting the "setVisible( false )" code in many places, but cannot seem to get it to work. I have tried making each side of the cubes invisible separately, and that did not work either. I need to start the program not seeing any of the cubes and then see the cubes that change as they change. I have tried starting with nothing in the VBO and adding the cube as they change, but the performance is worse that writing everything separately without a VBO. Any suggestions are welcome.
Below is the MFE that I stripped my code down to in order to show how the setVisible function is not working.
import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape world;
int CPS = 10;
int totalcubes = CPS*CPS*CPS;
int rcolor;
float CS = .25;
float offset = CPS/2;
color colors[]= {0x88FF0000,0x8800FF00,0x880000FF,0x88FFFF00,0x8800FFFF,0x88FF00FF};
int orientation[][][]={{{1,6,2,4,5,3},{1,6,4,5,3,2},{1,6,5,3,2,4},{1,6,3,2,4,5}},
{{6,1,2,3,5,4},{6,1,3,5,4,2},{6,1,5,4,2,3},{1,6,4,2,3,5}},
{{2,5,4,6,3,1},{2,5,6,3,1,4},{2,5,3,1,4,6},{2,5,1,4,6,3}},
{{4,3,1,2,6,5},{4,3,2,6,5,1},{4,3,6,5,1,2},{4,3,5,1,2,6}},
{{5,2,1,3,6,4},{5,2,3,6,4,1},{5,2,6,4,1,3},{5,2,4,1,3,6}},
{{3,4,5,6,2,1},{3,4,6,2,1,5},{3,4,2,1,5,6},{3,4,1,5,6,2}}};
void setup() {
size(2100,2100, P3D);
cam = new PeasyCam(this, 150*CPS);
noStroke();
print("Making World ");
world = createShape(GROUP);
for (int i = 0; i < CPS; i++) {
for (int j = 0; j < CPS; j++) {
for (int k = 0; k < CPS; k++) {
MyCube cube = new MyCube(i - offset, j - offset, k - offset);
world.addChild(cube.output);
}}print("-");}
println(" done");} // end setup
void draw() {
background(127);
scale(95);
shape(world, 0, 0);
UpdateCubes();
} // end draw
void UpdateCubes(){
PShape cube = world.getChild(int(random(totalcubes)));
color sidecolor;
int tempfront = int(random(6));
int temptop = int(random(4));
int tempside = 0;
for (int side=0; side < 6; side++) {
tempside=orientation[tempfront][temptop][side];
sidecolor=colors[tempside-1];
for (int V=0; V < 4; V++) {
cube.setStroke(side*4+V,sidecolor);
cube.setFill(side*4+V,sidecolor);
cube.setVisible( true );
} // end V
} // end side
} // end updatecells
class MyCube {
PShape output;
MyCube(float x, float y, float z) {
output = createShape();
output.translate(x, y, z);
output.setVisible(false);
output.beginShape(QUADS);
output.fill(colors[0]);
output.vertex(-CS, CS, CS);output.vertex( CS, CS, CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
output.fill(colors[1]);
output.vertex( CS, CS, CS);output.vertex( CS, CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);
output.fill(colors[2]);
output.vertex( CS, CS,-CS);output.vertex(-CS, CS,-CS);output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);
output.fill(colors[3]);
output.vertex(-CS, CS,-CS);output.vertex(-CS, CS, CS);output.vertex(-CS,-CS, CS);output.vertex(-CS,-CS,-CS);
output.fill(colors[4]);
output.vertex(-CS, CS,-CS);output.vertex( CS, CS,-CS);output.vertex( CS, CS, CS);output.vertex(-CS, CS, CS);
output.fill(colors[5]);
output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
output.endShape(CLOSE);
} // end constructor
}// end MyCube
Answers
duplicate:
https://forum.processing.org/two/discussion/18965/setvisible
please don't post duplicate questions.