Skip to content

Core concepts ​

The scene ​

<XrScene> goes directly inside <TresCanvas>. It creates the XR session store, input sources and a frame loop that keeps running inside the headset (the browser's requestAnimationFrame stops in an XR session). Every vue-xr-ui component must be below it.

Roots and children ​

A component with a position is a root: a surface in the 3D scene (<XrPanel>, <XrWindow>, or a root <XrKeyboard>). Everything inside a root is laid out with flexbox, like a <div> tree:

vue
<XrPanel :position="[0, 1.45, -1]" :width="440" :gap="4">
  <XrBox direction="row" justify="space-between">
    <XrText variant="title">Settings</XrText>
    <XrButton size="sm" variant="ghost">Close</XrButton>
  </XrBox>
</XrPanel>

Units: dmm ​

Sizes are in dmm: one dmm is a millimetre seen from one metre away. A root at 2 m is scaled 2x so it reads the same, so fontSize: 18 always looks like 18 px text on a laptop at arm's length. Positions in the scene (:position) are metres, as in three.js.

Rules of thumb for comfortable XR UI, all built into the themes:

Value
Smallest text14 dmm (caption)
Body text18 dmm
Smallest target you can poke44 dmm (theme.interaction.minTarget)
Panel distance0.7 m to 1.5 m

The ui prop ​

Every component that draws UI takes ui: raw uikit properties merged over the component's own. It is the escape hatch for one-off layout and style:

vue
<XrSlider v-model="volume" :ui="{ flexGrow: 1 }" />

Props and events: the conventions ​

The same name means the same thing on every component:

NameMeaning
v-model (modelValue)The value a control edits. Updated while it changes (a slider while dragging).
changeThe user changed the value. Fires only when it differs from the current one, after the v-model update. On <XrSlider>, once on release.
optionsThe choices of <XrSelect>, <XrRadioGroup> and <XrTabs>: strings, or { label, value, disabled? } (plus description? on select and radio). A plain string is both label and value. Values are strings on tabs, strings or numbers elsewhere. change passes the option too.
labelThe visible text of a control.
disabledGreyed out; ignores every input. On a group, applies to every option. On <XrTooltip>, never show the hint.
blockStretch to the parent's width. Text fields, selects and number inputs always do.
variantA style from the theme: colour role on buttons, surface layer on panels and windows, type step on <XrText>, bar or spinner on <XrProgress>.
sizesm, md or lg on buttons; a number in dmm on <XrIcon> and <XrProgress>.
positionMetres in the scene, [x, y, z]. Only on roots and anchored things.
distanceReading distance in metres: a root is scaled so its dmm read the same there. On <XrFollow>, how far in front of the viewer it stays.
openv-model:open on <XrDialog> and <XrSessionMenu>: whether it shows. <XrSelect> and <XrHandMenu> open by themselves and emit open and close events.
uiRaw uikit properties, merged last.

Event payloads are typed: a press passes a ControlPointerEvent (exported as a type), with pointerId, the hit point in metres and how it hit in details.type (ray, sphere for a fingertip, screen-ray for the mouse).

Frame callbacks ​

useXrFrame((delta, frame) => {}) runs every frame, in the browser and in the headset. Use it instead of TresJS useLoop for anything that must keep moving in XR.

MIT License