valepu Posted June 29, 2016 Share Posted June 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
jerome Posted June 29, 2016 Share Posted June 29, 2016 I guess that if your SPS isn't pickable, like any other mesh, (SPS is NOT pickable by default) it's "transparent" in terms of pickability. So the first picked mesh is the one behind the SPS. valepu 1 Quote Link to comment Share on other sites More sharing options...
valepu Posted June 29, 2016 Author Share Posted June 29, 2016 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)? Quote Link to comment Share on other sites More sharing options...
adam Posted June 29, 2016 Share Posted June 29, 2016 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. http://www.babylonjs-playground.com/#HKEPK#3 valepu 1 Quote Link to comment Share on other sites More sharing options...
adam Posted June 29, 2016 Share Posted June 29, 2016 Also note: scene.constantlyUpdateMeshUnderPointer = true; valepu 1 Quote Link to comment Share on other sites More sharing options...
valepu Posted June 29, 2016 Author Share Posted June 29, 2016 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. http://www.babylonjs-playground.com/#HKEPK#3 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) http://www.babylonjs-playground.com/#HKEPK#4 Quote Link to comment Share on other sites More sharing options...
adam Posted June 29, 2016 Share Posted June 29, 2016 26 minutes ago, valepu said: Wouldn't this affect performance even though they are not rendered? It shouldn't be as bad as not using SPS. valepu 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 29, 2016 Share Posted June 29, 2016 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 valepu 1 Quote Link to comment Share on other sites More sharing options...
valepu Posted July 2, 2016 Author Share Posted July 2, 2016 Thanks, I solved by doing this: 1. add scene.constantlyUpdateMeshUnderPointer = true; 2. set the SPS as pickable (even without any action) 3. remove setParticles() from the render loop 4. Call refreshVisibleSize() after setParticles() http://www.babylonjs-playground.com/#HKEPK#5 GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.