13 February 2011

MEL and Expression : Variables and Data types


Variables

A variable is like a place saves a changing value. You can assign a value to a variable or read a variable's value. All variables' name should be begin with '$'. It is upper and lower case sensitive and you can use number and underscore (_) in the name. Variables can be used after it has declared. When it is declared, it can be assigned memory from computer. When you declare a variable, type in data type of variable first and variable name with $ in front.

Example :
                  int $temp;
                  float$Temp;
                  string $tEmp;
                  vector $teMp;

Wrong example:
                  int temp;
                  float $te mp;

MEL supports implicit declaration. Even if you didn't indicate its type, variable's typecan be evaluated by assigned data type.

Example :
                 $temp = 0;                                   int
                 $Temp = 1.2;                               float
                 $sEmp = "Hello"                         string
                 $teMp = << 1.2, 4.3, 7.5 >>        vector

Maya maintains values in two predefined variables as an animation plays.

frame : float type, number of frames the animation has played.
time : float type, time in seconds the animation has played.

You can read their values but not set the values. The time updates as an animation plays. The value increases with the increasing frame number.

time = frame / rate ( frame per second)

rate can be different by NTSC or PAL. If it is NTSC, it will be 24 frames per second and if it is PAL, it will be 25 frames per second.


Data Type

int          : Integer numbers               : example (1, 0, -10 )
float       : floating point numbers     : example ( 3.234, -4.52 )
string     : one or more characters     : example ( "sphere", "plane" )
boolean : on or off selection            : example ( on / off )

Integer data types are rarely used and float type is the most common used. When you use boolean type, programme can't understand on and off when you type in "on" or "off". So it normally use int 0 and 1. In programming, 0 means False, No, Off and 1 means True, Yes, Off.

Particle shape nodes have additional attribute data types.

vector array   : array of vectors
    example attribute : ParticleShape.position
    example data : << 1.4, 5.2, 0.6 >>, << 3.34, 6.45, 8.3 >>

you must type a vector in left, middle and right component in double brackets

float array      : array of floating point numbers
    example attribute : ParticleShape.lifespan
    example data : 1.333
                            1.666
                            2.333
                            1.333

In maya, a vector is a related group of three floating point numbers that set an attribute or variable.
Vector array data types are useful for animating position, velocity, colour and other particle attributes made of three components.
Float array data types are useful for setting lifespan, opacity and other particle attributes which have a single number value.






Reference
  • Jo Sang Bum., 2002. programming with MAYA MEL & Expression. Seoul: Ahn Dae Sik
  • 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].
  • Jeon Gye do, 2000. MEL 4 Artists. [online] Available at: <http://gyedo.pe.kr/zbxe/mayaExpression> [Accessed 25 February 2011]

No comments:

Post a Comment