So basically I’m trying to expand upon TaeZ’s sample here. I’ve created a CubeManager class that will be adding/removing the appropriate vertices and faces from the main mesh when I need it to.
Here’s what I’ve got so far:
from meshgenerator import MeshGenerator
class CubeManager():
def __init__(self):
self.cubes = {}
self.mesh = MeshGenerator('blocks')
def addCube(self, x, y, z, blockID):
self.cubes[x][y][z] = blockID
if x-1 not in self.cubes or self.cubes[x-1][y][z] == 0:
self.mesh.makeLeftFace(x, y, z, id)
if x+1 not in self.cubes or self.cubes[x+1][y][z] == 0:
self.mesh.makeRightFace(x, y, z, id)
if y-1 not in self.cubes or self.cubes[x][y-1][z] == 0:
self.mesh.makeBackFace(x, y, z, id)
if y+1 not in self.cubes or self.cubes[x][y+1][z] == 0:
self.mesh.makeFrontFace(x, y, z, id)
if z-1 not in self.cubes or self.cubes[x][y][z-1] == 0:
self.mesh.makeBottomFace(x, y, z, id)
if z+1 not in self.cubes or self.cubes[x][y][z+1] == 0:
self.mesh.makeTopFace(x, y, z, id)
def delCube(self, x, y, z):
self.cubes[x][y][z] = 0
#Code to remove faces
def getGeomNode(self):
return mesh.getGeomNode()
When I run this, I get KeyError: 0 at the line:
self.cubes[x][y][z] = blockID
I have not the slightest clue what this means or how to go about fixing this, so I’m hoping somebody with more experience can help me out. Thanks to anyone who does help!