Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR manual room capture #5774

Merged
merged 3 commits into from Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/framework/xr/xr-manager.js
Expand Up @@ -25,6 +25,13 @@ import { XrAnchors } from './xr-anchors.js';
* @param {Error|null} err - The Error object or null if operation was successful.
*/

/**
* Callback used by manual room capturing.
*
* @callback XrRoomCaptureCallback
* @param {Error|null} err - The Error object or null if manual room capture was successful.
*/

/**
* Manage and update XR session and its states.
*
Expand Down Expand Up @@ -551,6 +558,40 @@ class XrManager extends EventHandler {
}
}

/**
* Initiate manual room capture. If the underlying XR system supports manual capture of the
* room, it will start the capturing process, which can affect plane and mesh detection,
* and improve hit-test quality against real-world geometry.
*
* @param {XrRoomCaptureCallback} callback - Callback that will be fired once capture is complete
* or failed.
*
* @example
* this.app.xr.initiateRoomCapture((err) => {
* if (err) {
* // capture failed
* return;
* }
* // capture was successful
* });
*/
initiateRoomCapture(callback) {
if (!this._session) {
callback(new Error('Session is not active'));
return;
}
if (!this._session.initiateRoomCapture) {
callback(new Error('Session does not support manual room capture'));
return;
}

this._session.initiateRoomCapture().then(() => {
if (callback) callback(null);
}).catch((err) => {
if (callback) callback(err);
});
}

/**
* @param {string} type - Session type.
* @private
Expand Down