Since MSU switched to Maya in the fall of 2009, these pages have not been updated
and Wobbe F. Koning moved on to Monmouth University in the Fall of 2014
BACK INDEX

Expressions 101

Expressions are a powerful tool to have an animation channel automatically react to another animation channel. Here are some pointers to help you on your way

Enclosing Brackets |  Creating Expressions |  Example: turning the wheel

Enclosing brackets

Bracketed Stuff Square brackets are used to enclose references to animation channels:

[myBall.Position.X]

You always need to use the full name of the object, followed by a dot, followed by the parameter (Position in this case), another dot and the channel (X).

A layer of an abject can be specified using a colon after the object name, followed by the layer name:

[01_Gears_v003:SixteenTeeth.Rotation.B]

You can also reference a channel at a different time:

[myBall.Position.X, Time -1]

This will cause a lack of one second (usually 30 frames). You can also specify frames:

[myBall.Position.X, Frame -1]

This causes a lag of one frame.

Round brackets (a.k.a. parentheses) are used in two ways. They can determine the order in which operations get executed:

3 * (2 + 4)

means that 2 and 4 first get added up and then the result gets multiplied by 3, resulting in 18. 3 * 2 + 4 equals 10. You know that multiplication comes before addition, right?

Parentheses are also used to pass arguments to a function:

min( 10, [myBall.Position.X] )

The above expression will return the minimum of 10 or the X position of myBall. This means that as long as the X position of myBall is smaller than ten, the expression returns that position. If not, it returns 10.

Always make sure you have the same amount of closing brackets as you have opening ones!
And in the same order, not like this: [channel(3+2]*5)

The image is taken from the Lightwave Manual

↑ Top ↑

Creating Expressions

You can create expressions in the Graph Editor, under the expression tab found in the lowe right quadrant, under the curves. From the manual:

An expression does not do anything unless it is assigned to a channel. In the left-upper quadrant of the Graph Editor, select the channel you want the expression to work on, and the click Apply (found under the Expression Tab)

The same Expression can be applied to as many channels as you want! To find out which channels an expression is applied to, click on Get Channels (Yes, again under the Epression tab),p>

You can append the name of a channel to your expression by right-clicking on channel an choosing Append to expression

If you start of your expression with Value the expression works additive: on top of the animation curve:

Value + [myBall.Position.X]

↑ Top ↑

Example: Getting a wheel to turn at the right speed

Here is an example of how you can make a wheel turn at the right speed if it is attached to an object that travels along a straight line

Say, the object "myCar" has wheels attached to it that have a diameter of 2.5m. It is animated to move along the Z axis. In order to figure out how fast the wheel should rotate, we need to determine how many degrees the wheel needs to turn per meter movement along Z. This amount of degrees needs to result in 1 meter of the outer edge of the wheel to "hit the road".

We know the wheel has a diameter of 2.5 meters. We also know that

the circumference of a circle = 2 * π * r

where r stands for radius. Lightwave expressions have a constant named PI, which is π or about 3.14159256

Since we know the diameter (d), which is twice the radius, we can replace the 2*r part with the diameter. So the circumference of the wheel is:

2 * π * r = 2 * r * PI = d * PI = 2.5 * PI

Next we need to figure out how many degrees of the circle correspond to 1 meter of the circumference. if the wheel had a circumference of 1 meter, the answer would be 360 degrees. If the wheel had a circumference of 2 meters, the answer is 180 degrees. If we devide the amount of degrees of a full circle (=360) by the circumference, we get the amount of degrees a wheel needs to turn for one meter of its circumference to hit the road:

360 / (2 * π * r) = 360 / (2.5 * PI)

The only thing left is to multiply this by the amount the car actually moved

[Distance Traveled] * 360 / (2 * π * r) = [myCar.Position.X] * 360 / (2.5 * PI)

And Bob's your uncle!

Okay, we may want to make it a wee bit nicer by subtracting the starting X position of the car from its current X position, but we do not need to do so.

↑ Top ↑

BACK
LW Index
3D Index