Having the configuration of world tracking that this be a call on the session will allow it to be updated while the session is running, which is good
planeDetectionState : {
enabled : true
}
BUT, it also means that the call may happen after a UA has asked the user if they will approve WebXR starting, which may require another dialog.
Can we change this to add something like:
navigator.xr.requestSession('immersive-ar', {worldKnowledge: true})
.then(onSessionStarted)
.catch(err => {
// May fail for a variety of reasons. Probably just want to
// render the scene normally without any tracking at this point.
window.requestAnimationFrame(onDrawFrame);
});
We could still support popping up permissions if sensing state is called when permissions haven't been requested. So
function onSessionStarted(session) {
// Store the session for use later.
xrSession = session;
xrSession.updateWorldSensingState({
planeDetectionState : {
enabled : true
})
could pop up permissions if worldKnowledge hasn't been requested. This would, however, that updateWorldSensingState
is a Promise, since it could fail:
xrSession.updateWorldSensingState({
planeDetectionState : {
enabled : true
}).then(stateUpdated)
.catch(err => {
// May fail for a variety of reasons, depending on the implementation and the
// permissions granted by the user, or the capabilities of the platform
});
Also, two other things here:
-
for the option for requestSession, I suggest worldKnowledge
, meaning "this page has access to world knowledge". The sensing and tracking will happen regardless, in the platform, even if it's not available to this app.
-
I change updateWorldTrackingState
to updateWorldSensingState
because tracking is about "tracking changes and motion", while sensing is broader (e.g., detecting static structure, etc).
UPDATE: Changed a bit of the text above for clarity. This is also discussed in #7