I'm not ready to actually implement this but it's been on my mind so I figured I'd share it. Maybe I'm missing an easy option. Also please excuse the long and rambliness of this post; I'm brainstorming this as I write it.
What I want to be able to do is to strip away layers of voxels to expose the gooey innards of a solid region i.e. take a cross section along a cardinal direction. The problem isn't that this is a particularly difficult operation (although library support for setting the material for a whole region at once would be welcome).
The problem is with mesh generation and generally with performance.
Removing entire layers of voxels and re-meshing the entire landscape is too slow.
If there is no voxel/no-voxel boundary then no mesh vertices are generated so I can't generate meshes for each level and show/hide them as I move cross section. I could generate meshes for each level as I built the volume from the ground up but that's only a partial solution because once I start making updates to the inner voxels the pre-build meshes will go stale.
I could solve this by making a customized version of the mesh generator that generates vertices either on voxel/no-voxel boundary or the edge of the given region but I think that would probably introduce new problems, like unwanted vertices that aren't on the cross section since I won't be updating the whole layer all at once (see
ManualRegion::sectionVolume)
I could remove all the voxels in the layer above, re-generate the mesh then put them back. This might actually work if I'm only working in small-ish regions
I could arrange the volume so that I alternate a real layer with an empty layer but that is waay ugly and I think it would cause more problems than it's worth considering cases like vertical shafts through the volume ugh no. Not to mention the coordinate hell that would be introduced across the board.
OK so the solution that I have is:
1) Divide the volume into regions that are 1 voxel thick in the direction we will be taking the section along and of reasonable size in the other two dimensions (see ManualRegion code)
2) When generating or re-generating the meshes fake out the mesh generator by removing the voxels in the layer above the region we are generating.
3) Show/hide the meshes as we as move the section through the volume.
Does anyone have any thoughts about this, did I miss any issues, is there an easier way?
Cheers,
Charlie