Browse Source

Face3ized common geometries.

Mr.doob 12 years ago
parent
commit
44b1b3ab11

+ 18 - 7
src/extras/geometries/CubeGeometry.js

@@ -85,18 +85,29 @@ THREE.CubeGeometry = function ( width, height, depth, widthSegments, heightSegme
 				var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
 				var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
 				var d = ( ix + 1 ) + gridX1 * iy;
 				var d = ( ix + 1 ) + gridX1 * iy;
 
 
-				var face = new THREE.Face4( a + offset, b + offset, c + offset, d + offset );
+				var face = new THREE.Face3( a + offset, b + offset, c + offset );
 				face.normal.copy( normal );
 				face.normal.copy( normal );
-				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
+				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
 				face.materialIndex = materialIndex;
 				face.materialIndex = materialIndex;
 
 
 				scope.faces.push( face );
 				scope.faces.push( face );
 				scope.faceVertexUvs[ 0 ].push( [
 				scope.faceVertexUvs[ 0 ].push( [
-							new THREE.Vector2( ix / gridX, 1 - iy / gridY ),
-							new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY ),
-							new THREE.Vector2( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
-							new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY )
-						] );
+					new THREE.Vector2( ix / gridX, 1 - iy / gridY ),
+					new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY ),
+					new THREE.Vector2( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY )
+				] );
+
+				face = new THREE.Face3( a + 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( [
+					new THREE.Vector2( ix / gridX, 1 - iy / gridY ),
+					new THREE.Vector2( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
+					new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY )
+				] );
 
 
 			}
 			}
 
 

+ 5 - 2
src/extras/geometries/CylinderGeometry.js

@@ -85,8 +85,11 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegme
 			var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
 			var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
 			var uv4 = uvs[ y ][ x + 1 ].clone();
 			var uv4 = uvs[ y ][ x + 1 ].clone();
 
 
-			this.faces.push( new THREE.Face4( v1, v2, v3, v4, [ n1, n2, n3, n4 ] ) );
-			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3, uv4 ] );
+			this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
+			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
+
+			this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
+			this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
 
 
 		}
 		}
 
 

+ 13 - 3
src/extras/geometries/LatheGeometry.js

@@ -56,22 +56,32 @@ THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
 			var c = base + 1 + np;
 			var c = base + 1 + np;
 			var d = base + 1;
 			var d = base + 1;
 
 
-			this.faces.push( new THREE.Face4( a, b, c, d ) );
-
 			var u0 = i * inverseSegments;
 			var u0 = i * inverseSegments;
 			var v0 = j * inversePointLength;
 			var v0 = j * inversePointLength;
 			var u1 = u0 + inverseSegments;
 			var u1 = u0 + inverseSegments;
 			var v1 = v0 + inversePointLength;
 			var v1 = v0 + inversePointLength;
 
 
+			this.faces.push( new THREE.Face3( a, b, c ) );
+
 			this.faceVertexUvs[ 0 ].push( [
 			this.faceVertexUvs[ 0 ].push( [
 
 
-				new THREE.Vector2( u0, v0 ), 
+				new THREE.Vector2( u0, v0 ),
 				new THREE.Vector2( u1, v0 ),
 				new THREE.Vector2( u1, v0 ),
+				new THREE.Vector2( u1, v1 )
+
+			] );
+
+			this.faces.push( new THREE.Face3( a, c, d ) );
+
+			this.faceVertexUvs[ 0 ].push( [
+
+				new THREE.Vector2( u0, v0 ),
 				new THREE.Vector2( u1, v1 ),
 				new THREE.Vector2( u1, v1 ),
 				new THREE.Vector2( u0, v1 )
 				new THREE.Vector2( u0, v1 )
 
 
 			] );
 			] );
 
 
+
 		}
 		}
 
 
 	}
 	}

+ 13 - 2
src/extras/geometries/PlaneGeometry.js

@@ -50,14 +50,25 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
 			var c = ( ix + 1 ) + gridX1 * ( iz + 1 );
 			var c = ( ix + 1 ) + gridX1 * ( iz + 1 );
 			var d = ( ix + 1 ) + gridX1 * iz;
 			var d = ( ix + 1 ) + gridX1 * iz;
 
 
-			var face = new THREE.Face4( a, b, c, d );
+			var face = new THREE.Face3( a, b, c );
 			face.normal.copy( normal );
 			face.normal.copy( normal );
-			face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
+			face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
 
 
 			this.faces.push( face );
 			this.faces.push( face );
 			this.faceVertexUvs[ 0 ].push( [
 			this.faceVertexUvs[ 0 ].push( [
 				new THREE.Vector2( ix / gridX, 1 - iz / gridZ ),
 				new THREE.Vector2( ix / gridX, 1 - iz / gridZ ),
 				new THREE.Vector2( ix / gridX, 1 - ( iz + 1 ) / gridZ ),
 				new THREE.Vector2( ix / gridX, 1 - ( iz + 1 ) / gridZ ),
+				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ )
+			] );
+
+
+			face = new THREE.Face3( a, c, d );
+			face.normal.copy( normal );
+			face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
+
+			this.faces.push( face );
+			this.faceVertexUvs[ 0 ].push( [
+				new THREE.Vector2( ix / gridX, 1 - iz / gridZ ),
 				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ ),
 				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ ),
 				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iz / gridZ )
 				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iz / gridZ )
 			] );
 			] );

+ 5 - 2
src/extras/geometries/SphereGeometry.js

@@ -77,8 +77,11 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
 
 
 			} else {
 			} else {
 
 
-				this.faces.push( new THREE.Face4( v1, v2, v3, v4, [ n1, n2, n3, n4 ] ) );
-				this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3, uv4 ] );
+				this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
+				this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
+
+				this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
+				this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
 
 
 			}
 			}
 
 

+ 11 - 2
src/extras/geometries/TorusGeometry.js

@@ -51,16 +51,25 @@ THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments,
 			var c = ( this.tubularSegments + 1 ) * ( j - 1 ) + i;
 			var c = ( this.tubularSegments + 1 ) * ( j - 1 ) + i;
 			var d = ( this.tubularSegments + 1 ) * j + i;
 			var d = ( this.tubularSegments + 1 ) * j + i;
 
 
-			var face = new THREE.Face4( a, b, c, d, [ normals[ a ], normals[ b ], normals[ c ], normals[ d ] ] );
+			var face = new THREE.Face3( a, b, c, [ normals[ a ], normals[ b ], normals[ c ] ] );
 			face.normal.add( normals[ a ] );
 			face.normal.add( normals[ a ] );
 			face.normal.add( normals[ b ] );
 			face.normal.add( normals[ b ] );
 			face.normal.add( normals[ c ] );
 			face.normal.add( normals[ c ] );
+			face.normal.normalize();
+
+			this.faces.push( face );
+
+			this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ c ].clone() ] );
+
+			face = new THREE.Face3( a, c, d, [ normals[ a ], normals[ c ], normals[ d ] ] );
+			face.normal.add( normals[ a ] );
+			face.normal.add( normals[ c ] );
 			face.normal.add( normals[ d ] );
 			face.normal.add( normals[ d ] );
 			face.normal.normalize();
 			face.normal.normalize();
 
 
 			this.faces.push( face );
 			this.faces.push( face );
 
 
-			this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
+			this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
 		}
 		}
 
 
 	}
 	}

+ 5 - 2
src/extras/geometries/TorusKnotGeometry.js

@@ -70,8 +70,11 @@ THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegmen
 			var uvc = new THREE.Vector2( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
 			var uvc = new THREE.Vector2( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
 			var uvd = new THREE.Vector2( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
 			var uvd = new THREE.Vector2( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
 
 
-			this.faces.push( new THREE.Face4( a, b, c, d ) );
-			this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );
+			this.faces.push( new THREE.Face3( a, b, c ) );
+			this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvc ] );
+
+			this.faces.push( new THREE.Face3( a, c, d ) );
+			this.faceVertexUvs[ 0 ].push( [ uva, uvc, uvd ] );
 
 
 		}
 		}
 	}
 	}