API

Interface XrCamera

XrCamera — a Camera whose view and projection matrices come from an XRView (one camera per eye) rather than from fov/position. Pure data, no scene knowledge (pillar 4b).

Integration is deliberately zero-cost for non-XR scenes: instead of adding an override branch to the shared camera.ts getters (which would grow every scene's bundle), the XR camera writes directly into the existing matrix caches that getViewMatrix / getProjectionMatrix / getViewProjectionMatrix already read:

  • View matrix + eye position derive for free from Camera.worldMatrix: we set _world = XRView.transform.matrix (the eye pose, view→world, column-major) and bump worldMatrixVersion. getViewMatrix then produces the inverse rigid transform (the view matrix) and _packSceneUniforms reads the eye position from the world matrix translation column — both automatically.
  • Projection is the per-eye asymmetric frustum from XRView.projectionMatrix, which the symmetric-perspective getProjectionMatrix cannot reproduce. We inject it straight into _projCache and set _projVer/_projAspect so the cache returns it verbatim for the exact aspect the render task will request.

Handedness + depth. WebXR reports right-handed poses/projections while Babylon Lite renders a left-handed world with a reverse-Z ([near→1, far→0]) depth buffer. The eye pose is converted with H·T·H and the projection with P·H, where H = diag(1,1,-1,1). Input and hand poses use the same boundary conversion, so every material pipeline sees an ordinary left-handed scene with normal winding.

  • Reverse-Z: the WebGPU binding's XRView.projectionMatrix targets z ∈ [0,1] (near→0, far→1). Babylon Lite's pipeline expects reverse-Z (near→1, far→0), so we remap row2 ← row3 − row2. This is handedness-independent and specific to this engine.
interface XrCamera {
    children: SceneNode[];
    eye: XrEye;
    farPlane: number;
    fov: number;
    name?: string;
    nearPlane: number;
    ortho?: OrthographicBounds | null;
    viewport?: NormalizedViewport;
    worldMatrix: Mat4;
    worldMatrixVersion: number;
}

Hierarchy (View Summary)

Index
children: SceneNode[]
eye: XrEye

Which eye this camera renders ("left", "right", or "none" for mono).

farPlane: number
fov: number
name?: string

Optional source/debug name. Imported glTF cameras use the glTF camera name, or camera{index} when the source definition is unnamed.

nearPlane: number
ortho?: OrthographicBounds | null

Live orthographic view-volume extents, installed by enableOrthographicCamera and mutable/animatable thereafter. Null or undefined means the camera projects perspectively through fov.

worldMatrix: Mat4
worldMatrixVersion: number