Skip to main content

Expressions and Drivers

Math Expressions

Any animatable actor property (color, radius, position, etc.) can be animated with a math expression (Similar to SFM's expression operators). The implementation is based on the high-performance exprtk library, which includes support for:

  • Logical operators (and/or/not/etc.)
  • Conditions (if/ternary/etc.)
  • Loops (for/while/etc.)
  • Vectors
Examples

As a basic example, let's say you want to animate the position of your actor, so you move it to [0,30,0] at timestamp 0, [0,50,20] at timestamp 1 and [30,0,-20] at timestamp 2. You can then apply the math expression value *2 to the property, which will double values, meaning your actor will move from [0,60,0] to [0,100,40] and then to [60,0,-40] instead.

Here are some other basic examples:

  • var newValue[3] := {0,value[1],0}; return [newValue];: Returns [0,value.y,0], which means the actor will only move on the y-axis.
  • var newValue[3] := {time *100,0,0}; return [newValue];: The channel value will be ignored, and the actor will move on the x-axis depending on how much time has passed since the start of the animation.
  • var f := time /duration; var newValue[3] := {sin(f *pi *2) *100,0,cos(f *pi *2) *100}; return [newValue]; The channel value will be ignored, and the actor will move in a circular motion.
Inputs

These are the variables available for use with math expressions:

  • value:value: The current value
  • time:time: The current time in seconds
  • timeIndex:timeIndex:
  • startOffset:startOffset:
  • timescale:timescale:
  • duration:duration:

Constants:

  • pi
  • epsilon
  • inf
Base Functions
  • All built-in exprtk functions
  • float noise(float v1,float v2,float v3): Perlin noise.
  • float[X] valueAt(int timeIndex): Returns the value at the specified time index. 
  • float sqr(float v): returns v *v
  • float ramp(float x,float a,float b): returns
  • float cramp(float v1, float v2,float v3): returns 
  • float lerp(float x,float a,float b): returns 
  • float clerp(float 1,float v2,float v3): returns 
  • float elerp(float v1,float v2,float v3): returns 
  • float rescale(float x,float xa,float xb,float ya,float yb): returns 
  • float crescale(float v1,float v2,float v3,float v4,float v5): returns 
  • print(...): For debugging purposes, prints the specified arguments to the console.
Quaternion Functions
  • q_from_axis_angle(float[3] axis,float angle,float[4] out): returns 
  • q_forward(float[4] quat,float[3] out): returns 
  • q_right(float[4] quat,float[3] out): returns 
  • q_up(float[4] quat,float[3] out): returns 
  • q_slerp(float[4] q0,float[4] q1,float factor,float[4] out): returns 
  • q_lerp(float[4] q0,float[4] q1,float factor,float[4] out): returns 
  • q_dot(float[4] q0,float[4] q1): returns 
  • q_mul(float[4] q0,float[4] q1,float[4] out): returns 
  • q_inverse(float[4] quatInOut): returns 
  • float q_length(float[4] quat): returns 

Contrary to SFM's expression operators, PFM's math expressions cannot reference anything outside of the animation channel for the property it's assigned to. To create dependencies between properties, you need to use animation drivers instead. 

 

Animation Drivers

This is a placeholder.