Skip to content

Commit 8b41700

Browse files
authored
GLTFExporter: Remove embedImages option. (#24003)
1 parent ce66f72 commit 8b41700

File tree

3 files changed

+41
-52
lines changed

3 files changed

+41
-52
lines changed

docs/examples/en/exporters/GLTFExporter.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ <h3>[method:undefined parse]( [param:Object3D input], [param:Function onComplete
119119
<li>onlyVisible - bool. Export only visible objects. Default is true.</li>
120120
<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
121121
<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
122-
<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
123-
<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>
122+
<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. Default is Infinity.</li>
124123
<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
125124
<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
126125
<li>includeCustomExtensions - bool. Export custom glTF extensions defined on an object's <em>userData.gltfExtensions</em> property. Default is false.</li>

docs/examples/zh/exporters/GLTFExporter.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ <h3>[method:undefined parse]( [param:Object3D input], [param:Function onComplete
119119
<li>onlyVisible - bool. Export only visible objects. Default is true.</li>
120120
<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
121121
<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
122-
<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
123-
<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>
122+
<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. Default is Infinity.</li>
124123
<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
125124
<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
126125
<li>includeCustomExtensions - bool. Export custom glTF extensions defined on an object's <em>userData.gltfExtensions</em> property. Default is false.</li>

examples/jsm/exporters/GLTFExporter.js

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ class GLTFWriter {
421421
trs: false,
422422
onlyVisible: true,
423423
truncateDrawRange: true,
424-
embedImages: true,
425424
maxTextureSize: Infinity,
426425
animations: [],
427426
includeCustomExtensions: false
@@ -1056,88 +1055,80 @@ class GLTFWriter {
10561055

10571056
const imageDef = { mimeType: mimeType };
10581057

1059-
if ( options.embedImages ) {
1060-
1061-
const canvas = getCanvas();
1062-
1063-
canvas.width = Math.min( image.width, options.maxTextureSize );
1064-
canvas.height = Math.min( image.height, options.maxTextureSize );
1065-
1066-
const ctx = canvas.getContext( '2d' );
1067-
1068-
if ( flipY === true ) {
1069-
1070-
ctx.translate( 0, canvas.height );
1071-
ctx.scale( 1, - 1 );
1058+
const canvas = getCanvas();
10721059

1073-
}
1060+
canvas.width = Math.min( image.width, options.maxTextureSize );
1061+
canvas.height = Math.min( image.height, options.maxTextureSize );
10741062

1075-
if ( image.data !== undefined ) { // THREE.DataTexture
1063+
const ctx = canvas.getContext( '2d' );
10761064

1077-
if ( format !== RGBAFormat ) {
1065+
if ( flipY === true ) {
10781066

1079-
console.error( 'GLTFExporter: Only RGBAFormat is supported.' );
1067+
ctx.translate( 0, canvas.height );
1068+
ctx.scale( 1, - 1 );
10801069

1081-
}
1070+
}
10821071

1083-
if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
1072+
if ( image.data !== undefined ) { // THREE.DataTexture
10841073

1085-
console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
1074+
if ( format !== RGBAFormat ) {
10861075

1087-
}
1076+
console.error( 'GLTFExporter: Only RGBAFormat is supported.' );
10881077

1089-
const data = new Uint8ClampedArray( image.height * image.width * 4 );
1078+
}
10901079

1091-
for ( let i = 0; i < data.length; i += 4 ) {
1080+
if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
10921081

1093-
data[ i + 0 ] = image.data[ i + 0 ];
1094-
data[ i + 1 ] = image.data[ i + 1 ];
1095-
data[ i + 2 ] = image.data[ i + 2 ];
1096-
data[ i + 3 ] = image.data[ i + 3 ];
1082+
console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
10971083

1098-
}
1084+
}
10991085

1100-
ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
1086+
const data = new Uint8ClampedArray( image.height * image.width * 4 );
11011087

1102-
} else {
1088+
for ( let i = 0; i < data.length; i += 4 ) {
11031089

1104-
ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
1090+
data[ i + 0 ] = image.data[ i + 0 ];
1091+
data[ i + 1 ] = image.data[ i + 1 ];
1092+
data[ i + 2 ] = image.data[ i + 2 ];
1093+
data[ i + 3 ] = image.data[ i + 3 ];
11051094

11061095
}
11071096

1108-
if ( options.binary === true ) {
1097+
ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
11091098

1110-
let toBlobPromise;
1099+
} else {
11111100

1112-
if ( canvas.toBlob !== undefined ) {
1101+
ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
11131102

1114-
toBlobPromise = new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
1103+
}
11151104

1116-
} else {
1105+
if ( options.binary === true ) {
11171106

1118-
toBlobPromise = canvas.convertToBlob( { type: mimeType } );
1107+
let toBlobPromise;
11191108

1120-
}
1109+
if ( canvas.toBlob !== undefined ) {
1110+
1111+
toBlobPromise = new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
11211112

1122-
pending.push( toBlobPromise.then( blob =>
1113+
} else {
11231114

1124-
writer.processBufferViewImage( blob ).then( bufferViewIndex => {
1115+
toBlobPromise = canvas.convertToBlob( { type: mimeType } );
11251116

1126-
imageDef.bufferView = bufferViewIndex;
1117+
}
11271118

1128-
} )
1119+
pending.push( toBlobPromise.then( blob =>
11291120

1130-
) );
1121+
writer.processBufferViewImage( blob ).then( bufferViewIndex => {
11311122

1132-
} else {
1123+
imageDef.bufferView = bufferViewIndex;
11331124

1134-
imageDef.uri = canvas.toDataURL( mimeType );
1125+
} )
11351126

1136-
}
1127+
) );
11371128

11381129
} else {
11391130

1140-
imageDef.uri = image.src;
1131+
imageDef.uri = canvas.toDataURL( mimeType );
11411132

11421133
}
11431134

0 commit comments

Comments
 (0)