Browse Source

Dumber (but safer) approach for material.clone().

Mr.doob 13 years ago
parent
commit
b973152c38
2 changed files with 50 additions and 21 deletions
  1. 22 20
      src/materials/Material.js
  2. 28 1
      src/materials/MeshBasicMaterial.js

+ 22 - 20
src/materials/Material.js

@@ -43,43 +43,45 @@ THREE.Material.prototype.setValues = function ( values ) {
 
 
 	for ( var key in values ) {
 	for ( var key in values ) {
 
 
-		if ( key === 'id' || key === 'setValues' || key === 'clone' ) continue;
-
 		var value = values[ key ];
 		var value = values[ key ];
 
 
 		if ( this[ key ] !== undefined ) {
 		if ( this[ key ] !== undefined ) {
 
 
-			if ( this[ key ] instanceof THREE.Color ) {
-				
-				if ( value instanceof THREE.Color ) {
+			this[ key ] = value;
 
 
-					this[ key ].copy( value );
+		}
 
 
-				} else {
+	}
+
+};
 
 
-					this[ key ].setHex( value );
+THREE.Material.prototype.clone = function () {
 
 
-				}
-				
-			} else if ( this[ key ] instanceof THREE.Vector3 ) {
+	material.name = this.name;
 
 
-				this[ key ].copy( value );
+	material.side = this.side;
 
 
-			} else {
+	material.opacity = this.opacity;
+	material.transparent = this.transparent;
 
 
-				this[ key ] = value;
+	material.blending = this.blending;
 
 
-			}
+	material.blendSrc = this.blendSrc;
+	material.blendDst = this.blendDst;
+	material.blendEquation = this.blendEquation;
 
 
-		}
+	material.depthTest = this.depthTest;
+	material.depthWrite = this.depthWrite;
 
 
-	}
+	material.polygonOffset = this.polygonOffset;
+	material.polygonOffsetFactor = this.polygonOffsetFactor;
+	material.polygonOffsetUnits = this.polygonOffsetUnits;
 
 
-};
+	material.alphaTest = this.alphaTest;
 
 
-THREE.Material.prototype.clone = function () {
+	material.overdraw = this.overdraw;
 
 
-	return new THREE.Material( this );
+	material.visible = this.visible;
 
 
 };
 };
 
 

+ 28 - 1
src/materials/MeshBasicMaterial.js

@@ -67,6 +67,33 @@ THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
 
 
 THREE.MeshBasicMaterial.prototype.clone = function () {
 THREE.MeshBasicMaterial.prototype.clone = function () {
 
 
-	return new THREE.MeshBasicMaterial( this );
+	var material = new THREE.MeshBasicMaterial();
+
+	material.color.copy( this.color );
+
+	material.map = this.map;
+
+	material.lightMap = this.lightMap;
+	
+	material.envMap = this.envMap;
+	material.combine = this.combine;
+	material.reflectivity = this.reflectivity;
+	material.refractionRatio = this.refractionRatio;
+
+	material.fog = this.fog;
+
+	material.shading = this.shading;
+
+	material.wireframe = this.wireframe;
+	material.wireframeLinewidth = this.wireframeLinewidth;
+	material.wireframeLinecap = this.wireframeLinecap;
+	material.wireframeLinejoin = this.wireframeLinejoin;
+
+	material.vertexColors = this.vertexColors;
+
+	material.skinning = this.skinning;
+	material.morphTargets = this.morphTargets;
+
+	return material;
 
 
 };
 };