First version of octree recursive building function