22 October 2017
So splitting a volume involves:
- Identifying "islands" of voxels in the volume - that is; groups of voxels that are completely surrounded by inactive voxels (blank space)
- Where two or more islands are detected, we split them apart into new Volumes and deactivate the original volume.
In the script, the "islands" are called "splits". The scripts iterates over the volume until it finds an active voxel that isn't already part of a previous split, and then it starts a new split.
It then adds all the active voxels surrounding the first voxel to a queue to check. Then, for each voxel in the queue it will again check for surrounding active voxels and add them to the queue, until there are no more voxels left in the queue. We now have a split that is completely surrounded by inactive voxels (or is at the edge of the volume).
As long as there is an active voxel in the volume, there will always be one split. We only want to actually divide the volume into new ones if there is more than one split. That's the last bit of the script. For each split it copies the entire volume gameobject, and then activates only the voxels that are part of the split.
So yeah, that's a general explanation. The script will split your original volume into as many "islands" as you create when you do whatever it is you're doing to "explode" the volume.