@pixi/3d
    Preparing search index...

    Class Skeleton

    The bones of a skinned Mesh3D, and their pose

    A Model3D builds one per skin in its file and gives it to every mesh that skin deforms, so you rarely build one yourself. The bones are numbered nodes: the joints that deform the mesh, plus the nodes above them. Each node's local position, rotation and scale sit in the flat arrays localPosition, localRotation and localScale.

    To pose a bone, write into those arrays and set dirty, or call setLocalTRS, which does both. In a Model3D, a bone with a mesh under it, such as a hand holding a sword, is also one of the model's nodes and follows that node, so move the node instead. The view recomputes a dirty skeleton's matrices before it draws. A playing animation rewrites the bones it drives on every update, so a change you make to one of those lasts only until then.

    A skeleton from a Model3D shares its parent, joints and inverseBindMatrices with every model built from the same source, so don't write into them. A skeleton holds no GPU memory.

    const skeleton = robot.skeletons[0];
    const head = skeleton.indexOf('Head');
    const half = Math.PI / 12;

    // Set the head's local rotation to 30 degrees around Y.
    skeleton.localRotation.set([0, Math.sin(half), 0, Math.cos(half)], head * 4);
    skeleton.dirty = true;

    SkeletonOptions For constructor options.

    Index
    dirty: boolean = true

    Whether the local pose changed since the last updateWorld

    Set it after writing into the local arrays; setLocalTRS and animations set it for you. While it's false, the view skips recomputing the matrices.

    skeleton.localScale.fill(1.5, head * 3, head * 3 + 3);
    skeleton.dirty = true;
    inverseBindMatrices: Float32Array

    One column-major 4x4 matrix per joint, taking a vertex from the bind pose into the joint's space

    jointCount: number = 0

    Number of joints, the nodes that deform the mesh

    joints: Int16Array

    The node index of each joint

    const handJoint = skeleton.joints.indexOf(skeleton.indexOf('Hand'));
    
    localPosition: Float32Array

    Local position of each node, three floats per node: x, y, z

    const hips = skeleton.indexOf('Hips') * 3;

    skeleton.localPosition[hips + 1] -= 0.2;
    skeleton.dirty = true;
    localRotation: Float32Array

    Local rotation of each node, a four-float quaternion per node: x, y, z, w

    const jaw = skeleton.indexOf('Jaw') * 4;

    skeleton.localRotation.set([Math.sin(open / 2), 0, 0, Math.cos(open / 2)], jaw);
    skeleton.dirty = true;
    localScale: Float32Array

    Local scale of each node, three floats per node: x, y, z

    A scale that differs between axes skews the lighting of the skin it moves, since the skin's normals aren't corrected for it.

    const head = skeleton.indexOf('Head') * 3;

    skeleton.localScale.fill(1.5, head, head + 3);
    skeleton.dirty = true;
    nodeCount: number = 0

    Number of nodes: the joints plus the nodes above them

    parent: Int16Array

    Parent of each node, as a node index, or -1 for a root

    const shoulder = skeleton.parent[skeleton.indexOf('UpperArm')];
    
    worldMatrix: Float32Array

    The skinning matrix of each joint, in joint order: its posed matrix times its inverse bind

    Each is three rows of four floats, row-major, without the bottom row, which is always 0, 0, 0, 1. updateWorld fills it, and the view uploads it only after a fill, so pose the local arrays rather than writing this.

    defaultOptions: Partial<SkeletonOptions> = {}

    Defaults for every new Skeleton, empty to start; an option passed as undefined keeps its default

    • Advanced

      Makes a node follow a scene-graph container's local position, rotation and scale

      A Model3D does this for a node above the joints that also holds meshes, so moving or animating that container moves the skin. The node follows until the skeleton is destroyed.

      Parameters

      • boneIndex: number

        Index of the node that follows src

      • src: Container3D

        The container to follow

      Returns void

      skeleton.bindContainerBone(skeleton.indexOf('Armature'), armature);
      
    • Stops the nodes following their containers, without destroying the containers

      A Model3D destroys its own skeletons. Calling it again does nothing.

      Returns void

      tailMesh.destroy();
      tail.destroy();
    • Returns the index of the node with a label

      A Model3D labels each node with its name in the file, or node_<n> for an unnamed one, where n is the node's index in the file.

      Parameters

      • label: string

        Node label to look up

      Returns number

      The node index for label

      const head = skeleton.indexOf('Head');
      

      When no node has label, or the skeleton was built without labels.

    • Sets a node's local position, rotation and scale, and marks the skeleton dirty

      Scale defaults to 1 on each axis, so leaving it out resets any scale the node had. The rotation is used as given, without normalizing, so pass a unit quaternion.

      Parameters

      • i: number

        Node index; indexOf finds it from a label

      • tx: number

        Translation X

      • ty: number

        Translation Y

      • tz: number

        Translation Z

      • qx: number

        Rotation quaternion X

      • qy: number

        Rotation quaternion Y

      • qz: number

        Rotation quaternion Z

      • qw: number

        Rotation quaternion W

      • sx: number = 1

        Scale X

      • sy: number = 1

        Scale Y

      • sz: number = 1

        Scale Z

      Returns void

      const tip = tail.indexOf('tip');

      tail.setLocalTRS(tip, 0, 1, 0, 0, 0, Math.sin(bend / 2), Math.cos(bend / 2));
    • Advanced

      Recomputes worldMatrix from the local pose, if the skeleton is dirty

      The view calls it every frame for each skeleton it draws, so call it yourself only to read worldMatrix before the next render. Bones bound with bindContainerBone copy their containers' transforms first, which can make the skeleton dirty.

      Returns void