diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index c89b3d5122df5cef68dd120d3ef5335e6846d24e..a2e486e76101107e35aac60f908cafad58f730ca 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -785,21 +785,32 @@ THREE.GLTFExporter.prototype = { } else { - if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat ) - throw "Only RGB and RGBA formats are supported"; + if ( format !== THREE.RGBAFormat && format !== THREE.RGBFormat ) { - if ( image.width !== canvas.width || image.height !== canvas.height ) - console.warn( "Image size and imposed canvas sized do not match" ); + console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' ); + + } + + if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) { + + console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image ); + + } let data = image.data; + if ( format === THREE.RGBFormat ) { data = new Uint8ClampedArray( image.height * image.width * 4 ); - data.forEach( function ( _, i ) { - data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ]; + for ( var i = 0; i < data.length; i += 4 ) { - } ); + data[ i + 0 ] = image.data[ i + 0 ]; + data[ i + 1 ] = image.data[ i + 1 ]; + data[ i + 2 ] = image.data[ i + 2 ]; + data[ i + 3 ] = 255; + + } } diff --git a/examples/jsm/exporters/GLTFExporter.js b/examples/jsm/exporters/GLTFExporter.js index 20dfaf0f61e649a093b1515a86f8da986f288599..3dace3767e1edac7e2a5304b70ef920298993841 100644 --- a/examples/jsm/exporters/GLTFExporter.js +++ b/examples/jsm/exporters/GLTFExporter.js @@ -14,9 +14,9 @@ import { NearestMipmapLinearFilter, NearestMipmapNearestFilter, PropertyBinding, - RepeatWrapping, RGBAFormat, RGBFormat, + RepeatWrapping, Scene, Vector3 } from "../../../build/three.module.js"; @@ -24,6 +24,7 @@ import { //------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------ + var WEBGL_CONSTANTS = { POINTS: 0x0000, LINES: 0x0001, @@ -753,7 +754,7 @@ GLTFExporter.prototype = { /** * Process image * @param {Image} image to process - * @param {Integer} format of the image (e.g. THREE.RGBFormat, RGBAFormat etc) + * @param {Integer} format of the image (e.g. RGBFormat, RGBAFormat etc) * @param {Boolean} flipY before writing out the image * @return {Integer} Index of the processed texture in the "images" array */ @@ -807,21 +808,32 @@ GLTFExporter.prototype = { } else { - if ( format !== RGBAFormat && format !== RGBFormat ) - throw "Only RGB and RGBA formats are supported"; + if ( format !== RGBAFormat && format !== RGBFormat ) { + + console.error( 'GLTFExporter: Only RGB and RGBA formats are supported.' ); + + } + + if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) { + + console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image ); - if ( image.width !== canvas.width || image.height !== canvas.height ) - console.warn( "Image size and imposed canvas sized do not match" ); + } let data = image.data; + if ( format === RGBFormat ) { data = new Uint8ClampedArray( image.height * image.width * 4 ); - data.forEach( function ( _, i ) { - data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ]; + for ( var i = 0; i < data.length; i += 4 ) { + + data[ i + 0 ] = image.data[ i + 0 ]; + data[ i + 1 ] = image.data[ i + 1 ]; + data[ i + 2 ] = image.data[ i + 2 ]; + data[ i + 3 ] = 255; - } ); + } } diff --git a/utils/modularize.js b/utils/modularize.js index 30787506f9e07c8f52d441210d1529b8e627c81b..1a5935f03cb61d239b03e36120a184a758c7f073 100644 --- a/utils/modularize.js +++ b/utils/modularize.js @@ -35,7 +35,7 @@ var files = [ { path: 'exporters/ColladaExporter.js', dependencies: [], ignoreList: [] }, { path: 'exporters/DRACOExporter.js', dependencies: [], ignoreList: [ 'Geometry' ] }, - { path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'RGBFormat', 'Scenes', 'ShaderMaterial', 'Matrix4' ] }, + { path: 'exporters/GLTFExporter.js', dependencies: [], ignoreList: [ 'AnimationClip', 'Camera', 'Geometry', 'Material', 'Mesh', 'Object3D', 'Scenes', 'ShaderMaterial', 'Matrix4' ] }, { path: 'exporters/MMDExporter.js', dependencies: [ { name: 'MMDParser', path: 'libs/mmdparser.module.js' } ], ignoreList: [] }, { path: 'exporters/OBJExporter.js', dependencies: [], ignoreList: [] }, { path: 'exporters/PLYExporter.js', dependencies: [], ignoreList: [] },