BVH::BVH(Shape** shapes, int num_shapes) { if (num_shapes == 1) {*this = BVH(shapes[0], shapes[0]);} else if (num_shapes == 2) {*this = BVH(shapes[0], shapes[1]);} //find midpoint of bbox to use as qsplit pivot bbox = shapes[0] -> boundingBox(0.0f, 0.0f); for (int i = 1; i < num_shapes; i++) { bbox = surround(bbox, shapes[i] -> boundingBox(0.0f, 0.0f)); } Vector3 pivot = (bbox.max() + bbox.min()) / 2.0f; int midpt = QSplit::qsplit(shapes, num_shapes, pivot.x(), 0); //create new bounding volume left = buildBranch(shapes, midpt, 1); right = buildBranch(&shapes[midpt], num_shapes - midpt, 1); }
void SceneData::refreshBVH() { BVHItems objectItems; for ( koi::RenderablePtr object : m_renderables ) { const Bounds3f &bounds = object->getWorldBounds(); objectItems.push_back( BVHItem( bounds ) ); } m_bvh = BVH( objectItems ); }