Initial implementation of bsp-tree algorithm, needs debugging.