فهرست منبع

GLTFExporter: Clean up.

Mr.doob 4 سال پیش
والد
کامیت
6910a7a207
3فایلهای تغییر یافته به همراه40 افزوده شده و 17 حذف شده
  1. 18 7
      examples/js/exporters/GLTFExporter.js
  2. 21 9
      examples/jsm/exporters/GLTFExporter.js
  3. 1 1
      utils/modularize.js

+ 18 - 7
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;
+
+						}
 
 					}
 

+ 21 - 9
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;
 
-						} );
+						}
 
 					}
 

+ 1 - 1
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: [] },