Explorar o código

Update Polyfill for Helio 0.98.

Yi Huang %!s(int64=5) %!d(string=hai) anos
pai
achega
46620b4f03
Modificáronse 1 ficheiros con 15 adicións e 158 borrados
  1. 15 158
      examples/js/vr/HelioWebXRPolyfill.js

+ 15 - 158
examples/js/vr/HelioWebXRPolyfill.js

@@ -2,29 +2,23 @@
  * @author mvilledieu / http://github.com/mvilledieu
  * @author mvilledieu / http://github.com/mvilledieu
  */
  */
 
 
-if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator && 'isSessionSupported' in navigator.xr === false) {
+if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator) {
+	console.log( "Helio WebXR Polyfill (Lumin 0.98.0)" );
 
 
-	console.log( "Helio WebXR Polyfill (Lumin 0.97.0)" );
+	if ('isSessionSupported' in navigator.xr) {
 
 
-	const isHelio96 = navigator.userAgent.includes( "Chrome/73" );
+		const tempIsSessionSupported = navigator.xr.isSessionSupported.bind( navigator.xr );
 
 
-	// WebXRManager - XR.supportSession() Polyfill - WebVR.js line 147
-
-	if (
-		"supportsSession" in navigator.xr === false &&
-	"supportsSessionMode" in navigator.xr
-	) {
-
-		navigator.xr.supportsSession = function ( /*sessionType*/ ) {
+		navigator.xr.isSessionSupported = function ( /*sessionType*/ ) {
 
 
 			// Force using immersive-ar
 			// Force using immersive-ar
-			return navigator.xr.supportsSessionMode( 'immersive-ar' );
+			return tempIsSessionSupported( 'immersive-ar' );
 
 
 		};
 		};
 
 
 	}
 	}
 
 
-	if ( "requestSession" in navigator.xr ) {
+	if ('isSessionSupported' in navigator.xr && "requestSession" in navigator.xr) {
 
 
 		const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr );
 		const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr );
 
 
@@ -32,158 +26,21 @@ if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator && 'isSessionSu
 
 
 			return new Promise( function ( resolve, reject ) {
 			return new Promise( function ( resolve, reject ) {
 
 
-				const sessionType = ( isHelio96 ? {
-					mode: 'immersive-ar' // Force using immersive-ar
-				} : 'immersive-ar' );
-
-				tempRequestSession( sessionType )
-					.then( function ( session ) {
-
-						// WebXRManager - xrFrame.getPose() Polyfill - line 279
-
-						const tempRequestAnimationFrame = session.requestAnimationFrame.bind(
-							session
-						);
-
-						session.requestAnimationFrame = function ( callback ) {
-
-							return tempRequestAnimationFrame( function ( time, frame ) {
-
-								// WebXRManager - xrFrame.getViewerPose() Polyfill - line 279
-								// Transforms view.viewMatrix to view.transform.inverse.matrix
-
-								const tempGetViewerPose = frame.getViewerPose.bind( frame );
-
-								frame.getViewerPose = function ( referenceSpace ) {
-
-									const pose = tempGetViewerPose( referenceSpace );
-
-									pose.views.forEach( function ( view ) {
-
-										view.transform = {
-											inverse: {
-												matrix: view.viewMatrix
-											}
-										};
-
-									} );
-
-									return pose;
-
-								};
-
-								// WebXRManager - xrFrame.getPose() Polyfill - line 259
-
-								const tempGetPose = ( isHelio96 ? null : frame.getPose.bind( frame ) );
-
-								frame.getPose = function ( targetRaySpace, referenceSpace ) {
-
-									if ( isHelio96 ) {
-
-										const inputPose = frame.getInputPose(
-											targetRaySpace,
-											referenceSpace
-										);
-
-										inputPose.transform = {
-											matrix: inputPose.targetRay.transformMatrix
-										};
-
-										return inputPose;
-
-									} else {
-
-										return tempGetPose( targetRaySpace.gripSpace, referenceSpace );
-
-									}
-
-								};
-
-								callback( time, frame );
+				var sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor' ] };
 
 
-							} );
+				tempRequestSession( 'immersive-ar', sessionInit).then(function ( session ) {
 
 
-						};
+					resolve( session );
 
 
-						// WebXRManager - xrFrame.getPose( inputSource.targetRaySpace, referenceSpace) Polyfill - line 279
+				}).catch( function ( error ) {
 
 
-						const tempGetInputSources = session.getInputSources.bind( session );
+					return reject( error );
 
 
-						session.getInputSources = function () {
+				});
 
 
-							const res = tempGetInputSources();
+			});
 
 
-							res.forEach( function ( xrInputSource ) {
-
-								Object.defineProperty( xrInputSource, "targetRaySpace", {
-									get: function () {
-
-										return xrInputSource;
-
-									}
-								} );
-
-							} );
-
-							return res;
-
-						};
-
-						// WebXRManager - xrSession.getInputSources() Polyfill Line 132 - 136
-
-						session.inputSources = Object.defineProperty(
-							session,
-							"inputSources",
-							{
-								get: session.getInputSources
-							}
-						);
-
-						// WebXRManager - xrSession.updateRenderState() Polyfill Line 129
-
-						if ( isHelio96 ) {
-
-							session.updateRenderState = function ( { baseLayer } ) {
-
-								session.baseLayer = baseLayer;
-
-								// WebXRManager - xrSession.renderState.baseLayer Polyfill Line 219
-
-								session.renderState = {
-									baseLayer: baseLayer
-								};
-
-							};
-
-						}
-
-						// WebXRManager - xrSession.requestReferenceSpace() Polyfill Line 130
-
-						const tempRequestReferenceSpace = session.requestReferenceSpace.bind(
-							session
-						);
-
-						session.requestReferenceSpace = function () {
-
-							return tempRequestReferenceSpace( {
-								type: "stationary",
-								subtype: "floor-level"
-							} );
-
-						};
-
-						resolve( session );
-
-					} )
-					.catch( function ( error ) {
-
-						return reject( error );
-
-					} );
-
-			} );
-
-		};
+		}
 
 
 	}
 	}