Jump to content

Prevent picking on Meshes behind other Meshes


Recommended Posts

As you can see in this playground http://www.babylonjs-playground.com/#HKEPK#1

If i put a mesh with an actionManager behind a particle generated using a Solid Particle System i can click on the meshes behind. (There's a sphere behind the panel and it's pickable, if you move the mouse on the panel you will trigger the spere's actions)

Is this intended? Is there some way to prevent it?


EDIT: I have realized it's not just SPS but any mesh will let you pick meshes behind, how do you prevent this?

Link to comment
Share on other sites

This is embarassing but...

For performance reasons i have turned my scene into an SPS (which was composed of 900 cubes, now it runs smoothly!) , each with a pickable panel on top so that they use the same actionManager as the cubes used to have. I didn't realize it was possible to pick meshes behind unpickable meshes because in my previous scene the whole cube was pickable so i couldn't pick cubes behind it.

Anyways, i see i don't just have to set the SPS as pickable but i have to set an action through scene.onPointerDown to prevent picking meshes behind http://www.babylonjs-playground.com/#HKEPK#2

Oh by the way i have noticed an error in the SPS documentation, in the example code for picking a particle the variable is "meshFaceId" on a line and "faceId" on the line after https://doc.babylonjs.com/overviews/Solid_Particle_System

So the question now is....What's the easiest way to prevent picking meshes behind a mesh (for example if there's an object behind a door)?

Link to comment
Share on other sites

2 hours ago, adam said:

One thing you could do is not dispose the cubes, but set their visibility to 0 and then whenever you update the position/rotation of an SPS cube, do the same for the corresponding invisible cube.


Wouldn't this affect performance even though they are not rendered?

If i set an SPS as Pickable (without actions) and use scene.constantlyUpdateMeshUnderPointer = true; something weird happens: the mesh behind is picked only on certain points (like just slightly below the top edge of the square)


Link to comment
Share on other sites

if your SPS doesn't need to be updated each frame (say, the particle positions, rotations, colors, etc don't change), no need for calling setParticles() each time in the render loop.

Maybe didn't you also force the SPS bounding box to be recomputed at least once after adding the particles (what are all at the local origin when the SPS mesh is built) ? This may have significant effects on the pickability behavior or pickability area

Please have a read at this explanation : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility

The simplest way is to call once refreshVisibleSize() after the first call to setParticles()

This should solve most of your SPS pickability issues

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...