Class WebXRTrackedBody
Implements
Constructors
constructor
-
new WebXRTrackedBody(
scene: Scene,
bodyMesh?: AbstractMesh,
rigMapping?: XRBodyMeshRigMapping,
jointScaleFactor?: number,
preserveBindPoseBonePositions?: boolean,
useBoneOrientationOffsets?: boolean,
aimChildOverrides?: Partial<Record<WebXRBodyJoint, WebXRBodyJoint>>,
jointLocalRotationOffset?: Quaternion,
): WebXRTrackedBodyConstruct a new tracked body instance.
Parameters
- scene: Scene
The Babylon.js scene.
OptionalbodyMesh: AbstractMeshOptional rigged body mesh to attach immediately.
OptionalrigMapping: XRBodyMeshRigMappingOptional mapping from WebXR joint names to skeleton bone names.
- jointScaleFactor: number = 1.0
Scale factor for local joint offsets (default 1.0).
- preserveBindPoseBonePositions: boolean = false
Whether mapped bones should keep bind-pose local translations.
- useBoneOrientationOffsets: boolean = false
Whether mapped bones should correct XR joint rotations using bind-space offsets.
OptionalaimChildOverrides: Partial<Record<WebXRBodyJoint, WebXRBodyJoint>>Per–XR-joint override for the aim child used with
useBoneOrientationOffsets.OptionaljointLocalRotationOffset: QuaternionOptional rotation re-basing each XR joint's local frame (e.g. Z-along-bone → Y-along-bone).
Returns WebXRTrackedBody
- scene: Scene
Properties
auto Capture Bind On First Frame
When true (default), the first tracked frame after the feature
attaches is used as the "rest" pose for delta-from-bind retargeting.
Set to false to require an explicit captureTrackedBind call.
joint Local Rotation Offset
Runtime-mutable rotation applied in each tracked joint's local frame to
re-base XR joint axes (e.g., "+Z-along-bone" → "+Y-along-bone").
null = identity / disabled.
Readonlyon Body Mesh Set Observable
Fired when the body mesh is changed via setBodyMesh.
Accessors
body Mesh
-
Get the current body mesh (if any).
Returns Nullable<AbstractMesh>
joint Scale Factor
-
get jointScaleFactor(): number
Get or set the scale factor for local joint offsets.
Returns number
-
set jointScaleFactor(value: number): void
Parameters
- value: number
Returns void
joint Transforms
-
Returns the array of transform nodes representing each body joint. The order matches WebXRBodyTracking.AllBodyJoints; use getJointTransform or getBodyPartTransforms for name-based lookup.
Note: when a body mesh is attached, these transform nodes are also used as the skeleton's link targets for mapped joints. In that case the values held by mapped-joint nodes are skeleton-local (parent bone's frame), not XR world-space. Unmapped-joint nodes always hold world-space pose. If you need world-space poses for every joint regardless of mapping, sample the bone matrices directly via the attached skeleton.
Returns readonly TransformNode[]
Methods
capture Tracked Bind
-
Capture the current tracked-joint desired-final rotations and positions as the "rest pose" for delta-from-bind retargeting.
Delta-from-bind is the production retarget path: every subsequent frame is interpreted as a rotation delta from this snapshot, which makes retargeting invariant to the XR-joint axis convention and to any skeletal-proportion differences between the tracked user and the avatar.
Call this after the user assumes a known rest pose (e.g. T-pose, A-pose, arms-at-sides). By default the feature auto-captures on the first tracked frame — disable via autoCaptureBindOnFirstFrame.
Returns void
clear Tracked Bind
-
Clear any captured bind, reverting subsequent frames to the fallback direct-retarget path (or re-triggering auto-capture on the next frame).
Returns void
dispose
-
Dispose of this tracked body and its resources.
Parameters
- disposeMesh: boolean = false
If
true, the body mesh and its skeleton are disposed as well.
Returns void
- disposeMesh: boolean = false
get Body Part Transforms
-
Get all joint transform nodes that belong to a given body part.
Parameters
- part: BodyPart
The body part to query.
Optionalresult: TransformNode[]Optional pre-allocated array to fill (avoids per-call allocation). The array is cleared and populated with the results.
Returns TransformNode[]
An array of TransformNodes for that body part.
- part: BodyPart
get Joint Transform
-
Get the transform node for a specific body joint.
Parameters
- jointName: WebXRBodyJoint
The name of the body joint (from WebXRBodyJoint).
Returns TransformNode | undefined
The transform node corresponding to that joint, or
undefinedif not found. - jointName: WebXRBodyJoint
replay Raw Joint Matrices
-
replayRawJointMatrices(
rawMatrices: number[] | Float32Array<ArrayBufferLike>,
isAlreadyLhs?: boolean,
): voidReplay a pre-captured joint matrix set through the retargeting pipeline as if it had just been delivered by an XR frame.
Useful for headset-less testing: call with a snapshot captured via snapshotFrame (the
jointMatricesRHSarray, orjointMatricesLHSalready flipped). The matrices are assumed to be RHS unlessisAlreadyLhs=true, in which case the RHS→LHS flip step is skipped.Parameters
- rawMatrices: number[] | Float32Array<ArrayBufferLike>
Float32Array of BODY_JOINT_COUNT × 16 (= 1328) floats.
- isAlreadyLhs: boolean = false
Set to
trueif matrices are already LHS-converted.
Returns void
- rawMatrices: number[] | Float32Array<ArrayBufferLike>
set Body Mesh
-
Attach (or replace) a rigged body mesh.
The mesh's skeleton bones are linked to the internal transform nodes that receive WebXR tracking data each frame. If the mesh has a skeleton, the
rigMapping(or a direct name match) is used to bind each bone.Parameters
- bodyMesh: AbstractMesh
The rigged mesh to drive.
OptionalrigMapping: XRBodyMeshRigMappingAn optional mapping from WebXRBodyJoint to bone name. If omitted, bones are expected to be named after the WebXR joint names.
Returns void
- bodyMesh: AbstractMesh
snapshot Frame
-
Capture a snapshot of the current frame's raw XR joint matrices and skeleton metadata. Returns a JSON string that can be used offline to replay / debug bone-local computation without a headset.
The snapshot includes:
jointMatricesRHS– 83 × 16 raw RHS matrices (before LHS conversion)jointMatricesLHS– 83 × 16 LHS-converted matrices (after step 3)meshWorldMatrix– 16 floats, the skeleton mesh's world matrix (if any)jointHasBone– boolean[83], which joints are mapped to bonesjointParentJointIdx– number[83], mapped ancestor for each jointuseRightHandedSystem– scene handedness settingjointNames– the 83 joint names in order
Returns string
A JSON string with the snapshot data.
snapshot Frame To Clipboard Async
-
Capture a snapshot and copy it to the system clipboard. Logs to the console on success or failure.
Returns Promise<void>
A promise that resolves when the copy completes.
update From XR Frame
-
updateFromXRFrame(
xrFrame: XRFrame,
referenceSpace: XRReferenceSpace,
xrCameraParent: Nullable<Node>,
): booleanUpdate joint transforms from the current XR frame.
This method is called once per frame by the feature class. Internally it:
- Extracts all XRBodySpaces from the XRBody.
- Fills the transform-matrix buffer via
fillPoses()(or per-joint fallback). - Converts from WebXR right-handed to Babylon left-handed coordinates.
- Decomposes each matrix into the corresponding TransformNode.
- Parents the body mesh root to the XR camera so it tracks correctly.
Parameters
Returns boolean
trueif valid tracking data was processed,falseotherwise.
Represents a tracked body during a WebXR session.
This class manages the bridge between the WebXR body pose data and the Babylon.js scene graph. It creates a set of TransformNodes — one per body joint — whose transforms are updated every frame from the XR runtime. When a rigged body mesh is attached, its skeleton bones are linked to these transform nodes, causing the mesh to follow the user's body automatically.
Coordinate-system handling: