Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USDZExporter] added flipY support #25559

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class USDZExporter {
const color = id.split( '_' )[ 1 ];
const isRGBA = texture.format === 1023;

const canvas = imageToCanvas( texture.image, color );
const canvas = imageToCanvas( texture.image, color, texture.flipY );
const blob = await new Promise( resolve => canvas.toBlob( resolve, isRGBA ? 'image/png' : 'image/jpeg', 1 ) );

files[ `textures/Texture_${ id }.${ isRGBA ? 'png' : 'jpg' }` ] = new Uint8Array( await blob.arrayBuffer() );
Expand Down Expand Up @@ -122,7 +122,7 @@ class USDZExporter {

}

function imageToCanvas( image, color ) {
function imageToCanvas( image, color, flipY ) {

if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
Expand All @@ -136,6 +136,14 @@ function imageToCanvas( image, color ) {
canvas.height = image.height * Math.min( 1, scale );

const context = canvas.getContext( '2d' );

if ( flipY === true ) {

context.translate( 0, canvas.height );
context.scale( 1, - 1 );

}

context.drawImage( image, 0, 0, canvas.width, canvas.height );

if ( color !== undefined ) {
Expand Down