Kaynağa Gözat

feat: allow early set foveation (#25282)

Currently foveation is set to 1.0 on setSession,
and there's no way to set it before,
because it's not saved anywere when session is not active.
So the only way to set it to a non-default value is to call setSession and
call setFoveation afterwards.
That leads to hacks in certain scenarios like https://github.com/pmndrs/react-xr/pull/235.
This PR allows setting it beforehand, while being backwards compatible
Michael サイトー 中村 Bashurov 2 yıl önce
ebeveyn
işleme
5275bbf8ff
1 değiştirilmiş dosya ile 11 ekleme ve 14 silme
  1. 11 14
      src/renderers/webxr/WebXRManager.js

+ 11 - 14
src/renderers/webxr/WebXRManager.js

@@ -29,6 +29,8 @@ class WebXRManager extends EventDispatcher {
 
 
 		let referenceSpace = null;
 		let referenceSpace = null;
 		let referenceSpaceType = 'local-floor';
 		let referenceSpaceType = 'local-floor';
+		// Set default foveation to maximum.
+		let foveation = 1.0;
 		let customReferenceSpace = null;
 		let customReferenceSpace = null;
 
 
 		let pose = null;
 		let pose = null;
@@ -338,8 +340,7 @@ class WebXRManager extends EventDispatcher {
 
 
 				newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278
 				newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278
 
 
-				// Set foveation to maximum.
-				this.setFoveation( 1.0 );
+				this.setFoveation( foveation );
 
 
 				customReferenceSpace = null;
 				customReferenceSpace = null;
 				referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
 				referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
@@ -568,36 +569,32 @@ class WebXRManager extends EventDispatcher {
 
 
 		this.getFoveation = function () {
 		this.getFoveation = function () {
 
 
-			if ( glProjLayer !== null ) {
-
-				return glProjLayer.fixedFoveation;
-
-			}
-
-			if ( glBaseLayer !== null ) {
+			if ( glProjLayer === null && glBaseLayer === null ) {
 
 
-				return glBaseLayer.fixedFoveation;
+				return undefined;
 
 
 			}
 			}
 
 
-			return undefined;
+			return foveation;
 
 
 		};
 		};
 
 
-		this.setFoveation = function ( foveation ) {
+		this.setFoveation = function ( value ) {
 
 
 			// 0 = no foveation = full resolution
 			// 0 = no foveation = full resolution
 			// 1 = maximum foveation = the edges render at lower resolution
 			// 1 = maximum foveation = the edges render at lower resolution
 
 
+			foveation = value;
+
 			if ( glProjLayer !== null ) {
 			if ( glProjLayer !== null ) {
 
 
-				glProjLayer.fixedFoveation = foveation;
+				glProjLayer.fixedFoveation = value;
 
 
 			}
 			}
 
 
 			if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {
 			if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {
 
 
-				glBaseLayer.fixedFoveation = foveation;
+				glBaseLayer.fixedFoveation = value;
 
 
 			}
 			}