Strata - v1.4.10
    Preparing search index...

    Class FABRIKSolver

    Forward And Backward Reaching Inverse Kinematics (FABRIK) Solver.

    Industry-standard IK algorithm used in games like The Witcher 3 and Uncharted. Provides fast, stable convergence for multi-bone chains like arms, tentacles, tails, and spines.

    When to use FABRIK:

    • Multi-segment chains (3+ bones)
    • Smooth, natural-looking motion
    • Arms, legs, tentacles, spines
    • When you need pole targets for elbow/knee direction

    Algorithm Overview:

    1. Backward Pass: Start at end effector, pull toward target
    2. Forward Pass: Start at root, restore correct bone lengths
    3. Repeat: Until target is reached or max iterations exceeded
    // Spider leg reaching for ground
    const legRoot = new THREE.Object3D();
    const legChain = createBoneChainFromLengths(
    legRoot,
    [0.2, 0.3, 0.25, 0.15] // 4-segment leg
    );

    const solver = new FABRIKSolver(
    0.001, // tolerance: stop when within 1mm of target
    20 // max iterations per frame
    );

    // Solve for foot position on terrain
    const groundTarget = new THREE.Vector3(1.5, 0, 0.5);
    const result = solver.solve(legChain, groundTarget);

    if (result.reached) {
    console.log(`Reached target in ${result.iterations} iterations`);
    solver.apply(legChain, result); // Apply rotations to bones
    } else {
    console.log(`Target out of reach by ${result.error.toFixed(3)}m`);
    }
    // Character arm with pole target for elbow direction
    const armChain = createBoneChainFromLengths(armRoot, [0.3, 0.25]);
    const solver = new FABRIKSolver();

    // Target is where the hand should go
    const handTarget = new THREE.Vector3(0.5, 1.5, 0.3);

    // Pole target controls where the elbow points
    const elbowPole = new THREE.Vector3(0, 1.5, 0.5); // Point elbow forward

    const result = solver.solve(armChain, handTarget, elbowPole);
    solver.apply(armChain, result);
    Index

    Constructors

    Methods

    Constructors

    • Create a new FABRIK solver.

      Parameters

      • tolerance: number = 0.001

        Distance threshold for convergence (meters). Default: 0.001

      • maxIterations: number = 20

        Maximum solver iterations per frame. Default: 20

      Returns FABRIKSolver

    Methods

    • Apply solved rotations to the bone chain.

      Takes the computed rotations from solve() and applies them to the actual Three.js objects. Call this after solving to update your scene.

      Parameters

      Returns void

      const result = solver.solve(chain, target);
      solver.apply(chain, result); // Bones now point toward target
    • Solve IK for a bone chain to reach a target position.

      Computes joint angles needed to position the end effector at the target. If the target is out of reach, the chain stretches as far as possible.

      Parameters

      • chain: BoneChain

        The bone chain to solve

      • target: Vector3

        World position the end effector should reach

      • Optionalpole: Vector3

        Optional pole target to control mid-joint orientation (e.g., elbow/knee direction)

      Returns IKSolverResult

      Solver result with positions, rotations, and convergence info

      const solver = new FABRIKSolver();
      const result = solver.solve(armChain, targetPos);

      // Check if solution is valid
      if (result.reached) {
      solver.apply(armChain, result);
      }

      // Monitor performance
      console.log(`Converged in ${result.iterations} iterations`);
      console.log(`Final error: ${result.error.toFixed(4)}m`);