How do I Group PShapes

I have a short little program to draw some cubes. The following works:

import processing.opengl.*;
PShape cube;
float CS = .25;  //CubeSize
int CPS = 60;    //CubesPerSide
float offset = CPS/2;

void setup()  { 
  size(640, 640, P3D); 
  noStroke(); 

  cube = createShape();
  cube.beginShape(QUADS);
  cube.fill(0x44FF0000); cube.vertex(-CS,  CS,  CS);cube.vertex( CS,  CS,  CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.fill(0x4400FF00); cube.vertex( CS,  CS,  CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);
  cube.fill(0x440000FF); cube.vertex( CS,  CS, -CS);cube.vertex(-CS,  CS, -CS);cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);
  cube.fill(0x44FFFF00); cube.vertex(-CS,  CS, -CS);cube.vertex(-CS,  CS,  CS);cube.vertex(-CS, -CS,  CS);cube.vertex(-CS, -CS, -CS);
  cube.fill(0x4400FFFF); cube.vertex(-CS,  CS, -CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS,  CS,  CS);cube.vertex(-CS,  CS,  CS);
  cube.fill(0x44FF00FF); cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.endShape(CLOSE);
} 

void draw()  { 
  background(127);
  scale(5); 
  for (int i = 0; i < CPS; i++) {
      for (int j = 0; j < CPS; j++) {
          for (int k = 0; k < CPS; k++) { 
  pushMatrix();
  translate(i+offset,j+offset,k+offset);  
  shape(cube,0,0);
  popMatrix();
  }}}
} 

But when I try and move the cubes all into one GROUP, I cannot get the GROUP to display. I have made the most basic example so that I can understand where I am going wrong. It is probably something very simple, but I cannot figure it out. Thank you for any and all suggestions.

import processing.opengl.*;
PShape cube, world;
float CS = .25;
int CPS = 20;
float offset = CPS/2;

void setup()  { 
  size(640, 640, P3D); 
  noStroke(); 

  cube = createShape();
  cube.beginShape(QUADS);
  cube.fill(0x44FF0000); cube.vertex(-CS,  CS,  CS);cube.vertex( CS,  CS,  CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.fill(0x4400FF00); cube.vertex( CS,  CS,  CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);
  cube.fill(0x440000FF); cube.vertex( CS,  CS, -CS);cube.vertex(-CS,  CS, -CS);cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);
  cube.fill(0x44FFFF00); cube.vertex(-CS,  CS, -CS);cube.vertex(-CS,  CS,  CS);cube.vertex(-CS, -CS,  CS);cube.vertex(-CS, -CS, -CS);
  cube.fill(0x4400FFFF); cube.vertex(-CS,  CS, -CS);cube.vertex( CS,  CS, -CS);cube.vertex( CS,  CS,  CS);cube.vertex(-CS,  CS,  CS);
  cube.fill(0x44FF00FF); cube.vertex(-CS, -CS, -CS);cube.vertex( CS, -CS, -CS);cube.vertex( CS, -CS,  CS);cube.vertex(-CS, -CS,  CS);
  cube.endShape(CLOSE);

  world=createShape();
  world.beginShape(GROUP);
  for (int i = 0; i < CPS; i++) {
      for (int j = 0; j < CPS; j++) {
          for (int k = 0; k < CPS; k++) { 
          pushMatrix();
          translate(i+offset,j+offset,k+offset);  
          world.addChild(cube);
          popMatrix();
          }}}
   world.endShape(CLOSE);
 } 

void draw()  { 
  background(127);
  scale(5); 
  shape(world,0,0);   //shape(cube,0,0);
} 

Answers

Sign In or Register to comment.