Skip to content

Commit 01b8d30

Browse files
bogganThomas LanteigneMugen87
authored
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 <[email protected]> Co-authored-by: Michael Herzog <[email protected]>
1 parent 730c742 commit 01b8d30

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

examples/jsm/exporters/GLTFExporter.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -543,32 +543,36 @@ function getCanvas() {
543543

544544
function getToBlobPromise( canvas, mimeType ) {
545545

546-
if ( canvas.toBlob !== undefined ) {
546+
if ( typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas ) {
547547

548-
return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
548+
let quality;
549549

550-
}
550+
// Blink's implementation of convertToBlob seems to default to a quality level of 100%
551+
// Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
552+
if ( mimeType === 'image/jpeg' ) {
551553

552-
let quality;
554+
quality = 0.92;
553555

554-
// Blink's implementation of convertToBlob seems to default to a quality level of 100%
555-
// Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
556-
if ( mimeType === 'image/jpeg' ) {
556+
} else if ( mimeType === 'image/webp' ) {
557557

558-
quality = 0.92;
558+
quality = 0.8;
559559

560-
} else if ( mimeType === 'image/webp' ) {
560+
}
561561

562-
quality = 0.8;
562+
return canvas.convertToBlob( {
563563

564-
}
564+
type: mimeType,
565+
quality: quality
566+
567+
} );
565568

566-
return canvas.convertToBlob( {
569+
} else {
567570

568-
type: mimeType,
569-
quality: quality
571+
// HTMLCanvasElement code path
570572

571-
} );
573+
return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
574+
575+
}
572576

573577
}
574578

0 commit comments

Comments
 (0)