Browse Source

WebGLRenderer: Fix WebXR depth sensing. (#28530)

* webxr depth sensing fixes

* address review comment
Rik Cabanier 1 year ago
parent
commit
e388fc42cd

+ 4 - 1
examples/webxr_xr_ballshooter.html

@@ -81,7 +81,10 @@
 				controls.target.y = 1.6;
 				controls.target.y = 1.6;
 				controls.update();
 				controls.update();
 
 
-				document.body.appendChild( XRButton.createButton( renderer, { 'optionalFeatures': [ 'depth-sensing'] } ) );
+				document.body.appendChild( XRButton.createButton( renderer, {
+					'optionalFeatures': [ 'depth-sensing' ],
+					'depthSensing': { 'usagePreference': [ 'gpu-optimized' ], 'dataFormatPreference': [] }
+				} ) );
 
 
 				// controllers
 				// controllers
 
 

+ 4 - 1
examples/webxr_xr_cubes.html

@@ -140,7 +140,10 @@
 
 
 				//
 				//
 
 
-				document.body.appendChild( XRButton.createButton( renderer, { 'optionalFeatures': [ 'depth-sensing' ] } ) );
+				document.body.appendChild( XRButton.createButton( renderer, {
+					'optionalFeatures': [ 'depth-sensing' ],
+					'depthSensing': { 'usagePreference': [ 'gpu-optimized' ], 'dataFormatPreference': [] }
+				} ) );
 
 
 			}
 			}
 
 

+ 4 - 1
examples/webxr_xr_dragging.html

@@ -124,7 +124,10 @@
 				renderer.xr.enabled = true;
 				renderer.xr.enabled = true;
 				container.appendChild( renderer.domElement );
 				container.appendChild( renderer.domElement );
 
 
-				document.body.appendChild( XRButton.createButton( renderer, { 'optionalFeatures': [ 'depth-sensing' ] } ) );
+				document.body.appendChild( XRButton.createButton( renderer, {
+					'optionalFeatures': [ 'depth-sensing' ],
+					'depthSensing': { 'usagePreference': [ 'gpu-optimized' ], 'dataFormatPreference': [] }
+				} ) );
 
 
 				// controllers
 				// controllers
 
 

+ 12 - 0
src/renderers/WebGLRenderer.js

@@ -1141,6 +1141,18 @@ class WebGLRenderer {
 
 
 			renderListStack.push( currentRenderList );
 			renderListStack.push( currentRenderList );
 
 
+			if ( xr.enabled === true && xr.isPresenting === true ) {
+
+				const depthSensingMesh = _this.xr.getDepthSensingMesh();
+
+				if ( depthSensingMesh !== null ) {
+
+					projectObject( depthSensingMesh, camera, - Infinity, _this.sortObjects );
+
+				}
+
+			}
+
 			projectObject( scene, camera, 0, _this.sortObjects );
 			projectObject( scene, camera, 0, _this.sortObjects );
 
 
 			currentRenderList.finish();
 			currentRenderList.finish();

+ 3 - 3
src/renderers/webxr/WebXRDepthSensing.js

@@ -65,7 +65,7 @@ class WebXRDepthSensing {
 
 
 	}
 	}
 
 
-	render( renderer, cameraXR ) {
+	getMesh( cameraXR ) {
 
 
 		if ( this.texture !== null ) {
 		if ( this.texture !== null ) {
 
 
@@ -86,10 +86,10 @@ class WebXRDepthSensing {
 
 
 			}
 			}
 
 
-			renderer.render( this.mesh, cameraXR );
-
 		}
 		}
 
 
+		return this.mesh;
+
 	}
 	}
 
 
 	reset() {
 	reset() {

+ 6 - 2
src/renderers/webxr/WebXRManager.js

@@ -664,6 +664,12 @@ class WebXRManager extends EventDispatcher {
 
 
 		};
 		};
 
 
+		this.getDepthSensingMesh = function () {
+
+			return depthSensing.getMesh( cameraXR );
+
+		};
+
 		// Animation Loop
 		// Animation Loop
 
 
 		let onAnimationFrameCallback = null;
 		let onAnimationFrameCallback = null;
@@ -789,8 +795,6 @@ class WebXRManager extends EventDispatcher {
 
 
 			}
 			}
 
 
-			depthSensing.render( renderer, cameraXR );
-
 			if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
 			if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
 
 
 			if ( frame.detectedPlanes ) {
 			if ( frame.detectedPlanes ) {