diff --git a/src/framework/xr/xr-manager.js b/src/framework/xr/xr-manager.js index e4ff3e8ec24..03d10a18067 100644 --- a/src/framework/xr/xr-manager.js +++ b/src/framework/xr/xr-manager.js @@ -265,6 +265,12 @@ class XrManager extends EventHandler { */ _depthFar = 1000; + /** + * @type {number[]|null} + * @private + */ + _supportedFrameRates = null; + /** * @type {number} * @private @@ -633,6 +639,30 @@ class XrManager extends EventHandler { }); } + /** + * Update target frame rate of an XR session to one of supported value provided by + * supportedFrameRates list. + * + * @param {number} frameRate - Target frame rate. It should be any value from the list + * of supportedFrameRates. + * @param {Function} [callback] - Callback that will be called when frameRate has been + * updated or failed to update with error provided. + */ + updateTargetFrameRate(frameRate, callback) { + if (!this._session?.updateTargetFrameRate) { + callback?.(new Error('unable to update frameRate')); + return; + } + + this._session.updateTargetFrameRate(frameRate) + .then(() => { + callback?.(); + }) + .catch((err) => { + callback?.(err); + }); + } + /** * @param {string} type - Session type. * @private @@ -709,6 +739,16 @@ class XrManager extends EventHandler { this._createBaseLayer(); + if (this.session.supportedFrameRates) { + this._supportedFrameRates = Array.from(this.session.supportedFrameRates); + } else { + this._supportedFrameRates = null; + } + + this._session.addEventListener('frameratechange', () => { + this.fire('frameratechange', this._session?.frameRate); + }); + // request reference space session.requestReferenceSpace(spaceType).then((referenceSpace) => { this._referenceSpace = referenceSpace; @@ -949,6 +989,25 @@ class XrManager extends EventHandler { return this._session; } + /** + * XR session frameRate or null if this information is not available. This value can change + * during an active XR session. + * + * @type {number|null} + */ + get frameRate() { + return this._session?.frameRate ?? null; + } + + /** + * List of supported frame rates, or null if this data is not available. + * + * @type {number[]|null} + */ + get supportedFrameRates() { + return this._supportedFrameRates; + } + /** * Framebuffer scale factor. This value is read-only and can only be set when starting a new * XR session.