I have a voxel engine that generates a mesh per chunk and now I want my meshes to be 1 mesh, but if I create them as a single mesh I kind of lose the benefit of chunking the data in the first place.

=Here's what i'm currently getting

enter image description here

I need to remove the gaps, any ideas?


You can still generate meshes per chunk, but to ensure the edges line up, you need to access voxels outside the current chunk. So, your chunks need to know about each other. When accessing a voxel in a chunk, have it access the 'world' level to retrieve the voxel. The 'world' level shouldn't care about which chunk a voxel is in. So inside your chunk it would be something like:

//inside chunk class
getVoxelAt(x, y, z)

And the function inside parent world

// inside world class
    chunk = getChunkThatContains(x,y,z)
    chunk.getChunkLocalVoxel(x - chunk.base.x, y - chunk.base.y, z - chunk.base.z)

Where getChunkLocalVoxel takes the local coordinates of the voxel. So it would access whatever data structure you're using to hold chunk data, like an array:

 //inside chunk class
    return voxels[x][y][z];

You're likely getting gaps now because when you come to the edge of a chunk, you assume there's nothing beyond the edge when generating your mesh. So the mesh has gaps.

  • \$\begingroup\$ that sounds about right ... i think its because i give the chunk data to marching cubes "per chunk", I just can't figure out how to have the marching cubes algorithm have access to the entire world without bogging it down, I wonder if i can pass in some sort ref to a "voxel provider" type object and have the world hold the lot and implement that ... hmmmm. \$\endgroup\$ – War Apr 12 '13 at 17:58
  • \$\begingroup\$ You'll still do it per chunk. Each mesh will still be independent from the other. However, they will know about the voxels that surround them, so their meshes will line up to each other. \$\endgroup\$ – MichaelHouse Apr 12 '13 at 18:02
  • \$\begingroup\$ ive been trying to refactor my code so that the chunk parent (of type IBlockContainter) is passed in so when I want to get a block value during setup i simply do parent.Get(x,y,z) and if that falls outside of the current chunk the parent will know and return the block anyway. This is the data i pass in to mcarching cubes. But for some reason since i refactored my marching cubes it's not rendering anything at all. \$\endgroup\$ – War Apr 12 '13 at 19:43
  • \$\begingroup\$ Use the debugger. See where it's going wrong. Not sure what I can do to help, sorry. \$\endgroup\$ – MichaelHouse Apr 12 '13 at 19:51
  • \$\begingroup\$ for some reason GetVal is always returning 0 ... not sure what i did but i definately broke it somehow ... lol i don't think its the mc code at least. \$\endgroup\$ – War Apr 12 '13 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.