RE: Particle scripting "MaxLife" on a collision

Date : Mon, 17 Apr 2006 13:26:43 +0100
To : <XSI(at)Softimage.COM>
From : "Andy Nicholas" <andy(at)andynicholas.com>
Subject : RE: Particle scripting "MaxLife" on a collision
Hi Todd,
 
There's no need to rewrite XSI's collision code, you can do it like this:
 
You need to set up two events - a collision event for your grid, and an "Every N Frame" event with the trigger value set to 1 so that it triggers every frame. You also need to add two user parameters for your particles of type Vector3, one called "PrevPos", and another called "PrevVel".
 
You then need to set up your events to point to an external JScript file, and to the appropriate event function below
 

function OnCollide(inParticleCloud, inTriggerParticleIndices, inSimFrame)
{
        var vbarr = new VBArray(inTriggerParticleIndices);
        var triggerParticlesIndexList = vbarr.toArray();
        var num = triggerParticlesIndexList.length;
        var particles = inParticleCloud.Particles;
 
        for(var i=0;i<num;++i)
        {
                var inParticle = particles(triggerParticlesIndexList[i]);
                inParticle.Attributes("HasCollided").value=true;
               
                var newpos = XSIMath.CreateVector3();
                var newvel = XSIMath.CreateVector3();
                var veloffset = XSIMath.CreateVector3();
               
                newpos.copy(inParticle.Attributes("PrevPos").value);
                newvel.copy(inParticle.Attributes("PrevVel").value);
                
                //Carry on ignoring the collision
                veloffset.Scale(1/29.997, newvel);
               
                newpos.AddInPlace(veloffset);
                inParticle.Position=newpos;
                inParticle.Velocity=newvel;
 
                //Make the particle live longer
                inParticle.AgeLimit *=5;
               
        }
}
 

function OnEveryFrame(inParticleCloud, inTriggerParticleIndices, inSimFrame)
{       
        var particles = inParticleCloud.Particles;
        var num = particles.count;
        for(var i=0;i<num;++i)
        {
                var inParticle = particles(i);
               
                var newpos = XSIMath.CreateVector3();
                var newvel = XSIMath.CreateVector3();
               
                newpos.copy(inParticle.Position);
                newvel.copy(inParticle.Velocity);
               
                inParticle.Attributes("PrevPos").value=newpos;
                inParticle.Attributes("PrevVel").value=newvel;
        }
}
 
 
The events just store the previous position and velocity, then restore it appropriately upon a collision so that it looks like the particle never collided. BTW I've hard coded the frame rate as 29.997, so you'll maybe need to change that. I can send you an example scene if you like.
 
Andy
 


From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Todd Lawrimore
Sent: 12 April 2006 23:38
To: XSI(at)Softimage.COM
Subject: Particle scripting "MaxLife" on a collision

I’ve got a particle cloud in which the particles have a life of 3 seconds.  I need some of those particles (those that collide with a grid) to continue living much longer.

Seems simple but I can’t get the particles to stop sticking or bouncing off the collision grid.

 

I’m using “per Trigger Particle” with the following lines:

 

inParticle.Size = 1   ‘no problem with this line

inParticle.Life = 10   ‘ “doesn’t support property or method”

 

What’s the correct phrase for setting the Max Life and how do I get the particles to continue along their path without sticking or bouncing?

 

Thanks in advance.

-Todd


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.