Jump to content

Solid Particle System Collisions?


dbawel
 Share

Recommended Posts

here's a PG example : http://www.babylonjs-playground.com/#10RCC9

There's no physics engine here, just a simple implementation of bouncing against a sphere : resultVelocity = -incomingVelocity + 2 * dot(normal, incomingVelocity) * normal

As you can see, 200 solid particles (boxes) are emitted from some kind of fountain with an initial velocity and fall down to the ground because of the gravity. A slowly moving sphere waves in the air and the particles bounce against its surface. When they hit the sphere, they change slightly their color and are applied some energy loss.

This PG runs also at 60 fps in Chrome here with 5000 boxes ! http://www.babylonjs-playground.com/#10RCC9#1

Link to comment
Share on other sites

(Wingy wears-out a mouse from so much bookmarking)  :)

You guys are pretty close to basic fluid-dynamics, as is Raanan's cloth demo.  hmm.  Jerome, yours is not doing particle-to-particle collision, right?  Particle-to-particle collision (p2pc) would take lots more computing horsepower, I would suspect.  And then... into a tube they go.  :)  Hydraulics Sim version 1.0!  Yeah!  :o

Nice demos, you guys.

Link to comment
Share on other sites

Oimojs is better than my implementation because it checks also collisions between particles (what I don't do, I just check against the sphere) and needs less user code, but the framerate is also a bit lower then. ([EDIT] oimo hardly works here with 5000 boxes)

Really nice demo @adam :), just what @dbawel was asking for in the first post, I suppose

Link to comment
Share on other sites

@jerome -

Outstanding! I wish I had this a week ago, as I'm too far into the projet to switch now. And it appears that @adam may have fixed the bug in Oimo (still testing), so the future is looking bright.

Thanks for all of your hard work, and we'll all be watching to see what you do next.:)

Cheers,

DB

Link to comment
Share on other sites

@Deltakosh unless you prefer this more polished version with no alpha but shadows instead (will work fine as soon as the PR fix is merged) : http://www.babylonjs-playground.com/#2BXZC

1500 solid particles, global bbox (for shadows) computed in the same loop than the particle computations, so extra-fast

 

[EDIT] ooops, didn't notice the first version was already on-line in the BJS site

Link to comment
Share on other sites

  • new SPS optimization feature : boundingSphereOnly (default = false)
    If the SPS is created for computing particle intersections, we can now limit this computation to the particle bounding spheres only, what can usually be enough for tiny animated objects.
var sps = new BABYLON.SolidParticleSystem("sps", scene, {particleIntersection: true, boundingSphereOnly: true});

This increases noticeably the perfs with big numbers of managed particles, as a BoundingBox requires 8 extra iterations per particle (each box vertex).

 

[EDIT] In order to give you an idea about the gain, this former pseudo-fluid-dynamics PG, http://www.babylonjs-playground.com/#1QWKFV#1 , (beware before clicking, this is CPU intensive and can freeze FF) that was running at 60 fps in my Chrome with 10K particles, can now run at 60 fps with 25K particles checking their intersection on their bounding spheres only.

Link to comment
Share on other sites

Pending PR of a new feature related to intersection (fast bounding sphere intersection improved for spherical(-like) particles) :

var sps = new BABYLON.SolidParticleSystem("sps", scene, {particleIntersection: true, boundingSphereOnly: true, bSphereRadiusFactor : 1.0 / Math.sqrt(3.0)};

The new paramater bSphereRadiusFactor allows to modify the bounding sphere radius : the bounding sphere radius is multiplied by this parameter.

Example : with the factor 1 / SQRT(3), a spherical particle will exactly match its bounding sphere.
As sometimes tiny animated objects (solid particles) can be approximated by little spheres, this is really useful to set their bounding spheres close to their own shape and then just use the fast bounding sphere intersection only.

Link to comment
Share on other sites

Hello,

Here is a set of PG examples to understand the differences between the intersection computation modes.

As you may know, mesh or solid particle intersections are computed according to their bounding boxes and bounding spheres. In short, a mesh is inside its bounding box, and its bounding box is inside its bounding sphere, so the sphere is bigger than the box, what is bigger than the mesh.

The intersection rules are those :

1 - if two bounding spheres don't intersect, then the related meshes don't intersect.

2 - Else, if both related bounding boxes don't intersect, then the meshes still don't intersect.

3 - Else, the meshes intersect.

Solid particle intersections work the same way when you enable them in your SPS.

The default mode is then to compute each particle bounding box and check (AABB) intersections between them, whatever the shape of the embedded particle.

example 1 : default mode with a sphere, AABB bounding boxes intersections =>  http://www.babylonjs-playground.com/#29F0EG

Contrary to what you can imagine, this is the most accurate mode to compute the intersections with the SPS. Here, you can notice (in purpose), that the blue particles intersect somewhat cuboid around the red sphere. I chose a sphere intentionally to make it very visible, but you probably wouldn't have noticed this with real solid particles (these are planar and billboarded) and another kind of shape than a sphere. This mode is also the most CPU intensive.

If we don't mind about accuracy but need more performances, we can force the intersection computations on the bounding spheres only and no longer on the bounding boxes :

example 2 : boundingSphereOnly = true  =>  http://www.babylonjs-playground.com/#29F0EG#1

Now the blue particles intersect something spherical around the red sphere. This is its bounding sphere... farther from it, because, remember, the red sphere (mesh) is inside its bounding box, what is inside its bounding sphere.

We would like to tweak this bounding sphere, to make it closer to its embedded mesh since we don't care about the bounding boxes. We can then moderate its radius by some factor. For instance, the bounding sphere, around a sphere with a radius R, has a radius of R * SQRT(3)   I let you discover the maths behind by your own ;). So if we multiply the current bounding sphere radius by 1 / SQRT(3), the bounding sphere will have the same radius than its embedded sphere (mesh).

example 3 : bSphereRadiusFactor = 1 / SQRT(3) => http://www.babylonjs-playground.com/#29F0EG#2

The bounding sphere now exactly matches the red sphere and the blue particles intersect right its surface.

 

We can also play with this factor to produce the inverted result with higher factor values. Here's a small red ball protected from the water drops by an invisible force around it http://www.babylonjs-playground.com/#29F0EG#3

 

Have fun :P

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