02 March 2011

Particle Example 4 : Emit Function

There are five different types of emitter.
  • Omni :  Omnidirectional point emitter. particle emits in all directions. 
  • Directional : Directional point emitter. Particles emit in the direction you specify with the Direction X, Y, and Z attributes.
  • SurfaceIt emits particle from randomly distributed positions on or near a NURBS or polygonal surface. When you emit from an object, the emitter is a surface emitter. 
  • Curve : It emits particle from randomly distributed positions on or near a curve.
  • Volume : It emits particle from a closed volume. You pick the shape from the Volume Shape option. Make sure the emitter is bigger than one voxel when you select volume.
 In this tutorial, we will use directional emitter and make primary and secondary particles.

1.  Create new scene. Select Particles - Create Emitter - Option box.
2.  Settings for emitter
     Name : primaryEmitter
     Emitter Type : Directional
     Rate : 100
     Direction : 0, 1, 0
     Spread : 0.25
     Speed : 10

3.  Select particle in the outliner. Change the name to primaryParticles.
     Open the attribute editor - primaryParticlesShape and change the values as below.

     Name : primaryParticles
     Particle Render Type : Spheres
     Radius 0.2
     Lifespan Mode : lifespanPP only














4.  Type the following line in the command line and press Enter.
     It creates an empty particle object.

     particle -n secondaryParticles;

5.  Select the secondaryParticles in the outliner and change as below in the channel box.

     Particle Render Type : Multi-Streak
     Lifespan Mode : lifespanPP only

6.  Select primaryParticles. Select Fields - Gravity.

7.  Right mouse button click the box next to the lifespanPP attribute under primaryParticles.
     Add Runtime expression before dynamics. Because the particles is keep changing its
     position after its birth from emitter. Click Create.

     $pos = position;
     $vel = velocity;
     if ($vel.y < 0)
     {
          lifespanPP = 0;
          emit -object secondaryParticles -position ($pos.x) ($pos.y) ($pos.z)
                  -at velocity -vectorValue ($vel.x) ($vel.y) ($vel.z);
      }

     If the expression worked well, congratulation. When I typed in the expression, I had
         an error message saying "Illegal extension on an expression of type float."
         So I corrected the components of $pos and $vel like below. "position" and "velocity"
         are value of pribaryParticles, it directly access to the position and velocity value.
         If you had same error message like me, try change the components' names.




8.  Set the time range as approximately 500 frames and playback.






















Now, we will change the colour of multi-streak.

9.  Add an rgbPP attribute to secondaryParticles as we did earlier tutorial.
     Attribute Editor - Per Particle (Array) Attribute - select color - add "per particle"

10.  Go to the Runtime expression before dynamics on primaryParticles and add some lines as below.

     $pos = position;
     $vel = velocity;
     $col = sphrand(1);

     if ($vel.y < 0)
     {
          lifespanPP = 0;
          emit -object secondaryParticles -position ($pos.x) ($pos.y) ($pos.z)
                  -at velocity -vectorValue ($vel.x) ($vel.y) ($vel.z)
                  -at rgbPP -vectorValue ($col.x)($col.y)($col.z);
      }
















11. Click Edit and playback the animation.




























Analyze Expression


$pos = position;
$vel = velocity;
$col = sphrand(1); 

  • We have made the two variable called $pos and $vel. Each variable contains the value of position and velocity of primaryParticles. 'pos' and 'vel' are short name of position and velocity attributes. Both are vector types : $pos has vector value of position and $vel has vector value of velocity of particle.

  • In the expression of colour, the sphrand() function has been used. sphrand is short for 'sphere rand'. sphrand function can specify the range of vector / float type return value. The range of return value has form of sphere or oval. The standard form of sphrand function is sphrand<<x,y,z>> but if you use as sphrand(n), sphrand(1) in this example, it convert to sphrand<<1, 1, 1>> automatically. In this example, sphrand() function returns the value of spheres which has the colour information of Red, Green, Blue.


     if ($vel.y < 0) : If primaryParticle's velocity Y value is smaller than 0.
     {
          lifespanPP = 0; : Set the lifespanPP value as 0.
          emit -object secondaryParticles -position ($pos.x) ($pos.y) ($pos.z)
                  -at velocity -vectorValue ($vel.x) ($vel.y) ($vel.z)
                  -at rgbPP -vectorValue ($col.x)($col.y)($col.z);
      }

  •  emit : The emit function can set any attribute for a particle, not just its position. It makes emit from selected particle object.
  • -object secondaryParticles : Select an object
  • -position ($pos.x) ($pos.y) ($pos.z) : emit from secondaryParticles at the position which decided by primaryParticles' position x,y,z. 
  • -at velocity -vectorValue ($vel.x) ($vel.y) ($vel.z) : Select an attribute of velocity. Get values of the primaryParticles' velocity x,y,z and assembly as secondaryParticles' vector components.
  • -at rgbPP -vectorValue ($col.x) ($col.y) ($col.z) : Select an attribute of rgbPP. Get random values from the sphrand(1) and assembly as secondaryParticles' colour components.
 













Reference
  • Autodesk Maya 2011, 2010. Autodesk Maya Online Help :
    Introduction. [online] Available at : <
    file:///Applications/Autodesk/maya2011/docs/Maya2011/en_US/index.html?url=./files/GS_Introduction.htm,topicNumber=d0e1838
    > [Accessed 25 February 2011].
  • Marc-André Guindon., 2005. Learning Maya 7 : The Special Effects Handbook. Unknown: Sybex
  • http://download.novedge.com/Brands/Alias/Helps/Maya6.5/en_US/MEL/listofparticleattributes.html


No comments:

Post a Comment