Is there any way to debug scene pick performance?

Hello everyone! It is your friendly neighborhood optimizer here :slight_smile:

Just a short question about scene.pick. I have a Diablo style game movement where you hold your mouse button and and then I just do a scene pick once in a render loop. I noticed it takes a good chunk of the frame budget and wondered if I could actually see some debug data on the matter (and do something about it). If I understood correctly, the scene.pick goes through all the meshes I have in the scene that are pickable? Is there a way to see which ones are affected or where the performance bottleneck might be? :thinking: I do have fastCheck also enabled.

Most of your budget is eaten by the intersectTriangles which means the system is picking against the geometry so you do not have fastcheck active (fastCheck only checks against bounding boxes)

If you need to pick against geometry I would recommend to have a really simplified version of each mesh attached to the real mesh (and set the real mesh as non pickable so you can only pick the impostor)

4 Likes

Hmmm I had fastcheck as fourth parameter set as true, but I guess it should not have worked properly if it just checks bounding boxes…

Anyway, what you said game me an idea… I have quite many objects in my scene that are pickable, but for the game movement I would only need the room meshes to be pickable! So! I realized I could have different kinds of picks for different purposed with the predicate function :slight_smile: So I don’t have to check every single mesh at least!

const pickinfo: Nullable<PickingInfo> = scene.pick(
  x,
  y,
  (mesh: AbstractMesh) => mesh.name?.includes('room')
)

Other thing I was thinking of maybe doing some manual caching to the pick result vector 3 for couple of milliseconds so you wouldn’t call scene.pick every frame… Not sure what is the best way to see the “how much time since last picked” :thinking:

Hi there @Panuchka just checking in, do you have any more questions? :slightly_smiling_face:

1 Like

Not really on this subject, thank you for asking though! :sunglasses: The solution to the problem I had is a bit of everything;

  • I had a lot of floor/wall tiles that needed to be checked => I now merge all my map floors/walls to a single mesh to speed up everything
  • I have a custom ground position checker where I cache the scene.pick result for few milliseconds so it doesn’t trigger on every frame => more speed.
  • Check that I only try to collide against the map mesh and not other assets, with the predicate function the scene.pick can be provided with.
2 Likes