split method
Implementation
void split(int level){
List<Octree> _subTrees = [];
Vector3 halfsize = _v2.copy(box.max).sub(box.min).multiplyScalar(0.5);
for (int x = 0; x < 2; x ++ ) {
for (int y = 0; y < 2; y ++ ) {
for (int z = 0; z < 2; z ++ ) {
Box3 _box = Box3();
final Vector3 v = _v1.set(x.toDouble(), y.toDouble(), z.toDouble());
_box.min.copy(box.min).add(v.multiply(halfsize));
_box.max.copy(_box.min).add(halfsize);
_subTrees.add(Octree(_box));
}
}
}
while(triangles.isNotEmpty){
Triangle triangle = triangles.removeLast();
for (int i = 0; i < _subTrees.length; i ++ ) {
if(_subTrees[i].box.intersectsTriangle(triangle)){
_subTrees[i].triangles.add(triangle);
}
}
};
for (int i = 0; i < _subTrees.length; i ++ ) {
int len = _subTrees[i].triangles.length;
if (len > 8 && level < 16) {
_subTrees[ i ].split( level + 1 );
}
if ( len != 0 ) {
subTrees.add( _subTrees[ i ] );
}
}
}