Skip Valid Mesh Evaluation for Scene.PickWithRay?

My understanding of how the pick with ray might be off so correct me if I am wrong.

But I am under the impression before the picking predicate is ran, that a “valid” meshes array is built that the picking predicate has those entries looped through it?

Or is it that the predicate is what creates the valid meshes array to run the pick against?

I figured it was the first, and so continuing on with that thought is there a way to fire a pick manually against a specific mesh instead of the entire scene? Or a manually array of valid meshes? I have a specific setup where I know the exact mesh that needs to have the ray ran against and currently I’m using the predicate to filter, but feel like that is iterating through all active meshes in the scene and I could get more performance if only ran against the specific meshes I need.

1 Like

Your assumption is correct:

Extract:

    for (let meshIndex = 0; meshIndex < scene.meshes.length; meshIndex++) {
        const mesh = scene.meshes[meshIndex];

        if (predicate) {
            if (!predicate(mesh, -1)) {
                continue;
            }
        } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
            continue;
        }

hmmm so if I want to do a “filtered” one then I should copy this method and reshape it to my needs?

1 Like

If I know the exact mesh can I just use this method:

UPDATE
Kinda basically had to just do the chain of scene.pickWithRay but override the InteralPick to use a new array argument for meshes.

And yes it is way way faster in large scenes, where I have specific meshes I want to target.