OXY11 Posted May 14, 2016 Share Posted May 14, 2016 there's a way to intercept the rollover on a single particle, in addition to the click? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 14, 2016 Share Posted May 14, 2016 what do you mean by "rollover" on a single particle ? NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
OXY11 Posted May 14, 2016 Author Share Posted May 14, 2016 on a Solid Particle System each particle is Pickable, and it is possible to trigger a function when mouse click on them. I need to trigger a function when the mouse rolls over a particle. Is it possible? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 15, 2016 Share Posted May 15, 2016 http://doc.babylonjs.com/tutorials/Picking_Collisions Well, I'm not the specialist in pickability and rays. But the SPS is a simple mesh, so dectecting when the mouse pointer rolls over it is the same process than with any other mesh (just can't retrieve the right PG, @Wingnut might have this in his endless indexed archive somewhere ) I guess the right way is to emit a ray, what actually the function pick() does, permanently and not only on the mouse click event. Not sure it's performance friendly though. So in brief, this would be the same code than for the click event, but not registered to any event and called each frame : var pickResult = scene.pick(x, y); if (pickResult.hit) ... NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
OXY11 Posted May 15, 2016 Author Share Posted May 15, 2016 OK thank you very much But this way I can not know what hit particle, but only if I hit the SPS. Or am I wrong? I would need to read the IDX of the affected particle. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 15, 2016 Share Posted May 15, 2016 yep you can : http://doc.babylonjs.com/overviews/Solid_Particle_System#pickable-particles set the SPS as pickable (isPickable: true) and an array called sps.pickedParticles is then populated for you : each key is the mesh faceId, each array element is an object {idx: particleID, faceId: faceIDInTheParticle} here is a slightly modified example with a rollover : http://www.babylonjs-playground.com/#2FPT1A#68 RyanONeill1970 1 Quote Link to comment Share on other sites More sharing options...
OXY11 Posted May 15, 2016 Author Share Posted May 15, 2016 WOW!!! thanks a lot!! Quote Link to comment Share on other sites More sharing options...
RyanONeill1970 Posted December 1, 2018 Share Posted December 1, 2018 This works really well and it doesn't suffer from CPU or GPU performance as @jerome thought it might. If I was really wary of performance issues (mobile for example) then maybe mouse / touch events could be captured which would flag that the ray should be checked again. For example, surrounding the scene.pick with the following; SPS.setParticles(); pl.position = camera.position; if ( mouseUpdated ) { mouseUpdated = false; var pickResult = scene.pick(scene.pointerX, scene.pointerY); if (pickResult.hit) { rollover(pickResult); } } Quote Link to comment Share on other sites More sharing options...
RyanONeill1970 Posted December 1, 2018 Share Posted December 1, 2018 Actually, I'm wrong, it seems to hit the GPU quite hard so I'll try this with the mouse monitoring flag approach. 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.