Motion SDK

State Machines

Interactive scenes with states that play or scrub clips, triggered by hover, click, scroll, keys and timers.

state_machines make a scene interactive. Each machine has states, an initial one, and transitions that fire on triggers.

A button that grows and changes colour on hover, springing back on leave.
{
  "camera": { "position": [0, 0, 6], "target": [0, 0, 0], "fov": 40 },
  "lighting": { "rig": "studio_soft" },
  "environment": {
    "background": {
      "radial_gradient": { "inner": "#1b2233", "outer": "#07090f" }
    }
  },
  "nodes": {
    "button": {
      "interactive": true,
      "mesh": {
        "geometry": {
          "rounded_box": { "size": [2.4, 0.8, 0.3], "radius": 0.15 }
        },
        "material": "preset:glossy_plastic"
      },
      "color": "#3d85c6"
    },
    "label": {
      "parent": "button",
      "transform": { "position": [0, 0, 0.2] },
      "text": { "content": "Hover me", "font": "inter_bold", "size": 0.3 }
    }
  },
  "state_machines": {
    "button": {
      "initial": "idle",
      "states": {
        "idle": {},
        "hover": {
          "set": [
            {
              "target": "button",
              "property": "scale",
              "value": [1.15, 1.15, 1.15]
            },
            { "target": "button", "property": "color", "value": "#e07a5f" }
          ]
        }
      },
      "transitions": [
        {
          "from": "idle",
          "to": "hover",
          "trigger": { "hover_enter": { "node": "button" } }
        },
        {
          "from": "hover",
          "to": "idle",
          "trigger": { "hover_leave": { "node": "button" } },
          "easing": "spring_bouncy"
        }
      ]
    }
  }
}
A button that grows and changes colour on hover, springing back on leave. apps/docs/examples/state-machines.json · render it with motion-sdk render apps/docs/examples/state-machines.json -t 1 -o state-machines.png

States

A state can play a clip (from clips), scrub a clip from an input instead of the clock (scroll, pointer_x or pointer_y), and set values to hold while it's active.

Transitions

Transitions are evaluated in order and the first match wins. from is a state or "*" for any. Each blends over duration with easing, spring_snappy by default.

Triggers

hover_enter, hover_leave and click on a node (children count; mark the node interactive), scroll progress entering [min, max], in_view, after a number of seconds, clip_end, a key, and a custom event sent by the host with player.event(name).

See examples/interactive-state-machine.json.

API Reference

StateMachine

PropertyTypeDefaultDescription
initial*stringrequiredState entered on load.
statesmap of State{}States keyed by name.
transitionsTransition[][]Evaluated in order; the first matching transition wins.

State

PropertyTypeDefaultDescription
clipstring—Clip (from clips) played when entering this state.
scrubScrubSource—Drive the clip's time from an input instead of the clock.
setPropertySet[]—Property values held while in this state.

Transition

PropertyTypeDefaultDescription
durationnumber (≥ 0)0.35Blend time in seconds.
easingEasing"spring_snappy"Curve used to blend between the states.
from*stringrequiredSource state name, or "*" for any state.
to*stringrequiredTarget state name.
trigger*TriggerrequiredWhat fires the transition.

Trigger

What fires a transition. Written as {"click": {"node": "button"}}, {"scroll": {"min": 0.5}}, {"after": {"seconds": 2}}, "clip_end", ...

ValueDescription
"in_view"The embed scrolls into the viewport.
"clip_end"The current state's clip finished (once/ping-pong clips).

{"hover_enter": { … }}Pointer starts hovering a node (or any of its descendants).

PropertyTypeDefaultDescription
node*stringrequiredNode id. Hovering a child counts.

{"hover_leave": { … }}Pointer stops hovering a node.

PropertyTypeDefaultDescription
node*stringrequiredNode id.

{"click": { … }}Node is clicked/tapped.

PropertyTypeDefaultDescription
node*stringrequiredNode id. Clicking a child counts.

{"scroll": { … }}Scroll progress (0..1) enters [min, max].

PropertyTypeDefaultDescription
maxnumber1Upper bound of scroll progress, 0 to 1.
minnumber0Lower bound of scroll progress, 0 to 1.

{"after": { … }}Time spent in the current state reaches seconds.

PropertyTypeDefaultDescription
seconds*numberrequiredSeconds spent in the state before it fires.

{"key": { … }}Keyboard key (KeyboardEvent.key) pressed while focused.

PropertyTypeDefaultDescription
key*stringrequiredKey name, like ArrowRight or Space.

{"event": { … }}Custom event sent from the host app via the SDK.

PropertyTypeDefaultDescription
name*stringrequiredCustom event name the host sends.

PropertySet

Pin a property of a node (or $camera) to a value.

PropertyTypeDefaultDescription
property*PropertyrequiredThe property to pin.
target*stringrequiredNode id, or $camera.
value*AnimValuerequiredThe value to hold.

ScrubSource

Input that scrubs a clip (0..1 maps to the clip's 0..duration).

ValueDescription
"scroll"Page scroll progress of the embed through the viewport.
"pointer_x"Horizontal pointer position over the canvas.
"pointer_y"Vertical pointer position over the canvas.