/** * Creates a Collision Tree by recursively creating children nodes, splitting the primitives this * node is responsible for in half until the desired primitive count is reached. * * @param start The start index of the primitivesArray, inclusive. * @param end The end index of the primitivesArray, exclusive. * @param doSort True if the primitives should be sorted at each level, false otherwise. */ public void createTree(final int section, final int start, final int end, final boolean doSort) { _section = section; _start = start; _end = end; if (_primitiveIndices == null) { return; } createBounds(); // the bounds at this level should contain all the primitives this level is responsible for. _bounds.computeFromPrimitives( getMesh().getMeshData(), _section, _primitiveIndices, _start, _end); // check to see if we are a leaf, if the number of primitives we reference is less than or equal // to the maximum // defined by the CollisionTreeManager we are done. if (_end - _start + 1 <= CollisionTreeManager.getInstance().getMaxPrimitivesPerLeaf()) { return; } // if doSort is set we need to attempt to optimize the referenced primitives. optimizing the // sorting of the // primitives will help group them spatially in the left/right children better. if (doSort) { sortPrimitives(); } // create the left child if (_left == null) { _left = new CollisionTree(_type); } _left._primitiveIndices = _primitiveIndices; _left._mesh = _mesh; _left.createTree(_section, _start, (_start + _end) / 2, doSort); // create the right child if (_right == null) { _right = new CollisionTree(_type); } _right._primitiveIndices = _primitiveIndices; _right._mesh = _mesh; _right.createTree(_section, (_start + _end) / 2, _end, doSort); }