Resetting a PShape

Hello everyone, I am making a voxel game and have been using PShapes to generate chunk meshes. I am currently working on Raycasting so that the player can break and place a block. However, when the player breaks a block, the chunk’s mesh is supposed to regenerate so that there is an empty space when the player broke the block. When I break blocks, the mesh doesn’t regenerate. How would I go about resetting the PShape so that I can regenerate it?
Here is the meshing code:

import processing.core.PApplet;
import processing.core.PVector;
import processing.core.PShape;
import processing.core.PConstants;
import java.util.ArrayList;
class Chunk {
  Cube[][][] chunk;
  static int w = 16, h = 64, d = 16;
  public int size;
  PApplet app;
  PVector position = new PVector(0, 0, 0);
  int maxValue;
  PShape mesh;
  PShape transparentMesh;
  ArrayList<PVector> trees = new ArrayList<PVector>();
  public Chunk(PApplet p, float x, float y, float z) {
	  app = p;
	  mesh = app.createShape();
	  transparentMesh = app.createShape();
	  mesh.setTexture(Minecraft.textureAtlas);
	  transparentMesh.setTexture(Minecraft.textureAtlas);
	  position = new PVector(x, y, z);
	  chunk = new Cube[w][h][d];
	  size = Minecraft.size;
	  generateTerrain(this);
  }
  public void setPosition(int x, int y, int z) {
	position = new PVector(x, y, z);
  }
  public float noise(int x, int y) {
	  return Minecraft.generator.GetNoise(x, y);
  }
  public int[][] generateHeightMap() {
	int[][] map = new int[w][d];
	for(int i = 0; i < w; i++) {
		for(int j = 0; j < d; j++) {
		    int x = (int) (i + position.x) * 3;
		    int y = (int) (j + position.y) * 3;
//			float e = noise(x, y) + 0.5f * noise(2 * x, 2 * y) + 0.25f * noise(4 * x, 4 * y);
//			e = e / (1f + 0.5f + 0.25f);
		    float e = noise(x, y);
			e = PApplet.constrain(e, -1, 1);
			e = Float.parseFloat(PApplet.nf(e, 1, 1));
			e = PApplet.map(e, -1, 1, 15, 0);
			map[i][j] = (int) e;
		}
	}
	return map;
  }
  public void setTreeBlock(int x, int y, int z) {
	  if(inBounds(x, y, z)) {
		  chunk[z][y][x] = new OakBlock(size, app, this);
		  chunk[z][y][x].setPosition(z, y, x);
	  }
  }
  public void setLeavesBlock(int x, int y, int z, int xPos, int height, int zPos) {
	  if(inBounds(x, y, z)) {
		  chunk[z][y][x] = new Leaves(size, app, this);
		  chunk[z][y][x].setPosition(zPos, height, xPos);
	  }
  }
  public boolean isBlockAt(double x, double y, double z) {
		PVector pos = new PVector((float) x, (float) y, (float) z);
		if(!inBounds(pos.x, pos.y, pos.z)) {
			return false;
		}
		  for (int i = 0; i < w; i++) {
		    for (int j = 0; j < h; j++) {
		      for (int k = 0; k < d; k++) {
		    	if(chunk[j][i][k] != null && chunk[j][i][k].position.equals(pos)) {
				            return true;
		    	  }
		        }
		      }
		    }
		  return false;
	}
  public void generateTerrain(Chunk c) {
	int[][] map = generateHeightMap();
	int y = 11;
	  for (int i = 0; i < w; i++) {
		for (int j = 0; j < d; j++) {
			/*
			int a = map[j][i];
			chunk[i][a][j] = new GrassBlock(size, app, c);
			chunk[i][a][j].setPosition(i, a, j);
			*/
			for(int k = 0; k < h; k++) {
				/*
			      int y2 = map[j][i];
			      if(y2 > 7) {
			    	  y2 = 7;
			      }
			      if(y2 < 0) {
			    	  y2 = 0;
			      }
			      chunk[j][i][y2] = new GrassBlock(size, app, c);
				  chunk[j][i][y2].setPosition(j,  y2,  i);
			      if(y2 >= k) {
			    	  chunk[j][i][k] = new WaterBlock(size, app, c);
			    	  chunk[j][i][k].setPosition(j, k, i);
			      }
			      */
				if(k == 11) {
			  chunk[i][k][j] = new GrassBlock(size, app, c);
			  chunk[i][k][j].setPosition(i, k, j);
				} else if (k >= 12 && k <= 13) {
					chunk[i][k][j] = new DirtBlock(size, app, c);
					chunk[i][k][j].setPosition(i, k, j);
				} else if(k >= 14 && k <= 61) {
					chunk[i][k][j] = new StoneBlock(size, app, c);
					chunk[i][k][j].setPosition(i, k, j);
				} else if(k >= 62 && k <= 63) {
					chunk[i][k][j] = new Bedrock(size, app, c);
					chunk[i][k][j].setPosition(i, k, j);
				}
				if(app.random(0, 1) <= 0.000125) {
					   generateTree(d/2 + (int) Math.round(app.random(-6, 6)), y, w/2 + (int) Math.round(app.random(-6, 6)));	
					}
				if(app.random(0, 1) <= 0.0005) {
					chunk[i][y - 1][j] = new TallGrass(size, app, c);
					chunk[i][y - 1][j].setPosition(i, y - 1, j);
				}
				/*
				if(k > y) {
					if(y < 25) {
						chunk[i][k][j] = new WaterBlock(size, app, c);
						chunk[i][k][j].setPosition(i, j, k);
					}
				}
				*/
		}
	  }
	}
  }
  public void generateTree(int x, int y, int z) {
	  boolean gen = true;
	  for(int i = 0; i < trees.size(); i++) {
		  if(trees.get(i).equals(new PVector(x, y, z))) {
			  gen = false;
		  }
	  }
	  if(gen) {
		  trees.add(new PVector(x, y, z));
	  int height = (int) (Math.round(app.random(6, 10)));
	  for(int i = 1; i < height; i++) {
		  chunk[z][y - i][x] = new OakBlock(size, app, this);
		  chunk[z][y - i][x].setPosition(z, y - i, x);
		if(i == height - 1 || i == height - 2) {
		  if(inBounds(z, y - i, x + 1)) {
		  chunk[z][y - i][x + 1] = new Leaves(size, app, this);
		  chunk[z][y - i][x + 1].setPosition(z + 1, y - i, x);
		    }
		  if(inBounds(z - 1, y - i, x + 1)) {
			  chunk[z - 1][y - i][x + 1] = new Leaves(size, app, this);
			  chunk[z - 1][y - i][x + 1].setPosition(z + 1, y - i, x - 1);
			    }
		  if(inBounds(z - 1, y - i, x - 1)) {
			  chunk[z - 1][y - i][x - 1] = new Leaves(size, app, this);
			  chunk[z - 1][y - i][x - 1].setPosition(z - 1, y - i, x - 1);
			    }
		  if(inBounds(z, y - i, x - 1)) {
			  chunk[z][y - i][x - 1] = new Leaves(size, app, this);
			  chunk[z][y - i][x - 1].setPosition(z - 1, y - i, x);
			    }
		  if(inBounds(z + 1, y - i, x)) {
			  chunk[z + 1][y - i][x] = new Leaves(size, app, this);
			  chunk[z + 1][y - i][x].setPosition(z, y - i, x + 1);
			    }
		  if(inBounds(z - 1, y - i, x)) {
			  chunk[z - 1][y - i][x] = new Leaves(size, app, this);
			  chunk[z - 1][y - i][x].setPosition(z, y - i, x - 1);
			    }
		  if(inBounds(z + 1, y - i, x + 1)) {
			  chunk[z + 1][y - i][x + 1] = new Leaves(size, app, this);
			  chunk[z + 1][y - i][x + 1].setPosition(z + 1, y - i, x + 1);
			    }
		  if(inBounds(z + 1, y - i, x - 1)) {
			  chunk[z + 1][y - i][x - 1] = new Leaves(size, app, this);
			  chunk[z + 1][y - i][x - 1].setPosition(z - 1, y - i, x + 1);
			    }
		  if(i == height - 1) {
		  if(inBounds(z, y - i - 1, x)) {
			  chunk[z][y - i - 1][x] = new Leaves(size, app, this);
			  chunk[z][y - i - 1][x].setPosition(z, y - i - 1, x);
			    }
		    }
		  }
	    }
	  }
  }
  public PVector getPixelPosition() {
	  PVector p = new PVector(0, 0, 0);
		            p.x = position.x * (w*size);
		            p.y = position.y * (h*size);
		            p.z = position.z * (d*size);
		            return p;
		          }
  public float round3(float x) {
	  float a = Math.round(x);
	  float b = a / size;
	  float c = Math.round(b);
	  float d = c * size;
	  return d;
	}
  public PVector round2(PVector p) {
	  return new PVector(round3(p.x), round3(p.y), round3(p.z));
  }
  boolean inBounds(double x, double y, double z) {
	  return x < w && y < h && z < d && x > 0 && y > 0 && z > 0;
  }
  public void generateMesh() {
	  mesh.beginShape(PConstants.QUADS);
	  transparentMesh.beginShape(PConstants.QUADS);
	  for (int i = 0; i < w; i++) {
		    for (int j = 0; j < d; j++) {
		      for (int k = 0; k < h; k++) {
		    	  if(chunk[i][k][j] != null) {
		    		  chunk[i][k][j].generateMesh();
		    	  }
	    }
	  }
	}
	  transparentMesh.endShape(PConstants.CLOSE);
	  mesh.endShape(PConstants.CLOSE);
  }
  public void render() {
	app.pushMatrix();
    app.translate(position.x * (w*size), position.y * (h*size), position.z * (d*size));
    app.shape(mesh);
    app.shape(transparentMesh);
    app.popMatrix();
  }
}
import processing.core.PApplet;
import processing.core.PVector;
import processing.core.PConstants;
import processing.core.PShape;
public class Cube {
	float size;
	  public boolean isTransparent;
//	  PVector frontPos, backPos, topPos, leftPos, rightPos, bottomPos;
//	  ArrayList<Vector4> vertices;
  boolean wireframe;
  PVector position = new PVector(0, 0, 0);
  Chunk belongsTo;
  MultiTexture textures;
  AABB collisionBox;
  PApplet app;
  float x1, y1, z1, x2, y2, z2;
  public static enum renderType{BLOCK, SPRITE};
  public renderType type;
  boolean isSolid;
  TextureManager manager;
  String name;
//  ArrayList<Vector4> vertices = new ArrayList<Vector4>();
  Cube(float s, PApplet p, Chunk c) {
	    size = s;
	    x1 = y1 = z1 = -s/2;
	    x2 = y2 = z2 = s/2;
	    collisionBox = new AABB(new PVector(x1, y1, z1), new PVector(x2, y2, z2));
	    isTransparent = false;
	    name = "";
//	    frontPos = backPos = topPos = leftPos = rightPos = bottomPos = new PVector(0, 0, 0);
	    /*
	    vertices = new ArrayList<Vector4>();
	    vertices.add(new Vector4(-1, -1, -1));
	    vertices.add(new Vector4(1, -1, -1));
	    vertices.add(new Vector4(1, 1, -1));
	    vertices.add(new Vector4(-1, 1, -1));
	    
	    vertices.add(new Vector4(1, -1, -1));
	    vertices.add(new Vector4(1, -1, 1));
	    vertices.add(new Vector4(1, 1, 1));
	    vertices.add(new Vector4(1, 1, -1));
	    
	    vertices.add(new Vector4(1, -1, 1));
	    vertices.add(new Vector4(-1, -1, 1));
	    vertices.add(new Vector4(-1, 1, 1));
	    vertices.add(new Vector4(1, 1, 1));
	    
	    vertices.add(new Vector4(-1, -1, 1));
	    vertices.add(new Vector4(-1, -1, -1));
	    vertices.add(new Vector4(-1, 1, -1));
	    vertices.add(new Vector4(-1, 1, 1));
	    
	    vertices.add(new Vector4(-1, -1, 1));
	    vertices.add(new Vector4(1, -1, 1));
	    vertices.add(new Vector4(1, -1, -1));
	    vertices.add(new Vector4(-1, -1, -1));
	    */
	app = p;
	textures = new MultiTexture();
	belongsTo = c;  
    wireframe = false;
    isSolid = true;
    manager = Minecraft.manager;
    app.textureMode(PConstants.NORMAL);
  }
  public void setRenderType(renderType type) {
		this.type = type;
	}
  public void generateMesh() {
	  belongsTo.mesh.noStroke();
	  belongsTo.mesh.noFill();
	  belongsTo.transparentMesh.noStroke();
//	  belongsTo.transparentMesh.noFill();
	  belongsTo.transparentMesh.tint(255);
	  if(type == renderType.BLOCK) {
		  if(!isTransparent) {
			  belongsTo.mesh.tint(225);
	    if (!isFaceAt(position.x, position.y, position.z - 1)) {
	    	belongsTo.mesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	        belongsTo.mesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	        belongsTo.mesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	        belongsTo.mesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    belongsTo.mesh.tint(225);
	    if (!isFaceAt(position.x + 1, position.y, position.z)) {
	    	belongsTo.mesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.mesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    belongsTo.mesh.tint(200);
	    if (!isFaceAt(position.x, position.y, position.z + 1)) {
	    	belongsTo.mesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.mesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    belongsTo.mesh.tint(210);
	    if (!isFaceAt(position.x - 1, position.y, position.z)) {
	    	belongsTo.mesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.mesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.mesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    belongsTo.mesh.tint(175);
		   if (!isFaceAt(position.x, position.y + 1, position.z)) {
			   belongsTo.mesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.BOTTOM).minX, manager.getTextureIndex(textures.BOTTOM).minY);
			   belongsTo.mesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.BOTTOM).maxX, manager.getTextureIndex(textures.BOTTOM).minY);
			   belongsTo.mesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.BOTTOM).maxX, manager.getTextureIndex(textures.BOTTOM).maxY);
			   belongsTo.mesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.BOTTOM).minX, manager.getTextureIndex(textures.BOTTOM).maxY);
		   }
			  belongsTo.mesh.tint(255);
	    if(name == "GrassBlock") {
	    belongsTo.mesh.tint(130, 250, 90);
	    }
		    if (!isFaceAt(position.x, position.y - 1, position.z)) {
		    	belongsTo.mesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).minY);
		    	belongsTo.mesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).minY);
		    	belongsTo.mesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).maxY);
		    	belongsTo.mesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).maxY);
		    }
			   belongsTo.mesh.tint(255);
		  } else {
			  if(name == "Leaves") {
			    	belongsTo.transparentMesh.tint(72, 181, 24);
			    }
			    if (!isFaceAt(position.x, position.y, position.z - 1)) {
			    	belongsTo.transparentMesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
			        belongsTo.transparentMesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
			        belongsTo.transparentMesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
			        belongsTo.transparentMesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
			    }
			    belongsTo.transparentMesh.tint(255);
			    if(name == "Leaves") {
			    	belongsTo.transparentMesh.tint(72, 181, 24);
			    }
			    if (!isFaceAt(position.x + 1, position.y, position.z)) {
			    	belongsTo.transparentMesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
			    	belongsTo.transparentMesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
			    }
			    belongsTo.transparentMesh.tint(255);
			    if(name == "Leaves") {
			    	belongsTo.transparentMesh.tint(72, 181, 24);
			    }
			    if (!isFaceAt(position.x, position.y, position.z + 1)) {
			    	belongsTo.transparentMesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
			    	belongsTo.transparentMesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
			    }
			    belongsTo.transparentMesh.tint(255);
			    if(name == "Leaves") {
			    	belongsTo.transparentMesh.tint(72, 181, 24);
			    }
			    if (!isFaceAt(position.x - 1, position.y, position.z)) {
			    	belongsTo.transparentMesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
			    	belongsTo.transparentMesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
			    	belongsTo.transparentMesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
			    }
			    belongsTo.transparentMesh.tint(255);
			    if(name == "GrassBlock") {
			    belongsTo.transparentMesh.tint(100, 255, 100);
			    } else if(name == "Leaves") {
			    	belongsTo.transparentMesh.tint(72, 181, 24);
			    }
				    if (!isFaceAt(position.x, position.y - 1, position.z)) {
				    	belongsTo.transparentMesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).minY);
				    	belongsTo.transparentMesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).minY);
				    	belongsTo.transparentMesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).maxY);
				    	belongsTo.transparentMesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).maxY);
				    }
				    if(name == "Leaves") {
				    	belongsTo.transparentMesh.tint(72, 181, 24);
				    }
					   if (!isFaceAt(position.x, position.y + 1, position.z)) {
						   belongsTo.transparentMesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.BOTTOM).minX, manager.getTextureIndex(textures.BOTTOM).minY);
						   belongsTo.transparentMesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.BOTTOM).maxX, manager.getTextureIndex(textures.BOTTOM).minY);
						   belongsTo.transparentMesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.BOTTOM).maxX, manager.getTextureIndex(textures.BOTTOM).maxY);
						   belongsTo.transparentMesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.BOTTOM).minX, manager.getTextureIndex(textures.BOTTOM).maxY);
					   }
						  belongsTo.transparentMesh.tint(255);
		  }
	  } else if(type == renderType.SPRITE) {
		  if(name == "TallGrass") {
			  belongsTo.transparentMesh.tint(100, 255, 100);
		  }
		  belongsTo.transparentMesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.transparentMesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    	
	    	belongsTo.transparentMesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.transparentMesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    	
	    	belongsTo.transparentMesh.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.transparentMesh.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    	
	    	belongsTo.transparentMesh.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	belongsTo.transparentMesh.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	belongsTo.transparentMesh.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
		  }
  }
  public void setPosition(float a, float b, float c) {
	  position = new PVector(a, b, c);
//	  position.add(belongsTo.position);
//	  backPos = new PVector(position.x, position.y, (float) (position.z + 0.5f));
//	  frontPos = new PVector(position.x, position.y, (float) (position.z - 0.5f));
//	  rightPos = new PVector((float) (position.x + 0.5f), position.y, position.z);
//	  leftPos = new PVector((float) (position.x - 0.5f), position.y, position.z);
//	  topPos = new PVector(position.x, (float) (position.y - 0.5f), position.z);
//	  bottomPos = new PVector(position.x, (float) (position.y + 0.5f), position.z);
//	  for(int i = 0; i < vertices.size(); i++) {
//		  vertices.get(i).x += x;
//		  vertices.get(i).y += y;
//		  vertices.get(i).z += z;
//	  }
	  x1 += a * size;
	  y1 += b * size;
	  z1 += c * size;
	  x2 += a * size;
	  y2 += b * size;
	  z2 += c * size;
  }
  public float round3(float x) {
	  float a = Math.round(x);
	  float b = a / size;
	  float c = Math.round(b);
	  float d = c * size;
	  return d;
	}
  public PVector getPixelPosition() {
	return new PVector(position.x*size, position.y*size, position.z*size);  
  }
  public void show() {
	  /*
	    if (!wireframe) {
	      app.noStroke();
	    } else {
	      app.stroke(0);
	      app.noFill();
	      app.noTexture();
	    }
	    if(isTransparent) {
	    	app.tint(255, 200);
	    } else {
	    	app.noTint();
	    }
	    app.beginShape(PConstants.QUADS);
	    if(!wireframe) {
	    app.texture(Minecraft.textureAtlas);
	    }
	    // front
	    if (!isFaceAt(position.x, position.y, position.z - 1)) {
	    	app.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	        app.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	        app.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	        app.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    // right
	    if (!isFaceAt(position.x + 1, position.y, position.z)) {
	    	app.vertex(x2, y1, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	app.vertex(x2, y2, z1, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    // back
	    if (!isFaceAt(position.x, position.y, position.z + 1)) {
	    	app.vertex(x2, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	app.vertex(x2, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    // left
	    if (!isFaceAt(position.x - 1, position.y, position.z)) {
	    	app.vertex(x1, y1, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x1, y1, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).minY);
	    	app.vertex(x1, y2, z1, manager.getTextureIndex(textures.SIDES).maxX, manager.getTextureIndex(textures.SIDES).maxY);
	    	app.vertex(x1, y2, z2, manager.getTextureIndex(textures.SIDES).minX, manager.getTextureIndex(textures.SIDES).maxY);
	    }
	    // top
	    if (!isFaceAt(position.x, position.y - 1, position.z)) {
	    	app.vertex(x1, y1, z2, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).minY);
	    	app.vertex(x2, y1, z2, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).minY);
	    	app.vertex(x2, y1, z1, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).maxY);
	    	app.vertex(x1, y1, z1, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).maxY);
	    }
	    // bottom
	    if (!isFaceAt(position.x, position.y + 1, position.z)) {
	      app.beginShape(PConstants.QUAD);
	    	if(!wireframe) {
	    	app.texture(Minecraft.textureAtlas);
	    	}
	      app.vertex(x1, y2, z1, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).minY);
		  app.vertex(x2, y2, z1, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).minY);
		  app.vertex(x2, y2, z2, manager.getTextureIndex(textures.TOP).maxX, manager.getTextureIndex(textures.TOP).maxY);
		  app.vertex(x1, y2, z2, manager.getTextureIndex(textures.TOP).minX, manager.getTextureIndex(textures.TOP).maxY);
	      app.endShape(PConstants.CLOSE);
		    }
	    app.endShape(PConstants.CLOSE);
	    */
  }
  public boolean isFaceAt(double x, double y, double z) {
		try {
	  if(belongsTo.chunk[(int) x][(int) y][(int) z] != null) {
          if (belongsTo.chunk[(int) x][(int) y][(int) z].isOpaque()) {
	            return true;
	            }
	          if(!isOpaque() && !belongsTo.chunk[(int) x][(int) y][(int) z].isOpaque()) {
	        	  return true;
	          }
	       }
		} catch (Exception e) {
			
		}
	/*
	  PVector pos = new PVector((float) x, (float) y, (float) z);
	  for (int i = 0; i < Chunk.w; i++) {
	    for (int j = 0; j < Chunk.d; j++) {
	      for (int k = 0; k < Chunk.h; k++) {
	    	if(c[i][k][j] != null) {
	          if (c[i][k][j].position.equals(pos) && c[i][k][j].isOpaque()) {
	            return true;
	            }
	          if(!isOpaque() && !c[i][k][j].isOpaque() && c[i][k][j].position.equals(pos)) {
	        	  return true;
	          }
	          if (c[i][k][j].frontPos.equals(pos)) {
		            return true;
		            } else if (c[i][k][j].backPos.equals(pos)) {
			            return true;
		            } else if (c[i][k][j].rightPos.equals(pos)) {
			            return true;
		            } else if (c[i][k][j].leftPos.equals(pos)) {
			            return true;
		            } else if (c[i][k][j].topPos.equals(pos)) {
			            return true;
		            } else if (c[i][k][j].bottomPos.equals(pos)) {
			            return true;
		            }
	    	  }
	        }
	      }
	    }
	    */
	  return false;
	  }
  public boolean isOpaque() {
	  return !isTransparent;
  }
  public boolean isSolid() {
	  return isSolid;
  }
  public MultiTexture getTexture() {
	return textures;  
  }
}

@SNICKRS - were you able to resolve this problem?

I haven’t examined this code closely, but multiple things about the PShape design are not meant to be edited. If you need to edit a PShape, the most reliable procedure is to create a new PShape and copy the contents over, skipping the things you want to delete and adding any extras. There are a number of other approaches as well:

Past related discussions:

Actually, yes. All I had to do was use beginShape() again and all the vertices were cleared. The problem was that the mesh didn’t change because the voxel data that the mesh was based on didn’t change. Fixing that, and a lot of performance/memory issues, it works fine now.

Good to hear.! Yes, wiping the whole vertex list works – and editing vertices without changing the list works. Editing PShape vertices vs drawing immediate mode

…it is only when you want to add or remove a vertex that the PShape design becomes intractable…

1 Like