Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions docs/examples/en/exporters/GLTFExporter.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ <h3>[method:undefined parse]( [param:Object3D input], [param:Function onComplete
<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>
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/zh/exporters/GLTFExporter.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ <h3>[method:undefined parse]( [param:Object3D input], [param:Function onComplete
<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>
Expand Down
87 changes: 39 additions & 48 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ class GLTFWriter {
trs: false,
onlyVisible: true,
truncateDrawRange: true,
embedImages: true,
maxTextureSize: Infinity,
animations: [],
includeCustomExtensions: false
Expand Down Expand Up @@ -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 );

}

Expand Down