浏览代码

Clean up GLTFLoader

Takahiro 8 年之前
父节点
当前提交
9e3c279340
共有 1 个文件被更改,包括 39 次插入13 次删除
  1. 39 13
      examples/js/loaders/GLTFLoader.js

+ 39 - 13
examples/js/loaders/GLTFLoader.js

@@ -567,18 +567,31 @@ THREE.GLTFLoader = ( function () {
 			results = [];
 
 			var length = object.length;
+
 			for ( var idx = 0; idx < length; idx ++ ) {
+
 				var value = callback.call( thisObj || this, object[ idx ], idx );
+
 				if ( value ) {
+
 					fns.push( value );
+
 					if ( value instanceof Promise ) {
+
 						value.then( function( key, value ) {
+
 							results[ idx ] = value;
+
 						}.bind( this, key ));
+
 					} else {
+
 						results[ idx ] = value;
+
 					}
+
 				}
+
 			}
 
 		} else {
@@ -586,25 +599,41 @@ THREE.GLTFLoader = ( function () {
 			results = {};
 
 			for ( var key in object ) {
+
 				if ( object.hasOwnProperty( key ) ) {
+
 					var value = callback.call( thisObj || this, object[ key ], key );
+
 					if ( value ) {
+
 						fns.push( value );
+
 						if ( value instanceof Promise ) {
+
 							value.then( function( key, value ) {
+
 								results[ key ] = value;
+
 							}.bind( this, key ));
+
 						} else {
+
 							results[ key ] = value;
+
 						}
+
 					}
+
 				}
+
 			}
 
 		}
 
 		return Promise.all( fns ).then( function() {
+
 			return results;
+
 		});
 
 	}
@@ -1142,15 +1171,20 @@ THREE.GLTFLoader = ( function () {
 
 				if ( khr_material ) {
 
+					// don't copy over unused values to avoid material warning spam
+					var keys = [ 'ambient', 'emission', 'transparent', 'transparency', 'doubleSided' ];
+
 					switch ( khr_material.technique ) {
 
 						case 'BLINN' :
 						case 'PHONG' :
 							materialType = THREE.MeshPhongMaterial;
+							keys.push( 'diffuse', 'specular', 'shininess' );
 							break;
 
 						case 'LAMBERT' :
 							materialType = THREE.MeshLambertMaterial;
+							keys.push( 'diffuse' );
 							break;
 
 						case 'CONSTANT' :
@@ -1160,18 +1194,11 @@ THREE.GLTFLoader = ( function () {
 
 					}
 
-					// don't copy over unused values to avoid material warning spam
-					var c = ['ambient', 'transparent', 'transparency', 'doubleSided'];
-					var allowedValues = {
-						'CONSTANT': c.concat('emission'),
-						'LAMBERT':  c.concat('emission', 'diffuse'),
-						'BLINN':    c.concat('emission', 'diffuse', 'specular', 'shininess'),
-						'PHONG':    c.concat('emission', 'diffuse', 'specular', 'shininess')
-					};
-
-					allowedValues[khr_material.technique].forEach(function(v){
-						materialValues[v] = khr_material.values[v];
-					});
+					keys.forEach( function( v ) {
+
+						if ( khr_material.values[ v ] !== undefined ) materialValues[ v ] = khr_material.values[ v ];
+
+					} );
 
 					if ( khr_material.doubleSided || materialValues.doubleSided ) {
 
@@ -1639,7 +1666,6 @@ THREE.GLTFLoader = ( function () {
 
 						var attributes = primitive.attributes;
 
-
 						for ( var attributeId in attributes ) {
 
 							var attributeEntry = attributes[ attributeId ];