Shattering an object with particles

The new xpShatter object in X-Particles can be used to break an object apart when it collides with another object. using the xpCollider tag on that object. This is explained in the manual for the Shatter object, but what if you want to break an object by firing particles at it? This is a slightly more complex process and the purpose of this article is to show how it is done and explain why the various steps are necessary.

Let's start with a simple setup: a Cube with 5 segments on each axis being broken by a Shatter object. We want to fire particles at the cube so that it breaks when hit. The object manager might look like this:

And the setup inside the Shatter object would be like this:

An emitter ('Shatter_Emitter') has been assigned to the Shatter object. This will put particles in each shard so that the shards will move with those particles when the object breaks. The other emitter ('Breaking_Emitter') is the one which fires particles at the cube. If we play this now, we get this:

As you can see, nothing happens. For this to work the particles from Breaking_Emitter must collide with something, but we can't use the xpCollider tag on the Shatter object to do that: all that will happen then is that the particles bounce off the cube.

Using the xpDynamics tag

To make this work the breaking particles must collide with other particles on the cube. The Shatter_Emitter can't provide those, since only one particle is emitted from that emitter until the cube breaks, and then one particle is assigned to each shard. So we need another source of particles and we can get these from an xpDynamics tag.

With an xpDynamics tag attached to the Shatter object, and all values in the tag at their defaults (apart from the Radius value in the tag, which is set to 10 units) a particle is emitted at each vertex on the cube. Now if we play it, the result is this:

Now we can see the particles from the tag being emitted at each vertex of the cube, but there is still no shattering. This is because so far there are no collisions between the breaking particles and the dynamic particles. To add those, we have three choices:

  1. Use a FluidPBD object
  2. Use a Particle-Particle Collisions object
  3. Use a Constraint object with collision constraints enabled

Using FluidPBD for collisions

The use of a FluidPBD object might seem strange at first, but what this object does is to keep particles separate from one another - it has to, to simulate incompressible fluid. This acts like a collision system, forcing particles apart if they get too close together. If we add a FluidPBD object, all we need to do is set its parameter 'Treat Collision As' to 'Different Emitter'. This will detect collisions between particles from different emitters. Now we get this:

Now we are shattering the cube. But this isn't perfect yet. For one thing, the shards fly apart with some force and for another, take a close look at the edges of the shards - they are very irregular and oddly-shaped. This is because when using a fluids engine there simply aren't enough particles on the cube as they are restricted to the vertices. For better results, we need to change the 'Distribution' setting in the xpDynamics tag to 'Volume'. Now we have particles distributed throughout the volume and the result looks like this:

That is much smoother and more controllable. To make the shards fly apart faster, you can turn on 'Push' in the xpDynamics tag and adjust as desired. Or, you can increase the number of particles from the breaking emitter - this will give more collisions with the shard particles and make them move faster.

Using the Particle-Particle Collisions object

The second way to generate collisions is to use the Particle-Particle Collisions (PPC) object. If we reset the particle distribution to 'Vertices' and delete the FluidPBD object, we can add a PPC object to the scene. Then we see this:

Now the cube is breaking up before the collisions even take place! This is because 'Self Collisions' are turned on by default in the PPC object, so the particles from the xpDynamics tag are colliding with one another. We need to turn that off. With that done, the object will break on collision but the shards move very slowly, as the movement relies on collision between the breaking particles and the single particle generated by the Shatter object in each shard. If we increase the number of breaking particles (and make them smaller to make it easier to see what is happening) we get this:

This works but you can see a significant problem: the shards don't collide with one another because we had to turn self-collisions off in the PPC object. Worse, they interpenetrate. There is no way around this, so if this is a problem, do not use the PPC object to generate the collisions. In some circumstances it will not matter so you can use the PPC object if it meets your needs.

Using the Constraints object

The third method is to use the Constraints object. In that object's Collisions tab, turn on the 'Collisions' switch. Then the scene looks like this:

In many ways that is the best result of the three, but this is for a very simple scene; for other scenes one of the other methods may be better. The disadvantage of using the Constraints object is that we have to leave the 'Same Emitter' switch turned on to ensure the shards collide with each other and don't interpenetrate, so you may see collisions occurring between the particles from the breaking emitter as well.

Summary

This article has demonstrated how to break objects using a combination of the xpShatter object, the xpDynamics tag, and some way to generate particle-particle collisions. Using one of these methods you can fire particles at objects and break them up easily.