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).
import { createApp } from 'vue'
import { createXrUi, darkTheme } from 'vue-xr-ui'
createApp(App).use(createXrUi({ theme: darkTheme })).mount('#app')| Option | Type | Default | Description |
|---|---|---|---|
theme | ThemeTokens | darkTheme | The starting theme. Switch it later with useXrTheme().value = …. |
reducedMotion | boolean | the user's prefers-reduced-motion | Keep 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.
import { createXrEmulator } from 'vue-xr-ui/emulator'
const emulator = import.meta.env.DEV ? createXrEmulator() : undefined| Option | Type | Default | Description |
|---|---|---|---|
device | EmulatedDevice | 'metaQuest3' | 'metaQuest3' | 'metaQuest2' | 'metaQuestPro' | 'oculusQuest1' |
room | EmulatedRoom | 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. |
devUI | boolean | true | The 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.
| Export | Returns | Description |
|---|---|---|
webSpeechRecognizer() | XrSpeechRecognizer | undefined | The browser's Web Speech API, undefined where there is none (the Quest browser has none). |
recordingRecognizer(transcribe) | XrSpeechRecognizer | Records 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:
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.