Per particle attributes
Particles share a single particle shape node. As a result, particle object attributes do not distinguish between individual particles. However, there are also per particle attributes which allow you to set a unique value for each particle. A per particle attribute is a single attribute that allows for an entire list (array) of values, one per particle.
Age
In animation expressions, you can use frame and time to retrieve the current frame and time of an animation. In dynamic expressions, you can also use age to retrieve a particle's age, that is the time since the particle's birth.
Below we will create a smoke emitter where the smoke particles grow bigger as they get older, and die at a random age. We will make use of both creation and runtime expressions and also of per particle attributes.
Start by creating a new scene
Smoke emitter
Create an emitter (choose Particles → Create Emitter)
Render Attributes .. Particle Render Type : Cloud
Lifespan Attributes .. Lifespan Mode : lifespanPP only
lifespanPP is a per particle (PP) attribute.
lifespanPP = rand(4,6);
radiusPP = 0;
radiusPP = linstep(0, lifespanPP, age);
Now, start the animation
Fading
We will change the opacity of the particles such that they fade away rather than popping out.
opacityPP = 1;
opacityPP = 1 - smoothstep((lifespanPP * 0.5), lifespanPP, age);
Start the animation in shaded mode
All of these actions, including the creation of the dynamic expressions, can be performed by a script. For your information, this script is included here:
file -f -new;
emitter -name "smokeSource";
// Result: smokeSource //
setAttr smokeSource.emitterType 0; // Directional
setAttr smokeSource.rate 50;
setAttr smokeSource.directionX 0;
setAttr smokeSource.directionY 1;
setAttr smokeSource.directionZ 0;
setAttr smokeSource.spread 0.25;
setAttr smokeSource.speed 2;
particle -name "smokePart";
// Result: smokePart smokePartShape //
connectDynamic -em smokeSource smokePart;
// Result: smokePartShape //
setAttr smokePartShape.particleRenderType 8; // Cloud
setAttr smokePartShape.lifespanMode 3; // lifespanPP only
addAttr -ln radiusPP -dt doubleArray smokePartShape;
addAttr -ln opacityPP -dt doubleArray smokePartShape;
dynExpression -s "lifespanPP = rand(4,6);\nradiusPP = 0;\nopacityPP = 1;" -c smokePartShape;
dynExpression -s "radiusPP = linstep(0, lifespanPP, age);\nopacityPP = 1 - smoothstep((lifespanPP * 0.5), lifespanPP, age);" -r smokePartShape;