It seems that Scene.pick checks every mesh in the scene. In my case, this is really inefficient (and gets slow) if you already have a short list of eligible meshes to check.
Is it possible to just pass in your own array of meshes to check for? I’m not sure how to override the default behavior.
I need to get the position of the pick, so I’d like to use this method for that.
The predicate function is still checked for every mesh in the scene I believe… so with a lot of meshes, that will still potentially loop through many meshes even though I already know the mesh I need to check.
It just checks whether a mesh is eligible for picking during traversal.
Also, as an alternative to using a predicate, you could create a custom function that traverses all meshes in the scene and updates the isPickable flag based on your custom list of pickable meshes. You would call this function only when your custom pickable list changes.
Then, when you use scene.pick, it will simply traverse all the meshes in the scene and check the isPickable flag, which is cheaper than checking whether the mesh is inside an array.
If you don’t want to traverse the scene meshes at all, then instead of using scene.pick, you could perhaps use Ray class for picking: Babylon.js docs