2
0
Эх сурвалжийг харах

Removing MeshFaceMaterial.

Mr.doob 10 жил өмнө
parent
commit
03b8391b2f

+ 0 - 9
examples/canvas_materials.html

@@ -80,15 +80,6 @@
 
 				];
 
-				for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) {
-
-					var face = geometry.faces[ i ];
-					if ( Math.random() > 0.5 ) face.materialIndex = Math.floor( Math.random() * materials.length );
-
-				}
-
-				materials.push( new THREE.MeshFaceMaterial( materials ) );
-
 				objects = [];
 
 				for ( var i = 0, l = materials.length; i < l; i ++ ) {

+ 3 - 10
examples/js/loaders/AssimpJSONLoader.js

@@ -94,13 +94,8 @@ THREE.AssimpJSONLoader.prototype = {
 		// read faces
 		var cnt = 0;
 		for (in_data = json.faces, i = 0, e = in_data.length; i < e; ++ i) {
-			face = new THREE.Face3();
 			src = in_data[i];
-			face.a = src[0];
-			face.b = src[1];
-			face.c = src[2];
-
-			face.materialIndex = 0; //json.materialindex;
+			face = new THREE.Face3(src[0],src[1],src[2]);
 			geometry.faces.push(face);
 		}
 
@@ -189,7 +184,7 @@ THREE.AssimpJSONLoader.prototype = {
 	},
 
 	parseMaterial : function(json) {
-		var mat = null, 
+		var mat = null,
 		scope = this, i, prop, has_textures = [],
 
 		init_props = {
@@ -286,7 +281,7 @@ THREE.AssimpJSONLoader.prototype = {
 				init_props[has_textures[i]] = defaultTexture();
 			}
 		}
-		
+
 		mat = new THREE.MeshPhongMaterial( init_props );
 		return mat;
 	},
@@ -313,5 +308,3 @@ THREE.AssimpJSONLoader.prototype = {
 		return obj;
 	},
 };
-
-

+ 6 - 6
examples/js/loaders/BinaryLoader.js

@@ -488,7 +488,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				m = materialIndexBuffer[ i ];
 
-				scope.faces.push( new THREE.Face3( a, b, c, null, null, m ) );
+				scope.faces.push( new THREE.Face3( a, b, c ) );
 
 			}
 
@@ -510,8 +510,8 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				m = materialIndexBuffer[ i ];
 
-				scope.faces.push( new THREE.Face3( a, b, d, null, null, m ) );
-				scope.faces.push( new THREE.Face3( b, c, d, null, null, m ) );
+				scope.faces.push( new THREE.Face3( a, b, d ) );
+				scope.faces.push( new THREE.Face3( b, c, d ) );
 
 			}
 
@@ -554,7 +554,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 					new THREE.Vector3( nax, nay, naz ),
 					new THREE.Vector3( nbx, nby, nbz ),
 					new THREE.Vector3( ncx, ncy, ncz )
-				], null, m ) );
+				] ) );
 
 			}
 
@@ -603,13 +603,13 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 					new THREE.Vector3( nax, nay, naz ),
 					new THREE.Vector3( nbx, nby, nbz ),
 					new THREE.Vector3( ndx, ndy, ndz )
-				], null, m ) );
+				] ) );
 
 				scope.faces.push( new THREE.Face3( b, c, d, [
 					new THREE.Vector3( nbx, nby, nbz ),
 					new THREE.Vector3( ncx, ncy, ncz ),
 					new THREE.Vector3( ndx, ndy, ndz )
-				], null, m ) );
+				] ) );
 
 			}
 

+ 0 - 7
examples/js/loaders/ColladaLoader.js

@@ -1179,13 +1179,6 @@ THREE.ColladaLoader = function () {
 
 					material = new THREE.MeshFaceMaterial( used_materials_array );
 
-					for ( j = 0; j < geom.faces.length; j ++ ) {
-
-						var face = geom.faces[ j ];
-						face.materialIndex = used_materials[ face.daeMaterial ]
-
-					}
-
 				}
 
 				if ( skinController !== undefined ) {

+ 3 - 16
examples/webgl_materials.html

@@ -91,18 +91,6 @@
 
 				var geometry_smooth = new THREE.SphereGeometry( 70, 32, 16 );
 				var geometry_flat = new THREE.SphereGeometry( 70, 32, 16 );
-				var geometry_pieces = new THREE.SphereGeometry( 70, 32, 16 ); // Extra geometry to be broken down for MeshFaceMaterial
-
-				for ( var i = 0, l = geometry_pieces.faces.length; i < l; i ++ ) {
-
-					var face = geometry_pieces.faces[ i ];
-					face.materialIndex = Math.floor( Math.random() * materials.length );
-
-				}
-
-				geometry_pieces.materials = materials;
-
-				materials.push( new THREE.MeshFaceMaterial( materials ) );
 
 				objects = [];
 
@@ -112,8 +100,7 @@
 
 					material = materials[ i ];
 
-					geometry = material instanceof THREE.MeshFaceMaterial ? geometry_pieces :
-							   ( material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth );
+					geometry = material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth;
 
 					sphere = new THREE.Mesh( geometry, material );
 
@@ -238,8 +225,8 @@
 
 				}
 
-				materials[ materials.length - 3 ].emissive.setHSL( 0.54, 1, 0.35 * ( 0.5 + 0.5 * Math.sin( 35 * timer ) ) );
-				materials[ materials.length - 4 ].emissive.setHSL( 0.04, 1, 0.35 * ( 0.5 + 0.5 * Math.cos( 35 * timer ) ) );
+				materials[ materials.length - 2 ].emissive.setHSL( 0.54, 1, 0.35 * ( 0.5 + 0.5 * Math.sin( 35 * timer ) ) );
+				materials[ materials.length - 3 ].emissive.setHSL( 0.04, 1, 0.35 * ( 0.5 + 0.5 * Math.cos( 35 * timer ) ) );
 
 				particleLight.position.x = Math.sin( timer * 7 ) * 300;
 				particleLight.position.y = Math.cos( timer * 5 ) * 400;

+ 19 - 19
examples/webgl_mirror.html

@@ -85,17 +85,17 @@
 			function fillScene() {
 
 				var planeGeo = new THREE.PlaneBufferGeometry( 100.1, 100.1 );
-				
+
 				// MIRROR planes
 				groundMirror = new THREE.Mirror( renderer, camera, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT, color: 0x777777 } );
-				
+
 				var mirrorMesh = new THREE.Mesh( planeGeo, groundMirror.material );
 				mirrorMesh.add( groundMirror );
 				mirrorMesh.rotateX( - Math.PI / 2 );
 				scene.add( mirrorMesh );
 
 				verticalMirror = new THREE.Mirror( renderer, camera, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT, color:0x889999 } );
-				
+
 				var verticalMirrorMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 60, 60 ), verticalMirror.material );
 				verticalMirrorMesh.add( verticalMirror );
 				verticalMirrorMesh.position.y = 35;
@@ -110,50 +110,50 @@
 				var sphereCap = new THREE.Mesh( geometry, material );
 				sphereCap.position.y = -15 * Math.sin( Math.PI / 180 * 30 ) - 0.05;
 				sphereCap.rotateX(-Math.PI);
-				
+
 				var geometry = new THREE.SphereGeometry( 15, 24, 24, Math.PI / 2, Math.PI * 2, 0, Math.PI / 180 * 120 );
 				var halfSphere = new THREE.Mesh( geometry, material );
 				halfSphere.add( sphereCap );
-				halfSphere.rotateX( - Math.PI / 180 * 135 ); 
-				halfSphere.rotateZ( - Math.PI / 180 * 20 ); 
+				halfSphere.rotateX( - Math.PI / 180 * 135 );
+				halfSphere.rotateZ( - Math.PI / 180 * 20 );
 				halfSphere.position.y = 7.5 + 15 * Math.sin( Math.PI / 180 * 30 );
-				
+
 				sphereGroup.add( halfSphere );
-				
+
 				var geometry = new THREE.IcosahedronGeometry( 5, 0 );
-				var material = new THREE.MeshLambertMaterial( { color: 0xffffff, emissive: 0x333333, shading: THREE.FlatShading } );
+				var material = new THREE.MeshPhongMaterial( { color: 0xffffff, emissive: 0x333333, shading: THREE.FlatShading } );
 				smallSphere = new THREE.Mesh( geometry, material );
-				scene.add(smallSphere);	
-				
+				scene.add(smallSphere);
+
 				// walls
 				var planeTop = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xffffff } ) );
 				planeTop.position.y = 100;
 				planeTop.rotateX( Math.PI / 2 );
 				scene.add( planeTop );
-				
+
 				var planeBack = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xffffff } ) );
 				planeBack.position.z = -50;
 				planeBack.position.y = 50;
 				scene.add( planeBack );
-				
+
 				var planeFront = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0x7f7fff } ) );
 				planeFront.position.z = 50;
 				planeFront.position.y = 50;
 				planeFront.rotateY( Math.PI );
 				scene.add( planeFront );
-				
+
 				var planeRight = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0x00ff00 } ) );
 				planeRight.position.x = 50;
 				planeRight.position.y = 50;
 				planeRight.rotateY( - Math.PI / 2 );
 				scene.add( planeRight );
-				
+
 				var planeLeft = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xff0000 } ) );
 				planeLeft.position.x = -50;
 				planeLeft.position.y = 50;
 				planeLeft.rotateY( Math.PI / 2 );
 				scene.add( planeLeft );
-				
+
 				// lights
 				var mainLight = new THREE.PointLight( 0xcccccc, 1.5, 250 );
 				mainLight.position.y = 60;
@@ -178,13 +178,13 @@
 				// render (update) the mirrors
 				groundMirror.renderWithMirror( verticalMirror );
 				verticalMirror.renderWithMirror( groundMirror );
-				
+
 				renderer.render(scene, camera);
 
 			}
 
 			function update() {
-				
+
 				requestAnimationFrame( update );
 
 				var timer = Date.now() * 0.01;
@@ -200,7 +200,7 @@
 				smallSphere.rotation.z = timer * 0.8;
 
 				cameraControls.update();
-				
+
 				render();
 			}
 

+ 1 - 5
src/core/Face3.js

@@ -3,7 +3,7 @@
  * @author alteredq / http://alteredqualia.com/
  */
 
-THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
+THREE.Face3 = function ( a, b, c, normal, color ) {
 
 	this.a = a;
 	this.b = b;
@@ -17,8 +17,6 @@ THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
 
 	this.vertexTangents = [];
 
-	this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
-
 };
 
 THREE.Face3.prototype = {
@@ -32,8 +30,6 @@ THREE.Face3.prototype = {
 		face.normal.copy( this.normal );
 		face.color.copy( this.color );
 
-		face.materialIndex = this.materialIndex;
-
 		for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
 
 			face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();

+ 1 - 14
src/core/Geometry.js

@@ -583,7 +583,7 @@ THREE.Geometry.prototype = {
 
 	},
 
-	merge: function ( geometry, matrix, materialIndexOffset ) {
+	merge: function ( geometry, matrix ) {
 
 		if ( geometry instanceof THREE.Geometry === false ) {
 
@@ -601,8 +601,6 @@ THREE.Geometry.prototype = {
 		uvs1 = this.faceVertexUvs[ 0 ],
 		uvs2 = geometry.faceVertexUvs[ 0 ];
 
-		if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
-
 		if ( matrix !== undefined ) {
 
 			normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
@@ -663,8 +661,6 @@ THREE.Geometry.prototype = {
 
 			}
 
-			faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
-
 			faces1.push( faceCopy );
 
 		}
@@ -872,15 +868,6 @@ THREE.Geometry.prototype = {
 			faces.push( faceType );
 			faces.push( face.a, face.b, face.c );
 
-
-			/*
-			if ( hasMaterial ) {
-
-				faces.push( face.materialIndex );
-
-			}
-			*/
-
 			if ( hasFaceVertexUv ) {
 
 				var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];

+ 7 - 9
src/extras/geometries/BoxGeometry.js

@@ -28,14 +28,14 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
 	var height_half = height / 2;
 	var depth_half = depth / 2;
 
-	buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
-	buildPlane( 'z', 'y',   1, - 1, depth, height, - width_half, 1 ); // nx
-	buildPlane( 'x', 'z',   1,   1, width, depth, height_half, 2 ); // py
-	buildPlane( 'x', 'z',   1, - 1, width, depth, - height_half, 3 ); // ny
-	buildPlane( 'x', 'y',   1, - 1, width, height, depth_half, 4 ); // pz
-	buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
+	buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
+	buildPlane( 'z', 'y',   1, - 1, depth, height, - width_half ); // nx
+	buildPlane( 'x', 'z',   1,   1, width, depth, height_half ); // py
+	buildPlane( 'x', 'z',   1, - 1, width, depth, - height_half ); // ny
+	buildPlane( 'x', 'y',   1, - 1, width, height, depth_half ); // pz
+	buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz
 
-	function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
+	function buildPlane( u, v, udir, vdir, width, height, depth ) {
 
 		var w, ix, iy,
 		gridX = scope.widthSegments,
@@ -100,7 +100,6 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
 				var face = new THREE.Face3( a + offset, b + offset, d + offset );
 				face.normal.copy( normal );
 				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
-				face.materialIndex = materialIndex;
 
 				scope.faces.push( face );
 				scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
@@ -108,7 +107,6 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
 				face = new THREE.Face3( b + offset, c + offset, d + offset );
 				face.normal.copy( normal );
 				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
-				face.materialIndex = materialIndex;
 
 				scope.faces.push( face );
 				scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );

+ 19 - 25
src/extras/geometries/ExtrudeGeometry.js

@@ -17,8 +17,6 @@
  *  extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  *  frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  *
- *  material: <int> // material index for front and back faces
- *  extrudeMaterial: <int> // material index for extrusion and beveled faces
  *  uvGenerator: <Object> // object that provides UV generator functions
  *
  * }
@@ -80,9 +78,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	var extrudePath = options.extrudePath;
 	var extrudePts, extrudeByPath = false;
 
-	var material = options.material;
-	var extrudeMaterial = options.extrudeMaterial;
-
 	// Use default WorldUVGenerator if no UV generators are specified.
 	var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
 
@@ -190,14 +185,14 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	function getBevelVec( inPt, inPrev, inNext ) {
 
 		var EPSILON = 0.0000000001;
-		
+
 		// computes for inPt the corresponding point inPt' on a new contour
 		//   shiftet by 1 unit (length of normalized vector) to the left
 		// if we walk along contour clockwise, this new contour is outside the old one
 		//
 		// inPt' is the intersection of the two lines parallel to the two
 		//  adjacent edges of inPt at a distance of 1 unit on the left side.
-		
+
 		var v_trans_x, v_trans_y, shrink_by = 1;		// resulting translation vector for inPt
 
 		// good reading for geometry algorithms (here: line-line intersection)
@@ -205,38 +200,38 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 		var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
 		var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
-		
+
 		var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
-		
+
 		// check for colinear edges
 		var colinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
-		
+
 		if ( Math.abs( colinear0 ) > EPSILON ) {		// not colinear
-			
+
 			// length of vectors for normalizing
-	
+
 			var v_prev_len = Math.sqrt( v_prev_lensq );
 			var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
-			
+
 			// shift adjacent points by unit vectors to the left
-	
+
 			var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
 			var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
-			
+
 			var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
 			var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
-	
+
 			// scaling factor for v_prev to intersection point
-	
+
 			var sf = (  ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
 						( ptNextShift_y - ptPrevShift_y ) * v_next_x    ) /
 					  ( v_prev_x * v_next_y - v_prev_y * v_next_x );
-	
+
 			// vector from inPt to intersection point
-	
+
 			v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
 			v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
-	
+
 			// Don't normalize!, otherwise sharp corners become ugly
 			//  but prevent crazy spikes
 			var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y )
@@ -245,7 +240,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			} else {
 				shrink_by = Math.sqrt( v_trans_lensq / 2 );
 			}
-			
+
 		} else {		// handle special case of colinear edges
 
 			var direction_eq = false;		// assumes: opposite
@@ -592,8 +587,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 		b += shapesOffset;
 		c += shapesOffset;
 
-		// normal, color, material
-		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
+		scope.faces.push( new THREE.Face3( a, b, c ) );
 
 		var uvs = uvgen.generateTopUV( scope, a, b, c );
 
@@ -608,8 +602,8 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 		c += shapesOffset;
 		d += shapesOffset;
 
-		scope.faces.push( new THREE.Face3( a, b, d, null, null, extrudeMaterial ) );
-		scope.faces.push( new THREE.Face3( b, c, d, null, null, extrudeMaterial ) );
+		scope.faces.push( new THREE.Face3( a, b, d ) );
+		scope.faces.push( new THREE.Face3( b, c, d ) );
 
 		var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
 

+ 3 - 6
src/loaders/JSONLoader.js

@@ -138,7 +138,7 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 
 		offset, zLength,
 
-		colorIndex, normalIndex, uvIndex, materialIndex,
+		colorIndex, normalIndex, uvIndex,
 
 		type,
 		isQuad,
@@ -225,9 +225,7 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 
 				if ( hasMaterial ) {
 
-					materialIndex = faces[ offset ++ ];
-					faceA.materialIndex = materialIndex;
-					faceB.materialIndex = materialIndex;
+					offset ++;
 
 				}
 
@@ -334,8 +332,7 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 
 				if ( hasMaterial ) {
 
-					materialIndex = faces[ offset ++ ];
-					face.materialIndex = materialIndex;
+					offset ++;
 
 				}
 

+ 4 - 39
src/materials/MeshFaceMaterial.js

@@ -4,46 +4,11 @@
 
 THREE.MeshFaceMaterial = function ( materials ) {
 
-	this.uuid = THREE.Math.generateUUID();
+	THREE.error( 'THREE.MeshFaceMaterial has been removed.' );
 
-	this.type = 'MeshFaceMaterial';
+	var material = materials !== undefined ? materials[ 0 ] : new THREE.MeshBasicMaterial();
+	material.materials = []; // temporal workaround
 
-	this.materials = materials instanceof Array ? materials : [];
-
-};
-
-THREE.MeshFaceMaterial.prototype = {
-
-	constructor: THREE.MeshFaceMaterial,
-
-	toJSON: function () {
-
-		var data = THREE.Material.prototype.toJSON.call( this );
-
-		data.materials = [];
-
-		for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
-
-			data.materials.push( this.materials[ i ].toJSON() );
-
-		}
-
-		return data;
-
-	},
-
-	clone: function () {
-
-		var material = new THREE.MeshFaceMaterial();
-
-		for ( var i = 0; i < this.materials.length; i ++ ) {
-
-			material.materials.push( this.materials[ i ].clone() );
-
-		}
-
-		return material;
-
-	}
+	return material;
 
 };