瀏覽代碼

GLTFLoader: Make `navigator` access more robust. (#24989)

* GLTFLoader: headless

This pull request will only request navigator if it is defined, as GLTFLoader attempts to retrieve navigator, but this will throw an error for headless gltf support.

* Update GLTFLoader.js

Co-authored-by: Michael Herzog <[email protected]>
Benjamin 2 年之前
父節點
當前提交
830370ff69
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      examples/jsm/loaders/GLTFLoader.js

+ 11 - 3
examples/jsm/loaders/GLTFLoader.js

@@ -2262,10 +2262,18 @@ class GLTFParser {
 
 		// Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
 		// expensive work of uploading a texture to the GPU off the main thread.
+		
+		let isSafari = false;
+		let isFirefox = false;
+		let firefoxVersion = - 1;
 
-		const isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
-		const isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
-		const firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
+		if ( typeof navigator !== 'undefined' ) {
+
+			isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
+			isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
+			firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
+
+		}
 
 		if ( typeof createImageBitmap === 'undefined' || isSafari || ( isFirefox && firefoxVersion < 98 ) ) {