Browse Source

First attempt at MeshBasicMaterial / MeshLambertMaterial / MeshPhongMaterial. Also: testing branching :)

This is not supposed to work yet, all is in the flux, do not base any code on this.
alteredq 14 years ago
parent
commit
477b1e8440

+ 44 - 3
src/materials/MeshBasicMaterial.js

@@ -1,15 +1,56 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ 
+ * params = {
+ * 	color: new THREE.Color(),
+ *  bitmap: new THREE.UVMap( <Image> ),
+ *  alpha: float,
+ *  blending: THREE.AdditiveBlending,
+ *  wireframe: false
+ * }
  */
  */
 
 
-THREE.MeshColorFillMaterial = function ( hex, opacity ) {
+THREE.MeshBasicMaterial = function ( params ) {
 
 
-	this.color = new THREE.Color( ( opacity !== undefined ? opacity : 1 ) * 0xff << 24 ^ hex );
+    this.id = THREE.MeshBasicMaterial.value ++;
+    
+    this.params = this.setDefaultParams( params );
 
 
 	this.toString = function () {
 	this.toString = function () {
 
 
-		return 'THREE.MeshColorFillMaterial ( color: ' + this.color + ' )';
+		return 'THREE.MeshBasicMaterial ( color: ' + this.params.color 
+        + ', alpha: ' + this.params.alpha 
+        + ', blending: ' + this.params.blending 
+        + ', wireframe: ' + this.params.wireframe 
+        + ', id: ' + this.id + ' )';
 
 
 	};
 	};
 
 
 };
 };
+
+THREE.MeshBasicMaterial.setDefaultParams = function ( override ) {
+    
+    var params = {
+        color: new THREE.Color( 0xeeeeee ),
+        bitmap: null,
+        alpha: 1.0,
+        blending: THREE.AdditiveBlending,
+        wireframe: false
+    };
+        
+    if ( override != undefined ) {
+        
+        if( override.color != undefined ) params.color = override.color;
+        if( override.bitmap != undefined ) params.bitmap = override.bitmap;
+        if( override.alpha != undefined ) params.alpha = override.alpha;
+        if( override.blending != undefined ) params.blending = override.blending;
+        if( override.wireframe != undefined ) params.wireframe = override.wireframe;
+        
+    }
+    
+    return params;
+    
+};
+
+THREE.MeshBasicMaterial = { value: 0 };

+ 49 - 4
src/materials/MeshLambertMaterial.js

@@ -1,15 +1,60 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ 
+ * params = {
+ * 	diffuse: new THREE.Color(),
+ *  diffuse_map: new THREE.UVMap( <Image> ),
+ *  alpha: float,
+ *  shading: THREE.Gourad,
+ *  blending: THREE.AdditiveBlending,
+ *  wireframe: false
+ * }
  */
  */
 
 
-THREE.MeshColorFillMaterial = function ( hex, opacity ) {
-
-	this.color = new THREE.Color( ( opacity !== undefined ? opacity : 1 ) * 0xff << 24 ^ hex );
+THREE.MeshLambertMaterial = function ( params ) {
 
 
+    this.id = THREE.MeshLambertMaterial.value ++;
+    
+    this.params = this.setDefaultParams( params );
+    
 	this.toString = function () {
 	this.toString = function () {
 
 
-		return 'THREE.MeshColorFillMaterial ( color: ' + this.color + ' )';
+		return 'THREE.MeshLambertMaterial ( diffuse: ' + this.params.diffuse 
+        + ', alpha: ' + this.params.alpha 
+        + ', shading: ' + this.params.shading 
+        + ', blending: ' + this.params.blending 
+        + ', wireframe: ' + this.params.wireframe 
+        + ', id: ' + this.id +' )';
 
 
 	};
 	};
 
 
 };
 };
+
+THREE.MeshLambertMaterial.setDefaultParams = function ( override ) {
+    
+    var params = {
+        diffuse: new THREE.Color( 0xeeeeee ),
+        diffuse_map: null,
+        alpha: 1.0,
+        shading: THREE.Gourad,
+        blending: THREE.AdditiveBlending,
+        wireframe: false
+    };
+        
+    if ( override != undefined ) {
+        
+        if( override.diffuse != undefined ) params.diffuse = override.diffuse;
+        if( override.diffuse_map != undefined ) params.diffuse_map = override.diffuse_map;
+        if( override.alpha != undefined ) params.alpha = override.alpha;
+        if( override.shading != undefined ) params.shading = override.shading;
+        if( override.blending != undefined ) params.blending = override.blending;
+        if( override.wireframe != undefined ) params.wireframe = override.wireframe;
+        
+    }
+    
+    return params;
+    
+};
+
+THREE.MeshLambertMaterial = { value: 0 };

+ 63 - 12
src/materials/MeshPhongMaterial.js

@@ -1,24 +1,75 @@
 /**
 /**
+ * @author mr.doob / http://mrdoob.com/
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
+ 
+ * params = {
+ * 	ambient: new THREE.Color(),
+ * 	diffuse: new THREE.Color(),
+ * 	specular: new THREE.Color(),
+ *  diffuse_map: new THREE.UVMap( <Image> ),
+ *  specular_map: new THREE.UVMap( <Image> ),
+ *  shininess: float,
+ *  alpha: float,
+ *  shading: THREE.Phong,
+ *  blending: THREE.AdditiveBlending,
+ *  wireframe: false
+ * }
  */
  */
 
 
 THREE.MeshPhongMaterial = function ( ambient, diffuse, specular, shininess, opacity ) {
 THREE.MeshPhongMaterial = function ( ambient, diffuse, specular, shininess, opacity ) {
 
 
-	this.ambient = new THREE.Color( ( opacity !== undefined ? opacity : 1 ) * 0xff << 24 ^ ambient );
-	this.diffuse = new THREE.Color( ( opacity !== undefined ? opacity : 1 ) * 0xff << 24 ^ diffuse );
-	this.specular = new THREE.Color( ( opacity !== undefined ? opacity : 1 ) * 0xff << 24 ^ specular );
-
-	this.shininess = shininess;
-	this.opacity = opacity;
-
+    this.id = THREE.MeshPhongMaterial.value ++;
+    
+    this.params = this.setDefaultParams( params );
+    
 	this.toString = function () {
 	this.toString = function () {
 
 
-		return 'THREE.MeshPhongMaterial ( <br/>ambient: ' + this.ambient 
-                + ', <br/>diffuse: ' + this.diffuse 
-                + ', <br/>specular: ' + this.specular 
-                + ', <br/>shininess: ' + this.shininess 
-                + ', <br/>opacity: ' + this.opacity + ')';
+		return 'THREE.MeshPhongMaterial ( <br/>ambient: ' + this.params.ambient_color
+                + ', <br/>diffuse: ' + this.params.diffuse 
+                + ', <br/>specular: ' + this.params.specular 
+                + ', <br/>shininess: ' + this.params.shininess 
+                + ', <br/>alpha: ' + this.params.alpha
+                + ', <br/>shading: ' + this.params.shading
+                + ', <br/>wireframe: ' + this.params.wireframe
+                + ', <br/>id: ' + this.params.id        
+                + ')';
 
 
 	};
 	};
 
 
 };
 };
+
+THREE.MeshPhongMaterial.setDefaultParams = function ( override ) {
+    
+    var params = {
+        ambient: new THREE.Color( 0x050505 ),
+        diffuse: new THREE.Color( 0xeeeeee ),
+        specular: new THREE.Color( 0x111111 ),
+        diffuse_map: null,
+        specular_map: null,
+        shininess: 30,
+        alpha: 1.0,
+        shading: THREE.Gourad,
+        blending: THREE.AdditiveBlending,
+        wireframe: false
+    };
+        
+    if ( override != undefined ) {
+        
+        if( override.ambient != undefined ) params.ambient = override.ambient;
+        if( override.diffuse != undefined ) params.diffuse = override.diffuse;
+        if( override.specular != undefined ) params.specular = override.specular;
+        if( override.diffuse_map != undefined ) params.diffuse_map = override.diffuse_map;
+        if( override.specular_map != undefined ) params.specular_map = override.specular_map;
+        if( override.shininess != undefined ) params.shininess = override.shininess;
+        if( override.alpha != undefined ) params.alpha = override.alpha;
+        if( override.shading != undefined ) params.shading = override.shading;
+        if( override.blending != undefined ) params.blending = override.blending;
+        if( override.wireframe != undefined ) params.wireframe = override.wireframe;
+        
+    }
+    
+    return params;
+    
+};
+
+THREE.MeshPhongMaterial = { value: 0 };