Expression
Function. A programmable calculator that evaluates a mathematical expression. Supports multiple named inputs and outputs the result of the expression.
There are several predefined Expression blocks in the Blocks Palette for common operations (Add, Subtract, Multiply, Divide). You can modify the expression and input configuration of any Expression block.
You can change the number of inputs with the Inputs number property, and change the type and name of each input.
The special variable dt is available in update chains and equals the time since the previous frame in seconds. In initialization or generation chains, dt equals zero.
Supported functions:
- vec2(x, y) – creates a 2D vector.
- vec3(x, y, z) – creates a 3D vector.
- quat(x, y, z, w) – creates a quaternion from its four components. Use
quat(0, 0, 0, 1)for the identity rotation. - axisAngle(axis, angle) – creates a quaternion from a rotation axis (
vec3) and an angle in degrees. - slerp(q1, q2, i) – spherical linear interpolation between two quaternions by factor i [0;1]. Produces a smooth, shortest-arc rotation (use this instead of
lerpfor quaternions). - inverse(q) – returns the inverse of a quaternion. Multiplying a quaternion by its inverse yields the identity.
- abs(a) – returns absolute value.
- cross(a, b) – cross product of two 3D vectors.
- dot(a, b) – dot product of two 2D or 3D vectors.
- norm(a) – returns normalized vector.
- length(a) – returns length of a vector.
- length2(a) – returns squared length of a vector.
- round(a), floor(a), ceil(a) – rounding functions.
- sign(a) – returns -1, 0, or 1 based on sign.
- lerp(a, b, i) – linear interpolation between a and b by factor i [0;1].
- x(a), y(a), z(a) – extract component from vector.
- xy(a), xz(a), yz(a), ... – swizzle to 2D vector.
- xzy(a), yxz(a), yzx(a), ... – swizzle to 3D vector.
Operators:
- +, -, *, / – standard arithmetic on floats and vectors.
- q1 * q2 – quaternion multiplication composes two rotations (Hamilton convention: apply
q2first, thenq1).
Examples:
a + b * c - 1.1(a + b) * (c - 1.1)vec3(a, b * 2, -1) * 100length(xy(a))axisAngle(vec3(0, 0, 1), 90)– 90° rotation around the Z axis.slerp(quat(0, 0, 0, 1), axisAngle(vec3(0, 0, 1), 90), 0.5)– halfway from identity to a 90° Z rotation.inverse(q) * q– equals the identity quaternion.
Properties & inputs:
- Inputs number (property): Number of inputs.
- Expression (property): The mathematical expression to evaluate.
- Name (property): Name of each input variable.
- Type (property): Type of each input (Float, Vector2, Vector3, Quaternion).
Output:
- Result of the expression. The output type is determined by the expression.