haathWebXR

Feeding your own poses

updateFromPoses() runs the same pipeline as update() without an XRFrame. Use it for recorded playback, non-WebXR trackers, server-side validation, and unit tests.

import { Haath, XR_HAND_JOINTS, JOINT_COUNT, FLOATS_PER_JOINT } from '@treefour/haath';

const haath = new Haath();

// Option A: flat Float32Array, 25 joints x 7 floats (x, y, z, qx, qy, qz, qw) in XR_HAND_JOINTS order.
// Positions-only buffers (25 x 3) are accepted too.
const left = new Float32Array(JOINT_COUNT * FLOATS_PER_JOINT);

// Option B: joint name map with { position, orientation? } or plain { x, y, z }
const right = { wrist: { x: 0.2, y: 1.2, z: -0.3 }, 'index-finger-tip': { x: 0.25, y: 1.3, z: -0.45 } /* ... */ };

const state = haath.updateFromPoses(left, right, 1 / 90);

Pass null for a hand that is not present.

Synthetic hands for tests #

The repo's examples/shared/syntheticHand.js builds a valid 25-joint hand for every core sign, at any wrist position and direction. Move the wrist between frames to test strikes and claps:

import { Haath } from '@treefour/haath';
import { buildSyntheticHand } from './syntheticHand.js';

const haath = new Haath();
const buf = new Float32Array(175);
let state;
for (let f = 0; f < 20; f++) {
  const wrist = [0.18, 1.2, -0.3 - f * 0.04]; // 3.6 m/s forward at 90 Hz
  state = haath.updateFromPoses(null, buildSyntheticHand({ poseName: 'fist', hand: 'right', wristPos: wrist }, buf), 1 / 90, f * 11.1);
}
state.right.gesture; // 'punch'

Stateless helpers #

For custom pipelines, the pieces are exported on their own: classifyHandSign, evaluateFingerExtensions, promoteStrikeGesture, evaluateTriangleFromPoses, and evaluateBlastFromPoses.

Last updated 2026-11-16