Flood fill algorithm implemented for 3D