Scene.pick and rendering groups

I’d like scene.pick to return higher render layers before lower render layers.

For example in this PG:

https://playground.babylonjs.com/#SPISSS

I’d like scene.pick to return sphere2 (rendering group 1) instead of sphere1 when clicking on sphere2.

Do I need to do separate picks for each render layer to achieve this?

Hmm, maybe multiPick and sort by renderGroup & distance from camera ? :thinking:
Edit
Never used multiPick, looks like it just picks sphere1 multiple times, or rather picks multiple times at same distance

The picker will use only geometrical data and thus completely ignore the layers.
I think @aWeirdo idea is probably the best here. With multiPick you should be able to get all meshes and then be able to sort by renderingGroupId

I used the idea that @aWeirdo provided in this playground:

https://playground.babylonjs.com/#SPISSS#2

Hope it goes in the right direction and can help you :blush:

1 Like

The solution / hack a came up with was overriding scene._internalPick.

https://playground.babylonjs.com/#SPISSS#3

2 Likes