This fixes the top-level BVH implementation and enables it during rendering. A couple of additional notes:
I'm not sure about having a global polygon array. Why not have this be part of the mesh? After all, each mesh owns its polygon array, so having global data there is strange.
If the remark above is taken care of, then callbacks in the BVH can be simplified by having their user data being the scene for the top-level, and a mesh for the bottom level.
You can strip the meshIndex and polyIndex out of the poly structure. Just add a meshIndex to the hitRecord and let the BVH set it when it iterates over the meshes contained in a top-level leaf. The same can be said for the bottom-level leaves and the polyIndex member.
This fixes the top-level BVH implementation and enables it during rendering. A couple of additional notes:
meshIndex
andpolyIndex
out of thepoly
structure. Just add ameshIndex
to thehitRecord
and let the BVH set it when it iterates over the meshes contained in a top-level leaf. The same can be said for the bottom-level leaves and thepolyIndex
member.