25 February 2011

Particle Example 2 : Ordinary expressions and a Newton field

There are two kinds of expressions which are ordinary expressions and particle expressions. Ordinary Expressions control per-object attributes. Particle expressions affect per-particle attributes and are executed differently from ordinary expressions. This example presents an ordinary expression being used to control particle behaviour that seem like a candidate for a particle expression.

1.  Create a new scene. Set dynamic mode, go to Particle - Particle Tool.
     Click 10-20 times in the perspective view to make particles and press Enter.


2.  Change the Particle Render Type to sphere in the channel box.















3.  Switch into Component selection mode.

4.  Drag and select all the particles. Go to Window - General Editors - Component Editor

5.  Select the Velocity Y for all the particles. Make sure the time slider is at 0.

6.  Type "1.0" into the box, initiate all Velocity Y value as 1.0. Close the Component Editor.



7.  Switch into Object selection mode.

8.  With the particles selected, select Fields - Newton to create a Newton field.

Now, animate the centre point.

9.  At the frame 0, press Shift-w to key selecting Translation X,Y, and Z.
10. Drag time slide to 100-200 frame, move the newton field wherever you want to move
      but make sure the newton field is located within -5 or -6 in Translation Z value.
11. At the 100~200 frame you set, with the newton field selected, press Shift-w.
12. Playback your animation. Spheres will orbit around following the newton field.

Adding the repulsion expression.

13. Select the newton field. Open the Expression Editor (Window - Animation Editor - Expression Editor)

14. Enter the below expression.

      if (tz > -5)
      {
           magnitude = 5.0;
       }
      else
      {
           magnitude = -35.0;
       }



15. Click Create and playback your animation.




Analyzing Expression

This expression is for testing value of one attribute to control the behaviour of another.

if (tz > -5) : If the value of translation Z is bigger than -5
magnitude = 5.0 : The value of newton field's magnitude is set to 5.0. The newton field attracts the particles with a strength of 5.0

else : When the value of translation Z is smaller than -5
magnitude = -35.0 : The value of newton field's magnitude is -35.0. The newton field repels them with a strength of -35.0

A newton field is the natural choice for the particles will orbit. When its magnitude turned to negative value, the newton field loose the strength and it forces the particles to fly outward.
















Reference
  • Mark R.Wilkins and Chris Kazmier., 2003. MEL Scripting for Maya Animators. SanFrancisco: Diane D. Cerra
  • 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].

No comments:

Post a Comment