I am working at dynamic voxel engine in Unity (something like Space Engineers) where player can create object from voxels, push them, damage and split in to other object.
I store all data in 3D array, 1 mean voxel, 0 mean empty node.
So I looking for solution to break object (array). For example when I remove enough voxels object should split in to two.
00000000 00000 0000 01110110 ====> 01110 0110 01110110 01110 0110 00000000 00000 0000
In 2D example it should split like that.
I try to use BFS search but it not fast enough ;(. It works fine for small grids like 5x5x5, when I creat 5x5x50 grid it works few seconds before break arrays.
My algorithm: 1) First find empty node 2) When you find empty node start BFS from that node, collect all not empty nodes, when you cant find not empty node finish.
If break exist it will collect only one part of array so it find break, if there is no break it will return whole array.
The problem is speed of it ;/ How to make it faster?