Expression Techniques

In 3ds Max, you can use mathematical expressions (rather than constant numbers) to express parameter values. For example, you could use the expression 24*6 to represent the number 144.

You can use mathematical expressions to control the following object properties:

- Object parameters, such as length, width, and height
- Transform and modifier values, such as an object's position coordinates

Parameter wiring, the expression controller, and the numerical expression evaluator all use expressions, which are described in this topic.

An expression is a mathematical function that returns a value. You can use expressions to control the following scene elements:

NoteExpressions work
only with the individual XYZ components of Euler rotation. You can't
assign an expression to TCB rotation or other kinds of rotation
controllers.

The following links jump to sections within this topic:

The type of value returned by an expression depends on the kind of controller:

- Float expressions return a floating-point
scalar value (For example, 5.617). Scalars are used in the animation
controllers of numeric parameters.
If the parameter has an integer value, the expression rounds the float value to the nearest integer.

- Position, Scale, and Point3 expressions return a three-component vector. For example, [5, 18, 24]. The vector can represent an object's X,Y,Z location, percent scaling in X, Y, and Z, or a color (RGB values) in a material.

In the following tables, p and q are any scalar value or expression, V and W are any vector value or expression. (The character "x" is used as the vector cross-product operator.)

These are the arithmetic operators for scalar values:

Operator | Use | Meaning |
---|---|---|

+ | p+q | Addition |

- | p-q | Subtraction |

- | -p | Additive inverse |

* | p*q | Multiplication |

/ | p/q | Division |

^ | p^q | power (p to the power of q) |

** | p**q | ^ and ** are the same operation |

You can also use logical (Boolean) operators with scalar values. These operators all return 1 if true, 0 otherwise:

Operator | Use | Meaning |
---|---|---|

= | p=q | equal to |

< | p<q | less than |

> | p>q | Greater than |

<= | p<=q | less than or equal to |

>= | p>=q | Greater than or equal to |

| | p|q | Logical OR, returns 1 if either p or q is nonzero; otherwise, returns 0 |

& | p&q | Logical AND, returns 1 if p and q are both nonzero; otherwise, returns 0 |

For vectors that have a variable name, you can use a special component operator (.) to refer to the three scalar components of the vector:

Use | Meaning |
---|---|

V.x | first component (X) |

V.y | second component (Y) |

V.z | third component (Z) |

These are the operators for vector arithmetic:

Operator | Use | Meaning |
---|---|---|

+ | V+W | Addition |

- | V-W | subtraction |

* | p*V | scalar multiplication |

* | V*p | scalar multiplication |

* | V*W | dot product |

X | VxW | cross product |

/ | V/p | scalar division |

Expressions have eight levels of precedence. The higher the operator is on the list, the earlier it is evaluated.

Operator | Level of Precedence |
---|---|

- + | as unary operators, as in -8, +25 |

. | the component operator, as in V.x |

** ^ | |

X | cross product |

* / | |

+ - | |

= < > <= >= | |

| & |

Parentheses are a special case. They are a grouping or subexpression operator that is provided so you can override the precedence order of the other operators.

In expressions you write for expression controllers, variables are represented by symbolic names. You create them to contain constant or variable values in your expressions. Several predefined variables are also provided. Some of these have a constant value, others can vary.

In expressions used for parameter wiring and the numerical expression evaluator, you can use predefined variables with constant values.

Predefined Variables with Constant Values

These are the predefined variables that have a constant value (variable names are case-sensitive):

Variable Name | Constant Value | Use |
---|---|---|

pi | 3.14159 | Ratio of a circle's circumference to its diameter. |

e | 2.71828 | Base of natural logarithms. |

TPS | 4800 | Ticks per second. The tick is the basic time unit of 3ds Max animation. |

Predefined Variables with Variable Values

These are the predefined variables that have a variable, time-based value (variable names are case-sensitive).

Variable Name | Meaning |
---|---|

F | Frame number. For each frame, F equals the current frame number, counting from zero. The range of frames can vary depending on the number of frames in the active time segment. |

NT | Normalized time. By definition, normalized time (NT) ranges from 0 to 1 over the active time segment, regardless of how many frames are in the segment. If you base an expression on NT, its effect happens exactly once over the range. You can also multiply NT by a factor for the expression's effect to occur a certain number of times (for example, 2*NT causes the expression's effect to occur twice). Expressions based on NT speed up or slow down if you change the length of the time segment. |

S | Seconds (elapsed time in seconds). Elapsed time is measured from the first frame to the current frame. The range of seconds can vary depending on the total time of the active time segment. |

T | Ticks (elapsed time in ticks). There are 4800 ticks per second. Elapsed time is measured from the first frame to the current frame. The range of ticks can vary depending on the total time of the active time segment. |

- Variable names can contain as many alphanumeric characters as you like. Their length is not limited.
- Variable names cannot contain spaces.
- The variable name must begin with a letter. Numbers are valid within a variable name (as in "Pos1" or "M23").
- Variable names are case-sensitive. For example, "pos", "Pos", and "POS" designate three different variables.
- You can't create a variable with a name that duplicates another name, including the variable names that are predefined.

Following is a list of the functions provided for expressions. In this list, p, q, and r represent scalar values or scalar expressions. V and W represent vector values or vector expressions.

To use a function in an expression, enter the name of the function and appropriate arguments to it.

The sine, cosine, and tangent functions take an angle in degrees and return a floating-point value. The arc functions take a floating-point value and return a value in degrees.

Function | Meaning |
---|---|

sin(p) | sine |

cos(p) | cosine |

tan(p) | tangent |

asin(p) | arc sine |

acos(p) | arc cosine |

atan(p) | arc tangent |

Hyperbolic functions take a floating-point value and return a floating-point value.

Function | Meaning |
---|---|

sinh(p) | hyperbolic sine |

cosh(p) | hyperbolic cosine |

tanh(p) | hyperbolic tangent |

Conversion Between Radians and Degrees

Function | Meaning |
---|---|

radToDeg(p) | takes p in radians and returns the same angle in degrees |

degToRad(p) | takes p in degrees and returns the same angle in radians |

Function | Meaning |
---|---|

ceil(p) | smallest integer greater than or equal to p |

floor(p) | largest integer less than or equal to p |

Function | Meaning |
---|---|

ln(p) | natural (base e) logarithm |

log(p) | common (base 10) logarithm |

exp(p) | exponential function exp(p)=e^p |

pow(p,q) | p to the power of q (p^q) |

sqrt(p) | square root |

abs(p) | absolute value |

min(p,q) | minimum returns p or q, depending on which is smaller |

max(p,q) | maximum returns p or q, depending on which is greater |

mod(p,q) | remainder of p divided by q |

- Trigonometric Functions
This topic is a quick review for readers who need a reminder about this area of mathematics. If you’re familiar with trigonometry, you can skip this topic. If you find this topic difficult to follow, you might consult a more basic reference on mathematics.

- Vectors
This topic is a quick review for readers who need a reminder about vector arithmetic. If you’re familiar with vectors and vector calculations, you can skip this topic. If this topic is difficult to follow, you might consult a more basic reference on mathematics.