protected void splitMesh( final Mesh mesh, final int sectionStart, final int sectionEnd, final boolean doSort) { _mesh = makeRef(mesh); // Split range in half final int rangeSize = sectionEnd - sectionStart; final int halfRange = rangeSize / 2; // odd number will give +1 to right. // left half: // if half size == 1, create as regular CollisionTree if (halfRange == 1) { // compute section final int section = sectionStart; // create the left child _left = new CollisionTree(_type); _left._primitiveIndices = new int[mesh.getMeshData().getPrimitiveCount(section)]; for (int i = 0; i < _left._primitiveIndices.length; i++) { _left._primitiveIndices[i] = i; } _left._mesh = _mesh; _left.createTree(section, 0, _left._primitiveIndices.length, doSort); } else { // otherwise, make an empty collision tree and call split with new range _left = new CollisionTree(_type); _left.splitMesh(mesh, sectionStart, sectionStart + halfRange, doSort); } // right half: // if rangeSize - half size == 1, create as regular CollisionTree if (rangeSize - halfRange == 1) { // compute section final int section = sectionStart + 1; // create the left child _right = new CollisionTree(_type); _right._primitiveIndices = new int[mesh.getMeshData().getPrimitiveCount(section)]; for (int i = 0; i < _right._primitiveIndices.length; i++) { _right._primitiveIndices[i] = i; } _right._mesh = _mesh; _right.createTree(section, 0, _right._primitiveIndices.length, doSort); } else { // otherwise, make an empty collision tree and call split with new range _right = new CollisionTree(_type); _right.splitMesh(mesh, sectionStart + halfRange, sectionEnd, doSort); } // Ok, now since we technically have no primitives, we need our bounds to be the merging of our // children bounds // instead: _bounds = _left._bounds.clone(_bounds); _bounds.mergeLocal(_right._bounds); _worldBounds = _bounds.clone(_worldBounds); }
/** * Recreate this Collision Tree for the given mesh. * * @param mesh The mesh that this tree should represent. * @param doSort true to sort primitives during creation, false otherwise */ public void construct(final Mesh mesh, final boolean doSort) { _mesh = makeRef(mesh); if (mesh.getMeshData().getSectionCount() == 1) { _primitiveIndices = new int[mesh.getMeshData().getPrimitiveCount(0)]; for (int i = 0; i < _primitiveIndices.length; i++) { _primitiveIndices[i] = i; } createTree(0, 0, _primitiveIndices.length, doSort); } else { // divide up the sections into the tree by adding intermediate nodes as needed. splitMesh(mesh, 0, mesh.getMeshData().getSectionCount(), doSort); } }