Rig tool

Put a character on our animations, give it hair or a tail, and save the result. Pick one of the demo characters or load your own GLB. Check which bone plays which role, hang spring chains on it, and try it with any of the Universal Animation Library's clips, beside the mannequin they were made on. Save the recipe: applyRigRecipe puts the same rig on the same model in a game.

import { rigTool } from 'tosijs-3d/rig-tool'

preview.closest('tosi-example')?.style.setProperty('--tosi-example-height', '600px')
preview.append(rigTool())

Using it

It opens standing still in its REST pose (a T or an A), in the front view. A mesh with no skeleton of its own (an OBJ, or a GLB without one, like the weasels and the space marine) gets UAL's fitted to it from eight red markers on its body, Mixamo's way: drag each onto its joint (chin, groin, elbows, wrists, knees). They start where they are guessed from the outline. A model with a skeleton of its own shows a dot on the bone each role uses instead: tap a dot (it turns yellow), then the body where that bone is.

view snaps to a face (front, back, left, right, top, bottom), which is how you line a marker, joint or handle up with the flesh, and stands it still; free orbits. Turn on animate (or pick a clip) to see it move: a mesh whose markers or joints moved is bound to them again then (binding takes a second or two and shows nothing at rest). In a headset you are the camera, so the view only switches between still and playing.

The panel has these sections, its job first.

A recipe in a game

import { applyRigRecipe, readSkeleton, retargetClip } from 'tosijs-3d'

const rig = applyRigRecipe(scene, root, skeleton, recipe)
const walk = retargetClip(ualWalk, readSkeleton(ualSkeleton, ualRoot), rig.read, {
  scene,
  armSpaceDeg: recipe.armSpaceDeg,
})
walk.start(true)

The element rigTool() returns carries .rig: recipe (get a copy, set one to apply it), applied and load(model), for a page or an editor driving the tool.

rig.problems lists anything in the recipe the model does not have (a bone renamed since it was saved), and rig.springs the live chains, whose bones.params can be changed while it runs.

In an editor: mounting it in your scene

mountRigTool(b3d, options) opens the tool in a <tosi-b3d> you already have: an editor opens it on a character and keeps the recipe in its own document.

import { mountRigTool } from 'tosijs-3d/rig-tool'

const tool = mountRigTool(scene, {
  models: [{ label: 'hero', url: '/hero.glb' }],
  recipe: doc.recipe, // start from the document's
  files: false, // no save / load / copy, nothing kept in the browser
  stage: false, // no floor or light: the scene's own lighting
  camera: editorCamera, // driven, and put back exactly on unmount
})
tool.addEventListener('change', (e) => preview(e.detail.recipe))
tool.addEventListener('commit', (e) => doc.record(e.detail.recipe)) // an undo step
// …
tool.unmount() // everything it added goes; safe to call twice

Rigging one body for a host (the character builder does this): give it handleDone and the panel has done and cancel at its top. Done unmounts the tool and hands the callback the rig: the recipe, and the body bound from its markers (a rigged body, ready for buildBody and applyRigRecipe).

mountRigTool(scene, {
  models: [{ label: 'body', url: '/body.glb' }],
  recipe: { version: 1, binding }, // bind from these markers
  files: false,
  handleDone: ({ recipe, body }) => wear(body, recipe),
  handleCancel: () => {},
})