playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.53k stars 1.33k forks source link

Mesh Picker BVH Improvements #4645

Open sri-30 opened 1 year ago

sri-30 commented 1 year ago

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.

mvaligursky commented 1 year ago
Maksims commented 1 year ago

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.
MAG-AdrianMeredith commented 1 year ago

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 commented 1 year ago

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

mvaligursky commented 1 year ago

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.