瀏覽代碼

GLTFExporter: Check for document before creating OffscreenCanvas (#24035)

Picked from https://github.com/mrdoob/three.js/pull/23998
Cody Bennett 3 年之前
父節點
當前提交
4f0ff2cd01
共有 1 個文件被更改,包括 21 次插入2 次删除
  1. 21 2
      examples/jsm/exporters/GLTFExporter.js

+ 21 - 2
examples/jsm/exporters/GLTFExporter.js

@@ -347,7 +347,7 @@ function getCanvas() {
 
 	}
 
-	if ( typeof OffscreenCanvas !== 'undefined' ) {
+	if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) {
 
 		cachedCanvas = new OffscreenCanvas( 1, 1 );
 
@@ -1112,7 +1112,26 @@ class GLTFWriter {
 
 			} else {
 
-				toBlobPromise = canvas.convertToBlob( { type: mimeType } );
+				let quality;
+
+				// Blink's implementation of convertToBlob seems to default to a quality level of 100%
+				// Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
+				if ( mimeType === 'image/jpeg' ) {
+
+					quality = 0.92;
+
+				} else if ( mimeType === 'image/webp' ) {
+
+					quality = 0.8;
+
+				}
+
+				toBlobPromise = canvas.convertToBlob( {
+
+					type: mimeType,
+					quality: quality
+
+				} );
 
 			}