Your Ad Here

Expression Examples

Let the math begin! Here are a few examples of some more advanced expressions.

Relational Expressions

At the beginning of this chapter (Jumping into Expressions), you saw how Parameter B can directly take the value of Parameter A. But you can also use the values from parameter A and modify them.

1. Create a sphere and a cube, just to keep things simple.

2. Animate the cube moving back and forth on its X axis.

3. Select the sphere and press Ctrl+k to open its Local Transform property editor.

4. Right-click the animation icon of the Position X parameter and choose Set Expression.

5. Enter the following into the expression editor:

cube.kine.local.posx * -1

6. Validate and apply the expression and close the expression editor.

Notice the expression on its own page inside the Local Transform property editor. The animation icon for the Position X parameter now has an arrow in it indicating that the parameter is being controlled by a relationship.

7. Play the animation and notice that as the cube moves back and forth on the X axis, the sphere moves the same but in the opposite direction (the -1 value did this).

If you plotted the Position X animation of the sphere, you would see that its fcurve is the same as the cube’s Position X fcurve, except that it would be flipped vertically.

8. Edit the expression in the property editor to the following:

cube.kine.local.posx * -0.5

 

Notice how the sphere now moves in the opposite direction, but only half as far. If you plotted its Position X fcurve, you would see that it’s upside-down and half as tall as the cube’s Position X fcurve.

By multiplying the value of the cube’s Position X parameter, you’re basically altering the shape of the source fcurve. You can make the fcurve taller by multiplying by numbers greater than 1, or shorter by dividing. Adding and subtracting values to the parameter shifts the resulting fcurve left and right.

9. With the sphere selected, choose Create > Parameter > New Custom Parameter Set from the Animate toolbar and name the set Control.

10. Choose Create > Parameter > New Custom Parameter (or press Shift+p) to create a custom parameter for the set and name it slider.

11. Set the Minimum value range to -10 and Maximum to 10 and leave everything else as a default.

12. Edit the expression for the sphere’s Position X parameter again, but this time as follows:

cube.kine.local.posx * sphere.Control.slider

13. In the explorer, find the Control custom parameter set under the sphere’s node and click its icon to open up its property editor. Inside, there should be the parameter you created (slider).

 

14. Loop the animation of the cube while dragging the custom parameter’s slider across its range of values.

Instead of multiplying the cube’s Position X parameter by a number like
-1 or -0.5, you multiplied it by the slider’s value. You can see that this slider now controls the amplitude of how the sphere translates in X relative to the cube translating in X.

You can imagine that when the slider is set to 1, the sphere’s Position X fcurve matches the cube’s Position X fcurve precisely. As you increase the slider value, the sphere’s Position X fcurve grows taller. As you decrease the value to zero, the fcurve flattens out, only to grow again in the opposite direction as you move the slider to negative values.

15. Change the expression so that instead of multiplying, you add the two parameters together:

cube.kine.local.posx + sphere.Control.slider

Now as you move the slider, the sphere shifts to the right or left.

This sort of mathematical manipulation of fcurves is exactly what’s taught in math analysis or pre-calculus. Basically, it’s drawing pictures with math equations. A pre-calculus text book can give you all the information you’ll need to know about how to manipulate the shapes of functions using different math operations.

Conditional Expressions

If you’re getting into expressions, try this simple exercise using a conditional expression.

1. In a new scene, get a primitive sphere.

2. Get two primitive nulls and translate them so that one is above the sphere and the other is below so that they have noticeably different Y positions.

3. Set an expression on the sphere’s local Position Y parameter:

cond( sphere.kine.local.posx > 0, null.kine.local.posy, null1.kine.local.posy )

This is a conditional expression, which works according to this format:

cond( True or False Condition, This Value if True, This Value if False )

 

If you choose Functions > Conditions > Condition in the expression editor, this formula is added for you in the expression pane so that you don’t have to type it all out.

4. Translate the sphere on its X axis to see how it jumps when the value is greater than or less zero.

5. If it’s greater than zero, the Position Y value from the first null is used; otherwise, the Position Y value from the second null (null1) is used.

 

Oscillation Using Cosine

And now for a simple oscillation using the cosine function and the frame rate of the scene’s playback.

1. In a new scene, get a primitive sphere.

2. Create a custom parameter set for it called Control.

3. Create two custom parameters for this set, called amp and freq, each with value ranges between -100 and 100.

4. Set the following expression on the sphere’s local Position X parameter:

cos( T * 90 * sphere.Control.freq ) * sphere.Control.amp

 

You can also find the cosine function in Functions > Trigonometry > Cosine in the expression editor.

T represents Time and is dependent on the frame rate setting of your playback. If it is set to 30 frames per second, T will equal 1 at frame 30.

5. Set the playback in a loop, play around with the custom amp and freq sliders (set the freq first).



SOFTIMAGE|XSI v.6.01     

Return to Softimage XSI Index


Your Ad Here