kalidokit

repository·main·Indexed 26 days ago

https://github.com/yeemachine/kalidokit

A blendshape and kinematics calculator for Mediapipe and TensorFlow.js Face, Eyes, Pose, and Finger tracking models. The library solves landmarks into usable blendshapes and rotations for animation, such as 3D avatars and VTubing, providing specialized solvers for face (FaceSolver), hands (HandSolver), and body pose (PoseSolver).

Tokens
1.7K
Snippets
0
Records
19
Agent score
90%

What's inside kalidokit

  1. Configure solver options with ISolveOptions

    main

    When using Kalidokit solvers, you can provide configuration via ISolveOptions. This interface defines the base settings for both face and pose solvers.

    Key properties:

    • runtime: Specifies the underlying engine. Defaults to `
  2. Calculate specific body parts using PoseSolver static methods

    main

    If you do not need a full body solve, PoseSolver exposes individual calculators as static methods:

    • PoseSolver.calcArms(lm3d): Calculates arm rotations.
    • PoseSolver.calcHips(lm3d, lm2d): Calculates hip position and spine rotation.
    • PoseSolver.calcLegs(lm3d): Calculates leg rotations.

    Note that calcHips requires both 3D and 2D landmarks, while calcArms and calcLegs primarily use 3D landmarks.

  3. Solve face landmarks with FaceSolver.solve()

    main

    The FaceSolver.solve static method is the primary entry point for calculating head, eye, brow, pupil, and mouth blendshapes and rotations from face landmarks. It accepts landmark results from either TensorFlow.js (tfjs) or MediaPipe (mediapipe).

    Parameters

    • lm: An array of landmark results (Results).
    • options (Partial<IFaceSolveOptions>):
      • runtime: Either "tfjs" (default) or "mediapipe". If using "mediapipe", providing imageSize is recommended for accurate calculations.
      • video: A string selector for a video element or an HTMLVideoElement instance. If provided, imageSize is automatically determined from the video dimensions.
      • imageSize: An object containing { width, height }. Required for accurate mediapipe calculations if video is not provided.
      • smoothBlink: Boolean. If true, applies the blink stabilizer to the eye results.
      • blinkSettings: An array of two numbers [low, high] to remap blink thresholds. Defaults to [0.55, 0.85] for tfjs and [0.35, 0.5] for mediapipe.
  4. Use HandSolver.solve() to calculate hand rotations

    main

    The HandSolver.solve() method calculates Euler rotations for the wrist and each finger segment (Proximal, Intermediate, and Distal) based on 3D hand landmarks. It accepts an array of 3D vectors (typically from MediaPipe or TensorFlow.js) and a side parameter to specify if the hand is LEFT or RIGHT.

    Returns an object containing the rotation values for the wrist and all finger joints, or undefined if no landmarks are provided.

  5. Solve full body pose with PoseSolver.solve()

    main

    The PoseSolver.solve() method is the primary entry point for calculating full body rotations and positions. It combines arm, hip, and leg calculations into a single result. It requires both 3D world pose landmarks and 2D pose landmarks.

    Parameters

    • lm3d: An array of 3D pose vectors (TFVectorPose).
    • lm2d: An array of 2D pose vectors (Omit<TFVectorPose, "z">).
    • options: An optional configuration object (Partial<IPoseSolveOptions>) containing:
      • runtime: Either `
  6. Configure PoseSolver runtime and video input

    main

    When calling PoseSolver.solve(), you can provide options to handle different landmark sources and automatic image scaling:

    • runtime: Set to "tfjs" or "mediapipe". If set to "tfjs", the solver will normalize the 2D landmarks using the provided imageSize (x/width, y/height).
    • video: Can be an HTMLVideoElement or a string selector (e.g., "#my-video"). If provided, the solver automatically extracts the videoWidth and videoHeight to use as imageSize.
    • imageSize: An object { width, height } used for normalizing landmarks if the runtime is "tfjs" and video is not provided.
  7. Reference coordinate and rotation types

    main

    Kalidokit uses several standard types for spatial data:

    • XYZ: A record of { x: number, y: number, z: number }.
    • LR<T>: A record mapping left and right sides to a type T (e.g., LR<Vector>).
    • RotationOrder: Valid strings are "XYZ" | "YZX" | "ZXY" | "XZY" | "YXZ" | "ZYX".
    • EulerRotation: An XYZ object that can optionally include a rotationOrder.
    • Side: Represents LEFT or RIGHT orientation.
  8. Reference the TPose output format

    main

    The PoseSolver.solve() method returns a TPose object (or undefined if landmarks are missing). The object contains the following keys:

    • RightUpperArm
    • RightLowerArm
    • LeftUpperArm
    • LeftLowerArm
    • RightHand
    • LeftHand
    • RightUpperLeg (Defaults to RestingDefault.Pose.RightUpperLeg if enableLegs is false)
    • RightLowerLeg (Defaults to RestingDefault.Pose.RightLowerLeg if enableLegs is false)
    • LeftUpperLeg (Defaults to RestingDefault.Pose.LeftUpperLeg if enableLegs is false)
    • LeftLowerLeg (Defaults to RestingDefault.Pose.LeftLowerLeg if enableLegs is false)
    • Hips
    • Spine
  9. Configure face solver options with IFaceSolveOptions

    main

    The IFaceSolveOptions interface extends ISolveOptions with specific settings for facial tracking.

    Key properties:

    • smoothBlink: A boolean to toggle blink smoothing. Defaults to false.
    • blinkSettings: An array of numbers used to configure blink behavior.
  10. Understand the TPose output format

    main

    The TPose type represents the processed body pose data. It maps specific body parts to rotation or position data.

    Key joints included:

    • RightUpperArm, RightLowerArm, LeftUpperArm, LeftLowerArm (Euler rotations)
    • RightHand, LeftHand (Vectors)
    • RightUpperLeg, RightLowerLeg, LeftUpperLeg, LeftLowerLeg (Euler or XYZ)
    • Hips: An IHips object containing position, optional rotation, and optional worldPosition.
    • Spine: A Vector or XYZ position.