int brep_build_bvh(struct brep_specific* bs, struct rt_brep_internal* bi) { ON_TextLog tl(stderr); ON_Brep* brep = bs->brep; if (brep == NULL || !brep->IsValid(&tl)) { bu_log("brep is NOT valid"); return -1; } bs->bvh = new BBNode(brep->BoundingBox()); // need to extract faces, and build bounding boxes for each face, // then combine the face BBs back up, combining them together to // better split the hierarchy std::list<SurfaceTree*> surface_trees; ON_BrepFaceArray& faces = brep->m_F; for (int i = 0; i < faces.Count(); i++) { TRACE1("Face: " << i); ON_BrepFace& face = faces[i]; SurfaceTree* st = new SurfaceTree(&face); face.m_face_user.p = st; brep_preprocess_trims(face, st); // add the surface bounding volumes to a list, so we can build // down a hierarchy from the brep bounding volume surface_trees.push_back(st); } brep_bvh_subdivide(bs->bvh, surface_trees); return 0; }