CE - Expressions

Expressions are the most convenient way to automate courses of motions and regular or repetitive animations without scripting knowledge. Have you ever tried to model a perfect sine-shaped motion curve? If your answer is “yes” and you had problems, then you will love expressions. With them you do not have to worry about keys, because you simply enter the appropriate function or formula and can immediately see the results. Theoretically, expressions go on for ever because it is always possible to add another frame to continue the range. You can also make them event-based. This means that you can define a certain condition to switch on a certain feature, e.g. rigid body dynamics. Such a condition could either be a particular frame or the position of a null object, to name but a few.

 

Expressions were used here for the vertical movement of spheres.

 

RealFlow provides all common functions, such as sine, cosine, square root, log, tan, etc. Additionally it is also possible to use operators to perform comparisons and simple calculations, for example <, >, +, *, and others. This way it is easy to combine different functions and create complex formulas. Expressions are very flexible and versatile.

RealFlow offers another feature: the combination of expressions and key-based curves. Though both methods work completely differently, it is possible to mix them and create a hybrid curve. Combining key-based curves and expressions can help you in many situations: for example, when you want to add some noise to an animation or create secondary motions within a higher-ranking movement. If you think it is complicated to combine these different curve types, you are totally wrong! A simple click on the “+” button, next to an expression, will do the job for you. The result is a completely new curve, showing characteristics of the animation and the expression – a hybrid type. For a better impression, the "Graph" window also shows you the original key-based curve with a less saturated colour.

Expressions are a very fast and reliable method to mimic different kinds of natural behaviour. In nature we rarely see perfect motion or endless expansion of forces, velocities or motion. They are all damped in some way, because everything loses a certain amount of energy over time. This behaviour can be perfectly simulated with expressions.

 

 

An example:

When you are working with lights inside your 3D program you probably would usually add a falloff to the light source. This prevents the light rays from strongly illuminating distant objects, as that normally would not look very realistic. Therefore, with most light sources you would usually be able to restrict the expansion of light with predefined modes, for example inverse, inverse square, or inverse cubic.

 

"Curve Editor" representation of various falloff functions.

 

Another method is to lower forces with an exponential function. This simulates the decline of forces over time. The same is possible for other values, like friction or temperature. With simple functions it is also no problem to switch certain attributes in constant intervals on and off, or create perfect motions along a certain formula-based path. Another important field of application is randomness. You often need a certain amount of randomness to make things more believable, for example wind direction. Of course, there is a base direction, where the wind comes from, but always with slight variations – see below:

 

 

Expressions have even more advantages: 

  • Multi-threaded. Expressions make use of all CPUs and cores.
  • No scripting required. If you are not familiar with Python, expressions are a perfect alternative.
  • Fast to create. You do not need debugging or many lines of code, because expressions only consist of a single line.
  • Use standard maths functions. Basic algebraic operations, like brackets, and a little trigonometry, are all you need.
  • Perfect motion. Since expressions are based on mathematical functions they are physically correct and produce absolutely perfect results.
  • If you are familiar with scripting or programming, expressions should be even easier for you to understand.