What does animeant do?
A figure is a tree of nodes. Each node has a local transform relative to its parent. Clips, IK, springs and the ragdoll all write the same thing back, joint rotations (plus the root's position), so they combine freely and bones never stretch.
| Package | Use |
|---|---|
@animeant/core | Everything: nodes, figures, IK, tweens, clips, animator, physics, 2D and 3D. Zero deps, ESM. |
@animeant/canvas | Draw a 2D Figure on a <canvas> |
@animeant/three | FigureView for a 3D Figure3D in a three.js scene (three is a peer dep) |
@animeant/mcp | MCP server; see "With the MCP tools" below |
Conventions (get these right first)
2D (Figure, Node) | 3D (Figure3D, Node3D) | |
|---|---|---|
| Units | pixels | meters |
| Up | -y (y points down, screen space) | +y |
| Forward | n/a | +z; the figure's left is +x |
| Rotation | rotation (radians, + is clockwise on screen) | rx, ry, rz (radians, XYZ Euler) or a quaternion via setQuaternion |
| Channels | x y rotation scaleX scaleY | x y z rx ry rz scaleX scaleY scaleZ |
| Limits | limits: [min, max] | limits: { x?: [min, max], y?, z? }; an axis with min === max is locked |
- Code works in radians; clips may say
units: "deg"; the MCP tools always speak degrees. - A node's
x/y(/z)is its offset from the parent joint, so a bone's length is the child's offset. - Joint limits are enforced by
turn,constrain, IK and physics. Clips are not clamped.
Recipes
Load a rig and pose it (FK)
import { Figure, humanoid, degToRad } from "@animeant/core";
const fig = Figure.fromRig(humanoid); // nodes: hips spine neck head shoulderL/R elbowL/R handL/R hipL/R kneeL/R footL/R hair1-4
fig.node("shoulderR").rotation = degToRad(-40); // everything below follows
fig.node("elbowR").turn(degToRad(20)); // relative, limit-aware
const p = fig.node("handR").worldPosition; // {x, y}, lazily recomputed
IK
fig.chain("handR").solve({ x: 240, y: 120 }); // shoulder→elbow→hand, FABRIK
fig.chain("footL", 2).solve(target, { solver: "ccd" }); // CCD often better against tight limits
fig.chain(["spine", "neck", "head"]).solve(lookAt); // explicit, base first
// → { reached, error, iterations }
3D is the same API on Figure3D. Its default solver "auto" uses CCD when the chain has a hinge (elbow, knee) and FABRIK otherwise. Hinges stay hinges.
Clips and the Animator
import { Animator, humanoidClips, type Clip } from "@animeant/core";
const wave: Clip = {
name: "wave", duration: 1.2, loop: true, units: "deg",
tracks: { elbowR: { rotation: [[0, -20, "inOutSine"], [0.6, -70, "inOutSine"], [1.2, -20]] } },
};
const animator = new Animator(fig);
animator.play(humanoidClips.idle); // layer 0
animator.play(wave, { layer: 1, fade: 0.3 }); // blends over layer 0
// per step: animator.update(dt)
- Key =
[time, value, ease?]; the ease shapes the segment to the next key. - Eases:
linear inQuad outQuad inOutQuad inCubic outCubic inOutCubic outQuint inSine outSine inOutSine outExpo outCirc outBack inOutBack outElastic step, orcubicBezier(x1,y1,x2,y2)in code. - Same layer: crossfade by weighted average. Higher layer: blends over lower by its weight.
mode: "additive"adds the change from the clip's first key. - Root
x/y(/z)are always additive (root motion). If the host moves the root itself, callanimator.rebase(fig.root)beforeupdate. stop(layer?, fade?)fades out and returns to the base pose;clear()drops clips without touching the pose (use before handing the figure to a ragdoll).- Playback controls:
pb.pause() resume() seek(t),pb.speed,pb.weight,await pb.finished.
Tweens
const tweens = new Tweens();
tweens.to(fig.node("head"), { rotation: 0.3 }, { duration: 0.5, ease: "outBack" });
tweens.to(node3d, { rx: 0.4 }, { duration: 0.4, angles: ["rx"] }); // 3D: name angle keys
// per step: tweens.update(dt)
The loop
const ticker = new Ticker(); // fixed 1/120 s steps
ticker.onFixed((dt) => { animator.update(dt); tweens.update(dt); hair.step(dt); });
ticker.onFrame(() => renderer.draw(fig));
ticker.start(); // or ticker.advance(dt) for tests/offline
Recommended step order: place the root → animator.update → IK → tweens → springs/physics.
Physics (2D)
const hair = new SpringChain(fig.chain(["hair1", "hair2", "hair3", "hair4"]), { stiffness: 0.05, damping: 0.9 });
const ragdoll = new Ragdoll(fig, { bounds: { floor: 400 } });
animator.clear();
ragdoll.start({ x: 120, y: 0 }); // optional starting velocity, units/s
ragdoll.grab(fig.node("handR"), pointer); ragdoll.drag(pointer); ragdoll.release();
// per step: ragdoll.step(dt)
A perfectly symmetric pose can balance; ragdoll.impulse({ x: 40, y: 0 }, fig.node("head")) tips it.
Rendering
// 2D
const renderer = new CanvasRenderer(canvas); // handles devicePixelRatio
renderer.draw(fig, { focus: { node, amount: 1 }, floor: 400 });
// 3D
import { Figure3D, humanoid3d, humanoid3dClips } from "@animeant/core";
import { FigureView } from "@animeant/three";
const fig3 = Figure3D.fromRig(humanoid3d);
const view = new FigureView(fig3); // spheres + capsules + head
scene.add(view.object);
// per frame, after the figure changes: view.update();
// picking: view.pick(raycaster, ["handL", "handR"]) → node name | null
Bodies (3D models from the rig)
import { BodyView } from "@animeant/three";
const body = new BodyView(fig3); // build at rest; reads meta.body / meta.blobs / root meta.bodyColor
scene.add(body.object);
// per frame: body.update(); fades: body.opacity = 0.5 (dithered, no sorting)
meta.body: { r: [r0, r1], squash?: [side, front], color? }on a node gives the bone from its parent a tapered capsule.meta.blobs: [{ r: [rx, ry, rz], at?: [x, y, z], rot?, color? }]attaches ellipsoids (skulls, torsos, ears, eyes) to a node.- Presets with bodies:
dog3d(+dog3dClips.idle | trot | sit) andhominids.ape | australopithecus | habilis | erectus | sapiens, orhominid(params)for your own. hominidGait(rig, { stride, crouch, lean, armSwing, quadruped })→{ clip, height, speed }. Setfig.root.y = heightbefore playing; move the figure atspeedm/s to keep the feet planted.
Rig JSON
// 2D. One node has no parent. Offsets in px, rotations and limits in radians.
{ "name": "arm", "nodes": [
{ "name": "shoulder", "x": 100, "y": 100 },
{ "name": "elbow", "parent": "shoulder", "x": 50, "limits": [-2.6, 0] },
{ "name": "hand", "parent": "elbow", "x": 45 },
{ "name": "tail1", "parent": "shoulder", "x": -10, "meta": { "boneWidth": 2 } }
]}
// 3D. Meters, y up, faces +z.
{ "name": "leg", "dimensions": 3, "nodes": [
{ "name": "hip", "y": 0.9 },
{ "name": "knee", "parent": "hip", "y": -0.42, "limits": { "x": [0, 2.6], "y": [0, 0], "z": [0, 0] } },
{ "name": "foot", "parent": "knee", "y": -0.42 }
]}
meta is free-form for renderers and tools; core never reads it. Conventions the renderers follow: boneWidth (0 hides the bone, any number marks a decorative chain), hidden.
humanoid3d signs, for writing 3D clips
On a limb hanging down, negative rx swings it forward. +rz raises a left limb out to the side, -rz a right one. Elbows bend with negative rx, knees with positive rx. Spine, neck and head bend forward with positive rx. Presets: humanoid3dClips.idle | walk | wave.
Pitfalls
- Wrong sign on 2D y. Up is negative. A head above the neck has
y: -26. - Degrees in radian fields. Rig JSON and node properties are radians; only clips with
units: "deg"and the MCP tools take degrees. - Clip fights IK. A clip rewrites the channels it animates every step. Run IK after
animator.update, or blend IK over the clip. - Dragging a joint mid-clip does nothing. Same cause. Stop the clip, or drive that joint with IK after the animator.
- Non-uniform scale on 3D IK parents. World rotation ignores scale; keep scale uniform on anything a chain passes through.
- Expecting clips to respect limits. They don't;
validate_clip(MCP) warns about keys past limits. FigurevsFigure3D. They don't mix:ChainvsChain3D,CanvasRenderervsFigureView.Animatorworks with both.
With the MCP tools
If animeant MCP tools are connected (create_figure, solve_ik, …), use them to check work instead of guessing:
create_figurewithpreset: "humanoid"/"humanoid3d"or your rig JSON. Read the node list it returns.- Pose with
set_pose(degrees) orsolve_ik(world target).clampedToLimitstells you when a joint hit its limit. - Look at it:
render_figurereturns SVG; for 3D passview: "front" | "side" | "top" | "three-quarter"andmarkersto show targets. - Author motion with
build_clip(timed poses → clip JSON). It validates against the figure, so fix any errors or limit warnings, then preview frames withsample_clipat a few times and render each. export_rigbakes the current pose in as rest, for saving a new rest pose or a custom rig.
Ship the clip JSON from build_clip straight into code: animator.play(clipJson).