Taos API Reference
    Preparing search index...

    Class XrHitTest

    WebXR hit-test helper for placing virtual content on real-world surfaces.

    A hit-test source casts a ray (from the viewer/center, a controller's pointing ray, or a screen tap) into the AR runtime's understanding of the room and returns where it strikes a real surface. The canonical use is a placement reticle: each frame, read hitMatrix (the latest strike pose in the session's reference space) and park a reticle mesh there; on a trigger/tap, drop content at that pose (optionally anchoring it — see XrAnchors).

    Construct one alongside an XrSession that was created with the 'hit-test' (and, for screen AR, 'hit-test' + transient input) feature, call one of the start* methods once (it's async — the runtime resolves the source), then call update every XRFrame before reading the pose.

    Part of the AR half of the WebXR integration — see TODO/webxr-integration.md.

    Index

    Constructors

    Properties

    hitMatrix: Mat4 | null = null

    Latest hit pose in the session's reference space, or null when no surface was struck this frame (also null until update runs). -Z of this matrix is the surface normal-ish forward; the translation is the contact point.

    hitPosition: Vec3 | null = null

    Convenience: the contact point (translation of hitMatrix).

    tracked: boolean = false

    True when a surface was struck on the most recent update.

    Accessors

    • get supported(): boolean

      Whether the active session exposes the hit-test API (feature granted).

      Returns boolean

    Methods

    • Cast from the viewer (head/center) straight ahead — the simplest "look at a surface to place" reticle. Resolves once the source is ready.

      Returns Promise<void>

    • Cast from an arbitrary XRSpace — pass a controller's targetRaySpace (from XrControllers) for a pointer-driven reticle. An offsetRay re-aims relative to that space.

      Parameters

      • space: XRSpace
      • OptionaloffsetRay: XRRay

      Returns Promise<void>

    • Transient-input hit-test for handheld (phone) AR: each screen tap is a short-lived input source. After this, read getTransientResults (or the convenience hitMatrix, which tracks the first active tap). profile defaults to the generic touchscreen profile.

      Parameters

      • profile: string = 'generic-touchscreen'
      • OptionaloffsetRay: XRRay

      Returns Promise<void>

    • Raw persistent-source results for this frame (empty if none / not started).

      Parameters

      • frame: XRFrame

      Returns readonly XRHitTestResult[]

    • Raw transient (per-tap) results for this frame.

      Parameters

      • frame: XRFrame

      Returns readonly XRTransientInputHitTestResult[]

    • Create a WebXR anchor at the current hit point, if the 'anchors' feature is enabled and a surface was struck this frame. Returns null otherwise. The returned anchor can be handed to XrAnchors to track its pose.

      Parameters

      • frame: XRFrame

      Returns Promise<XRAnchor | null>

    • Cancel the active hit-test source(s) without disposing the session.

      Returns void