33
Maya Dynamics Basics Lab 5: MEL and Expression Author: Khieu Van Bang Email: [email protected]

Session 05 – mel and expression

Embed Size (px)

Citation preview

Page 1: Session 05 – mel and expression

Maya Dynamics BasicsLab 5: MEL and Expression

Author: Khieu Van BangEmail: [email protected]

Page 2: Session 05 – mel and expression

CONTENTS

Basics:Why using MEL & expressions?

Differences between MEL and expression.

What you can do by using MEL and Expression ?

MEL Basics: How Maya Uses MEL.

Script Editor.

MEL Commands .

Variables .

Return Values.

Expression:

Create expression.

Helpful Resources.

Page 3: Session 05 – mel and expression

1) BASICS

1.1) What is MEL and Expressions?1.2) Differences between MEL and Expression.1.3) What you can do by using MEL and Expression ?

MEL and Expression

Page 4: Session 05 – mel and expression

1.1) What is MEL and Expressions?

1) MEL and Expression

MEL stands for Maya Embedded Language. MEL is a scripting language which canembody "open architecture" of maya. By using MEL, user can control maya functionsdirectly/indirectly. Even maya's GUI (graphic user interface) can be controlled by MEL.Therefore user can add new functions that maya doesn't have OR customize GUI astheir needs.

Expression controls attribute of object. User can control an animation which cannotbe key framed (e,g. particle). Using expression is similar to script MEL.

We will mainly learn how to work with Expression.

Page 5: Session 05 – mel and expression

1.2) Differences between MEL and Expression.

1) MEL and Expression

MEL Expression

MEL is more likely completely independent programme.

Expression is a correlation with objects.

MEL needs complete structure of grammar. Expression needs only the least rules.

MEL is executed no matter animation is played or not.

Expression is executed only while animation playing.

MEL is saved separately with the scene. Expression is saved as a part of the scene.

MEL access to the attribute indirectly. Expression access to the attribute directly.

Page 6: Session 05 – mel and expression

1.3) What we can do by using MEL and Expression.

1) MEL and Expression

MEL : control an attribute of object accurately, create new macro, create new userinterface, customize maya GUI.

Expression : control attributes of object apart from key framing by numericalexpression, control attributes by conditions, It can use MEL command in expression.However, it can't control the attribute that controlled by existing key, set driven key,constraint, motion path or other expression. It can occur an error if you run MELcommands such as connection/disconnection of attribute or creation/deletion ofobject within the expression.

Grammar of MEL is very similar to other programming languages like C, C++. Notonly the MEL, most script based languages are descended from C. It is not essentialto learn programming language for MEL. Although if you have experience withscripting language, it will be easier to understand the structure.

Page 7: Session 05 – mel and expression

Do not worry !

1) MEL and Expression

o I know you are designers.

Expression is very easy to use.

Page 8: Session 05 – mel and expression

2) MEL BASICS

2.1) How Maya Uses MEL.2.2) Script Editor.2.3) MEL Commands .2.4) Variables .2.5) Return Values.

MEL and Expression

Page 9: Session 05 – mel and expression

2.1) How Maya Uses MEL

2) MEL Basics

Menus.

Shelf Buttons.

Hotkeys.

Expressions.

GUI.

Page 10: Session 05 – mel and expression

2.2) Script Editor

Top area displays the MEL that Maya just did.

Bottom area is a work area where you type code interactively.

Selecting text and hitting „ctrl + Enter‟ executes code.

Make a shelf button by selecting text and middle mouse dragging to the shelf.

2) MEL Basics

You get to it by hitting.

Page 11: Session 05 – mel and expression

Structure:

<command name> -flags values;

Example 1:

sphere -radius 3;

Example 2:

polySphere -radius 2.5 -subdivisionsX 10

-subdivisionsY 30 -name "Rambo";

These flags are like the option box settings.

2) MEL Basics 2.3) MEL Commands

Variable type Default value

int 0

float 0.0

string ""

Page 12: Session 05 – mel and expression

Modes :

Creation

-By default.

Edit

-Used to change values of an existing object.

Query

-Used to get a value from an existing object.

2) MEL Basics 2.3) MEL Commands

Page 13: Session 05 – mel and expression

2.3) MEL Commands

2) MEL Basics

Examples of Modes:- Creation

polySphere;- Edit

polySphere -edit -radius 4 “Rambo”;- Query

polySphere -query -radius “Rambo”;

Page 14: Session 05 – mel and expression

2.4) Variables

- Are for storing data.

- Always start with a „$‟

- Data Types.

- Int (Stands for Integer)

4

- Float

7.259

- String

“Frito Chili Pie”

- Declaring a variable.

- int $theNumberAwesome = 42;

- Equals sign assigns a value to a variable.

2) MEL Basics

Page 15: Session 05 – mel and expression

2.5) Return Values

Are the result of running a command:returnValue <command name> -flags values;

Use backquotes to store the return value/result of a command in a variable:

int $variable = <command name> -flags values;

2) MEL Basics

Page 16: Session 05 – mel and expression

Example 1

2) MEL Basics

MEL commands

polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;

Command options

move -r -os -wd 0 0 5.109298 ;

move -r 0 0 5 pCube2;

Page 17: Session 05 – mel and expression

Example 2

2) MEL Basics

Variable declarations

int $height = 2;

polyCube -w 1 -h $height -d 1;

Variable assignments

int $width;

$width = 2;

polyCube -w $width -h $height -d 1;

$width = $width + 1;

polyCube -w $width -h $height -d 1;

Page 18: Session 05 – mel and expression

Example 3

2) MEL Basics

Selective structure

int $height = 2;

int $depth;

if ($height>2)

{

$depth = $height;

polyCube -w 1 -h $height -d $depth;

}

if($depth < 1) { polySphere -r 1;

}

Page 19: Session 05 – mel and expression

Example 4

2) MEL Basics

The for-construct

int $i;

for ($i = 0; $i < 20; $i++) {

sphere -pivot 0 $i 0;

}

A spiral surface

select -all;

delete;

circle -center 4 0 0;

int $i;

for($i = 0; $i < 60; $i++)

{ duplicate;

rotate -r 0 3 0;

move -r 0 .3 0;

}

select -all;

loft;

Page 20: Session 05 – mel and expression

3) EXPRESSION

MEL and Expression

Page 21: Session 05 – mel and expression

What is Particle expression ?

3) Expression

Are more complex than other types of expressions. For example, we can write anexpression to control all particles in an object the same way, or you can control eachparticle differently.

Page 22: Session 05 – mel and expression

3.1) Attributes Notes

3) Expression

1

2

Add dynamic attributes(Modify > Add Attribute)

o Control dynamic and custom attributes you add to a particle shape node.o When we add a dynamic attribute to an object, the attribute names appear in the

Expression Editor’s Attributes list.

Per Particle (Array) Attributeso Are created with Radius, Mass, Opacity,

Color, and Incandescence per-particleramps already added to the nParticleShapenode.

Page 23: Session 05 – mel and expression

Step 1: Create a object.o Example: Type "sphere" in command line and press enter. It will create a

new nurbs sphere.

Step 2: Change object attributes.o Example: Change the name of the sphere in channel box as "Ball".

Step 3: Create expression.o Select the ball. Go to Window > Animation Editor > Expression Editor,

run Expression Editor.o Type in "ScaleBallWidth" in the box of Expression Name.o Type "Ball.scaleX = Ball.scaleZ = time +1;" in the expression box.

3.1) Create expression

3) Expression

Page 24: Session 05 – mel and expression

Step 4: Click "Create" and playback the animation.

3.1) Create expression

3) Expression

Page 25: Session 05 – mel and expression

3.1) Create expression

3) Expression

Page 26: Session 05 – mel and expression

3) ExpressionExample 1 : Random Colored Particle.

Page 27: Session 05 – mel and expression

Random colored fireworks shot up into the sky every time

3) Expression

How to create it ?

Page 28: Session 05 – mel and expression

Example 2: Control the moon orbiting the earth

3) Expression

Page 29: Session 05 – mel and expression

3) Expression

How to create it ?

Page 30: Session 05 – mel and expression

Books Complete Maya Programming by

David A. D. Gould.

Websites area.autodesk.com fundza.com

ewertb.soundlinker.com

Helpful Resources.MEL and Expression

Page 31: Session 05 – mel and expression

Helpful Resources.MEL and Expression

Page 32: Session 05 – mel and expression

Helpful Resources.MEL and Expression

Page 33: Session 05 – mel and expression

Thanks!