This class manages an XRSession to provide helper methods and events. It provides easy access to the XRInputSources (controllers and hands)

  • Start a XRSession with NeedleXRSession.start(...)
  • Stop a XRSession with NeedleXRSession.stop()
  • Access a running XRSession with NeedleXRSession.active

If a XRSession is active you can use all XR-related event methods on your components to receive XR events e.g. onEnterXR, onUpdateXR, onLeaveXR

export class MyComponent extends Behaviour {
// callback invoked whenever the XRSession is started or your component is added to a scene with an active XRSession
onEnterXR(args: NeedleXREventArgs) {
console.log("Entered XR");
// access the NeedleXRSession via args.xr
}
// callback invoked whenever a controller is added (or you switch from controller to hand tracking)
onControllerAdded(args: NeedleXRControllerEventArgs) { }
}

XRRig

The XRRig can be accessed via the rig property
Set a custom XRRig via NeedleXRSession.addRig(...) or NeedleXRSession.removeRig(...)
By default the active XRRig with the highest priority in the scene is used

Implements

  • INeedleXRSession

Properties

context: Context

The needle engine context this session was started from

controllers: NeedleXRController[] = []

The currently active/connected controllers

mode: XRSessionMode

XR Session Mode: AR or VR

session: XRSession

Accessors

  • get interactionMode(): "screen-space" | "world-space"
  • The XRSession interface's read-only interactionMode property describes the best space (according to the user agent) for the application to draw an interactive UI for the current session.

    Returns "screen-space" | "world-space"

  • get isAR(): boolean
  • Returns boolean

  • get isPassThrough(): boolean
  • Returns true if running in pass through mode in immersive AR (e.g. user is wearing a headset while in AR)

    Returns boolean

  • get isScreenBasedAR(): boolean
  • If the AR mode is not immersive (meaning the user is e.g. holding a phone instead of wearing a AR passthrough headset)

    Returns boolean

  • get isSystemKeyboardSupported(): boolean
  • Check if the session has system keyboard support

    Returns boolean

  • get isTrackingImages(): boolean
  • returns true if images are currently being tracked

    Returns boolean

  • get isVR(): boolean
  • Returns boolean

  • get isVisibleBlurred(): boolean
  • Check if the session is visible-blurred - this means e.g. the keyboard is shown

    Returns boolean

  • get leftController(): NeedleXRController
  • shorthand to query the left controller. Use controllers to get access to all connected controllers

    Returns NeedleXRController

  • get poseOrientation(): any
  • Returns any

  • get posePosition(): any
  • Returns any

  • get referenceSpace(): any
  • Returns any

    the context.renderer.xr.getReferenceSpace() result

  • get rig(): IXRRig
  • The currently active XR rig

    Returns IXRRig

  • get rigScale(): number
  • get the XR rig worldscale

    Returns number

  • get rightController(): NeedleXRController
  • shorthand to query the right controller. Use controllers to get access to all connected controllers

    Returns NeedleXRController

  • get running(): boolean
  • Returns true if the xr session is still active

    Returns boolean

  • get transition(): SceneTransition
  • Returns SceneTransition

  • get viewerPose(): any
  • Returns any

    the XRFrame viewerpose using the xr referenceSpace

  • get activeMode(): any
  • The active xr session mode (if any xr session is active)

    Returns any

  • get currentSessionRequest(): any
  • Returns any

Methods

  • add a rig to the available XR rigs - if it's priority is higher than the currently active rig it will be enabled

    Parameters

    • rig: IXRRig

    Returns void

  • convert a XRRigidTransform from XR session space to threejs / Needle Engine XR space

    Parameters

    Returns {
        position: Vector3;
        quaternion: Quaternion;
    }

  • End the XR Session

    Returns void

  • Call to fade rendering to black for a short moment (the returned promise will be resolved when fully black)
    This can be used to mask scene transitions or teleportation

    Returns Promise<void>

    a promise that is resolved when the screen is fully black

    Example

    `fadeTransition().then(() => { <fully_black> })`
    
  • Returns a XR hit test result (if hit-testing is available) in rig space

    Parameters

    • Optional source: NeedleXRController

      If provided, the hit test will be performed for the given controller

    Returns NeedleXRHitTestResult

  • Returns Vector3

    the user position in the rig space

  • Remove a rig from the available XR Rigs

    Parameters

    • rig: IXRRig

    Returns void

  • Sets a XRRig to be active which will parent the camera to this rig

    Parameters

    • rig: IXRRig

    Returns void

  • Parameters

    • mode: Omit<XRSessionMode, "inline">

    Returns XRSessionInit

    a new XRSession init object with defaults

  • Returns any

  • Parameters

    • mode: XRSessionMode

    Returns any

  • Returns any

  • Unsubscribe from controller added evts

    Parameters

    Returns void

  • Unsubscribe from controller removed events

    Parameters

    Returns void

  • Unsubscribe from request end evt

    Parameters

    • evt: SessionRequestedEndEvent

    Returns void

  • Parameters

    • evt: SessionRequestedEvent

    Returns void

  • Unsubscribe from XRSession started events

    Parameters

    • evt: SessionChangedEvt

    Returns void

  • Unsubscribe from XRSession started events

    Parameters

    • evt: SessionChangedEvt

    Returns void

  • If the browser supports offerSession - creating a VR or AR button in the browser navigation bar

    Parameters

    • mode: XRSessionMode
    • init: any
    • context: Context

    Returns boolean

  • Listen to controller added events. Events are cleared when starting a new session

    Parameters

    Returns void

  • Listen to controller removed events Events are cleared when starting a new session

    Parameters

    Returns void

  • Called after the session request has finished

    Parameters

    • evt: SessionRequestedEndEvent

    Returns void

  • Parameters

    • evt: SessionRequestedEvent

    Returns void

  • Listen to XR session ended. Unsubscribe with offXRSessionEnd

    Parameters

    • evt: SessionChangedEvt

    Returns void

  • Listen to XR session started. Unsubscribe with offXRSessionStart

    Parameters

    • evt: SessionChangedEvt

    Returns void

  • stops the active XR session

    Returns void

Generated using TypeDoc