I am attempting to make a voxel-ish world builder, and I need to be able to stack the different blocks. How can I pick the separate sides of the block with the shapes3d library. Whenever I pick the shape, it renders it as the entire shape, and I am unsure of how to select only the part that I would like, so that I can build upon it.
import peasy.*;
import shapes3d.*;
import shapes3d.utils.*;
Shape3D picked = null;
boolean clicked = true;
PeasyCam cam;
float[] xArr,yArr,zArr;
float x,y,z;
Box[] boxArr;
color[] colArr;
CameraState defaultState;
void setup(){
size(1200,800,P3D);
cam = new PeasyCam(this,width/2,height/2,0,500);
cam.setMinimumDistance(200);
cam.setMaximumDistance(2000);
cam.setWheelScale(.05);
cam.setDistance(1000);
cam.rotateZ(PI/4);
cam.rotateX(-PI/3);
cam.setResetOnDoubleClick(false);
defaultState = cam.getState();
x=width/2;
y=height/2;
z=0;
xArr = new float[200];
yArr = new float[200];
zArr = new float[200];
colArr = new color[200];
boxArr= new Box[200];
for(int i=0;i<boxArr.length;i++){
boxArr[i]=null;
}
xArr[0]=x;
yArr[0]=y;
zArr[0]=z;
boxArr[0]=new Box(this);
colArr[0]=color(255,255,255);
}
final float xrot=-PI/8,yrot=PI/4,zrot=0;
color col = color(255,255,255);
void mouseClicked(){
clicked=true;
}
void draw(){
pushMatrix();
if (keyPressed&&key=='r'){
cam.setState(defaultState);
cam.setDistance(1000);
}
background(213, 243, 245);
ambientLight(200,200,200);
fill(col);
lights();
directionalLight(100,100,100,50,-50,0);
int actuallength=0;
for (int i=0;i<boxArr.length;i++){
if(boxArr[i]!=null){
actuallength++;
}
}
for(int i = 0; i<actuallength; i++){
boxArr[i].fill(colArr[i]);
boxArr[i].strokeWeight(1.75);
boxArr[i].stroke(155);
boxArr[i].moveTo(xArr[i],yArr[i],zArr[i]);
boxArr[i].drawMode(Shape3D.SOLID|Shape3D.WIRE);
boxArr[i].draw();
}
if (clicked){
clicked=false;
picked = Shape3D.pickShape(this, mouseX, mouseY);
int pos=0;
for(int i=0;i<boxArr.length;i++){
if(boxArr[i]==picked){
pos=i;
}
}
if(picked!=null){
println();
boxArr[actuallength]=new Box(this);
xArr[actuallength]=xArr[pos]+(100);
yArr[actuallength]=yArr[pos];
zArr[actuallength]=zArr[pos];
colArr[actuallength]=color(255,255,255);
}
}
popMatrix();
}