Browse Source

GLTFExporter: Make `getToBlobPromise()` more robust. (#31598)

* - fixed for Firefox 141.0.2+ not resolving promise with Offscreencanvas when exporting GLTF/GLB images

* Update package.json

* - updates based on PR comments

* Update GLTFExporter.js

* Update GLTFExporter.js

Rewrite `getToBlobPromise()`.

---------

Co-authored-by: Thomas Lanteigne <thomas.lanteigne@2020spaces.com>
Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
boggan 9 months ago
parent
commit
01b8d30100
1 changed files with 19 additions and 15 deletions
  1. 19 15
      examples/jsm/exporters/GLTFExporter.js

+ 19 - 15
examples/jsm/exporters/GLTFExporter.js

@@ -543,32 +543,36 @@ function getCanvas() {
 
 function getToBlobPromise( canvas, mimeType ) {
 
-	if ( canvas.toBlob !== undefined ) {
+	if ( typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas ) {
 
-		return new Promise( ( resolve ) => canvas.toBlob( resolve, 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' ) {
 
-	let quality;
+			quality = 0.92;
 
-	// 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' ) {
+		} else if ( mimeType === 'image/webp' ) {
 
-		quality = 0.92;
+			quality = 0.8;
 
-	} else if ( mimeType === 'image/webp' ) {
+		}
 
-		quality = 0.8;
+		return canvas.convertToBlob( {
 
-	}
+			type: mimeType,
+			quality: quality
+
+		} );
 
-	return canvas.convertToBlob( {
+	} else {
 
-		type: mimeType,
-		quality: quality
+		// HTMLCanvasElement code path
 
-	} );
+		return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
+
+	}
 
 }
 

粤ICP备19079148号