Jump to content

3 SolidParticleSystem many of meshes how do I know what I hit?


Recommended Posts

The examples they have online show if you want to know if you hit a particle do this. If you want to know if you hit a mesh do this. 

What if I have 3 SolidParticleSystems and lots of meshes. How do I do that? Seems like I always hit the ground or a mesh but no particles. 


  window.addEventListener("click",function() {
     // We try to pick an object
     var pickResult=scene.pick(scene.pointerX,scene.pointerY);
     // can add code here
     if(pickResult.hit == true)    {

     if(pickResult.pickedMesh.name != 'Ground') // I did not hit the ground

        // Now what? 



In the online example shows this. Problem is I have three particle sytems to choose from. 

scene.onPointerDown = function(evt,pickResult)


 var meshFaceId = pickResult.faceId; // get the mesh picked face

if (meshFaceId == -1) { return; } // return if nothing picked

var idx = SPS.pickedParticles[meshFaceId].idx; // get the picked particle idx from the pickedParticles array

var p = SPS.particles[idx]; // get the picked particle

p.color.r = 1; // turn it red p.color.b = 0; p.color.g = 0; p.velocity.y = -1; // drop it

SPS.setParticles(); // etc..



Link to comment
Share on other sites

Each SPS (if set as pickable) is a mesh (sps.mesh). So this is not different from picking one mesh between some others and identifying it. Please have a look at this : http://doc.babylonjs.com/tutorials/Picking_Collisions

The pickResult object has a property called pickedMesh 


Link to comment
Share on other sites

Thanks a bunch. Without your help and guidance I would not have been able to get where I am with this engine. I am about 85% complete with moving this from its origins in three js. So thank you for being so kind. I hope to be able to return the favor someday. 

I do have a question from something I don't quite understand. When you create a SolidParticleSystem

like this LotContainers=new BABYLON.SolidParticleSystem('ContainerMesh',scene, {isPickable:true});

        var m1=LotContainers.buildMesh();

When I dispose it the Mesh and material is automatically take care of? 


LotContainers = null;

The mesh and material are released as well? Just want to avoid making a leak; 

Link to comment
Share on other sites

Disposing a mesh doesn't dispose its material because the material can be shared by many other meshes. Mesh.dispose() is the way to go to prevent leaks, it takes care about this and about the internal cache updates.

You don't really need to set a material to the initial mesh what is used as the particle model in the SPS, only its geometry (+colors & uvs)  is copied, not its material. So, in your example :

m1.material = someMaterialVariable;

is enough

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