entropy Posted November 9, 2018 Share Posted November 9, 2018 I have a project where I have a collection of solid particles that I need to test if they intersect. I have a simplified demo of the project here: https://playground.babylonjs.com/#C7K3Q1 The particles themselves will have a box shape (as in the example) and I need to know if they physically overlap. According to the documentation for SPS, particle.intersectsMesh(otherParticle) uses less precise metrics to establish whether meshes intersect. Indeed, in the above playground, a collision is registered (red color) even if the actual meshes do not overlap. So I found the following line in babylon.solidParticle.ts located at https://github.com/BabylonJS/Babylon.js/blob/master/src/Particles/babylon.solidParticle.ts#L173: return this._boundingInfo.intersects(target._boundingInfo, false); In my local version of the script, I tried changing the "false" to "true" to force the more precise collision detection, but that seems to have no effect (I can't demo that in the playground, obviously). Is there a way to force the more precise calculation (even if it's on my local copy of babylon.js)? Or, perhaps there's some better way of achieving this? P.S. I realize this is an expensive CPU operation, but I only need to test for collisions once since the particles are stationary. Quote Link to comment Share on other sites More sharing options...
jerome Posted November 9, 2018 Share Posted November 9, 2018 You did exactly what should be expected when dealing with a mesh. Solid particles actually aren't real meshes because they don't have each a world matrix for memory and performance reasons. When you want to check precise collisions between two meshes (so when you set the parameter precise to true), each mesh bounding box is updated according to its world matrix in order to compute the Bbox rotated axes in the world. This can't be achieved for solid particles not having a world matrix. If you still want to do this, you'll have to : - get the stored rotation matrix of each particle (note : it's a dedicated light implementation, not a real BJS matrix object, just a 9 float array) : https://github.com/BabylonJS/Babylon.js/blob/master/src/Particles/babylon.solidParticle.ts#L96 - rotate manually the Bbox directions according to this matrix, a bit like you would update the Bbox according to some mesh world matrix. Once this done, you may consider the particle Bbox is updated according to the particle rotation, so the direction values are now right : https://github.com/BabylonJS/Babylon.js/blob/master/src/Culling/babylon.boundingInfo.ts#L233 - then apply the precision intersection test This should work. But it's quite a big work to do. Maybe could you consider another simpler approach : - create some nodeTransform objects in order to just compute some maths on them, one per particle to be checked. Apply each one the same rotation than its matching particle. Update its world matrix and its Bbox. https://doc.babylonjs.com/how_to/transformnode - then check precise intersections directly on these nodeTransform Bboxes and apply your wanted behavior to the related particles. In this case, no need for particle intersections within the SPS, the collisions are computed apart in a dedicated logic on pure math objects, a bit like a physics engine works actually. An even simpler approach is to use a real physics engine and to associate each particle to an impostor. This works also quite well. entropy 1 Quote Link to comment Share on other sites More sharing options...
entropy Posted November 9, 2018 Author Share Posted November 9, 2018 Those are some excellent suggestions. I didn't even consider the physics engine approach! I'm slowly but surely learning... Quote Link to comment Share on other sites More sharing options...
entropy Posted November 9, 2018 Author Share Posted November 9, 2018 @jerome One (hopefully quick) question. I think the transform node method is the most promising, but I can't seem to associate a bounding box to a node. E.g., look at lines 33 and following: https://playground.babylonjs.com/#FL6VBL#1 Could you elaborate a bit how to make that association? Quote Link to comment Share on other sites More sharing options...
jerome Posted November 10, 2018 Share Posted November 10, 2018 I can't remember if the transfomNode holds a Bbox or not. If not : - create a transformNode - create an independant BoundingInfo objects besides - each time you rotate the transformNode, get its updated world martix, then update the BoundingInfo by passing it the transformNode world matrix. This will update the Bbox directions. entropy 1 Quote Link to comment Share on other sites More sharing options...
entropy Posted November 11, 2018 Author Share Posted November 11, 2018 @jerome Here's the solution that I employed. Instead of using transformNode, I just used BoundingInfo and directly set its world matrix. Fortunately, the Matrix class has all the functionality needed to generate the necessary information. Here's the PG: https://playground.babylonjs.com/#C7K3Q1#1 Lines 60 through 62 contain the relevant new code. Everything works great...thanks for the help! GameMonetize and jerome 2 Quote Link to comment Share on other sites More sharing options...
jerome Posted November 11, 2018 Share Posted November 11, 2018 glad to hear this my transformNode suggestion was just to avoid you to compute the matrix by your own, but I can see that this is something you're conformtable with 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.