@@ -14,16 +14,17 @@ import {
1414 NearestMipmapLinearFilter ,
1515 NearestMipmapNearestFilter ,
1616 PropertyBinding ,
17- RepeatWrapping ,
1817 RGBAFormat ,
1918 RGBFormat ,
19+ RepeatWrapping ,
2020 Scene ,
2121 Vector3
2222} from "../../../build/three.module.js" ;
2323
2424//------------------------------------------------------------------------------
2525// Constants
2626//------------------------------------------------------------------------------
27+
2728var WEBGL_CONSTANTS = {
2829 POINTS : 0x0000 ,
2930 LINES : 0x0001 ,
@@ -753,7 +754,7 @@ GLTFExporter.prototype = {
753754 /**
754755 * Process image
755756 * @param {Image } image to process
756- * @param {Integer } format of the image (e.g. THREE. RGBFormat, RGBAFormat etc)
757+ * @param {Integer } format of the image (e.g. RGBFormat, RGBAFormat etc)
757758 * @param {Boolean } flipY before writing out the image
758759 * @return {Integer } Index of the processed texture in the "images" array
759760 */
@@ -807,21 +808,32 @@ GLTFExporter.prototype = {
807808
808809 } else {
809810
810- if ( format !== RGBAFormat && format !== RGBFormat )
811- throw "Only RGB and RGBA formats are supported" ;
811+ if ( format !== RGBAFormat && format !== RGBFormat ) {
812+
813+ console . error ( 'GLTFExporter: Only RGB and RGBA formats are supported.' ) ;
814+
815+ }
816+
817+ if ( image . width > options . maxTextureSize || image . height > options . maxTextureSize ) {
818+
819+ console . warn ( 'GLTFExporter: Image size is bigger than maxTextureSize' , image ) ;
812820
813- if ( image . width !== canvas . width || image . height !== canvas . height )
814- console . warn ( "Image size and imposed canvas sized do not match" ) ;
821+ }
815822
816823 let data = image . data ;
824+
817825 if ( format === RGBFormat ) {
818826
819827 data = new Uint8ClampedArray ( image . height * image . width * 4 ) ;
820- data . forEach ( function ( _ , i ) {
821828
822- data [ i ] = i % 4 === 3 ? 255 : image . data [ 3 * Math . floor ( i / 4 ) + i % 4 ] ;
829+ for ( var i = 0 ; i < data . length ; i += 4 ) {
830+
831+ data [ i + 0 ] = image . data [ i + 0 ] ;
832+ data [ i + 1 ] = image . data [ i + 1 ] ;
833+ data [ i + 2 ] = image . data [ i + 2 ] ;
834+ data [ i + 3 ] = 255 ;
823835
824- } ) ;
836+ }
825837
826838 }
827839
0 commit comments