3D MAX TUTORIALS

 

Expression Techniques

The expression controller, parameter wiring, 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:

Scene elementCalculatable property
Creation parametersAny numeric creation parameter
Transforms

Position [X, Y, Z]

X Rotation

Y Rotation

Z Rotation

Scale [X%, Y%, Z%]

ModifiersAny numeric modifier parameter (including creation parameters)
Materials

Colors [R, G, B]

Any numeric material parameter

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

Note: The links below are to the sections that follow in this topic.

Expression Return Types

Operators

Variables

Functions

See also

Trigonometric Functions

Vectors

Expression Controller Techniques

Expression Return Types

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.

Operators

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.)

Scalar Operators

These are the arithmetic operators for scalar values:

OperatorUseMeaning
+p+qAddition
-p-qSubtraction
--pAdditive inverse
*p*qMultiplication
/p/qDivision
^p^qpower (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:

OperatorUseMeaning
=p=qequal to
<p<qless than
>p>qGreater than
<=p<=qless than or equal to
>=p>=qGreater than or equal to
|p|qLogical OR, returns 1 if either p or q is nonzero; otherwise, returns 0
&p&qLogical AND, returns 1 if p and q are both nonzero; otherwise, returns 0

Tip: Logical operators are useful with the "if" function.

Vector Operators

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

UseMeaning
V.xfirst component (X)
V.ysecond component (Y)
V.zthird component (Z)

These are the operators for vector arithmetic:

OperatorUseMeaning
+V+WAddition
-V-Wsubtraction
*p*Vscalar multiplication
* V*pscalar multiplication
*V*Wdot product
XVxWcross product
/V/pscalar division

Operator Precedence

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

OperatorLevel of Precedence
- +as unary operators, as in -8, +25
.the component operator, as in V.x
** ^ 
Xcross 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.

Variables

In expressions, 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 thes have a constant value, others can vary.

Note: In the numerical expression evaluator, you can't use the predefined variables, but you can use the predefined constants.

Predefined Variables with Constant Values

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

Variable NameConstant ValueUse
Pi3.14159Ratio of a circle's circumference to its diameter.
E2.71828Base of natural logarithms.
TPS4800Ticks per second; 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 NameMeaning
FFrame 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.
NTNormalized 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.
SSeconds (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.
TTicks (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.

Rules for Variable Names

  • 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.

Functions

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.

Trigonometric Functions

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.

FunctionMeaning
sin(p)sine
cos(p)cosine
tan(p)tangent
asin(p)arc sine
acos(p)arc cosine
atan(p)arc tangent

Hyperbolic Functions

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

FunctionMeaning
sinh(p)hyperbolic sine
cosh(p)hyperbolic cosine
tanh(p)hyperbolic tangent

Conversion Between Radians and Degrees

FunctionMeaning
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

Rounding Functions

FunctionMeaning
ceil(p)smallest integer greater than or equal to p
floor(p)largest integer less than or equal to p

Standard Calculations

FunctionMeaning
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

Conditional Functions

FunctionMeaning
If(p,q,r)works like the common spreadsheet "if" (If p is nonzero then "if" returns q, otherwise "if" returns r.)
vif(c,V1,V2)"Vector If" (Value is V1 if c is true, else V2.)

Vector Handling Functions

FunctionMeaning
length(V)length of V
comp(V,i)i'th component (I=0,1,2): comp([5,6,7],1)=6
unit(V)returns a unit vector in the same direction as V

Note: The comp function is an alternative to the notation V.x, V.y, V.z.

Special Animation Function

FunctionMeaning
Noise(p,q,r)3D noise: returns a randomly generated position

The arbitrary values p, q and r, are used as a random-generation seed. You can re-use these values to ensure that noise() returns the same value.


Comments

Home
Selectiong Objects
Selection Commands
Objects Properties
Programmers Forum
Birthday Gift Baskets
Creating Geometry
Transforms: Moving, Rotating, and Scaling Objects
Creating Copies and Arrays
Effects and Post-Production

Systems Animation
Character Assemblies Lights and Cameras
Advanced Lighting
Material Editor, Materials, and Maps
Rendering
3D MAX FORUM

Managing Scenes and Projects
Utilities
User Interface
Customizing the User Interface
Default Keyboards
Transforms: Moving, Rotating, and Scaling Objects
Creating Copies and Arrays
Rendering to Textures

Introduction
Glossary
Getting Started with 3ds max
Viewing and Navigation 3D Space
Modifiers
Surface Modeling
Precision and Drawing Aids
SpaceWarps and Particle
Adobe_Premiere Tutorials

Web Designer - offers freelance web design services, redesign, graphic design, content management, web development and e-commerce.
LTD