Motion SDK

Models and Rigs

Import glTF 2.0 models, play their animation clips, and bend any mesh with bones.

glTF Models

{"model": {"src": "truck.glb", "fit": 2.4}} as a geometry imports a glTF 2.0 file: a .glb, or a .gltf with its buffers. src is a path next to the scene, a URL in the browser, or a data URI.

{
  "nodes": {
    "truck": { "mesh": { "geometry": { "model": { "src": "truck.glb", "fit": 2.4 } }, "material": "paint" } }
  }
}
  • fit scales the model so its largest side is that long, centred with its base at y = 0. glTF models face +z.
  • The node's material shades all of it. For several colours, add one node per part with "mesh": "<glTF mesh or node name>" and its own material.
  • "animation": {"clip": "Walk", "speed": 1, "offset": 0, "loop": true} plays one of the file's clips on scene time. Skinned characters bend with their skeleton. Omit clip for the first one. Without animation it draws in its rest pose.
  • It draws nothing until it has loaded. In the browser, models come with the authoring bundle.

Rigs

A capsule rigged with three bones, swaying on smooth curves.
{
  "camera": { "position": [0, 1.2, 6], "target": [0, 0.6, 0], "fov": 40 },
  "lighting": { "rig": "golden_hour" },
  "environment": {
    "background": {
      "radial_gradient": { "inner": "#1b2233", "outer": "#07090f" }
    }
  },
  "materials": {
    "floor": { "preset": "matte_clay", "color": "#2a2f3a" },
    "skin": { "preset": "velvet", "color": "#e07a5f" }
  },
  "nodes": {
    "floor": {
      "mesh": {
        "geometry": { "plane": { "size": [30, 30] } },
        "material": "floor"
      },
      "transform": { "rotation": [-90, 0, 0] }
    },
    "stalk": {
      "transform": { "position": [0, 1, 0] },
      "mesh": {
        "geometry": { "capsule": { "radius": 0.25, "length": 1.6 } },
        "material": "skin",
        "skin": { "bones": ["base", "mid", "tip"] }
      }
    },
    "base": { "transform": { "position": [0, 0.2, 0] } },
    "mid": { "parent": "base", "transform": { "position": [0, 0.8, 0] } },
    "tip": { "parent": "mid", "transform": { "position": [0, 0.8, 0] } }
  },
  "timeline": {
    "duration": 3,
    "loop": "loop",
    "tracks": {
      "bend_mid": {
        "target": "mid",
        "property": "rotation",
        "curve": "smooth",
        "keyframes": [
          { "t": 0, "value": [0, 0, -25] },
          { "t": 1.5, "value": [0, 0, 25] },
          { "t": 3, "value": [0, 0, -25] }
        ]
      },
      "bend_tip": {
        "target": "tip",
        "property": "rotation",
        "curve": "smooth",
        "keyframes": [
          { "t": 0, "value": [0, 0, -35] },
          { "t": 1.5, "value": [0, 0, 35] },
          { "t": 3, "value": [0, 0, -35] }
        ]
      }
    }
  }
}
A capsule rigged with three bones, swaying on smooth curves. apps/docs/examples/models.json · render it with motion-sdk render apps/docs/examples/models.json -t 1 -o models.png

skin.bones lists other nodes, root first, each a child of the one before. Empty nodes are fine. Vertices follow the nearest bones and blend smoothly across joints, measured in the bind pose (the bones' transforms). Keyframe the bones' rotation to bend it: tails, tentacles, limbs, a swaying stalk. Capsules and cylinders have rings to bend along, and a glTF model can be rigged too. Flat 2D shapes bend as well (see 2D Bone Rigs). Inside a prefab, bone names that match the prefab's own nodes refer to that copy's bones.

See examples/rig-octopus.json for eight bending tentacles.

API Reference

Model

Triangles from a glTF file, with its node transforms applied. The node's material shades it: give each part of a multi-material model its own node with mesh and material.

PropertyTypeDefaultDescription
animationModelAnimation—Play one of the file's animation clips: skinned characters bend with their skeleton, and animated parts move with their nodes. The clip runs on scene time, so it scrubs and loops with the timeline.
bonesmap of string—Drive glTF skin joints from scene nodes (glTF joint node name -> scene node id). Unmapped joints stay in their glTF rest pose (or follow their parent joint). Each mapped joint inherits the scene node's world delta from its rest transform, so articulated physics bodies or keyframed nodes can directly deform a rigged .glb.
fitnumber—Scale it so its largest side is this long, centred on the node with its base at y = 0 (default: the file's own units, metres in glTF). glTF models face +z.
meshstring—Only the glTF meshes or nodes with this name (default: all of them).
src*stringrequiredA data URI, a path next to the scene, or (in the browser) a URL.

ModelAnimation

Which glTF clip a model plays, and how fast.

PropertyTypeDefaultDescription
clipstring—The clip's name in the file (default: its first clip).
loopbooleantrueRepeat the clip (default); false plays it once and holds the last pose.
offsetnumber0Clip time, in seconds, at scene time 0 (offset copies so they don't move in step).
speednumber1Playback rate: 2 is double speed, negative plays backwards.

Skin

A procedural rig. Each vertex follows the bones nearest to it (weights blend smoothly across joints), measured in the bind pose: every node's transform without animation. Animate the bones (usually their rotation) and the mesh bends with them. A bone reaches from its origin to the origin of its first child in the list; the last bone in a chain is a point. Give the mesh enough rings to bend (capsules and cylinders have them).

PropertyTypeDefaultDescription
blendnumber—How far (world units) weights blend across a joint. Default: a quarter of the average bone length.
bones*string[]requiredNode ids, root first, e.g. ["hip", "knee", "ankle"] where each is a child of the one before.
weights[x, y][]—Hand weights that override the automatic ones: [vertex, bone] pins a vertex to a bone (its index in bones); a fraction blends to the next bone, e.g. [12, 1.5] is half bones[1], half bones[2].