mwg API
    Preparing search index...

    Interface Bone

    Skeletal pose math, renderer-free: a bone tree, keyframed clips, and layered blending.

    The pose half of a skeletal puppet (roadmap 399), as pure data and arithmetic so it loads headless and tests without a renderer - the same split every other module draws. A bone is a name, a parent name, a length and a local rotation; a pose is one rotation per bone, with optional per-bone translations and scales riding the same timeline; resolving a pose walks the tree so rotating an arm, a leg or a head is one number on one bone and the rest of the body follows. Clips are keyframed poses over time - plain data a game authors in JSON, never code, and never a borrowed game's animation data - with interpolation, looping, a playback rate and a crossfade between clips. Additive layers (aim on top of walk, hurt on top of idle) mix by priority, so a game composes motion instead of authoring every combination as its own clip.

    import * as Skeleton from '@datamoc/mwg/skeleton';

    const puppet = Skeleton.create([
    { name: 'body' },
    { name: 'arm', parent: 'body', length: 12 },
    ]);
    const mixer = Skeleton.createMixer(puppet, { id: 'idle', duration: 2, loop: true, frames: [
    { time: 0, rotations: {} },
    { time: 1, rotations: { arm: 90 } },
    ] });
    Skeleton.advance(mixer, 1); // the arm swings up over one second
    const pose = Skeleton.advance(mixer, 1); // the arm swings up over one second
    const arm = Skeleton.resolve(puppet, pose)[1]; // world x, y and angle per bone
    interface Bone {
        length?: number;
        limits?: { max: number; min: number };
        name: string;
        origin?: { x: number; y: number };
        parent?: string;
        rotation?: number;
    }
    Index
    length?: number

    how far the bone reaches from its base, world units

    limits?: { max: number; min: number }

    absolute local-angle bounds, degrees; out-of-range poses fail at sample time

    name: string

    unique within one skeleton

    origin?: { x: number; y: number }

    the bone's own offset from its parent's tip, before any pose

    parent?: string

    the parent bone's name; the roots have none

    rotation?: number

    the bone's rest rotation, degrees