Problem with mesh picking

I’ve spent most of today trying to work out why I can’t get the correct mesh pick 100% of the time - here’s a simplified PG which illustrates the problem: https://playground.babylonjs.com/#0AG68Y#10

Open a developer console and try clicking on the sphere - without zooming/reorienting the view, the picked mesh is sometimes blueLine, sometimes redLine and sometimes sphere. Why is this???

cc @Cedric

Hi @rjt,

I don’t know why it was designed this way, but it seems the pointer event only contains one mesh that intersected with the ray (maybe the first one hit by the ray, I don’t know).

To pick all the meshes intersected with the ray, you can use scene.multiPickWithRay:

And you decide the priority of which mesh should be considered as picked.

1 Like

Thanks Slin - I’ll look into this further.

I still don’t understand why the expected behaviour which is ‘pixels associated with object under the tip of the mouse pointer’ doesn’t return the correct object. This is standard in every software library I’ve bumped into in the past 40 yrs of programming.

So as a line is a single pixel and dpi is getting higher and higher single line pixel picking is really hard to click on or ray cast to. For convenience there is a bit of threshold around to ensure and easy interaction.

you can change it as you want like you can see here https://playground.babylonjs.com/#0AG68Y#19

4 Likes

Thanks - the threshold does help, but it still picks the red or blue line inside the sphere when I click in the corresponding position. How do I get the intuitive pick - e.g. the outer mesh (in this case the sphere) gets picked when clicking on the sphere (despite the fact there’s a red or blue line underneath)?

Oh I see yes, we currently use only a rough approximation for the hit point Fix Billboard mode use Position by sebavan · Pull Request #11870 · BabylonJS/Babylon.js · GitHub will make it more precise

2 Likes

Thanks - helps to know where this is headed - I can work round it with the information you’ve given me :slight_smile: