Motion SDK

TypeScript SDK

Write scenes as type-checked TypeScript with @motion-sdk/scene. Generated types, typed helpers, path-checked patches and the engine's validator.

@motion-sdk/scene lets you and your coding agent write scenes in TypeScript instead of hand-written JSON. The types are generated from the Rust spec, so a misspelled field, a wrong preset or a missing keyframe value fails to compile, and every field shows its docs on hover. What you build is still the plain scene document. JSON.stringify it, pass it to the player or render it with the CLI.

Installation

@motion-sdk/scene isn't on npm yet. In the repository it's a workspace package:

Terminal
npm install
package.json
{
  "dependencies": {
    "@motion-sdk/scene": "0.1.0",
    "@motion-sdk/core": "0.1.0"
  }
}

The package has no runtime dependencies and ships TypeScript source. Use it from Node 24 (type stripping), Vite, Next.js or any bundler.

Define a Scene

defineScene takes a Scene and returns it unchanged. It exists for the types: autocomplete for every field, docs on hover, and errors for anything the engine would reject.

scene.ts
import { defineScene, key, mesh, spring, text, track } from "@motion-sdk/scene"

export default defineScene({
  canvas: { width: 1080, height: 1080, fps: 30 },
  materials: { chrome: { preset: "chrome" } },
  nodes: {
    orb: { mesh: mesh({ sphere: { radius: 1 } }, { material: "chrome" }) },
    title: { transform: { position: [0, -1.8, 0] }, text: text("hello", { size: 0.5 }) },
  },
  timeline: {
    duration: 3,
    tracks: {
      bob: track("orb", "position", [key(0, [0, 0, 0]), key(1.5, [0, 0.6, 0], spring({ damping: 10 })), key(3, [0, 0, 0])]),
      fade: track("title", "opacity", [key(0, 0), key(0.6, 1, "ease_out_cubic")]),
    },
  },
})

Plain object literals work too. satisfies Scene gives the same checks without any helper:

scene.ts
import type { Scene } from "@motion-sdk/scene"

export default {
  nodes: { orb: { mesh: { geometry: { sphere: {} }, material: "preset:chrome" } } },
} satisfies Scene

Render it like any other scene:

Terminal
node -e 'import("./scene.ts").then((m) => console.log(JSON.stringify(m.default)))' > scene.json
motion-sdk render scene.json -t 1 -o frame.png

What the Compiler Catches

The generated types are exact. Single-key variants such as geometry, lights and easing are exclusive, colors are hex strings, and vectors are tuples.

agent.ts
defineScene({
  nodes: { orb: { transform: { positon: [0, 1, 0] } } },
  materials: { chrome: { preset: "chrom" } },
  timeline: { tracks: { bob: track("orb", "position", [key(0, 1)]) } },
})
tsc
error TS2561: Object literal may only specify known properties, but 'positon' does not exist in type 'Transform'. Did you mean to write 'position'?
error TS2820: Type '"chrom"' is not assignable to type 'MaterialPreset | null | undefined'. Did you mean '"chrome"'?
error TS2322: Type 'TypedKeyframe<1>' is not assignable to type 'TypedKeyframe<Vec3>'.
  Type 'number' is not assignable to type 'Vec3'.

These messages are enough for an agent to fix the code without reading the docs. Run tsc --noEmit after each edit.

Helpers

Every helper returns plain JSON. They add types, not behaviour.

HelperReturnsDescription
defineScene(scene)SceneA complete scene.
node(node)NodeA node: mesh, text, particles, group or prefab placement.
mesh(geometry, options?)MeshA geometry with a material name and shadow options.
shape(shape, options?)MeshA 2D vector shape (rect, circle, ellipse, polygon, bezier).
text(content, options?)TextA text block.
material(material)MaterialA material for scene.materials.
light(light)LightA light for scene.lighting.lights.
camera(camera)CameraThe scene camera.
track(target, property, keys, options?)TrackA timeline track. Key values are typed by the property: [x, y, z] for position, a number for opacity, a hex color for color.
key(t, value, easing?)KeyframeA keyframe at t seconds.
spring(params?)EasingA damped spring easing.
cubicBezier(x1, y1, x2, y2)EasingA CSS-style bezier easing.
steps(n)EasingJump in n steps.
patch.add / replace / remove / move / copy / testPatchOpRFC 6902 ops with checked paths. See below.

Every spec type is exported too: Scene, Node, Material, Geometry, Track, Easing, Color, Vec3, PatchOp, Report, Issue and the rest. See the Scene reference for their fields.

Validate

The compiler checks shapes. The engine's validator checks everything else: dangling references, ranges, prefab expressions and the rules on the errors page. validate runs the same validator as the player and the CLI, in Node or the browser, with no canvas or GPU.

check.ts
import { formatIssues, validate } from "@motion-sdk/core/validate"

const report = await validate(
  {
    materials: { chrome: { preset: "chrome" } },
    nodes: { orb: { mesh: { geometry: { sphere: {} }, material: "chrom" } } },
  },
  { final: true },
)
if (report.issues.length) console.log(formatIssues(report))
Output
warning unused /materials/chrome: material `chrome` is not used by any node (fix: remove it or reference it from a mesh/text node via "material")
error dangling_ref /nodes/orb/mesh/material: material `chrom` is not defined (the default material is used meanwhile) (fix: did you mean material `chrome`?)

Each issue has a JSON Pointer path, a stable code, a message and a suggested_fix. final: true treats dangling references as errors. Leave it off while a scene is still streaming in, because the missing value may arrive in a later patch.

OptionTypeDefaultDescription
finalbooleanfalseValidate a finished document. Dangling references become errors.
wasmBufferSource | URL | Response | stringnext to the moduleWhere to load the authoring wasm from.

validate loads the authoring wasm bundle. The lean player bundle doesn't change. Without the wasm, use the CLI: motion-sdk validate scene.json --final --json prints the same report. See Validation.

Play It

createPlayer and player.load take a typed Scene or JSON text:

main.ts
import { createPlayer } from "@motion-sdk/core"
import scene from "./scene.ts"

const player = await createPlayer(canvas, scene)

Streaming Patches

patch builds RFC 6902 ops. The JSON Pointer is checked against the scene types, and the value is typed by its path.

live.ts
import { key, mesh, patch, track } from "@motion-sdk/scene"

player.patch([
  patch.replace("/materials/chrome/color", "#ffcc66"),
  patch.add("/nodes/ring", { mesh: mesh({ torus: { radius: 1.6, tube: 0.05 } }, { material: "chrome" }) }),
  patch.add("/timeline/tracks/ring_spin", track("ring", "rotation", [key(0, [90, 0, 0]), key(3, [90, 360, 0])])),
])

A typo in a path fails to compile:

tsc
error TS2345: Argument of type '"/nodes/orb/transfrom/position"' is not assignable to parameter of type '"not a scene path: /nodes/orb/transfrom/position"'.

PathValue<"/nodes/orb/transform/position"> is the type at a path (Vec3 here) if you build ops yourself. See Streaming for how the player applies them.

Examples

How the Types Stay Current

scripts/gen-types.mjs turns schema/*.schema.json into packages/scene/src/generated.ts, and the schema is generated from the Rust spec. CI fails when either file is stale. After changing the spec:

Terminal
UPDATE_SCHEMA=1 cargo test -p motion-sdk-spec schema
npm run gen:types

CI also type-checks every committed example scene against Scene, so the types never reject a scene the engine accepts.