Skip to content

Plugin and setup ​

Everything here is exported from vue-xr-ui.

createXrUi(options?) ​

The Vue plugin. Install it once on the app: it creates the XR session controller (what useXr returns) and the app-wide theme (what useXrTheme returns).

ts
import { createApp } from 'vue'
import { createXrUi, darkTheme } from 'vue-xr-ui'

createApp(App).use(createXrUi({ theme: darkTheme })).mount('#app')
OptionTypeDefaultDescription
themeThemeTokensdarkThemeThe starting theme. Switch it later with useXrTheme().value = ….
reducedMotionbooleanthe user's prefers-reduced-motionKeep motion to a minimum. Switch it later with useXrReducedMotion().value = ….

The controller and theme are shared by your DOM app and by the TresJS canvas (which is a separate Vue app inside), so useXr() works in both an HTML "Enter VR" button and a component in the scene.

Emulator ​

createXrEmulator(options?) from vue-xr-ui/emulator makes a virtual headset for <XrScene :emulator>. It needs the optional peer dependencies iwer, @iwer/devui and @iwer/sem; see Testing in an emulator.

ts
import { createXrEmulator } from 'vue-xr-ui/emulator'
const emulator = import.meta.env.DEV ? createXrEmulator() : undefined
OptionTypeDefaultDescription
deviceEmulatedDevice'metaQuest3''metaQuest3' | 'metaQuest2' | 'metaQuestPro' | 'oculusQuest1'
roomEmulatedRoom | false'living_room'The synthetic room for MR (passthrough, planes). false for none.
inject'localhost' | 'always''localhost'Where to inject the emulator. 'always' also on a deployed site.
devUIbooleantrueThe on-screen controls to move the headset, controllers and hands. Off for tests that drive the device from code.

Voice input ​

<XrKeyboard :voice="…"> takes true (the browser's speech API, the default), false, or a speech recognizer. Two are built in; Text and voice input shows them in use.

ExportReturnsDescription
webSpeechRecognizer()XrSpeechRecognizer | undefinedThe browser's Web Speech API, undefined where there is none (the Quest browser has none).
recordingRecognizer(transcribe)XrSpeechRecognizerRecords the microphone and hands the audio to your transcribe(audio: Blob, lang: string) => Promise<string>, for a speech-to-text service of your choice.

Your own recognizer implements one method:

ts
interface XrSpeechRecognizer {
  start(session: XrSpeechSession): XrSpeechHandle
}
interface XrSpeechSession {
  lang: string                     // BCP 47, from the keyboard layout
  onPartial(text: string): void    // interim text while speaking
  onResult(text: string): void     // the final text
  onError(error: string): void
  onEnd(): void
}
interface XrSpeechHandle {
  stop(): void
}

Keyboard layouts ​

keyboardLayouts holds the built-in layouts by name (en, ru, uk, …); XrKeyboardLayoutName is the union of their names. Pass names or your own XrKeyboardLayout objects to <XrKeyboard :layouts>; see XrKeyboard.

MIT License