Browse Source

r140 (bis) (bis)

Mr.doob 3 years ago
parent
commit
bc15cd79bd
3 changed files with 38 additions and 5 deletions
  1. 1 1
      editor/sw.js
  2. 16 2
      examples/js/exporters/GLTFExporter.js
  3. 21 2
      examples/jsm/exporters/GLTFExporter.js

+ 1 - 1
editor/sw.js

@@ -1,4 +1,4 @@
-// r140.1
+// r140.2
 
 const cacheName = 'threejs-editor';
 

+ 16 - 2
examples/js/exporters/GLTFExporter.js

@@ -305,7 +305,7 @@
 
 		}
 
-		if ( typeof OffscreenCanvas !== 'undefined' ) {
+		if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) {
 
 			cachedCanvas = new OffscreenCanvas( 1, 1 );
 
@@ -1005,8 +1005,22 @@
 
 					} else {
 
+						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
+							type: mimeType,
+							quality: quality
 						} );
 
 					}

+ 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 );
 
@@ -1115,7 +1115,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
+
+					} );
 
 				}