Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions scripts/esm/xr/xr-menu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,11 @@ class XrMenu extends Script {
// Create menu container and UI
this._createMenu();

// Hide menu initially
this._setMenuVisible(false);
// Hide the menu until an XR session shows it. This can't go through
// _setMenuVisible(false) — _menuVisible is already false, so it early-outs and leaves the
// container enabled at the element opacities _createButton assigned, which renders the
// menu at the world origin outside XR.
this._hideImmediate();

// Listen for XR input sources
this.app.xr.input.on('add', this._onInputSourceAdd, this);
Expand Down Expand Up @@ -474,12 +477,35 @@ class XrMenu extends Script {
}

_onXrEnd() {
// _setMenuVisible fires 'xr:menu:active' for listeners when the menu was open, but only
// requests the fade-out — which update() can no longer advance now that the session has
// ended. _hideImmediate finishes the job, otherwise the menu stays frozen in the world at
// its last headset-relative pose.
this._setMenuVisible(false);
this._hideImmediate();
this._inputSources.clear();
this._activeInputSource = null;
this._followInitialized = false;
}

/**
* Hides the menu at once, bypassing the opacity fade. Required whenever no XR session is
* running: the fade in {@link XrMenu#update} only advances while `xr.active` is true, so a hide
* requested outside a session (before the first one starts, or as one ends) would never
* complete and the menu would keep rendering in the world.
*
* @private
*/
_hideImmediate() {
this._menuVisible = false;
this._currentOpacity = 0;
this._targetOpacity = 0;
this._updateMenuOpacity(0);
this._setHovered(null);
this._pressedButton = null;
if (this._menuContainer) this._menuContainer.enabled = false;
}

/**
* Handler for the raw 'selectstart' (pinch/trigger press) input event. Clicks the currently
* hovered button. This is the click path for platforms where the pinch arrives as a separate
Expand Down