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) { }
}

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 isVisibleBlurred(): boolean

    Check if the session is visible-blurred - this means e.g. the keyboard is shown

    Returns boolean

  • get isVR(): boolean

    Returns boolean

  • get leftController(): undefined | NeedleXRController

    shorthand to query the left controller. Use controllers to get access to all connected controllers

    Returns undefined | NeedleXRController

  • get poseOrientation(): Quaternion

    Returns Quaternion

  • get posePosition(): Vector3

    Returns Vector3

  • get referenceSpace(): null | XRSpace

    Returns null | XRSpace

    the context.renderer.xr.getReferenceSpace() result

  • get rig(): null | IXRRig

    The currently active XR rig

    Returns null | IXRRig

  • get rightController(): undefined | NeedleXRController

    shorthand to query the right controller. Use controllers to get access to all connected controllers

    Returns undefined | NeedleXRController

  • get rigScale(): number

    get the XR rig worldscale

    Returns number

  • get running(): boolean

    Returns true if the xr session is still active

    Returns boolean

  • get transition(): SceneTransition

    Returns SceneTransition

  • get viewerPose(): undefined | XRViewerPose

    Returns undefined | XRViewerPose

    the XRFrame viewerpose using the xr referenceSpace

  • get currentSessionRequest(): null | XRSessionMode

    Returns null | XRSessionMode

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

    Returns void

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

    Parameters

    • transform: XRRigidTransform

    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

    `fadeTransition().then(() => { <fully_black> })`
    
  • Parameters

    • side: number | XRHandedness

    Returns null | NeedleXRController

    the given controller if it is connected

  • Returns Vector3

    the user position in the rig space

  • Remove a rig from the available XR Rigs

    Parameters

    Returns void

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

    Parameters

    Returns void

  • Parameters

    • mode: Omit<XRSessionMode, "inline">

    Returns XRSessionInit

    a new XRSession init object with defaults

  • Parameters

    • mode: XRSessionMode

      The XRSessionMode to check if it is supported

    Returns Promise<boolean>

    true if the browser supports the given XRSessionMode

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

    Parameters

    • mode: XRSessionMode
    • init: "default" | XRSessionInit
    • context: Context

    Returns boolean

  • Unsubscribe from request end evt

    Parameters

    • evt: SessionRequestedEndEvent

    Returns void

  • Unsubscribe from request start evt. Register with onSessionRequestStart

    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

  • Called after the session request has finished

    Parameters

    • evt: SessionRequestedEndEvent

    Returns void

  • Register to listen to XRSession start events. Unsubscribe with offXRSessionStart

    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

  • Parameters

    • mode: XRSessionMode
    • session: XRSession
    • init: XRSessionInit
    • context: Context

    Returns NeedleXRSession

  • stops the active XR session

    Returns void