I considered adding just one single vertex to the mesh, this does work but feels like a hack; what I'm getting at is, is there a better way to store an empty mesh like this? (the reason I store an empty mesh is because a) users can add blocks there as they please, or blocks could be revealed on a chunk update in which case new block meshes need to be added to fill the void (according to metadata of course).
Or rather, that's what I narrowed down the odd crash to, it could be coincidental as I might be misunderstanding the data but here's the relevant code:
Code: Select all
byte x = 0, y= 0, z = 0;
bool vU,vD,vW,vE,vN,vS;
const int MAX = CHUNKSIZE-1;
const int MIN = 1;
BlockType BT = BT_grass; //Temporary hack, can't be bothered to add a material selection interface at this point
scene::SMesh* mesh = new scene::SMesh();
for(x = MIN; x < MAX; x++)
{
for(y = MIN; y < MAX; y++)
{
for(z = MIN; z < MAX; z++)
{
cm = b_blocks[x][y][z].material;
vU = b_blocks[x][y][z].visUp;
vD = b_blocks[x][y][z].visDown;
vE = b_blocks[x][y][z].visEast;
vW = b_blocks[x][y][z].visWest;
vN = b_blocks[x][y][z].visNorth;
vS = b_blocks[x][y][z].visSouth;
/*
* I'll add these comments to annotate the code, makes it easier to follow the logic
* check current block (within actual block region, excluding border region
* if air, then check surrounding blocks
* else do nothing
* the reason for this is that only blocks next to air (and potentially other nonsolid blocks like glass)
* get rendered and thus anything else doesn't need faces
*/
if( b_blocks[x][x][z].isSolid() )
{
continue;
}
/*
* okay, we've determined that we are an air block
* proceeding to check the surrounding blocks (including the border region)
*/
else
{
if( b_blocks[x+1][y][z].isSolid()
|| b_blocks[x-1][y][z].isSolid()
|| b_blocks[x][y+1][z].isSolid()
|| b_blocks[x][y-1][z].isSolid()
|| b_blocks[x][y][z+1].isSolid()
|| b_blocks[x][y][z-1].isSolid() )
/*
* if we get here then there's a solid block next to us and we should create a mesh
*/
{
createCube(x,y,z,c,mesh,cm, vU, vD, vE, vW, vN, vS);
}
}
}
}
}
/*
* here I attempt to solve the empty mesh issue by checking if there's a mesh
* however even an empty mesh seems to follow through here anyway
* as the else clause I had there never triggered even with chunks specifically
* (hence why said else clause was removed)
* designed to be completely empty.
* it is actually rather strange.
*/
if(mesh)
{
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
mesh->drop();
scaleMesh(anim_mesh, scale);
IMeshSceneNode *Chunk = smgr->addMeshSceneNode(anim_mesh);
Chunk->setPosition(poteto);
Chunk->setReadOnlyMaterials(true);
Chunk->getMesh()->getMeshBuffer(0)->setHardwareMappingHint(scene::EHM_STATIC);
//Chunk->getMesh()->getMeshBuffer(0)->setDirty();
nodes.at(p)=Chunk;
anim_mesh->drop();
}
On that matter, is there an interface for dynamically modifying vertex data in realtime (removing, adding, merging etc) directly from a scene node or does one have to construct a separate mesh buffer, optimize there, delete the mesh from the scene node and then attach the new mesh buffer to the scene node? Or would this be best done in shaders?