Jump to content

Solid Particle System rollover on particle event


OXY11
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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)  ...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 years later...

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);
           }
      }
 
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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