about us   links   contact contributors   

  

 

 Home

   MEL Home

 
 
   
  
  
  Downloads
 Mel Basics Notes (.pdf)
 Mel Basics Notes/Proj Files (.zip)
  
    
  
  
  Tips and Tricks
  
    
  
  
  Announcements
  
    
  
  
  Reading List
       
  
    
  
  
  Math Revision



When a circle's diameter is 1 unit, its circumference is pi (∏) units.

Circumference = ∏ * diameter
Circumference = 2∏ * radius

∏ = 3.14159
     



sin(angle)=O/H
cos(angle)=A/H
tan(angle)=O/A
     



degrees=radians*(180/∏)
radian=degrees*(∏/180)
     


     

  
    

  Please leave all references to the author intact in all documentation and tutorials.  
 

Terms of Use

 

  
   MEL Script Gems   

 

 

  Wheel Roll in Z axis
 
Type :  Expression
Description : A wheel rotates according the distance translated along a single axis.
Use :  Procedural Animation
Download : MAYA 2009 .ma file [click here]

//------------------------------------------------------------------------
//
// Create a cylinder, rotate and position it on the floor.
// Delete the History and Freeze Transforms
// Group the cylinder.
//
// The Group can be animated using Translation Z and
// the wheel will Rotate automatically
//
//------------------------------------------------------------------------

// declare and assign variables
float $PI = 3.1415;
float $wheelRadius = 10;

if(frame==1)
{
    // reset the wheel and global group back at the origin
    globalTransforms.translateZ=0;
    wheel.rotateX=0;
}
else
{
    // translate the global group
    globalTransforms.translateZ+=0.1;

    // rotate the wheel according to global group translateZ value
    wheel.rotateX=360*(globalTransforms.translateZ/
                                  (2*$PI*$wheelRadius));
}

 

  Wheel Roll back and forth
 
Type :  Expression
Description : A wheel rotates according the distance translated along a single axis.
Use :  Procedural/Mechanical Animation
Download : MAYA 2009 .ma file [click here]

//------------------------------------------------------------------------
//
// Create a cylinder, rotate and position it on the floor.
// Delete the History and Freeze Transforms
// Group the cylinder.
//
// The Group can be animated using Translation Z and
// the wheel will Rotate automatically
//
//------------------------------------------------------------------------

    // declare and assign variables
    float $PI = 3.1415;
    float $wheelRadius = 10;
    float $frequency = 2; // speed
    float $magnitude = 7; // value

if(frame==1)
{
    // reset the wheel and global group back at the origin
    globalTransforms.translateZ=0;
    wheel.rotateX=0;
}
else
{
    // translate the global group
    globalTransforms.translateZ=
               (sin(deg_to_rad((frame)*$frequency)))*$magnitude;

    // rotate the wheel according to global
    // group translateZ value
    wheel.rotateX=360*(globalTransforms.translateZ/
                                    (2 * $PI * $wheelRadius));
}


 

  Turbulence (Random Vibrations)
 
Type :  Expression
Description : Add some random turbulence to an Object. The main object is Grouped and a local turbulence Expression is applied. This Group is then Grouped again to allow GlobalTransforms or even a Motion Path.

This Expression has interesting possibilities when considered for other Attributes than Translation and Rotation.
eg. Light Intensity, Colour, Bump Depth

Use :  Procedural Animation. Objects, Cameras. Lights
Download : MAYA 2009 .ma file [click here]

//----------------------------------------------------------------------------
//
// Create a model. Group it twice and name it as indicated
// in the Outliner above. Apply the Expression below to the
// localTurbulenceExpression Group.
//
//----------------------------------------------------------------------------

// noise(time*frequency)*magnitude
// frequency = speed
// magnitude = value
 

// rotate the model between -3 and 3 degrees
local_turbulence.rotateZ = noise(time*0.8)*3;

// translate the model between -1.2 and 1.2 in X axis
local_turbulence.translateX = noise(time*0.8)*1.2;

// translate the model between -0.6 and 0.6 in Y axis
local_turbulence.translateY = noise((time-10)*2)*0.6;

 
 
  Crawling Insects (Automated Legs)
 
Type :  Expression
Description :  
Use :  Procedural Animation.
Download : MAYA 2009 .ma file [click here]

//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------


 

//////////////////////////////////////////////////////////////////
//
// MIDDLE LEG : LEFT
//
//////////////////////////////////////////////////////////////////

lft_leg2_01.rotateX=`getAttr -time (frame-20) lft_leg1_01.rotateX`;
lft_leg2_01.rotateY=`getAttr -time (frame-20) lft_leg1_01.rotateY`;
lft_leg2_01.rotateZ=`getAttr -time (frame-20) lft_leg1_01.rotateZ`;

lft_leg2_02.rotateX=`getAttr -time (frame-20) lft_leg1_02.rotateX`;
lft_leg2_02.rotateY=`getAttr -time (frame-20) lft_leg1_02.rotateY`;
lft_leg2_02.rotateZ=`getAttr -time (frame-20) lft_leg1_02.rotateZ`;

///////////////////////////////////////////////////////////////////
//
// MIDDLE LEG : RIGHT
//
///////////////////////////////////////////////////////////////////

rgt_leg2_01.rotateX=`getAttr -time (frame-20) rgt_leg1_01.rotateX`;
rgt_leg2_01.rotateY=`getAttr -time (frame-20) rgt_leg1_01.rotateY`;
rgt_leg2_01.rotateZ=`getAttr -time (frame-20) rgt_leg1_01.rotateZ`;

rgt_leg2_02.rotateX=`getAttr -time (frame-20) rgt_leg1_02.rotateX`;
rgt_leg2_02.rotateY=`getAttr -time (frame-20) rgt_leg1_02.rotateY`;
rgt_leg2_02.rotateZ=`getAttr -time (frame-20) rgt_leg1_02.rotateZ`;

///////////////////////////////////////////////////////////////////
//
// BACK LEG : LEFT
//
///////////////////////////////////////////////////////////////////

lft_leg3_01.rotateX=`getAttr -time (frame-40) lft_leg1_01.rotateX`;
lft_leg3_01.rotateY=`getAttr -time (frame-40) lft_leg1_01.rotateY`;
lft_leg3_01.rotateZ=`getAttr -time (frame-40) lft_leg1_01.rotateZ`;

lft_leg3_02.rotateX=`getAttr -time (frame-40) lft_leg1_02.rotateX`;
lft_leg3_02.rotateY=`getAttr -time (frame-40) lft_leg1_02.rotateY`;
lft_leg3_02.rotateZ=`getAttr -time (frame-40) lft_leg1_02.rotateZ`;

///////////////////////////////////////////////////////////////////
//
// BACK LEG : RIGHT
//
///////////////////////////////////////////////////////////////////

rgt_leg3_01.rotateX=`getAttr -time (frame-40) rgt_leg1_01.rotateX`;
rgt_leg3_01.rotateY=`getAttr -time (frame-40) rgt_leg1_01.rotateY`;
rgt_leg3_01.rotateZ=`getAttr -time (frame-40) rgt_leg1_01.rotateZ`;

rgt_leg3_02.rotateX=`getAttr -time (frame-40) rgt_leg1_02.rotateX`;
rgt_leg3_02.rotateY=`getAttr -time (frame-40) rgt_leg1_02.rotateY`;
rgt_leg3_02.rotateZ=`getAttr -time (frame-40) rgt_leg1_02.rotateZ`;

///////////////////////////////////////////////////////////////////


 

  Flapping Wings (Basic)
 
Type :  Expression
Description : This is a simple introductory Expression for flapping wings. It's used to illustrate the use and syntax of the sin() and cos() functions.

sin()
cos()

The sin()and cos() functions require an input value in radians, therefore values are converted from degrees to radians using the deg_to_rad() function.

sin(deg_to_rad())

The input value for the sin()and cos() functions are generated using the frame function. At this stage it would take 360 frames for the bird to flap it's wings once - very slow. To increase the wing speed a multiplier value of 10 is applied.

sin(deg_to_rad(frame*10))

This will now return a value of 0 to 1 to 0 to -1 to 0 over 36 frames. The last stage is to multiply these values by the angle you want to animate the wings. Add Attribute with float values from 0 - 60  to the body, and name it wingAngle.

sin(deg_to_rad(frame*10))*body.wingAngle;

 

Use :  Procedural Animation.
Download : MAYA 2010 .ma file [click here]

//---------------------------------------------------------------------------------------
//
// Note : Remember Add Attribute wingAngle to the body
// type float, min 0, max 60, default 0

//
//----------------------------------------------------------------------------------------

// body.wingAngle = custom attribute (keyable) of body
// body.wingAngle is the multiplier to make the wings flap

// reset all 4 wing objects and body at frame 1
if(frame==1)
{
    lwing1.rotateZ=0;
    rwing1.rotateZ=0;
    lwing2.rotateZ=0;
    rwing2.rotateZ=0;
    body.translateY=0;
}

// animation
if(frame>1)
{

    // rotate left and right wing joints nearest the body
    lwing1.rotateZ=sin(deg_to_rad(frame*10))*body.wingAngle;
    rwing1.rotateZ=sin(deg_to_rad(frame*10))*(body.wingAngle*-1);

    // rotate left and right middle joint, with offset to create overlap
    lwing2.rotateZ=sin(deg_to_rad((frame-8)*10))*body.wingAngle;
    rwing2.rotateZ=sin(deg_to_rad((frame-8)*10))*(body.wingAngle*-1);

    // translate body in opposite direction to wings
    body.translateY=cos(deg_to_rad((frame-8)*10))*(body.wingAngle/-100);
}

 

//---------------------------------------------------------------------------------------
//
// The example below demonstrates the Expression above.
//
// The body.wingAngle value is keyframed from 0 to 30 to 45 to 0
//
//---------------------------------------------------------------------------------------

 
Basic MELScript Expression

//----------------------------------------------------------------------------
//
// The example below demonstrates how you animate the
// model globally.
//
// Select body and Group it. Rename the Group "bird_path".
// You can now animate the translation and rotation of
// the bird_path Group.
//
// The example below simply translates the model in the Y..
//
// The body.wingAngle value is also keyframed to vary the
// wing speed.
//
//----------------------------------------------------------------------------

 
MELScript Expression + Keyframed body.wingAngle
 

//---------------------------------------------------------------------------------------
//
// The example below demonstrates how to add wind turbulence to
// the Expression.
//
// Select body and Group it again. Rename the Group "turbulenceGrp".
// This Group can now be used to Translate and Rotate the model
// locally while still inside the bird_path group.
//
// The example below applies a noise function to the X & Y translation
// and Z rotation.
//
//
noise(time*a)* b;
// a= speed
// b=value of translation or rotation
//
// Note : The translateY value is offset by 10 frames to ensure the
// does constantly move diagonally.
//
//---------------------------------------------------------------------------------------

 

if(frame==1)
{
lwing1.rotateZ=0;
rwing1.rotateZ=0;
lwing2.rotateZ=0;
rwing2.rotateZ=0;
body.translateY=0;
}

if(frame>1)
{
lwing1.rotateZ=sin(deg_to_rad(frame*10))*body.wingAngle;
rwing1.rotateZ=sin(deg_to_rad(frame*10))*(body.wingAngle*-1);

lwing2.rotateZ=sin(deg_to_rad((frame-8)*10))*body.wingAngle;
rwing2.rotateZ=sin(deg_to_rad((frame-8)*10))*(body.wingAngle*-1);

body.translateY=cos(deg_to_rad((frame-8)*10))*(body.wingAngle/-100);

// rotate the model between -3 and 3 degrees
turbulenceGrp.rotateZ = noise(time*1.2)*3;

// translate the model between -0.2 and 0.2 in X axis
turbulenceGrp.translateX = noise(time*0.6)*0.2;

// translate the model between -0.3 and 0.3 in Y axis
turbulenceGrp.translateY = noise((time-10)*0.9)*0.3;
}
 


 

 
Adding turbulence using the Noise function

 

//----------------------------------------------------------------------------
//
// For those of you wondering how the body.wingAngle
// label and value is displayed in the Viewport above, here
// is the code, which creates a Heads Up Display toggle
// switch (ON/OFF).
//
// Take note this a regular MEL Script run in the Script
// Editor, not an Expression. The code can therefore be
// dragged to your custom shelf to create a HUD button. 
//
//----------------------------------------------------------------------------

// This MEL Script is executed through the Script Editor (not an Expression)
// This script creates the Heads Up Display (HUD) in the movie above.

//global procedure to return the float value of body.wingAngle
global proc float fmWingAngle()
{
    float $WAngle;
    $WAngle = `getAttr body.wingAngle`;
    return $WAngle;
}


//toggle switch ON/OFF for HUD
if(`headsUpDisplay -ex HUDFrameNum`)
{
    headsUpDisplay -remove HUDFrameNum;
} else {
    headsUpDisplay
    -section 0
    -block 8
    -blockSize "large"
    -label "Wing Angle : "
    -labelFontSize "large"
    -command "fmWingAngle()"
    -decimalPrecision 1
    -dataFontSize "large"
    -dataAlignment "left"
    -attachToRefresh
    -vis 1
    HUDFrameNum;
}
 

 

 

 

 

 

 

 

 

 

 

 

 

 

      

copyright FridgeMonsters.com
all rights reserved forever!!