Skip to content

Expressions

Luna edited this page Aug 3, 2022 · 11 revisions

Enabling expression bindings

To switch a Binding over to Expression mode, right click the title of the binding, then click Type->Expression Binding
Mouse hovered over the expression type dropdown

Overview

List of changable options in the expressions editor

Dampening

The dampening value allows you to tell Inochi Session to automatically smoothen out the values your expression puts out, you can use this if your expression seems jarring. The higher the value the smoother and slower the transition will be.

Expression

The text box where you put your mathematical expression, you can check the Functions table to see which functions you are able to put in to your expression. There's a few rules to know when writing an expression:

  1. Expressions go from 0..1, any value below 0 or above 1 are deemed invalid and are clamped and will generate a warning.
  2. Expressions can only contain numbers and expressions evaluating to numbers.
  3. Expressions can only return a single value, any extra values returned are promptly ignored.

Output/Status area

The output and status area will both show you the output value of your expression at the given time, but also show any errors or warnings thay may pop up, such as:
Warning stating: Value out of range, clamped to 0 to 1. Error stating that the user tried to access an invalid table Error stating that the resulting expression did not result in a number, but text.

     

Your First Expression

As a first example of an expression, we can animate a Breathe parameter using math expressions to follow a sine wave.
Using usin (unsigned sine wave) and time, we can combine the current time with a sine wave going from 0 to 1, which results in a breathing motion, like this.

usin(time())

This will result in the following motion

A character breathing

Aka by seagetch

Functions

Function Signature Description Value Range
BLEND(name: string) Gets a blendshape with the specified name 0..1
BONE_X(name: string) Gets the X coordinate of the specified bone -infinity..+infinity
BONE_Y(name: string) Gets the Y coordinate of the specified bone -infinity..+infinity
BONE_Z(name: string) Gets the Z coordinate of the specified bone -infinity..+infinity
ROLL(name: string) Gets the roll of the specified bone -180..+180
PITCH(name: string) Gets the pitch of the specified bone -180..+180
YAW(name: string) Gets the yaw of the specified bone -180..+180
time() Gets the current run time in seconds 0..+infinity
sin(radian: number) Gets the sine of the specified radian -1..+1
cos(radian: number) Gets the cosine of the specified radian -1..+1
tan(radian: number) Gets the tangent of the specified radian -1..+1
sinh(radian: number) Gets the hyperbolic sine of the specified radian -infinity..+infinity
cosh(radian: number) Gets the hyperbolic cosine of the specified radian -infinity..+infinity
tanh(radian: number) Gets the hyperbolic tangent of the specified radian -infinity..+infinity
psin(radian: number) Gets the positive sine of the specified radian 0..1 (clamp(sin(v), 0, 1))
pcos(radian: number) Gets the positive cosine of the specified radian 0..1 (clamp(cos(v), 0, 1))
ptan(radian: number) Gets the positive tangent of the specified radian 0..1 (clamp(tan(v), 0, 1))
usin(radian: number) Gets the unsigned sine of the specified radian 0..1 ((1+sin(v))/2)
ucos(radian: number) Gets the unsigned cosine of the specified radian 0..1 ((1+cos(v))/2)
utan(radian: number) Gets the unsigned tangent of the specified radian 0..1 ((1+tan(v))/2)
abs(value: number) Gets the absolute (positive) value of the specified value. 0..+infinity
sqrt(value: number) Gets the square root of the specified value. -infinity..+infinity
floor(value: number) Rounds the specified value down -infinity..+infinity
ceil(value: number) Rounds the specified value up -infinity..+infinity
round(value: number) Rounds the specified value to nearest integer. -infinity..+infinity
min(a: number, b: number) Gets the smallest of the 2 passed values. -infinity..+infinity
max(a: number, b: number) Gets the biggest of the 2 passed values. -infinity..+infinity
clamp(value: number, a: number, b: number) Clamps the value between a..b a..b
lerp(x: number, min: number, max: number) Linearly interpolates between min and max. min..max
cubic(x: number, tx: number, y: number, ty: number, float value) Interpolates between x and y with tx and ty as anchors of a cubic spline. x..y
atan2(y: number, x: number) Gets the arc tangent of y / x in a range of -pi..+pi. -pi..+pi
degrees(value: number) Gets the value converted from radians to degrees -180..180
radians(value: number) Gets the value converted from degrees to radians -tau..+tau

Syntax

The syntax of Expression bindings is that of the scripting language Lua.
For the most part it's straight forward, though if you want to embed if statements then you'll have to do the following:

(BLEND("ftEyeBlinkLeft") > 0.5 and 1 or 0)

The following expression will be 0 if the left eye is half closed, 1 if more than half open.