Create a per particle expression
To give you a taste of what's to come, this expression involves essential programming concepts including a MEL command mag() and variables of types vector and float. These will be explained in detail in Chapter 12. The double slashes, //, indicate a comment—code that will be ignored by Maya.
The MEL command mag() calculates the magnitude of a vector.
- Select the particle object and open the Attribute Editor.
- Locate rgbPP, under the heading, Per Particle (Array) Attributes.
- RMB+click in the field next to rgbPP and select Runtime Expression After Dynamics.
- Type the following in the Expression field:
- Query the force PP attribute, vector $force / particleShapel.force; //A number to scale the magnitude of the force: float $thresholdScale = 300;
- mag() returns the scalar magnitude of a vector. /loat $mag = mag($force)/$thresholdScale; //Set the rgbPP value, p articleShapel.rgbPP / << $mag, 0, 0>>;
The magnitude of the Turbulence field fluctuates but remains under 100. For the most part, particles are dark red to black. When the total force acting on a particle exceeds 300 Maya force units in magnitude, due to a close encounter with the radial field, it turns bright red. This is a quick and easy way to report visually on inter-particle encounters. When working with a rigid body simulation, you can use the rigid solver node to report on true collisions between bodies.
5. Press the Create button.
If you get a red-highlighted error message in the Command Feedback field at the bottom of the main window, check that you entered the expression script exactly as it appears above, and press Create again.
Play the simulation a few times and observe the particles' behavior. After some trial and error, we set the radial field's Attenuate attribute to 0.5. This makes the force between particle stronger at Max Distance, resulting in more pronounced color changes to report the collisions. Figure 07.17 is a screen capture from the simulation.

FIGURE 07.17
Linking the rgbPP attribute to the per particle force attribute allows us to visualize colliding particles by changing their color from black to red. This technique is most effective when viewed in motion. We have included a Playblast movie of this simulation in the directory for this chapter on the book's CD-ROM.
FIGURE 07.17
Linking the rgbPP attribute to the per particle force attribute allows us to visualize colliding particles by changing their color from black to red. This technique is most effective when viewed in motion. We have included a Playblast movie of this simulation in the directory for this chapter on the book's CD-ROM.
Save the current file for use in the next tutorial, in which you will create a rough-quality animation to watch in a movie player. You'll find the complete scene file on the CD-ROM:
07_Dynamics/scenes/tutorial_07_02_done.ma rgbPP for Software render types
The per particle attribute rgbPP works for hardware render type, but not for software render type particles. For software-rendered particles, as special node called the Particle Sampler Info Node allows you to alter the color of a material, using rgbPP as an input. With the material assigned to the particle group, the color-change effect works in a software rendering.
^ Using the Particle Sampler Info Node for per particle colors
Help ^ Maya Help ^ Using Maya ^ General ^ Tools, Menus, and Nodes ^ Nodes ^ Particle nodes ^ Particle Sampler Info Node
Post a comment