Hi guys,
So this is my first post here, let me introduce shortly.
Back in the days I was a very active Flash games developer on Newgrounds with several games on my name like Unreal Flash that can be found here;
http://erik.newgrounds.com/Before I start about what I made, first quick why:
VS
So annoying how in the left Minecraft image stuff just floats.Enough reason to dedicate to much of my spare time to fix this, right?
Here is a quick example of me destroying a voxel building (I borrowed the building from the awesome tool MagicaVoxel)
By clicking it does a raycast into the world and when hitting a voxel it destroys all voxels within a dynamic radius.
I wrote a simple script to convert any mesh into my voxel world, and the converter is flexible in resolution.
Here is one more example of a very complex Pod racer object (I like Star Wars a little too much):
This image explains a little bit what is going on:
So my world consists of voxel groups, each group has a max of 20x20x20 (8000) voxels, one reason why I can’t go larger than this is the limit of the mesh vertex size, and another one is optimizing for physics queries.
Green lines show box colliders that I compress together as much as possible during creation.
Pink circles show where my voxel groups are joint together. I use advanced joints and just the normal physx engine.
Now some info for people that are interested about the concept behind it;
The hardest thing was to detect when an object should be split into multiple objects. On paper this sounds so easy, but making the engine understand this was quite hard to optimize.
How it currently works;
1) I destroy an x amount of voxels in an object.
2) I find the first voxel in my object and do a flood fill over all the neighbors (so for each neighbor I search its neighbors) until it has found all neighbors of the first voxel.
3) I see if the count of the voxels I found is the same size as the total voxel array.
4) Is it the same size? It means I’m still a single object
It’s not the same size? this means that I’m divided into multiple objects, and I push the found array in a new voxel group.
5) Repeat step2 for the rest of the voxels, because it could have split into multiple objects.
After all of this is done;
Each voxel group has a separate array of voxels that are visible, a voxel is visible when it has less than 6 neighbors.
After splitting it loops over all visible voxels and starts creating mesh for all the visible faces, this site was very helpful:
http://wiki.unity3d.com/index.php/ProceduralPrimitivesDuring the same loop I build box colliders. For every voxel it tries to see if a neighbor already has a boxcollider where he could push himself in. I found that creating box colliders on the fly was quite expensive so I use an object pooler that holds a couple of thousand boxcolliders gameobjects that I can swap in and out.
It’s also this loop where I build joints to connect to other voxel groups.
Now of course there is a little bit more to it than that, but this was it in a nutshell. If anyone is interested in more, just ask and I’ll try to reply to all questions.
Also if anyone knows a good application for this, feel more than welcome to reach out, I’m still unsure what type of game to build with this
.