Browse Source

GLTFExporter: Remove embedImages option. (#24003)

Michael Herzog 3 years ago
parent
commit
8b4170008f

+ 1 - 2
docs/examples/en/exporters/GLTFExporter.html

@@ -119,8 +119,7 @@
 			<li>onlyVisible - bool. Export only visible objects. Default is true.</li>
 			<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
 			<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
-			<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
-			<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. This option works only if embedImages is true. Default is Infinity.</li>
+			<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. Default is Infinity.</li>
 			<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
 			<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
 			<li>includeCustomExtensions - bool. Export custom glTF extensions defined on an object's <em>userData.gltfExtensions</em> property. Default is false.</li>

+ 1 - 2
docs/examples/zh/exporters/GLTFExporter.html

@@ -119,8 +119,7 @@
 			<li>onlyVisible - bool. Export only visible objects. Default is true.</li>
 			<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
 			<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
-			<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
-			<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. This option works only if embedImages is true. Default is Infinity.</li>
+			<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. Default is Infinity.</li>
 			<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
 			<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
 			<li>includeCustomExtensions - bool. Export custom glTF extensions defined on an object's <em>userData.gltfExtensions</em> property. Default is false.</li>

+ 39 - 48
examples/jsm/exporters/GLTFExporter.js

@@ -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 );
 
 		}