Mesh Picker BVH Improvements
https://github.com/playcanvas/engine/pull/4637 implements ray mesh-intersection. However, for animated scenes, it only refits the bvh when the mesh updates. This will result in the bvh losing quality over time, so it must be rebuilt after a certain number of frames. However, bvh building is currently not efficient enough for this to be seamless. In the future, a more efficient build method for the bvh must be implemented.
- we could also implement a Scene level mesh picking. Somehow, mesh instances / render components or similar, would be marked for picking (by perhaps adding them to some list on a Scene object). You could then raycast against all those using a single call.
- we could extend the return values the picker returns, or at least provide some convenience functions to evaluate those - for example normal and uv coordinates at the intersection point.
There could be multiple approaches to picker. Here are a few needs we found in our projects for pickers we've implemented:
- Filtering: call a raycast, optionally providing filtering function, that would be called for each entity which potentially can be picked (by aabb). Raycast would return first picked entity which was filtered. Using BHV can definitely help by ray traversal from ray origin and first checking for node aabb intersection, then calling filter callback, and only then triangle picking.
- Way to specify what is pickable: a new component - which is actually almost the way we did our pickers in many projects. Except it was a script, which then adds an entity to a picker list, so BHV would be built only with those.
- Multiple indexes - it can be common, when we need to pick things from different lists, which optimizes traversal a lot. There could be a way to define picker lists.
We have one annoying example where the animated model flys around, significantly departing from its point of origin making it near impossible to pick (in its current form).
Currently we pick from the physics engine and use that to select all meshes that the ray found and then fliter them by tags (pickable) we then use a customised version of the colour picker only against those meshes in order to get per pixel accuracy
I'm closing https://github.com/playcanvas/engine/pull/4637 until we have time to address feedback / make it into a final form of API, at which time it can be reopened and worked on.