engine icon indicating copy to clipboard operation
engine copied to clipboard

Mesh Picker BVH Improvements

Open sri-30 opened this issue 3 years ago • 4 comments

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.

sri-30 avatar Sep 16 '22 13:09 sri-30

  • 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.

mvaligursky avatar Sep 16 '22 15:09 mvaligursky

There could be multiple approaches to picker. Here are a few needs we found in our projects for pickers we've implemented:

  1. 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.
  2. 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.
  3. 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.

Maksims avatar Sep 16 '22 22:09 Maksims

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).

MAG-AdrianMeredith avatar Sep 20 '22 15:09 MAG-AdrianMeredith

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

MAG-AdrianMeredith avatar Sep 20 '22 15:09 MAG-AdrianMeredith

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.

mvaligursky avatar Jul 25 '23 14:07 mvaligursky