From e35267b1db965cab3a40e57d070845f21d4e06a8 Mon Sep 17 00:00:00 2001 From: mrmaxm Date: Wed, 21 Feb 2024 18:20:18 +0200 Subject: [PATCH 1/4] xr framerate --- src/framework/xr/xr-manager.js | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/framework/xr/xr-manager.js b/src/framework/xr/xr-manager.js index 6e9c167399f..2d5c13a09c2 100644 --- a/src/framework/xr/xr-manager.js +++ b/src/framework/xr/xr-manager.js @@ -622,6 +622,25 @@ class XrManager extends EventHandler { }); } + /** + * @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) + return callback?.(new Error('unable to update frameRate')); + + this._session.updateTargetFrameRate(frameRate) + .then(() => { + callback?.(); + }) + .catch((err) => { + callback?.(err); + }); + } + /** * @param {string} type - Session type. * @private @@ -698,6 +717,10 @@ class XrManager extends EventHandler { this._createBaseLayer(); + this._session.addEventListener('frameratechange', () => { + this.fire('frameratechange', this._session?.frameRate); + }); + // request reference space session.requestReferenceSpace(spaceType).then((referenceSpace) => { this._referenceSpace = referenceSpace; @@ -938,6 +961,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 {Float32Array|null} + */ + get supportedFrameRates() { + return this._session?.supportedFrameRates ?? null; + } + /** * Active camera for which XR session is running or null. * From 0f79f7d7fd3887e7ad8bcddcb00a4fd70433c3ce Mon Sep 17 00:00:00 2001 From: mrmaxm Date: Wed, 21 Feb 2024 18:37:00 +0200 Subject: [PATCH 2/4] float32array > array --- src/framework/xr/xr-manager.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/framework/xr/xr-manager.js b/src/framework/xr/xr-manager.js index 2d5c13a09c2..e8cf1db54e6 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 @@ -717,6 +723,12 @@ 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); }); @@ -974,10 +986,10 @@ class XrManager extends EventHandler { /** * List of supported frame rates, or null if this data is not available. * - * @type {Float32Array|null} + * @type {number[]|null} */ get supportedFrameRates() { - return this._session?.supportedFrameRates ?? null; + return this._supportedFrameRates; } /** From 3cf9e7119617fc078a9ecd2be8e4df5719e8a480 Mon Sep 17 00:00:00 2001 From: mrmaxm Date: Wed, 21 Feb 2024 18:42:14 +0200 Subject: [PATCH 3/4] lint --- src/framework/xr/xr-manager.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/framework/xr/xr-manager.js b/src/framework/xr/xr-manager.js index b81b70d7c87..876bfbbfd9b 100644 --- a/src/framework/xr/xr-manager.js +++ b/src/framework/xr/xr-manager.js @@ -640,14 +640,19 @@ 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) - return callback?.(new Error('unable to update frameRate')); + if (!this._session?.updateTargetFrameRate) { + callback?.(new Error('unable to update frameRate')); + return; + } this._session.updateTargetFrameRate(frameRate) .then(() => { From c456c2ff48cfae0f6a1b8be5a7bef0c3a1997762 Mon Sep 17 00:00:00 2001 From: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:57:02 +0000 Subject: [PATCH 4/4] Update src/framework/xr/xr-manager.js --- src/framework/xr/xr-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/xr/xr-manager.js b/src/framework/xr/xr-manager.js index 876bfbbfd9b..03d10a18067 100644 --- a/src/framework/xr/xr-manager.js +++ b/src/framework/xr/xr-manager.js @@ -642,7 +642,7 @@ 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