Skip to content

Commit

Permalink
USDZExporter: Improved resizing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Feb 15, 2021
1 parent 39efa38 commit 1e210ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ async function imgToU8( image ) {
( typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas ) ||
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {

const scale = 1024 / Math.max( image.width, image.height );

const canvas = document.createElement( 'canvas' );
canvas.width = Math.min( 1024, image.width );
canvas.height = Math.min( 1024, image.height );
canvas.width = image.width * Math.min( 1, scale );
canvas.height = image.height * Math.min( 1, scale );

const context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0, canvas.width, canvas.height );
Expand Down

0 comments on commit 1e210ac

Please sign in to comment.