Browse Source

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 năm trước cách đây
mục cha
commit
5275bbf8ff
1 tập tin đã thay đổi với 11 bổ sung14 xóa
  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 referenceSpaceType = 'local-floor';
+		// Set default foveation to maximum.
+		let foveation = 1.0;
 		let customReferenceSpace = null;
 
 		let pose = null;
@@ -338,8 +340,7 @@ class WebXRManager extends EventDispatcher {
 
 				newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278
 
-				// Set foveation to maximum.
-				this.setFoveation( 1.0 );
+				this.setFoveation( foveation );
 
 				customReferenceSpace = null;
 				referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
@@ -568,36 +569,32 @@ class WebXRManager extends EventDispatcher {
 
 		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
 			// 1 = maximum foveation = the edges render at lower resolution
 
+			foveation = value;
+
 			if ( glProjLayer !== null ) {
 
-				glProjLayer.fixedFoveation = foveation;
+				glProjLayer.fixedFoveation = value;
 
 			}
 
 			if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {
 
-				glBaseLayer.fixedFoveation = foveation;
+				glBaseLayer.fixedFoveation = value;
 
 			}