From d2f2d6d4b90663964e7479d72d9ca1be92ef1129 Mon Sep 17 00:00:00 2001 From: Diego Marcos Date: Mon, 12 Oct 2020 16:35:03 -0700 Subject: [PATCH] Add support for compositor VR layers. --- src/renderers/webxr/WebXRManager.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/renderers/webxr/WebXRManager.js b/src/renderers/webxr/WebXRManager.js index d9a6d6e5e8c847..2fc78605490001 100644 --- a/src/renderers/webxr/WebXRManager.js +++ b/src/renderers/webxr/WebXRManager.js @@ -67,8 +67,8 @@ class WebXRManager extends EventDispatcher { let _currentDepthFar = null; // - this.cameraAutoUpdate = true; + this.layersEnabled = false; this.enabled = false; this.isPresenting = false; @@ -381,8 +381,29 @@ class WebXRManager extends EventDispatcher { return session.environmentBlendMode; } + } - }; + this.addLayer = function(layer) { + if (!window.XRWebGLBinding || !this.layersEnabled || !session) { return; } + + layers.push( layer ); + this.updateLayers(); + } + + this.removeLayer = function(layer) { + + layers.splice( layers.indexOf(layer), 1 ); + if (!window.XRWebGLBinding || !this.layersEnabled || !session) { return; } + + this.updateLayers(); + } + + this.updateLayers = function() { + var layersCopy = layers.map(function (x) { return x; }); + + layersCopy.unshift( session.renderState.layers[0] ); + session.updateRenderState( { layers: layersCopy } ); + } this.getDepthTexture = function () {