AE01   CONTROLLING MAYA PARTICLES INDIVIDUALLY

Introduction:

This method controls the position, radius (and colour if needed) of individual Maya particles.   As well as being a very useful production method, this section serves as a good introduction to particle expressions, for those who have not tried this type code writing before.   If you need a general introduction to MEL expressions then take a look at A06 SIMPLE EXPRESSIONS in the LEARNING and PRACTICING ANIMATION section.

The Thing Why Control Particles Individually?

“Blobby Surface” is a software method of rendering Maya particles that look exactly like a blobby surface.   It renders each particle as a solid sphere but where two or more spheres converge, they actually join up with an element of viscosity and any inner converging surfaces disappear.   You can build interesting entities with this “meta ball” type surface which are difficult to implement using any other method.   Using MAYA particles in “Blobby Surface” mode you can build fatty deposits on meat, gooey stuff like snot, bread dough, forming icicles, snow deposits and many other entities.   Although these examples could be fabricated in a number of conventional ways, the movement of these “blobby surface” particles is difficult when your limited to just dynamic fields or deformers.   It is useful to gain control of individual particles so that you can choreograph the shape and movement of a “Blobby surface” precisely.

How It Works

Each Maya particle has a unique identity number in the form of an integer which can be extracted and used to identify an associated controlling locator which has the same integer as part of it's name.   You don't necessarily need to use a locator for this purpose as any object would do, but I have used locators in this example because they take up very little file space.

Setting Up a Practical System

The example described below, uses just 24 particles and 24 locators but you can use as many particles as you can manage.   Make sure, however, that you have as many locators as you have particles.   If your not sure, then too many locators are better then too few.
The example generates 24 particles by running the animation from frame 1 to frame 25.   The particle emitter “rate” attribute is keyed at value “1” until frame 26 where it is keyed at value “0”, thus shutting off the particle supply after frame 25.   You can generate more particles by shutting down the emitter later or by key framing a larger amount.   A rate of value “3” over one second should produce 74 particles.
The Expressions

The expressions in this example can handle, in theory, any number of particles.   Also in this example, there is a presumption that radius (and RGB) have to be updated every frame which is why the particle expression is in the ”Runtime after Dynamics” section of the expression editor.   If, for instance, the radius of the particle is fixed through out the sequence, then this part of the expression could be placed in the “Creation” section of the expression editor.   The same could apply to the RGB section.   Position, however, seems to need updating every frame, unless the “Speed” control of the emitter is set to zero.


Downloading the Scene File

I you can't be bothered to build this example scene file described below, then you may purchase it from the download section of this site for a small fee.   The download uses just 24 particles and 24 locators but but you can easily modify the scene file to control far more by duplicating more locators and generating more particles.   The download also includes the scene file used to generate the blobby demo gif sequence used at the start of this section.


Building the Scene File from Scratch

This section describes how to build the scene file to control the position, radius and RGB colour of 24 blobby particles.   After completion you can easily modify the scene file to control far more by duplicating locators and generating more particles.


Building the Particles
To save file space, I usually generate particles I need from a single emitter over the first 25 frames of the sequence.   These first 25 frames of particle generation are discarded in the final render.   In the Maya application in the Dynamics section, from the main menu bar select Particles/Create Emitter.   The emitter type should default to omni but you don't need to worry about what type of emitter it is.   Select particle1 from the Outliner and bring up the Attribute Editor (main menu bar Windows/Attribute Editor...   From the Attribute Editor tabs, select particeShape1 and in the General Control Attributes untick Forces In World (not essential but could help to speed up things).   Scroll down the Attribute Editor until you find the Render Attributes section.   Change Particle Render Type to Blobby Surface (s/w).   Where it says Add Attributes For, press the Current Render Type button.   Keep the Radius to 1.0 but change the Threshold to 0.5.   From Preferences, Timeline (selectable from the small box just below the time line controls) find Playback Speed and select Play every frame.   Press save button in the Preferences box.   Now try playing your animation from frame 1 to around frame 100.   Try rendering frame 100 (or thereabouts) and the result should be a blobby looking clump of particles.   Try different Threshold values.   Examples of different values that I tried are below.   Go to frame 25 of the time line. Select Emitter1 and from the Channel Box key rate to value 25. Got to frame 26 and key the rate to value 0.   When the animation is next run, the emitter will shut down particle generation after 24 particles.   (You may, of course have more, but if your new to this then stick to 24 for now)   From the Attribute Editor tabs, select particeShape1 and scroll down to Per Particle (Array) Attributes.   Just below this section is Add Dynamic Attributes.   Press the General button.   This should open a new window called Add Attribute: particeShape1.   From this window (from the New tab) in Attribute Type, press the Per Partice (Array) radio button.   From this window select the Particle tab and scroll down and select the word radiusPP.   Press the OK at the bottom of the Add Attribute: particeShape1 box.   This new attribute should now appear in the Per Particle (Array) Attributes section of the Attribute Editor.   This new “radiusPP” attribute will enable us to control the radius of individual particles.   Just below this section is Add Dynamic Attributes.   Press the Color button.   From the new window press the Add Per Particle Attribute check box (make sure the other check boxes are NOT checked) and then press Add Attribute.   You should now have a new attribute appear in the Per Particle (Array) Attributes section of the Attribute Editor called rgbPP.   This new attribute will enable us to control the colour of individual particles.

Three Different Threshold Settings

Building the Locators

From the main menu bar select Create/Locator.   Select the new locator and rename to “PL0” (ie pea ell zero and NOT pea ell oh).
From the the main menu select Modify/Add Attribute.   From this window (from the New tab) in Data Type press the Vector radio button.   The Make Attribute Keyable check box should be ticked.   In the Attribute Name text field type in “RGB” and press the OK button at the bottom of the window.
From the the main menu select Edit/Duplicate option box, duplicate this locator using the following Duplicate Options:-
Translate 0.0, 0.0, 0.5
Scale 1.0, 1.05, 1.0
Number of copies 23
You should now have a total of 24 locators all properly named PL followed by a numerical increment.
“PL0” to “PL23”.
Building the Shader Network for the Particles

We need to be able to control the colour of individual particles by using a “Paricle Sampler” utility node.   Use any type of shader you wish for your particles but in this example I will use a simple lambert shader.   From the main menu bar select Window/Rendering Editors/Hypershade and create a new lambert shader.   From the outliner select particle1 and assign the new shader (“lambert2”) to particle1.   From the Hypershade window create a Particle Sampler from the Particle Utilities section under Create Maya Nodes of the Hypershade window.   Connect this new ParticleSamplerInfo1 to the color input of lambert2.
( ParticleSamplerInfo1.outColor to lambert2.color)

Select particle1 from the Outliner and bring up the Attribute Editor (main menu bar Windows/Attribute Editor... From the Attribute Editor tabs, select particeShape1 and scroll down to Per Particle (Array) Attributes.
In the blank text field next to the Position
attribute, mouse right and select Runtime After Dynamics.   When the Expression Editor appears, make sure that the Runtime After Dynamics radio button is selected.   Type, or copy and paste this text into the Expression field and press the Create button.

// Define Locator name ***************************
string $locName = "PL" + particleShape1.particleId;

// Set Position **********************************
vector $tmpPos = `xform -q -t -ws $locName`;
particleShape1.position = $tmpPos;

Now run your animation from frame 1 stopping at any frame after frame 26.   Your perspective geometry window should look something like this.

Positioning the Particles


Particle Expressions Radius
The radius of each particle is set using the Y scale of the controlling locator but you could use the X scale, Y scale or an added variable of your own.   From the Expression Editor, add the following lines to expressions already there.
// Set Radius ************************************
string $locNameSY = $locName + ".sy";
particleShape1.radiusPP = `getAttr $locNameSY`;

Now run your animation from frame 1 stopping at any frame after frame 26.   Your perspective geometry window should look something like this.

Controlling the Radius


Particle Expressions Colour

From the Expression Editor, add the following lines to expressions already there.
// Set Colour ************************************
string $locNameRGB = $locName + ".RGB";
vector $RGB = `getAttr $locNameRGB`;
particleShape1.rgbPP = $RGB;

Now run your animation from frame 1 stopping at any frame after frame 26.   Render the perspective window.
It should look something like the render below.
For this example I loaded the locator RGB attributes as follows:-

PL0 to PL7
R = 0.25
G = 0.25
B = 1.0

PL8 to PL15
R = 0.5
G = 0.5
B = 1.0

PL16 to PL23
R = 0.75
G = 0.75
B = 1.0

Controlling the Colour



Analysing the Expressions

string $locName = "PL" + particleShape1.particleId;

This line takes the text string “PL” and concatenates it with the particle id integer and puts the result into a string variable called $locName (short for locator Name).
For example, for particle 17 it would do the following:-
string $locName = "PL" + “17”;
therefore:-
string $locName = "PL17”;

vector $tmpPos = `xform -q -t -ws $locName`;

This line loads a vector (a variable that stores three floating point numbers) called $tmpPos (short for temporary Position) with the absolute transform coordinates of the locator, by evoking a function called “xform” .   Xform uses the following arguments:-
-q = Query.
This means 'feed back information about an object rather then sending it to the object'.
-t = transform.
This means that we are asking for the transform (positional) coordinates of the object.
-ws = world space.
This means we want the absolute position and not some localised one.
$locName is the object being interrogated. For particle 17 it would be “PL17”

particleShape1.position = $tmpPos;

This line loads the values of the vector $tmpPos into the particle position attribute which also a vector.


string $locNameSY = $locName + ".sy";

This line builds the name of the locator attribute name that we need to extract the Y scale of the locator.   For particle 17 for example:-
string $locNameSY = “PL17” + ".sy";
therefore:-
string $locNameSY = “PL17.sy";

particleShape1.radiusPP = `getAttr $locNameSY`;

This gets the value of the attribute using the function “getAttr” which has a single argument of “PL17.sy" and loads it into the radiusPP attribute of the particle.

string $locNameRGB = $locName + ".RGB";

This line builds the name of the locator attribute name that we need to extract the RGB vector values of the locator.   For particle 17 for example:-
string $locNameRGB = “PL17” + ".RGB";
therefore:-
string $locNameRGB = “PL17.RGB";

vector $RGB = `getAttr $locNameRGB`;

This gets the value of the attribute using the function “getAttr” which has a single argument of “PL17.RGB" and loads it into a vector variable called “$RGB”.

particleShape1.rgbPP = $RGB;

This line loads the value of the $RGB vector into the particle rgbPP attribute which also a vector.



The Thing
The demonstration at the beginning of this section is a simple example of what can be achieved by controlling particles in this way.   This scene file, however, uses around 680 instanced NURBS spheres instead of locators, to control the position of the particles.   These spheres were distributed into three group nodes, called “base_grp”, “head_grp” and “stem_grp”.   This allowed the choreography of the sequence to be implemented using the spheres as a rough guide to the animation but they also act as locators for the actual particles.   Up until frame 140, the only animation in this sequence is the scaling, rotating and translating of these three groups apart from a noise function used to randomly disturb the position of the particles.
After frame 140, the expressions that control the particles are shut down using an “if (frame > 141)” thus releasing all the particles to the “forces in the world” which in this case are three fields called gravityField1, radialfield1and uniformField1.   The gravity field applies a constant force on the particles in the minus Y direction, the radial Field is effectively active for one or two fames at around 142 to blow the particles apart and the uniform Field helps prevent the particles from falling through the floor should the collision plane fail.


This site and all the learning materials are the copyright of Henry Lutman.   The sole purpose of the site and downloads are to aid the teaching of 3D Computer Animation and related topics.   Please do not reproduce any of the content of this site, or any of the downloads for purposes other than to use as a guide to learning, without the written permission of Henry Lutman.
Web Site Author: Henry Lutman.     Web Site Editor: Martin Capey
Lutman Animation Copyright Henry Lutman