Particle inside a volume and Field Influence checks

Often there’s a need to check whether a particle is inside an object or not and based on that to make something with it (usually kill 🙂 )

We can check the normal of nearest point on mesh, but such a calculation for each particle in each frame becomes very slow with increase of their amount. My friend has written a plugin that returns right away whether a coordinate is inside or outside the volume, but anyway due to slow speed of calculations I often had to avoid this method.

The solution is this – since various volume fields affect a particle when it gets inside their volume, if we can represent the object with a number of such fields and check whether any of them influence a particle, we can find out if it is inside the object. Of course, for difficult forms the result will be inaccurate, but we can create a pack of fields that represent them pretty closely. In any case, that’d be much faster 🙂

So, how do we check whether a field affects a particle. particleShape has an attribute array inputForce[] to which all fields connect (and get computed at once for optimization purposes, that’s what gives us quick results even with a lot of fields used) – if we find out which index our field under consideration is connected to (via hypergraph):

Two volumeAxisFields are connected to inputForce array

Two volumeAxisFields are connected to inputForce array

in particle expression we can read it’s influence on specific particle and kill that particle, if it doesn’t equal to zero:

runtimeBeforeDynamics or runtimeAfterDynamics:

vector $force1 = inputForce[1];
vector $force2 = inputForce[2];
if( `mag $force1` != 0 || `mag $force2` != 0 )
		lifespanPP = 0;

Here’s a simple practical example – crashing to the ground, glass of the car is smashed into debris that collide with this ground and the car itself:

Emitters for glass debris generation

Emitters for glass debris generation

Due to high speed, small distance and emitters being partially inside the object, some of the particles are caught inside and stupidly slide over inner surface, sticking outside through it and slowing the simulation down considerably:

Some debris stay inside the object

Some debris stay inside the object

Let’s connect two volumeAxisFields that roughly represent volume inside the car to kill particles via method described above:

Two volumeAxisFields roughly represent geometry volume

Two volumeAxisFields roughly represent geometry volume

Sticking debris and slow down issues get resolved:

Debris inside the object are killed by volumeAxisFields

Debris inside the object are killed by volumeAxisFields

Example scene is here:

07_ptInVolume_01.mb

4 Responses

Subscribe to comments via RSS

  1. Written by Rastler
    on 29 June 2009 at 11:42
    Permalink

    Прикольная статейка, все очень четко и понятно… 🙂
    Только анимированный GIF лучше наверное на flash заменить…..

  2. Written by Dreamer
    on 11 March 2011 at 20:39
    Permalink

    Очень полезная информация. Спасибо!

  3. Written by sukumar
    on 22 December 2011 at 11:11
    Permalink

    hi thnx for the nice tutorial….. i’m having some problem… when i run the script in expression editor… the particles is emitting fine and at once its died…. its like a flash of particle appearing and gone…. can i know wat may b the reason for this…..

  4. Written by Sagroth
    on 22 December 2011 at 21:49
    Permalink

    Can’t really say anything based on this description. If you send me the scene I’ll try to figure this out.

Subscribe to comments via RSS

Leave a Reply