Browse Source

MaterialLoader/MaterialExporter: Added blending and refactoring.

Mr.doob 12 years ago
parent
commit
86700091e4
2 changed files with 15 additions and 74 deletions
  1. 5 0
      examples/js/exporters/MaterialExporter.js
  2. 10 74
      src/loaders/MaterialLoader.js

+ 5 - 0
examples/js/exporters/MaterialExporter.js

@@ -27,6 +27,7 @@ THREE.MaterialExporter.prototype = {
 			output.type = 'MeshBasicMaterial';
 			output.color = material.color.getHex();
 			if ( material.vertexColors !== THREE.NoColors ) output.vertexColors = material.vertexColors;
+			if ( material.blending !== THREE.NormalBlending ) output.blending = material.blending;
 			output.opacity = material.opacity;
 			output.transparent = material.transparent;
 			output.wireframe = material.wireframe;
@@ -38,6 +39,7 @@ THREE.MaterialExporter.prototype = {
 			output.ambient = material.ambient.getHex();
 			output.emissive = material.emissive.getHex();
 			if ( material.vertexColors !== THREE.NoColors ) output.vertexColors = material.vertexColors;
+			if ( material.blending !== THREE.NormalBlending ) output.blending = material.blending;
 			output.opacity = material.opacity;
 			output.transparent = material.transparent;
 			output.wireframe = material.wireframe;
@@ -51,6 +53,7 @@ THREE.MaterialExporter.prototype = {
 			output.specular = material.specular.getHex();
 			output.shininess = material.shininess;
 			if ( material.vertexColors !== THREE.NoColors ) output.vertexColors = material.vertexColors;
+			if ( material.blending !== THREE.NormalBlending ) output.blending = material.blending;
 			output.opacity = material.opacity;
 			output.transparent = material.transparent;
 			output.wireframe = material.wireframe;
@@ -58,6 +61,7 @@ THREE.MaterialExporter.prototype = {
 		} else if ( material instanceof THREE.MeshNormalMaterial ) {
 
 			output.type = 'MeshNormalMaterial';
+			if ( material.blending !== THREE.NormalBlending ) output.blending = material.blending;
 			output.opacity = material.opacity;
 			output.transparent = material.transparent;
 			output.wireframe = material.wireframe;
@@ -65,6 +69,7 @@ THREE.MaterialExporter.prototype = {
 		} else if ( material instanceof THREE.MeshDepthMaterial ) {
 
 			output.type = 'MeshDepthMaterial';
+			if ( material.blending !== THREE.NormalBlending ) output.blending = material.blending;
 			output.opacity = material.opacity;
 			output.transparent = material.transparent;
 			output.wireframe = material.wireframe;

+ 10 - 74
src/loaders/MaterialLoader.js

@@ -34,82 +34,18 @@ THREE.MaterialLoader.prototype = {
 
 	parse: function ( json ) {
 
-		var material;
-
-		switch ( json.type ) {
-
-			case 'MeshBasicMaterial':
-
-				material = new THREE.MeshBasicMaterial( {
-
-					color: json.color,
-					opacity: json.opacity,
-					transparent: json.transparent,
-					wireframe: json.wireframe
-
-				} );
-
-				break;
-
-			case 'MeshLambertMaterial':
-
-				material = new THREE.MeshLambertMaterial( {
-
-					color: json.color,
-					ambient: json.ambient,
-					emissive: json.emissive,
-					opacity: json.opacity,
-					transparent: json.transparent,
-					wireframe: json.wireframe
-
-				} );
-
-				break;
-
-			case 'MeshPhongMaterial':
-
-				material = new THREE.MeshPhongMaterial( {
-
-					color: json.color,
-					ambient: json.ambient,
-					emissive: json.emissive,
-					specular: json.specular,
-					shininess: json.shininess,
-					opacity: json.opacity,
-					transparent: json.transparent,
-					wireframe: json.wireframe
-
-				} );
-
-				break;
-
-			case 'MeshNormalMaterial':
-
-				material = new THREE.MeshNormalMaterial( {
-
-					opacity: json.opacity,
-					transparent: json.transparent,
-					wireframe: json.wireframe
-
-				} );
-
-				break;
-
-			case 'MeshDepthMaterial':
-
-				material = new THREE.MeshDepthMaterial( {
-
-					opacity: json.opacity,
-					transparent: json.transparent,
-					wireframe: json.wireframe
-
-				} );
-
-				break;
-
-		}
+		var material = new THREE[ json.type ];
 
+		if ( json.color !== undefined ) material.color.setHex( json.color );
+		if ( json.ambient !== undefined ) material.ambient.setHex( json.ambient );
+		if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
+		if ( json.specular !== undefined ) material.specular.setHex( json.specular );
+		if ( json.shininess !== undefined ) material.shininess = json.shininess;
 		if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
+		if ( json.blending !== undefined ) material.blending = json.blending;
+		if ( json.opacity !== undefined ) material.opacity = json.opacity;
+		if ( json.transparent !== undefined ) material.transparent = json.transparent;
+		if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
 
 		return material;