chicagobob123 Posted June 21, 2016 Share Posted June 21, 2016 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 alert(pickResult.pickedMesh.name); else { // 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.. }; Quote Link to comment Share on other sites More sharing options...
jerome Posted June 21, 2016 Share Posted June 21, 2016 ground.isPickable = false; Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted June 21, 2016 Author Share Posted June 21, 2016 Jerome, that fixes the ground but how do I know which particle system I hit? I have 3 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 21, 2016 Share Posted June 21, 2016 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 http://doc.babylonjs.com/classes/2.4/PickingInfo chicagobob123 1 Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted June 22, 2016 Author Share Posted June 22, 2016 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}); LotContainers.addShape(ContainerModel,ContainerData.length); var m1=LotContainers.buildMesh(); m1.material=ContainerModel.material; ContainerModel.dispose(); When I dispose it the Mesh and material is automatically take care of? LotContainers.dispose(); LotContainers = null; The mesh and material are released as well? Just want to avoid making a leak; Quote Link to comment Share on other sites More sharing options...
jerome Posted June 22, 2016 Share Posted June 22, 2016 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 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.