From 1b45abe5649b9efc44f12918d3cc6d2fd9f7dc63 Mon Sep 17 00:00:00 2001 From: Blair MacIntyre Date: Sat, 28 Dec 2019 21:47:52 -0500 Subject: [PATCH 1/3] cancel rAF for inline when immersive-ar starts --- proposals/immersive-ar-session.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/proposals/immersive-ar-session.html b/proposals/immersive-ar-session.html index 46886a20a..298147e6e 100644 --- a/proposals/immersive-ar-session.html +++ b/proposals/immersive-ar-session.html @@ -69,6 +69,7 @@ let xrButton = null; let xrImmersiveRefSpace = null; let inlineViewerHelper = null; + let rAFHandle = null; // WebGL scene globals. let gl = null; @@ -113,6 +114,12 @@ .then((session) => { xrButton.setSession(session); session.isImmersive = true; + + if (rAFHandle) { + xrButton.session.cancelAnimationFrame(rAFHandle); + rAFHandle = null + } + onSessionStarted(session); }); } @@ -158,7 +165,7 @@ } else { inlineViewerHelper = new InlineViewerHelper(gl.canvas, refSpace); } - session.requestAnimationFrame(onXRFrame); + rAFHandle = session.requestAnimationFrame(onXRFrame); }); } @@ -184,7 +191,7 @@ scene.startFrame(); - session.requestAnimationFrame(onXRFrame); + rAFHandle = session.requestAnimationFrame(onXRFrame); scene.drawXRFrame(frame, pose); From d41ed0c1028d8155a7812d993fd3a019abc1dfcd Mon Sep 17 00:00:00 2001 From: Blair MacIntyre Date: Sun, 29 Dec 2019 06:58:41 -0500 Subject: [PATCH 2/3] cancel in the right place, restart inline too --- proposals/immersive-ar-session.html | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/proposals/immersive-ar-session.html b/proposals/immersive-ar-session.html index 298147e6e..139c7e3cb 100644 --- a/proposals/immersive-ar-session.html +++ b/proposals/immersive-ar-session.html @@ -70,6 +70,7 @@ let xrImmersiveRefSpace = null; let inlineViewerHelper = null; let rAFHandle = null; + let inlineSession = null; // WebGL scene globals. let gl = null; @@ -115,11 +116,6 @@ xrButton.setSession(session); session.isImmersive = true; - if (rAFHandle) { - xrButton.session.cancelAnimationFrame(rAFHandle); - rAFHandle = null - } - onSessionStarted(session); }); } @@ -152,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(); @@ -171,6 +175,14 @@ function onEndSession(session) { session.end(); + + // if this was immersive session stopping, restart the inlineSession + if (session != inlineSession) { + rAFHandle = inlineSession.requestAnimationFrame(onXRFrame); + } else { + console.warn("inline session unexpectedly ended"); + inlineSession = null; + } } function onSessionEnded(event) { From 98cde1bb325ee773892f4875725fc341f6237ad7 Mon Sep 17 00:00:00 2001 From: Blair MacIntyre Date: Sun, 29 Dec 2019 14:04:31 -0500 Subject: [PATCH 3/3] put inline restart in right place --- proposals/immersive-ar-session.html | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/proposals/immersive-ar-session.html b/proposals/immersive-ar-session.html index 139c7e3cb..e9ed8f5e7 100644 --- a/proposals/immersive-ar-session.html +++ b/proposals/immersive-ar-session.html @@ -175,14 +175,6 @@ function onEndSession(session) { session.end(); - - // if this was immersive session stopping, restart the inlineSession - if (session != inlineSession) { - rAFHandle = inlineSession.requestAnimationFrame(onXRFrame); - } else { - console.warn("inline session unexpectedly ended"); - inlineSession = null; - } } function onSessionEnded(event) { @@ -190,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; } }