Skip to content
Open
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
21 changes: 19 additions & 2 deletions proposals/immersive-ar-session.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
let xrButton = null;
let xrImmersiveRefSpace = null;
let inlineViewerHelper = null;
let rAFHandle = null;
let inlineSession = null;

// WebGL scene globals.
let gl = null;
Expand Down Expand Up @@ -113,6 +115,7 @@
.then((session) => {
xrButton.setSession(session);
session.isImmersive = true;

onSessionStarted(session);
});
}
Expand Down Expand Up @@ -145,6 +148,14 @@
// When in 'immersive-ar' mode don't draw an opaque background because
// we want the real world to show through.
skybox.visible = false;

// stop the inline session rendering
if (inlineSession && rAFHandle) {
inlineSession.cancelAnimationFrame(rAFHandle);
rAFHandle = null;
}
} else {
inlineSession = session;
}

initGL();
Expand All @@ -158,7 +169,7 @@
} else {
inlineViewerHelper = new InlineViewerHelper(gl.canvas, refSpace);
}
session.requestAnimationFrame(onXRFrame);
rAFHandle = session.requestAnimationFrame(onXRFrame);
});
}

Expand All @@ -171,6 +182,12 @@
xrButton.setSession(null);
// Turn the background back on when we go back to the inlive view.
skybox.visible = true;

// if this was immersive session stopping, restart the inlineSession
rAFHandle = inlineSession.requestAnimationFrame(onXRFrame);
} else {
console.warn("inline session unexpectedly ended");
inlineSession = null;
}
}

Expand All @@ -184,7 +201,7 @@

scene.startFrame();

session.requestAnimationFrame(onXRFrame);
rAFHandle = session.requestAnimationFrame(onXRFrame);

scene.drawXRFrame(frame, pose);

Expand Down