瀏覽代碼

MaterialLoader: Clean up.

Mr.doob 9 年之前
父節點
當前提交
fc1dd23d51
共有 1 個文件被更改,包括 20 次插入26 次删除
  1. 20 26
      src/loaders/MaterialLoader.js

+ 20 - 26
src/loaders/MaterialLoader.js

@@ -1,4 +1,3 @@
-import { MultiplyOperation } from '../constants';
 import { Vector2 } from '../math/Vector2';
 import { XHRLoader } from './XHRLoader';
 import { DefaultLoadingManager } from './LoadingManager';
@@ -35,23 +34,23 @@ Object.assign( MaterialLoader.prototype, {
 
 	},
 
-	getTexture: function ( name ) {
+	parse: function ( json ) {
 
 		var textures = this.textures;
 
-		if ( textures[ name ] === undefined ) {
+		function getTexture( name ) {
 
-			console.warn( 'THREE.MaterialLoader: Undefined texture', name );
+			if ( textures[ name ] === undefined ) {
 
-		}
+				console.warn( 'THREE.MaterialLoader: Undefined texture', name );
 
-		return textures[ name ];
+			}
 
-	},
+			return textures[ name ];
 
-	parse: function ( json ) {
+		}
 
-		var material = new THREE[ json.type ];
+		var material = new THREE[ json.type ]();
 
 		if ( json.uuid !== undefined ) material.uuid = json.uuid;
 		if ( json.name !== undefined ) material.name = json.name;
@@ -89,19 +88,19 @@ Object.assign( MaterialLoader.prototype, {
 
 		// maps
 
-		if ( json.map !== undefined ) material.map = this.getTexture( json.map );
+		if ( json.map !== undefined ) material.map = getTexture( json.map );
 
 		if ( json.alphaMap !== undefined ) {
 
-			material.alphaMap = this.getTexture( json.alphaMap );
+			material.alphaMap = getTexture( json.alphaMap );
 			material.transparent = true;
 
 		}
 
-		if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
+		if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
 		if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
 
-		if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
+		if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
 		if ( json.normalScale !== undefined ) {
 
 			var normalScale = json.normalScale;
@@ -118,31 +117,26 @@ Object.assign( MaterialLoader.prototype, {
 
 		}
 
-		if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
+		if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
 		if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
 		if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
 
-		if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
-		if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
+		if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
+		if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
 
-		if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
+		if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
 		if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
 
-		if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
-
-		if ( json.envMap !== undefined ) {
+		if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
 
-			material.envMap = this.getTexture( json.envMap );
-			material.combine = MultiplyOperation;
-
-		}
+		if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
 
 		if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
 
-		if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
+		if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
 		if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
 
-		if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
+		if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
 		if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
 
 		// MultiMaterial