threlte logo
@threlte/xr

<XR>

The <XR> component prepares your scene for a WebXR session. It sets up context that is provided by the useXR hook.

Usage

<script>
  import { XR } from '@threlte/xr'
  import { Text } from '@threlte/extras'
</script>

<XR>
  <Text
    position={[0, 1.6, -1]}
    text="I have entered another realm!"
  />
</XR>

The <XR> component will set the <Canvas> property renderMode="always" when the user enters an XR session, due to being incompatible with on-demand or manual. It will set the original value once the session has ended.

Any children of the <XR> component will not mount until the user enters an immersive session. This is useful for adding controllers, hands, or entire scenes that should only start when the user has begun their session.

Fallback

XR sessions have to be requested actively and you might want to show contents to the user before they have entered an immersive session. You can use the fallback slot to show a fallback scene to the user.

<script>
  import { T } from '@threlte/core'
  import { XR, Controller } from '@threlte/xr'
  import { OrbitControls } from '@threlte/extras'
  import Scene from './Scene.svelte'
</script>

<Scene />

<XR>
  <Controller left>
  <Controller right>

  <svelte:fragment slot="fallback">
    <T.PerspectiveCamera makeDefault position.z={5}>
      <OrbitControls />
    </T.PerspectiveCamera>
  </svelte:fragment>
</XR>

Component Signature

Props

name
type
required
default
description

foveation
number
no
1
Enables foveated rendering. 0 represents no foveation, full resolution. 1 represents maximum foveation, with the edges rendered at a lower resolution.

frameRate
number
no
The target framerate for the XRSystem. Recommended range is 72-120. Default is unset and left to the device. Smaller rates give more CPU headroom at the cost of responsiveness. If your experience cannot effectively reach the target framerate, it will be subject to frame reprojection which will halve the effective framerate. Choose a conservative estimate that balances responsiveness and headroom based on your experience.

referenceSpace
string
no
'local-floor'
Type of WebXR reference space to use.

Events

name
payload
description

sessionstart
THREE.Event & { target: XRSession }
Fired as an XRSession is requested.

sessionend
THREE.Event & { target: XRSession }
Fired after an XRSession is terminated.

visibilitychange
THREE.Event & { target: XRSession }
Fired when an XRSession is hidden or unfocused.

inputsourceschange
THREE.Event & { target: XRSession }
Fired when available inputsources change.