|
@@ -421,7 +421,6 @@ class GLTFWriter {
|
|
|
trs: false,
|
|
|
onlyVisible: true,
|
|
|
truncateDrawRange: true,
|
|
|
- embedImages: true,
|
|
|
maxTextureSize: Infinity,
|
|
|
animations: [],
|
|
|
includeCustomExtensions: false
|
|
@@ -1056,88 +1055,80 @@ class GLTFWriter {
|
|
|
|
|
|
const imageDef = { mimeType: mimeType };
|
|
|
|
|
|
- if ( options.embedImages ) {
|
|
|
-
|
|
|
- const canvas = getCanvas();
|
|
|
-
|
|
|
- canvas.width = Math.min( image.width, options.maxTextureSize );
|
|
|
- canvas.height = Math.min( image.height, options.maxTextureSize );
|
|
|
-
|
|
|
- const ctx = canvas.getContext( '2d' );
|
|
|
-
|
|
|
- if ( flipY === true ) {
|
|
|
-
|
|
|
- ctx.translate( 0, canvas.height );
|
|
|
- ctx.scale( 1, - 1 );
|
|
|
+ const canvas = getCanvas();
|
|
|
|
|
|
- }
|
|
|
+ canvas.width = Math.min( image.width, options.maxTextureSize );
|
|
|
+ canvas.height = Math.min( image.height, options.maxTextureSize );
|
|
|
|
|
|
- if ( image.data !== undefined ) { // THREE.DataTexture
|
|
|
+ const ctx = canvas.getContext( '2d' );
|
|
|
|
|
|
- if ( format !== RGBAFormat ) {
|
|
|
+ if ( flipY === true ) {
|
|
|
|
|
|
- console.error( 'GLTFExporter: Only RGBAFormat is supported.' );
|
|
|
+ ctx.translate( 0, canvas.height );
|
|
|
+ ctx.scale( 1, - 1 );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
|
|
|
+ if ( image.data !== undefined ) { // THREE.DataTexture
|
|
|
|
|
|
- console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
|
|
|
+ if ( format !== RGBAFormat ) {
|
|
|
|
|
|
- }
|
|
|
+ console.error( 'GLTFExporter: Only RGBAFormat is supported.' );
|
|
|
|
|
|
- const data = new Uint8ClampedArray( image.height * image.width * 4 );
|
|
|
+ }
|
|
|
|
|
|
- for ( let i = 0; i < data.length; i += 4 ) {
|
|
|
+ if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
|
|
|
|
|
|
- data[ i + 0 ] = image.data[ i + 0 ];
|
|
|
- data[ i + 1 ] = image.data[ i + 1 ];
|
|
|
- data[ i + 2 ] = image.data[ i + 2 ];
|
|
|
- data[ i + 3 ] = image.data[ i + 3 ];
|
|
|
+ console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
|
|
|
+ const data = new Uint8ClampedArray( image.height * image.width * 4 );
|
|
|
|
|
|
- } else {
|
|
|
+ for ( let i = 0; i < data.length; i += 4 ) {
|
|
|
|
|
|
- ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
|
|
|
+ data[ i + 0 ] = image.data[ i + 0 ];
|
|
|
+ data[ i + 1 ] = image.data[ i + 1 ];
|
|
|
+ data[ i + 2 ] = image.data[ i + 2 ];
|
|
|
+ data[ i + 3 ] = image.data[ i + 3 ];
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( options.binary === true ) {
|
|
|
+ ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
|
|
|
|
|
|
- let toBlobPromise;
|
|
|
+ } else {
|
|
|
|
|
|
- if ( canvas.toBlob !== undefined ) {
|
|
|
+ ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
|
|
|
|
|
|
- toBlobPromise = new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
+ if ( options.binary === true ) {
|
|
|
|
|
|
- toBlobPromise = canvas.convertToBlob( { type: mimeType } );
|
|
|
+ let toBlobPromise;
|
|
|
|
|
|
- }
|
|
|
+ if ( canvas.toBlob !== undefined ) {
|
|
|
+
|
|
|
+ toBlobPromise = new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
|
|
|
|
|
|
- pending.push( toBlobPromise.then( blob =>
|
|
|
+ } else {
|
|
|
|
|
|
- writer.processBufferViewImage( blob ).then( bufferViewIndex => {
|
|
|
+ toBlobPromise = canvas.convertToBlob( { type: mimeType } );
|
|
|
|
|
|
- imageDef.bufferView = bufferViewIndex;
|
|
|
+ }
|
|
|
|
|
|
- } )
|
|
|
+ pending.push( toBlobPromise.then( blob =>
|
|
|
|
|
|
- ) );
|
|
|
+ writer.processBufferViewImage( blob ).then( bufferViewIndex => {
|
|
|
|
|
|
- } else {
|
|
|
+ imageDef.bufferView = bufferViewIndex;
|
|
|
|
|
|
- imageDef.uri = canvas.toDataURL( mimeType );
|
|
|
+ } )
|
|
|
|
|
|
- }
|
|
|
+ ) );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- imageDef.uri = image.src;
|
|
|
+ imageDef.uri = canvas.toDataURL( mimeType );
|
|
|
|
|
|
}
|
|
|
|