Skip to content

Instantly share code, notes, and snippets.

@RainWarrior RainWarrior/grammar.js
Last active Oct 9, 2018

Embed
What would you like to do?
Animation State Machine grammar
{
"parameters": { "name": <time_value>, ... },
"clips": { "name": <clip>, ... },
"states": [ "name", ... ],
"transitions": { "name_from": "name_to", ... },
"start_state": "name"
}
<time_value> ::=
<number> // result = number; Constant value.
"#identity" // result = input; Value that returns its input.
"#name" // result = name(input); Reference to another value defined in "parameters" block.
[ "compose" <time_value> <time_value> ] // result = value1(value2(input)); Value composition.
[ regex("[+\\-*/mMrRfF]+"), <time_value>* ] // Simple arithmetic operation, see below.
<clip> ::=
"#identity" // Identity clip, does nothing to the model.
"#name" // Reference to another clip defined in "clips" block.
"domain:model#variant@clip" // reference to a clip loaded by the model loader. Variant is optional.
[ "apply", <clip>, <time_value> ] // clip with input transformed with the specified time value.
[ "slerp", <clip_from>, <clip_to>, <time_value_input>, <time_value_progress> ] // spherical linear blend between 2 clips; result = (1 - progress) * clip_from(input) + progress * clip_to(input).
[ "trigger_positive", <clip>, <time_value>, "name" ] // clip that fires an additional event when specified time_value switches from negative to positive.
Simple arithmetic operation time value expects 1 time value for each character in the operand string,
and applies operands in order to the input value.
Arithmetic operations:
"+": output = input + arg;
"-": output = input - arg;
"*": output = input * arg;
"/": output = input / arg;
"m": output = min(input, arg);
"M": output = max(input, arg);
"r": output = floor(input / arg) * arg;
"R": output = ceil(input / arg) * arg;
"f": output = input - floor(input / arg) * arg;
"F": output = ceil(input / arg) * arg - input;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.