WebXR component to enable VR, AR and Quicklook on iOS in your scene.
It provides a simple wrapper around the NeedleXRSession API and adds some additional features like creating buttons or enabling default movement behaviour.

Hierarchy (view full)

Properties

arScale: number = 1

Used when usePlacementReticle is enabled. This is the scale of the user in the scene in AR. Larger values make the 3D content appear smaller

autoCenter: boolean = true

When enabled the AR session root center will be automatically adjusted to place the center of the scene

autoPlace: boolean = true

When enabled the scene will be placed automatically when a point in the real world is found

createARButton: boolean = true

When enabled a button will be added to the UI to enter AR

createQRCode: boolean = true

When enabled a QRCode will be created to open the website on a mobile device

createSendToQuestButton: boolean = true

When enabled a send to quest button will be shown if the device does not support VR

createVRButton: boolean = true

When enabled a button will be added to the UI to enter VR

customARPlacementReticle?: AssetReference

When assigned this object will be used as the AR placement reticle

defaultAvatar?: boolean | AssetReference

This avatar representation will be spawned when you enter a webxr session

gameObject: GameObject

the object this component is attached to. Note that this is a threejs Object3D with some additional features

guid: string = "invalid"

the unique identifier for this component

showControllerModels: boolean = true

When enabled controller models will automatically be created and updated when you are using controllers in WebXR

showHandModels: boolean = true

When enabled hand models will automatically be created and updated when you are using hands in WebXR

sourceId?: string

holds the source identifier this object was created with/from (e.g. if it was part of a glTF file the sourceId holds the url to the glTF)

useDefaultControls: boolean = true

When enabled default movement behaviour will be added

useDepthSensing: boolean = false

Preview feature enabling occlusion (when available: https://github.com/cabanier/three.js/commit/b6ee92bcd8f20718c186120b7f19a3b68a1d4e47) Enables the 'depth-sensing' WebXR feature to provide realtime depth occlusion. Only supported on Oculus Quest right now.

usePlacementAdjustment: boolean = true

When enabled you can position, rotate or scale your AR scene with one or two fingers

usePlacementReticle: boolean = true

When enabled the scene must be placed in AR

useQuicklookExport: boolean = false

When enabled a USDZExporter component will be added to the scene (if none is found)

useSpatialGrab: boolean = true

When enabled the spatial grab raycaster will be added or enabled in the scene

Default

true
useXRAnchor: boolean = false

Experimental: When enabled an XRAnchor will be created for the AR scene and the position will be updated to the anchor position every few frames

Accessors

  • get activeAndEnabled(): boolean
  • Returns boolean

    true if the object is enabled and active in the hierarchy

  • get context(): Context
  • Use the context to get access to many Needle Engine features and use physics, timing, access the camera or scene

    Returns Context

  • set context(context): void
  • Parameters

    Returns void

  • get destroyed(): boolean
  • Returns boolean

    true if this component was destroyed (this.destroy()) or the whole object this component was part of

  • get enabled(): boolean
  • Returns boolean

  • set enabled(val): void
  • Parameters

    • val: boolean

    Returns void

  • get forward(): Vector3
  • Forward (0,0,-1) vector in world space

    Returns Vector3

  • get hideFlags(): HideFlags
  • Returns HideFlags

  • get layer(): number
  • Returns number

    the layer of the gameObject this component is attached to

  • get name(): string
  • Returns string

    the name of the gameObject this component is attached to

  • set name(str): void
  • Parameters

    • str: string

    Returns void

  • get right(): Vector3
  • Right (1,0,0) vector in world space

    Returns Vector3

  • get scene(): Scene
  • shorthand for this.context.scene

    Returns Scene

    the scene of the context

  • get sessionMode(): any
  • immersive-vr or immersive-ar

    Returns any

  • get static(): boolean
  • Is the gameObject marked as static

    Returns boolean

  • set static(value): void
  • Parameters

    • value: boolean

    Returns void

  • get tag(): string
  • Returns string

    the tag of the gameObject this component is attached to

  • set tag(str): void
  • Parameters

    • str: string

    Returns void

  • get up(): Vector3
  • Up (0,1,0) vector in world space

    Returns Vector3

  • get worldEuler(): Euler
  • Returns Euler

  • set worldEuler(val): void
  • Parameters

    Returns void

  • get worldPosition(): Vector3
  • Returns Vector3

  • set worldPosition(val): void
  • Parameters

    Returns void

  • get worldQuaternion(): Quaternion
  • Returns Quaternion

  • set worldQuaternion(val): void
  • Parameters

    Returns void

  • get worldRotation(): Vector3
  • Returns Vector3

  • set worldRotation(val): void
  • Parameters

    Returns void

Methods

  • Type Parameters

    Parameters

    • type: string
    • listener: ((evt) => any)
        • (evt): any
        • Parameters

          • evt: T

          Returns any

    Returns void

  • called once when the component becomes active for the first time (once per component)
    This is the first callback to be called

    Returns void

  • Destroys this component (and removes it from the object)

    Returns void

  • first callback in a frame (called every frame when implemented)

    Returns void

  • Call to end a WebXR (AR or VR) session

    Returns void

  • Calling this function will get the Needle WebXR button factory (it will be created if it doesnt exist yet)

    Returns WebXRButtonFactory

    the Needle WebXR button factory

  • late callback in a frame (called every frame when implemented)

    Returns void

  • called before the scene gets rendered in the main update loop

    Parameters

    • frame: any

    Returns void

  • Called before the XR session is requested. Use this callback if you want to modify the session init features

    Parameters

    • _mode: XRSessionMode
    • args: XRSessionInit

    Returns void

  • Called when the component gets destroyed

    Returns void

  • called every time the component gets disabled or if a parent object (or this.gameObject) gets set to invisible

    Returns void

  • called every time when the component gets enabled (this is invoked after awake and before start)
    or when it becomes active in the hierarchy (e.g. if a parent object or this.gameObject gets set to visible)

    Returns void

  • Callback when this component exists a xr session (or when it becomes inactive in a running XR session)

    Parameters

    Returns void

  • Called for all scripts when the context gets paused or unpaused

    Parameters

    • isPaused: boolean
    • wasPaused: boolean

    Returns void

  • called when you decorate fields with the @validate() decorator

    Parameters

    • Optional prop: string

      the name of the field that was changed

    Returns void

  • Callback when a controller is connected/added while in a XR session
    OR when the component joins a running XR session that has already connected controllers
    OR when the component becomes active during a running XR session that has already connected controllers

    Returns void

  • Type Parameters

    Parameters

    • type: string
    • listener: ((arg) => any)
        • (arg): any
        • Parameters

          • arg: T

          Returns any

    Returns void

  • called on a component with a map of old to new guids (e.g. when instantiate generated new guids and e.g. timeline track bindings needs to remape them)

    Parameters

    • guidsMap: GuidsMap

    Returns void

  • Call to enable or disable default controller rendering

    Parameters

    • enabled: boolean

    Returns XRControllerModel

  • Parameters

    • x: number
    • y: number
    • z: number
    • w: number

    Returns void

  • Parameters

    • x: number
    • y: number
    • z: number
    • degrees: boolean = true

    Returns void

  • called at the beginning of a frame (once per component)

    Returns void

  • starts a coroutine (javascript generator function)
    yield will wait for the next frame:

    • Use yield WaitForSeconds(1) to wait for 1 second.
    • Use yield WaitForFrames(10) to wait for 10 frames.
    • Use yield new Promise(...) to wait for a promise to resolve.

    Parameters

    • routine: Generator<unknown, any, unknown>

      generator function to start

    • evt: FrameEvent = FrameEvent.Update

      event to register the coroutine for (default: FrameEvent.Update). Note that all coroutine FrameEvent callbacks are invoked after the matching regular component callbacks. For example FrameEvent.Update will be called after regular component update() methods)

    Returns Generator<unknown, any, unknown>

    the generator function (use it to stop the coroutine with stopCoroutine)

    Example

    onEnable() { this.startCoroutine(this.myCoroutine()); }
    private *myCoroutine() {
    while(this.activeAndEnabled) {
    console.log("Hello World", this.context.time.frame);
    // wait for 5 frames
    for(let i = 0; i < 5; i++) yield;
    }
    }
  • Stop a coroutine that was previously started with startCoroutine

    Parameters

    • routine: Generator<unknown, any, unknown>

      the routine to be stopped

    • evt: FrameEvent = FrameEvent.Update

      the frame event to unregister the routine from (default: FrameEvent.Update)

    Returns void

  • Optional callback, you can implement this to only get callbacks for VR or AR sessions if necessary.

    Parameters

    • mode: XRSessionMode

    Returns boolean

    true if the mode is supported (if false the mode is not supported by this component and it will not receive XR callbacks for this mode)

  • regular callback in a frame (called every frame when implemented)

    Returns void

Generated using TypeDoc