I’m currently working on a program for which I need a voxel engine.
No, it is not another Minecraft clone ^^. My program intends to fasten and make it easier to build very large ships made of blocks.
These blocks are arranged in chunks of 16x16x16 size, this structure being arranged itself into a structure of 16x16x16 chunks, arranged into regions.
The problem is that there can be millions of cubes, which could be edited, hundred by hundred at a time, or even more.
It seems the answer is a voxel engine!
I have read many posts about it here on JME forums, but I can’t find how to use vertices, nor how to use them to render faces in JME. Docs are unreachable or outdated :/.
Also, should I go for the biggest faces possible (i.e. removing the most possible vertices from them) or should I keep them (in order to obtain a grid which I can then extrude to add/substract “cubes”)?
Plus, I’ve read the marching cubes algorithm but I don’t see how it fits here?
Maybe for particular blocks (corner, wedge, etc)?
Yes, usually every chunk is a mesh and its structure is saved somewhere else (ie 3dimensional array) then every time the chunk is updated the entire mesh is regenerated.
So there is no reason to keep a grid for extrusion or something.
With marching cube you can create smooth meshes, every voxel has a density like 0 = air 1=matter 0.5=half voxel air/ half matter , but i don’t think this will suit your case.
It’s not java, but you could take a look at Cube2: Sauerbraten http://sauerbraten.org/docs/dev/readme_developer.txt that is an opensource engine/game where the maps are created from an octree of cubes similar of what you’ve described.
And keep mvc in mind, that is:
You have your Blocks you can mass Edit and those are just instances in a 3D array.
For the view you just merge multiple Blocks and hide far away ones and such.
You want big Objects with many vertices and faces but only covering a small Region (so culling works).
There are other means by using some shaders and Tricks instead of the usual Pipeline.
Also see the cubes plugin
A short notice concerning marching cubes:
Usually you don’t go with densities between 0 and 1. Instead you use a level set / signed distance field. Every voxel stores the distance to the surface, positive inside and negative outside (or the other way round). The vertices of the mesh are then generated by interpolation so that they lie exactly on the zero-level / the surface. Using densities leads to discontinuities and undefined situations.
Only this made it possible for me to generate a smooth surface.
with densities between 0 and 1
with a signed distance function