# haath documentation (full text) Source: https://haath.treefour.studio/ ยท Version 0.0.4 --- URL: https://haath.treefour.studio/getting-started/ # Getting started with haath # Getting started haath is a zero-dependency WebXR hand tracking library. Create one `Haath`, call `update()` once per XR frame, and read hand signs, punches, slaps, claps, and other gestures from `haath.state`. ## Install ```bash npm i @treefour/haath ``` haath ships ESM and CJS builds with TypeScript types. It has zero runtime dependencies, so it works with Three.js, IWSDK, Babylon.js, React Three Fiber, PlayCanvas, or a raw WebXR loop. ## Request hand tracking Your XR session must ask for the `hand-tracking` feature: ```ts navigator.xr.requestSession('immersive-vr', { optionalFeatures: ['hand-tracking'] }); ``` On Meta Quest, hand tracking also has to be on in the headset settings. ## Three.js ```ts import { Haath } from '@treefour/haath'; const haath = new Haath(); let last = performance.now(); renderer.setAnimationLoop((_time, frame) => { const now = performance.now(); const dt = (now - last) / 1000; // seconds last = now; if (frame) { const session = renderer.xr.getSession(); const refSpace = renderer.xr.getReferenceSpace(); const state = haath.update(frame, refSpace, session?.inputSources, dt, now); if (state.right.tracked && state.right.gesture === 'punch') { console.log('right punch at', state.right.motionSpeed.toFixed(2), 'm/s'); } if (state.twoHand.clap.doubleClap) openPauseMenu(); } renderer.render(scene, camera); }); ``` ## IWSDK (Meta Immersive Web SDK) This is how DunJun runs haath. Keep one instance on a system and let other systems read `haath.state`. ```ts import { createSystem } from '@iwsdk/core'; import { Haath } from '@treefour/haath'; export class HandSystem extends createSystem({}) { haath = new Haath({ punchSpeed: 1.3, slapSpeed: 1.8 }); update(delta: number) { const xr = this.world.renderer.xr; if (!xr.isPresenting) return; const frame = xr.getFrame(); const session = xr.getSession(); if (!frame || !session) return; // delta is seconds (IWSDK clock), which is what haath expects this.haath.update(frame, xr.getReferenceSpace(), session.inputSources, delta); } } // elsewhere: this.world.getSystem(HandSystem).haath.state.left.gesture ``` > Create only one `Haath` per app. Velocity, circle history, and clap timing live inside the instance, so a second copy would see different motion. ## Entry points - `@treefour/haath`: the `Haath` engine (signs, strikes, circle, clap, triangle, blast), `HoldRecognizer`, colliders, vector math, constants, and types. - `@treefour/haath/v2`: [compositional engine](/v2/) with pose packs (including ASL), motion states, trajectory shapes, micro-gestures, and two-hand compounds. - `@treefour/haath/debug`: [DOM overlay](/debug-overlay/) with live signs, kinematics, and spells. - `@treefour/haath/emulator`: [PC hand emulator](/emulator/) for desktop testing with IWER. ## Next steps - [Read the hand state](/hand-state/): every field `update()` returns. - [Recipes](/recipes/): punch hits, hold-to-confirm menus, gun aim, spells. - [Examples](/examples/): runnable apps, including one that needs no headset. --- URL: https://haath.treefour.studio/hand-state/ # Reading hand state # Reading hand state `haath.update()` returns `haath.state`, with `left`, `right`, and `twoHand`. It is the same object every frame, updated in place. Positions are in the reference space you pass in, in metres, with forward as `-Z`. ## Per hand: state.left and state.right - `tracked`: false when the hand is missing or fails the anatomical sanity check. Other fields keep their last values. - `sign`: static hand shape. One of `open`, `fist`, `thehro` (open palm up), `niche` (open palm down), `gun`, `poke`, `pinch`, `thumb`, `thumbsup`, `thumbsdown`, `telephone` (shaka), `rock-horns`, `birdie-1`, `birdie-2`, `pinkie-out`, `unknown`, `idle`. - `gesture`: the `sign`, promoted to `punch` (fist faster than `punchSpeed`) or `slap` (open hand faster than `slapSpeed`). Use this for combat. - `fingers`: `{ thumb, index, middle, ring, pinky, count }` extension booleans plus a 0 to 5 count. - `motionSpeed`: speed in m/s, sampled at the ring finger tip so it captures arm swing and wrist whip. - `velocity`: `[vx, vy, vz]` in m/s. - `wristPosition`, `palmPosition`, `palmCenter`, `indexTipPosition`: `Float32Array` positions. - `palmQuaternion`: `[x, y, z, w]` at the index proximal joint. - `palmForward`: unit vector out of the fingers. - `aimOrigin`, `aimDirection`: a stable aim ray from the XR target ray. It stays steady during pinch and curl so it does not dip to the floor. Use it for guns and pointers. - `circle`: `{ triggered, centroid, normal, meanRadius, revolutions }`. `triggered` is true on the frame a circle completes. ## Sign table Fingers are listed as thumb, index, middle, ring, pinky. `1` is extended, `0` is curled, `*` is either. - `fist`: (*, 0, 0, 0, 0) - `open`, `thehro`, `niche`: (*, 1, 1, 1, 1), split by palm direction - `gun`: (*, 1, 1, 0, 0) or (1, 1, 0, 0, 0) - `poke`: (0, 1, 0, 0, 0) - `rock-horns`: (1, 1, 0, 0, 1) - `telephone` (shaka): (1, 0, 0, 0, 1) - `pinkie-out`: (0, 0, 0, 0, 1) - `birdie-1`: (0, 0, 1, 0, 0). `birdie-2`: (1, 0, 1, 0, 0) - `pinch`: index curled and thumb tip within `pinchDist` of the index tip - `thumbsup`, `thumbsdown`, `thumb`: only the thumb out, split by thumb direction Finger extension uses bone-segment dot products, not wrist-to-tip distance. That makes signs work at any hand size, wrist angle, or arm reach. ## Two hands: state.twoHand - `fingerCount`: 0 to 10 extended fingers across tracked hands. Good for finger-count menus. - `handsCrossed`, `wristDistance`. - `clap`: `{ state, singleClap, doubleClap }`. `singleClap` and `doubleClap` are true for one frame. - `triangle`: `{ active, centroid, normal }`. Index tips together and thumbs together. `normal` always points away from the player (`z <= 0`). - `blast`: `{ active, triggered, charge, origin, direction }`. Two palms pushed forward together, with `charge` from 0 to 1. ## One-frame flags `clap.singleClap`, `clap.doubleClap`, `circle.triggered`, and `blast.triggered` are true for a single frame. Read them in the same frame you call `update()`. --- URL: https://haath.treefour.studio/recipes/ # Recipes for WebXR hand gestures # Recipes Short, tested patterns for the most common hand-tracked game mechanics. Each one reads `haath.state` after `update()` in the same frame. ## Detect a punch or slap with momentum A fist moving faster than `punchSpeed` (1.3 m/s) becomes `punch`. An open hand faster than `slapSpeed` (1.8 m/s) becomes `slap`. ```ts const hand = haath.state.right; if (hand.gesture === 'punch' || hand.gesture === 'slap') { const mass = 1.5; // kg, tune per game applyHit(enemy, hand.velocity[0] * mass, hand.velocity[1] * mass, hand.velocity[2] * mass); } ``` ## Hit enemies with the whole hand `testHandSphere()` tests a target sphere against the palm, wrist, and index tip spheres. It also tests a swept palm segment, so fast hands cannot pass through a target between frames. Create the options object once. ```ts import { CollisionCooldownTracker, type HandSphereTestOptions } from '@treefour/haath'; const cooldown = new CollisionCooldownTracker(200); // ms per (target, hand, gesture) const opts: HandSphereTestOptions = { mode: 'combat', // needs a non-idle gesture requiredGesture: ['punch', 'slap', 'poke'], cooldown, }; for (const enemy of enemies) { opts.targetId = enemy.id; opts.prevTargetX = enemy.prev.x; opts.prevTargetY = enemy.prev.y; opts.prevTargetZ = enemy.prev.z; const part = haath.testHandSphere('right', enemy.pos.x, enemy.pos.y, enemy.pos.z, enemy.radius, opts); if (part !== 'none') damage(enemy, part); // 'palm' | 'wrist' | 'indexTip' | 'sweep' } ``` Use `mode: 'touch'` (any tracked pose) for buttons and pickups. ## Hold a sign to confirm `HoldRecognizer` fires once a value stays stable for a set time. It returns a 0 to 1 progress value for a loading ring. ```ts import { HoldRecognizer } from '@treefour/haath'; const confirm = new HoldRecognizer({ holdDurationMs: 1000, stabilityFrames: 10, cooldownMs: 800 }); // per frame (dt in seconds or ms, both accepted) const hold = confirm.update(haath.state.right.sign === 'thumbsup' ? 'thumbsup' : null, dt); progressRing.value = hold.progress; if (hold.triggered) startGame(); ``` It also works with numbers, for example `confirm.update(haath.state.twoHand.fingerCount, dt)` for finger-count menus. ## Finger gun and pointer ```ts const r = haath.state.right; if (r.sign === 'gun') fireBullet(r.aimOrigin, r.aimDirection); ``` `aimOrigin` and `aimDirection` come from the XR target ray and stay steady while fingers curl. ## Circle spell and triangle laser ```ts import { intersectLaserSphere, intersectDiscSphere } from '@treefour/haath'; const c = haath.state.right.circle; if (c.triggered) { spawnDisc(c.centroid, c.normal, c.meanRadius); haath.resetCircle('right'); // clear history so it cannot re-fire } const tri = haath.state.twoHand.triangle; if (tri.active) { for (const e of enemies) { // origin, direction, length (m), beam width (m), target, target radius if (intersectLaserSphere(tri.centroid, tri.normal, 12, 0.25, e.posArray, e.radius)) burn(e); } } // Spinning disc vs enemy: position, normal, disc radius, tube thickness, target, radius intersectDiscSphere(disc.pos, disc.normal, 0.3, 0.05, e.posArray, e.radius); ``` Circles are detected in any 3D plane: haath fits a plane to the wrist path, so vertical, flat, and tilted circles all count. ## Two-palm blast ```ts const b = haath.state.twoHand.blast; chargeBar.value = b.charge; if (b.triggered) fireBlast(b.origin, b.direction); ``` ## Double clap to pause ```ts if (haath.state.twoHand.clap.doubleClap) togglePause(); ``` The clap detector uses separate contact (0.17 m) and release (0.195 m) distances, so it stays reliable when the headset briefly loses one hand during a fast clap. --- URL: https://haath.treefour.studio/configuration/ # Configuration and thresholds # Configuration Every threshold is optional. The defaults are the values DunJun ships with. ```ts const haath = new Haath({ punchSpeed: 1.3, // m/s, fist promoted to 'punch' slapSpeed: 1.8, // m/s, open hand promoted to 'slap' pinchDist: 0.03, // m, thumb tip to index tip curlDot: 0.6, // bone-segment dot product above which a finger counts as extended useCurlDetection: true,// false = legacy wrist-to-tip distance mode thumbOpenDist: 0.07, // legacy mode only fingerOpenDist: 0.10, // legacy mode only directionThreshold: 0.72, // thumbs up/down, palm up/down split minBoneLength: 0.03, // m, rejects collapsed / garbage tracking frames // two-hand triangleTipDist: 0.12, triangleThumbDist: 0.14, triangleFingerDot: 0.35, clapContactDist: 0.17, clapSeparationDist: 0.195, clapOriginMinDist: 0.05, clapDoubleMinMs: 90, clapDoubleMaxMs: 1100, // circle circleHistoryFrames: 90, circleMinSamples: 30, circleMinRadius: 0.06, circleMaxIrregularity: 0.55, circleMinRevolutions: 1.2, discFireCooldownMs: 800, // blast blastPalmDist: 0.30, blastForwardDot: -0.4, blastChargeDurationMs: 600, blastThrustSpeed: 1.0, blastCooldownMs: 800, }); ``` ## Exported constants All defaults are also exported as constants, for example `PUNCH_SPEED`, `SLAP_SPEED`, `PINCH_DIST`, and `CLAP_CONTACT_DIST`. The joint layout is exported as `XR_HAND_JOINTS` (the 25 WebXR joint names in order) and `JOINT_INDEX` (name to index). ## Tuning tips - Lower `punchSpeed` for seated or casual games. Raise it if idle fists read as punches. - Raise `pinchDist` slightly for users with large hands or noisy tracking. - `circleMinRevolutions` below 1.0 makes circles easy to trigger by accident. --- URL: https://haath.treefour.studio/custom-poses/ # Feeding your own hand poses # 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. ```ts 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: ```js 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`. --- URL: https://haath.treefour.studio/v2/ # v2 compositional gesture engine # v2 compositional engine `@treefour/haath/v2` layers richer recognition on the same 25-joint buffers as the core engine. It adds named static poses with confidence scores (a core pack and an ASL alphabet pack), motion states, 3D trajectory shapes, micro-gestures, and two-hand compound gestures. > v2 is newer than the core engine and has not shipped in a production game yet. The pose classifier starts empty, so always pass a pose pack. ## Setup ```ts import { Haath } from '@treefour/haath'; import { CompositionalGestureEngine, CoreStaticPosePack, ASLStaticPosePack } from '@treefour/haath/v2'; const haath = new Haath(); const v2 = new CompositionalGestureEngine({ pose: { poses: [...CoreStaticPosePack, ...ASLStaticPosePack] } }); // per frame, after haath.update(...): reuse haath's joint buffers const L = haath.leftRecognizer, R = haath.rightRecognizer; const res = v2.update( haath.state.left.tracked ? L.getHistoryBuffer() : null, L.getFrameOffset(0), haath.state.right.tracked ? R.getHistoryBuffer() : null, R.getFrameOffset(0), dt, ); ``` ## What it returns ```ts res.right.pose?.name; // 'peace', 'asl_v', ... with res.right.pose.confidence res.right.motion.state; // 'STATIONARY' | 'MICRO_MOVING' | 'TRANSLATING' | 'BALLISTIC' res.right.trajectory.gesture; // 'circle_cw', 'line_swipe', 'infinity', 'star', ... or null res.right.micro.active; // 'money_rub', 'thumb_index_tap', 'finger_snap', ... res.bimanual.kamehameha.triggered; // also: bow, portal, timeout (T sign), dial ``` ## Custom poses Describe each finger as extended or curled, with an optional `match()` scorer and a priority: ```ts v2.pose.right.registerPose({ name: 'spidey', category: 'custom', fingers: { thumb: 'extended', index: 'extended', middle: 'curled', ring: 'curled', pinky: 'extended' }, priority: 1.1, }); ``` --- URL: https://haath.treefour.studio/emulator/ # PC hand emulator for WebXR # PC hand emulator `@treefour/haath/emulator` lets you play and debug hand-tracked WebXR apps on a desktop, without a headset. It drives [IWER](https://github.com/meta-quest/immersive-web-emulation-runtime) emulated hands, and adds a floating panel per hand, keyboard control, and finger poses IWER does not ship: fist, horns, thumbs up and down, shaka, and a two-finger gun. Real recognition still runs. The emulator poses IWER's joints, so `haath.update()` classifies them like real hands. > Experimental. The emulator relies on IWER internals that are not public API. It never imports IWER and guards every access, so an IWER change turns it into a no-op instead of a crash. Load it only in development builds. ## Setup IWSDK apps already run IWER in dev through `@iwsdk/vite-plugin-iwer`. In any other app, install IWER first and switch it to hands: ```ts import { XRDevice, metaQuest3 } from 'iwer'; import { DevUI } from '@iwer/devui'; const device = new XRDevice(metaQuest3); device.installRuntime({ forceInstall: true }); // desktop Chrome has a native navigator.xr device.primaryInputMode = 'hand'; new DevUI(device); ``` Then attach the emulator: ```ts import { createHandEmulator } from '@treefour/haath/emulator'; if (import.meta.env.DEV) { const emu = createHandEmulator({ getSession: () => renderer.xr.getSession(), hooks: { onPose: (target, pose, gesture, fingerCount) => { /* target: 'left' | 'right' | 'both' */ }, onStrike: (hand, kind, velocity) => { /* animated strike started */ }, onStrikeEnd: (hand, gesture) => { /* hand returned to its held pose */ }, onClap: () => { /* Double Clap button */ }, onCircleStart: (hand) => {}, onCircle: (hand, gesture) => { /* circle trace finished */ }, onResetToOpen: () => {}, }, }); // emu.setPose('thumbs_up', 'right'); emu.triggerClap(); emu.resetToOpenPalm(); emu.destroy(); } ``` The panels appear only while the session has hand input sources. Hooks are optional. Use them when game logic needs a gesture faster than velocity promotion gives it, for example mapping `onClap` to a pause overlay. ## Keys Keys are `KeyboardEvent.code` values. Override any map with `keyMap: { move, hold, strike }`. - Left hand: `W A S D` move. Hold `1` punch, `2` slap, `3` poke, `4` gun, `Q` thumbs up, `E` thumbs down, `R` horns, `T` shaka. - Right hand: arrow keys move. Hold `U` punch, `I` slap, `O` poke, `P` gun, `J` thumbs up, `K` thumbs down, `L` horns, `;` shaka. - Hold a key to keep a pose. Releasing it restores the previous pose. Clicking a chip in the panel keeps the pose until you click it again. - Punch, slap, and poke are static stances. The hand holds a fist, open palm, or pointed finger and reports the strike gesture, and you steer it into targets with the move keys. Animated lunges are available through `triggerStrike()` or the `keyMap.strike` map. - Movement starts at 0.3 m/s and speeds up to 1.5 m/s while you hold the key (`moveSpeed: { min, max, rampSeconds }`). Travel is clamped by `moveLimit` (0.8 m). - `Shift` + `WASD` and `Shift` + arrows stay with IWER DevUI for headset movement. ## Options - `getSession()` (required): returns the active `XRSession` or null. - `hooks`: the callbacks above, all optional. - `gestureMap`: override the gesture string reported for each pose. See `DEFAULT_EMULATOR_GESTURE_MAP`. - `keyMap`: partial `{ move, hold, strike }` maps. See `DEFAULT_EMULATOR_KEYMAP`. - `moveSpeed`, `moveLimit`: movement tuning. - `debug`: log `[HaathEmu]` lines to the console. Hands move by driving the IWER DevUI transform handle, so the gizmo, target ray, and IWER position readout follow the hand. ## Try it [Example 04](/examples/) runs a Three.js scene with IWER and the emulator in a desktop browser. --- URL: https://haath.treefour.studio/debug-overlay/ # Debug overlay # Debug overlay `@treefour/haath/debug` draws a small DOM panel with live signs, finger states, speeds, and spell triggers. It is useful on desktop with the emulator and in the Quest browser before entering VR. ```ts import { initGesturePreview } from '@treefour/haath/debug'; const preview = initGesturePreview({ position: 'top-right', showKinematics: true, showSigns: true, showSpells: true }); // per frame, after haath.update(...) preview.update(haath.state); // later preview.setVisible(false); preview.destroy(); ``` `position` accepts `top-left`, `top-right`, `bottom-left`, and `bottom-right`. Outside a browser (`document` undefined) it returns a no-op controller, so it is safe to import in tests. --- URL: https://haath.treefour.studio/examples/ # Examples # Examples The examples live in the [examples folder on GitHub](https://github.com/sma1692/haath/tree/main/examples). The browser examples need no install step: each page loads haath from the repo's `dist/` and Three.js or IWER from a CDN through an import map. ```bash git clone https://github.com/sma1692/haath.git cd haath npm install npm run examples ``` Then open `http://localhost:5173/examples/`. ## 01: Three.js A plain Three.js WebXR scene. It covers the per-frame `update()`, reading signs, punch and slap hits on orbs with `testHandSphere()`, and a thumbs-up hold with `HoldRecognizer` to reset. Needs a headset with hand tracking, or example 04. ## 02: IWSDK systems Code-only systems for `@iwsdk/core`: `HandSystem` owns the engine, `MenuSystem` handles double clap and hold-to-confirm, and `CombatSystem` does contact hits. Copy them into a project made with `npm create @iwsdk@latest`. ## 03: Pose playback (no headset) Synthetic 25-joint hands go through `updateFromPoses()`. Pick a pose for each hand, trigger a punch, slap, or double clap, and watch `haath.state` update. The live demo on the [home page](/) is this example. ## 04: PC hand emulator Example 01 in a desktop browser. IWER emulates a Quest 3 with hands, and `@treefour/haath/emulator` adds the hand panels and keyboard control. ## Testing on a Quest WebXR needs a secure context. `localhost` works, but a LAN IP needs HTTPS. Over USB, forward the port and open localhost in the Quest browser: ```bash adb reverse tcp:5173 tcp:5173 ``` --- URL: https://haath.treefour.studio/performance/ # Performance on Meta Quest # Performance haath is built for 72 to 120 Hz render loops on Quest-class mobile chips. Per-hand classification is a fixed pass over 25 joints, and hit tests are closed-form sphere, cylinder, and disc checks instead of raycasts. ## Rules - `update()` and `updateFromPoses()` allocate nothing per frame. `haath.state` and its arrays are reused, so copy values out if you need them after the frame. - Reuse option objects passed to per-frame calls, such as `HandSphereTestOptions`, instead of creating literals in the loop. - Call `update()` exactly once per XR frame with a real `deltaSeconds`. Velocity, clap timing, and circle history depend on it. - One-frame flags (`clap.singleClap`, `clap.doubleClap`, `circle.triggered`, `blast.triggered`, `hold.triggered`) are true for a single frame. Read them in the same frame. ## Cost - Hand vs enemy: one sphere distance check per enemy per hand. 20 enemies and 2 hands is 40 checks a frame. - Triangle laser and circle disc: vector projection only, no mesh triangles. - Collision with a BVH raycaster (for example three-mesh-bvh) does far more work per frame for no extra accuracy in arcade combat. --- URL: https://haath.treefour.studio/why-haath/ # Why haath # Why haath Most WebXR hand libraries stop at static pose detection. haath also handles motion, two-hand geometry, and hit testing, with the same per-frame budget. ## Geometry instead of templates Template libraries compare live joints against recorded wrist-relative snapshots. Hand size, wrist tilt, and punch angle make that distance drift, which causes misses. haath uses the hand's own geometry: - **Finger curl from bone segments.** A finger counts as extended when its consecutive bone vectors (metacarpal to tip) point the same way (`dot > 0.6`). This does not change with hand rotation, camera angle, or arm reach. - **Self-normalizing thumb test.** The thumb is out when the thumb tip is farther from the middle finger than the palm is wide. The player's own palm is the ruler, so it works for any hand size. - **Pinch guard.** Pinch requires a curled index, so a pointing or gun finger never misfires as a pinch. ## Zero-frame strike latency Physics engines in a Web Worker return results a frame or two later and can drop contact events across the worker boundary. haath runs on the main thread inside the same `XRFrame`: it samples joint poses, computes velocity, resolves hits, and records momentum before the frame renders. ## Motion and two-hand math - **Velocity gate.** Speed is sampled at the ring finger tip, which captures arm swing and wrist whip. A fist above 1.3 m/s is a punch, an open hand above 1.8 m/s is a slap. - **Triangle laser.** Both index tips and thumbs define a 3D plane. The beam follows its normal, locked to point away from the player, so players aim by tilting their hands. - **Occlusion-proof double clap.** Fast claps hide one palm from Quest cameras. Separate contact and release distances keep the detector stable through that. - **Circles in any plane.** A 90-frame wrist history is fit to a 3D plane with Newell's method, checked for roundness, and the swept angle is integrated. Vertical, flat, and tilted circles all count. ## Battle-tested haath came out of DunJun, a hand-tracked WebXR brawler on Meta Quest, where it runs every punch, slap, spell, and menu. --- URL: https://haath.treefour.studio/faq/ # FAQ # Frequently asked questions ### What is haath? haath (npm package `@treefour/haath`) is an open-source JavaScript and TypeScript library for WebXR hand tracking and gesture recognition. It reads the standard WebXR hand joints each frame and reports finger signs, punches, slaps, claps, circles, and two-hand gestures. It has zero runtime dependencies and is MIT licensed. ### Is haath related to Hardhat? No. Hardhat is an Ethereum development tool. haath is a WebXR hand tracking library by Tree Four Studio. The name means "hand" in Hindi and Urdu. Search for "haath webxr" or "@treefour/haath" to find it. ### Which engines does haath work with? Any engine that gives you a WebXR `XRFrame`: Three.js, Meta's Immersive Web SDK (IWSDK), Babylon.js, React Three Fiber, PlayCanvas, Wonderland Engine, or a raw WebXR loop. haath never imports an engine. ### Which headsets are supported? Any browser with the WebXR Hand Input API. It is developed and tuned on Meta Quest 2, 3, and 3S in the Meta Quest Browser. ### How do I detect a punch in WebXR? Call `haath.update()` every frame and check `haath.state.right.gesture === 'punch'`. haath promotes a fist to `punch` when the hand moves faster than 1.3 m/s. Use `testHandSphere()` to check that the punch actually touched a target. ### How do I detect hand gestures like thumbs up or pinch? Read `haath.state.left.sign` or `haath.state.right.sign`. Values include `fist`, `open`, `gun`, `poke`, `pinch`, `thumbsup`, `thumbsdown`, `rock-horns`, and `telephone` (shaka). For a hold-to-confirm, wrap the sign in a `HoldRecognizer`. ### Can I test hand tracking without a headset? Yes, in two ways. `updateFromPoses()` runs the full pipeline on recorded or synthetic joint data, with no WebXR at all. The `@treefour/haath/emulator` entry point adds hand panels and keyboard control to IWER emulated hands in a desktop browser. ### Does haath recognize sign language? The v2 engine includes an ASL static alphabet pose pack with confidence scores. It covers static hand shapes, not full signed sentences. ### Is haath free for commercial use? Yes. haath is MIT licensed. ### How fast is haath? Per-hand classification is a fixed pass over 25 joints, and the per-frame path allocates no memory. It runs inside 72 to 120 Hz render loops on Meta Quest.