Assign image sequences to sprites

 
 
 

We’ve supplied a MEL script (applySprite.mel) in the ExploreMe/particles directory on the Maya DVD to make it easier to assign image sequences to sprites. To use the MEL script, see Sprites.

If you want to assign an image sequence to sprites manually (without using the MEL script), you can use the following procedure.

To assign an image sequence to the sprites

  1. In the menus above the workspace, turn on Shading > Smooth Shade All and Shading > Hardware Texturing.
  2. Select the particle object.
  3. In the Attribute Editor, set Particle Render Type to Sprites.
  4. To add default Particle Render Type attributes that let you tune the appearance, click the Add Attributes For Current Render Type button.
  5. Create a Lambert material with shading group, and assign it to the selected particle object. See Rendering for details.
  6. From the Rendering menu set, select Lighting/Shading > Assign Existing Material to display the Lambert node in the Attribute Editor.
  7. In the Common Material Attributes section of the Attribute Editor, click the map button to the right of the Color slider.
  8. In the Create Render Node window, click the File button to create a texture file node.
  9. In the File Attributes section of the Attribute Editor, click the file browser button to the right of the Image Name box.
  10. Select the first file in the sequence and click Open.
    Important

    The image files you use as sprites must have filename extensions in the format file.n, not file.000n (zero-padded extensions).

  11. In the Interactive Sequence Caching Options section, turn on Use Interactive Sequence Caching.
  12. Specify the Sequence Start, Sequence End, and Sequence Increment.

    These attributes specify the files available for use in the sequence. These attributes do not select the actual cached files. You do this by setting the Sprite Num or spriteNumPP attribute in a later step.

    The Sequence Start and Sequence End specify the filename extension number of the first and last files available for the sequence. The Sequence Increment sets whether each frame is available for the sequence every other frame, every third frame, and so on.

    For example, to use every file of a 30-file sequence starting with Smoke.0, you would set the Sequence Start to 0, the Sequence End to 29, and the Sequence Increment to 1. To use every other file of the same file sequence, you would set Sequence Increment to 2. In other words, you could cycle through Smoke.0, Smoke.2, Smoke.4, and so on.

  13. Turn on Use Image Sequence.
  14. If you want to assign an identical image sequence to all the sprites, do the procedure that follows, Assign an identical image sequence to all sprites If you want to assign a different image sequence to each sprite, do the procedure Assign a different image sequence to each sprite.

Assign an identical image sequence to all sprites

When you added default Particle Render Type attributes for sprites in a prior step, Maya added a Sprite Num attribute to the particle object. Sprite Num sets which files are cycled from the pool of files specified by Sequence Start, Sequence End, and Sequence Increment. More specifically, Sprite Num is an index into the pool of files.

For example, suppose you have a file sequence starting with Smoke.0. If you set the Sequence Start to 0, the Sequence End to 29, and the Sequence Increment to 1, the pool of images and Sprite Num values that represent them are as follows.

Image Sprite Num

Smoke.0

1

Smoke.1

2

Smoke.2

3

Smoke.3

4

Smoke.29

30

If you set the Sequence Start to 0, the Sequence End to 29, and the Sequence Increment to 2, the pool of images and Sprite Num values that represent them are:

Image Sprite Num

Smoke.0

1

Smoke.2

2

Smoke.4

3

Smoke.6

4

Smoke.28

15

You can set keys or write an expression to animate Sprite Num and thereby cycle through the images. All sprites display the same image each frame.

For instance, if the start frame of your scene is frame 0 and you have 30 images named Smoke.0 through Smoke.29, you can use this creation expression:

particleShape1.spriteNum = (frame % 30);

and this runtime expression:

particleShape1.spriteNum = (frame % 30);

As the animation plays, all sprites cycle through the 30 images. At frames 0 through 29, the sprites display Smoke.0, Smoke.1, Smoke.2, and so on through Smoke.29. At frame 30, the cycle repeats for the next 30 frames.

See Expressions for details on writing expressions.

Assign a different image sequence to each sprite

  1. With the particle shape node selected, open the Add Dynamic Attributes section of the Attribute Editor and click the General button.
  2. In the Add Attribute window, click the Particle tab and select spriteNumPP. Click OK.

    This adds the per particle spriteNumPP attribute to the particle shape node. The spriteNumPP attribute works like Sprite Num, but you can set spriteNumPP on a per particle basis. See Assign an identical image sequence to all sprites for details on Sprite Num.

  3. Write creation and runtime expressions to animate the particle shape node’s spriteNumPP attribute. (If the particle object’s transform node is currently selected rather than the shape node, press the down arrow to correct the selection.)

    For example, if the start frame of your scene is frame 0 and you have 30 images Smoke.0 through Smoke.29, you can use this creation expression:

    particleShape1.spriteNumPP = rand(0,30);
    

    and this runtime expression:

    particleShape1.spriteNumPP = (particleShape1.spriteNumPP + 1) % 30;
    

    When you rewind the animation (or the sprite is emitted), the creation expression assigns a random number between 0 and 30 to the particleShape1.spriteNumPP attribute. Each particle therefore starts its sprite display with an image randomly selected from the 30 images.

    When you play the animation, the runtime expression executes each frame (before or after dynamics calculation) and increments each sprite’s number by 1. This makes each sprite cycle through the entire range of images. After Smoke.29 appears for a sprite, the animation cycles through the images again starting at Smoke.0.

    For more information, see the MEL and Expressions guide.