Browse Source

Unflipped UVs for ExtrudeGeometry.

This fixes also TextGeometry.
alteredq 13 years ago
parent
commit
cdd0b1f36f
3 changed files with 69 additions and 38 deletions
  1. 2 2
      build/Three.js
  2. 2 2
      build/custom/ThreeExtras.js
  3. 65 34
      src/extras/geometries/ExtrudeGeometry.js

+ 2 - 2
build/Three.js

@@ -668,8 +668,8 @@ n,false);z=new THREE.Vector3;C=new THREE.Vector3;E=new THREE.Vector3}if(!m)j=i=l
 for(I=0;I<N;I++){X=m?c(p[I],V[I],Q):p[I];if(q){C.copy(w.normals[0]).multiplyScalar(X.x);z.copy(w.binormals[0]).multiplyScalar(X.y);E.copy(o[0]).addSelf(C).addSelf(z);f(E.x,E.y,E.z)}else f(X.x,X.y,0)}for(F=1;F<=n;F++)for(I=0;I<N;I++){X=m?c(p[I],V[I],Q):p[I];if(q){C.copy(w.normals[F]).multiplyScalar(X.x);z.copy(w.binormals[F]).multiplyScalar(X.y);E.copy(o[F]).addSelf(C).addSelf(z);f(E.x,E.y,E.z)}else f(X.x,X.y,h/n*F)}for(G=l-1;G>=0;G--){F=G/l;ba=i*(1-F);Q=j*Math.sin(F*Math.PI/2);I=0;for(F=B.length;I<
 F;I++){X=c(B[I],r[I],Q);f(X.x,X.y,h+ba)}u=0;for(H=O.length;u<H;u++){A=O[u];na=da[u];I=0;for(F=A.length;I<F;I++){X=c(A[I],na[I],Q);q?f(X.x,X.y+o[n-1].y,o[n-1].x+ba):f(X.x,X.y,h+ba)}}}(function(){if(m){var a;a=N*0;for(I=0;I<ca;I++){aa=Z[I];g(aa[2]+a,aa[1]+a,aa[0]+a,true)}a=n+l*2;a=N*a;for(I=0;I<ca;I++){aa=Z[I];g(aa[0]+a,aa[1]+a,aa[2]+a,false)}}else{for(I=0;I<ca;I++){aa=Z[I];g(aa[2],aa[1],aa[0],true)}for(I=0;I<ca;I++){aa=Z[I];g(aa[0]+N*n,aa[1]+N*n,aa[2]+N*n,false)}}})();(function(){var a=0;e(B,a);a=
 a+B.length;u=0;for(H=O.length;u<H;u++){A=O[u];e(A,a);a=a+A.length}})()};
-THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(a,b,c,d,e,f){b=a.vertices[e].x;e=a.vertices[e].y;c=a.vertices[f].x;f=a.vertices[f].y;return[new THREE.UV(a.vertices[d].x,1-a.vertices[d].y),new THREE.UV(b,1-e),new THREE.UV(c,1-f)]},generateBottomUV:function(a,b,c,d,e,f){return this.generateTopUV(a,b,c,d,e,f)},generateSideWallUV:function(a,b,c,d,e,f,g,h){var b=a.vertices[e].x,c=a.vertices[e].y,e=a.vertices[e].z,d=a.vertices[f].x,i=a.vertices[f].y,f=a.vertices[f].z,j=a.vertices[g].x,l=
-a.vertices[g].y,g=a.vertices[g].z,m=a.vertices[h].x,n=a.vertices[h].y,a=a.vertices[h].z;return Math.abs(c-i)<0.01?[new THREE.UV(b,e),new THREE.UV(d,f),new THREE.UV(j,g),new THREE.UV(m,a)]:[new THREE.UV(c,e),new THREE.UV(i,f),new THREE.UV(l,g),new THREE.UV(n,a)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
+THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(a,b,c,d,e,f){b=a.vertices[e].x;e=a.vertices[e].y;c=a.vertices[f].x;f=a.vertices[f].y;return[new THREE.UV(a.vertices[d].x,a.vertices[d].y),new THREE.UV(b,e),new THREE.UV(c,f)]},generateBottomUV:function(a,b,c,d,e,f){return this.generateTopUV(a,b,c,d,e,f)},generateSideWallUV:function(a,b,c,d,e,f,g,h){var b=a.vertices[e].x,c=a.vertices[e].y,e=a.vertices[e].z,d=a.vertices[f].x,i=a.vertices[f].y,f=a.vertices[f].z,j=a.vertices[g].x,l=a.vertices[g].y,
+g=a.vertices[g].z,m=a.vertices[h].x,n=a.vertices[h].y,a=a.vertices[h].z;return Math.abs(c-i)<0.01?[new THREE.UV(b,1-e),new THREE.UV(d,1-f),new THREE.UV(j,1-g),new THREE.UV(m,1-a)]:[new THREE.UV(c,1-e),new THREE.UV(i,1-f),new THREE.UV(l,1-g),new THREE.UV(n,1-a)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
 THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
 THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);for(var b=b||12,c=c||2*Math.PI,d=[],e=(new THREE.Matrix4).makeRotationZ(c/b),f=0;f<a.length;f++){d[f]=a[f].clone();this.vertices.push(d[f])}for(var g=b+1,c=0;c<g;c++)for(f=0;f<d.length;f++){d[f]=e.multiplyVector3(d[f].clone());this.vertices.push(d[f])}for(c=0;c<b;c++){d=0;for(e=a.length;d<e-1;d++){this.faces.push(new THREE.Face4(c*e+d,(c+1)%g*e+d,(c+1)%g*e+(d+1)%e,c*e+(d+1)%e));this.faceVertexUvs[0].push([new THREE.UV(1-c/b,d/e),new THREE.UV(1-
 (c+1)/b,d/e),new THREE.UV(1-(c+1)/b,(d+1)/e),new THREE.UV(1-c/b,(d+1)/e)])}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=Object.create(THREE.Geometry.prototype);

+ 2 - 2
build/custom/ThreeExtras.js

@@ -205,8 +205,8 @@ y+1;y<F;y++,D++,K++){D===F&&(D=0);K===F&&(K=0);o[y]=d(H[y],H[D],H[K])}var Q=[],P
 c(k[y],R[y],K):k[y];if(p){z.copy(r.normals[0]).multiplyScalar(I.x);v.copy(r.binormals[0]).multiplyScalar(I.y);A.copy(q[0]).addSelf(z).addSelf(v);f(A.x,A.y,A.z)}else f(I.x,I.y,0)}for(F=1;F<=n;F++)for(y=0;y<M;y++){I=m?c(k[y],R[y],K):k[y];if(p){z.copy(r.normals[F]).multiplyScalar(I.x);v.copy(r.binormals[F]).multiplyScalar(I.y);A.copy(q[F]).addSelf(z).addSelf(v);f(A.x,A.y,A.z)}else f(I.x,I.y,h/n*F)}for(D=l-1;D>=0;D--){F=D/l;O=i*(1-F);K=j*Math.sin(F*Math.PI/2);y=0;for(F=H.length;y<F;y++){I=c(H[y],o[y],
 K);f(I.x,I.y,h+O)}w=0;for(C=G.length;w<C;w++){x=G[w];P=Q[w];y=0;for(F=x.length;y<F;y++){I=c(x[y],P[y],K);p?f(I.x,I.y+q[n-1].y,q[n-1].x+O):f(I.x,I.y,h+O)}}}(function(){if(m){var a;a=M*0;for(y=0;y<N;y++){J=L[y];g(J[2]+a,J[1]+a,J[0]+a,true)}a=n+l*2;a=M*a;for(y=0;y<N;y++){J=L[y];g(J[0]+a,J[1]+a,J[2]+a,false)}}else{for(y=0;y<N;y++){J=L[y];g(J[2],J[1],J[0],true)}for(y=0;y<N;y++){J=L[y];g(J[0]+M*n,J[1]+M*n,J[2]+M*n,false)}}})();(function(){var a=0;e(H,a);a=a+H.length;w=0;for(C=G.length;w<C;w++){x=G[w];e(x,
 a);a=a+x.length}})()};
-THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(b,a,c,d,e,f){a=b.vertices[e].x;e=b.vertices[e].y;c=b.vertices[f].x;f=b.vertices[f].y;return[new THREE.UV(b.vertices[d].x,1-b.vertices[d].y),new THREE.UV(a,1-e),new THREE.UV(c,1-f)]},generateBottomUV:function(b,a,c,d,e,f){return this.generateTopUV(b,a,c,d,e,f)},generateSideWallUV:function(b,a,c,d,e,f,g,h){var a=b.vertices[e].x,c=b.vertices[e].y,e=b.vertices[e].z,d=b.vertices[f].x,i=b.vertices[f].y,f=b.vertices[f].z,j=b.vertices[g].x,l=
-b.vertices[g].y,g=b.vertices[g].z,m=b.vertices[h].x,n=b.vertices[h].y,b=b.vertices[h].z;return Math.abs(c-i)<0.01?[new THREE.UV(a,e),new THREE.UV(d,f),new THREE.UV(j,g),new THREE.UV(m,b)]:[new THREE.UV(c,e),new THREE.UV(i,f),new THREE.UV(l,g),new THREE.UV(n,b)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
+THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(b,a,c,d,e,f){a=b.vertices[e].x;e=b.vertices[e].y;c=b.vertices[f].x;f=b.vertices[f].y;return[new THREE.UV(b.vertices[d].x,b.vertices[d].y),new THREE.UV(a,e),new THREE.UV(c,f)]},generateBottomUV:function(b,a,c,d,e,f){return this.generateTopUV(b,a,c,d,e,f)},generateSideWallUV:function(b,a,c,d,e,f,g,h){var a=b.vertices[e].x,c=b.vertices[e].y,e=b.vertices[e].z,d=b.vertices[f].x,i=b.vertices[f].y,f=b.vertices[f].z,j=b.vertices[g].x,l=b.vertices[g].y,
+g=b.vertices[g].z,m=b.vertices[h].x,n=b.vertices[h].y,b=b.vertices[h].z;return Math.abs(c-i)<0.01?[new THREE.UV(a,1-e),new THREE.UV(d,1-f),new THREE.UV(j,1-g),new THREE.UV(m,1-b)]:[new THREE.UV(c,1-e),new THREE.UV(i,1-f),new THREE.UV(l,1-g),new THREE.UV(n,1-b)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
 THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
 THREE.LatheGeometry=function(b,a,c){THREE.Geometry.call(this);for(var a=a||12,c=c||2*Math.PI,d=[],e=(new THREE.Matrix4).makeRotationZ(c/a),f=0;f<b.length;f++){d[f]=b[f].clone();this.vertices.push(d[f])}for(var g=a+1,c=0;c<g;c++)for(f=0;f<d.length;f++){d[f]=e.multiplyVector3(d[f].clone());this.vertices.push(d[f])}for(c=0;c<a;c++){d=0;for(e=b.length;d<e-1;d++){this.faces.push(new THREE.Face4(c*e+d,(c+1)%g*e+d,(c+1)%g*e+(d+1)%e,c*e+(d+1)%e));this.faceVertexUvs[0].push([new THREE.UV(1-c/a,d/e),new THREE.UV(1-
 (c+1)/a,d/e),new THREE.UV(1-(c+1)/a,(d+1)/e),new THREE.UV(1-c/a,(d+1)/e)])}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=Object.create(THREE.Geometry.prototype);

+ 65 - 34
src/extras/geometries/ExtrudeGeometry.js

@@ -9,7 +9,7 @@
  *  height: 		<float>, 	// thickness to extrude text
  *  curveSegments: 	<int>,		// number of points on the curves
  *  steps: 			<int>,		// number of points for z-side extrusions / used for subdividing segements of extrude spline too
- 	amount: <int>,	// Amount 
+ 	amount: <int>,	// Amount
  *
  *  bevelEnabled:	<bool>,			// turn on bevel
  *  bevelThickness: <float>, 		// how deep into text bevel goes
@@ -60,7 +60,7 @@ THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
 
 THREE.ExtrudeGeometry.prototype.addShapeList = function(shapes, options) {
 	var sl = shapes.length;
-	
+
 	for ( var s = 0; s < sl; s ++ ) {
 		var shape = shapes[ s ];
 		this.addShape( shape, options );
@@ -440,12 +440,12 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 
 			// v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
 
-			normal.copy(splineTube.normals[0]).multiplyScalar(vert.x);
-			binormal.copy(splineTube.binormals[0]).multiplyScalar(vert.y);
+			normal.copy( splineTube.normals[0] ).multiplyScalar(vert.x);
+			binormal.copy( splineTube.binormals[0] ).multiplyScalar(vert.y);
+
+			position2.copy( extrudePts[0] ).addSelf(normal).addSelf(binormal);
 
-			position2.copy(extrudePts[0]).addSelf(normal).addSelf(binormal);
-			
-			v(position2.x, position2.y, position2.z);
+			v( position2.x, position2.y, position2.z );
 
 		}
 
@@ -470,12 +470,12 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 
 				// v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
 
-				normal.copy(splineTube.normals[s]).multiplyScalar(vert.x);
-				binormal.copy(splineTube.binormals[s]).multiplyScalar(vert.y);
+				normal.copy( splineTube.normals[s] ).multiplyScalar( vert.x );
+				binormal.copy( splineTube.binormals[s] ).multiplyScalar( vert.y );
 
-				position2.copy(extrudePts[s]).addSelf(normal).addSelf(binormal);
+				position2.copy( extrudePts[s] ).addSelf( normal ).addSelf( binormal );
 
-				v(position2.x, position2.y, position2.z );
+				v( position2.x, position2.y, position2.z );
 
 			}
 
@@ -510,7 +510,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 			ahole = holes[ h ];
 			oneHoleMovements = holesMovements[ h ];
 
-			for ( i = 0, il = ahole.length; i < il; i++ ) {
+			for ( i = 0, il = ahole.length; i < il; i ++ ) {
 
 				vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
 
@@ -537,22 +537,25 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 	////
 
 	// Top and bottom faces
+
 	buildLidFaces();
 
 	// Sides faces
+
 	buildSideFaces();
 
 
 	/////  Internal functions
 
 	function buildLidFaces() {
+
 		if ( bevelEnabled ) {
 
 			var layer = 0 ; // steps + 1
 			var offset = vlen * layer;
 
 			// Bottom faces
-			
+
 			for ( i = 0; i < flen; i ++ ) {
 
 				face = faces[ i ];
@@ -566,48 +569,62 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 			// Top faces
 
 			for ( i = 0; i < flen; i ++ ) {
+
 				face = faces[ i ];
 				f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset, false );
+
 			}
+
 		} else {
-		
+
 			// Bottom faces
 
 			for ( i = 0; i < flen; i++ ) {
+
 				face = faces[ i ];
 				f3( face[ 2 ], face[ 1 ], face[ 0 ], true );
+
 			}
 
 			// Top faces
 
 			for ( i = 0; i < flen; i ++ ) {
+
 				face = faces[ i ];
 				f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps, false );
+
 			}
 		}
+
 	}
 
 	// Create faces for the z-sides of the shape
 
 	function buildSideFaces() {
+
 		var layeroffset = 0;
 		sidewalls( contour, layeroffset );
 		layeroffset += contour.length;
 
 		for ( h = 0, hl = holes.length;  h < hl; h ++ ) {
+
 			ahole = holes[ h ];
 			sidewalls( ahole, layeroffset );
 
 			//, true
 			layeroffset += ahole.length;
+
 		}
+
 	}
 
 	function sidewalls( contour, layeroffset ) {
+
 		var j, k;
 		i = contour.length;
 
 		while ( --i >= 0 ) {
+
 			j = i;
 			k = i - 1;
 			if ( k < 0 ) k = contour.length - 1;
@@ -617,24 +634,31 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 			var s = 0, sl = steps  + bevelSegments * 2;
 
 			for ( s = 0; s < sl; s ++ ) {
+
 				var slen1 = vlen * s;
 				var slen2 = vlen * ( s + 1 );
+
 				var a = layeroffset + j + slen1,
 					b = layeroffset + k + slen1,
 					c = layeroffset + k + slen2,
 					d = layeroffset + j + slen2;
 
 				f4( a, b, c, d, contour, s, sl, j, k );
+
 			}
 		}
+
 	}
 
 
 	function v( x, y, z ) {
+
 		scope.vertices.push( new THREE.Vector3( x, y, z ) );
+
 	}
 
 	function f3( a, b, c, isBottom ) {
+
 		a += shapesOffset;
 		b += shapesOffset;
 		c += shapesOffset;
@@ -642,23 +666,26 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 		// normal, color, material
 		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
 
-		var uvs = isBottom ? uvgen.generateBottomUV( scope, shape, options, a, b, c)
-		                   : uvgen.generateTopUV( scope, shape, options, a, b, c);
+		var uvs = isBottom ? uvgen.generateBottomUV( scope, shape, options, a, b, c )
+		                   : uvgen.generateTopUV( scope, shape, options, a, b, c );
+
+ 		scope.faceVertexUvs[ 0 ].push( uvs );
 
- 		scope.faceVertexUvs[ 0 ].push(uvs);
 	}
 
 	function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
+
 		a += shapesOffset;
 		b += shapesOffset;
 		c += shapesOffset;
 		d += shapesOffset;
 
  		scope.faces.push( new THREE.Face4( a, b, c, d, null, null, extrudeMaterial ) );
- 
+
  		var uvs = uvgen.generateSideWallUV( scope, shape, wallContour, options, a, b, c, d,
  		                                    stepIndex, stepsLength, contourIndex1, contourIndex2 );
- 		scope.faceVertexUvs[ 0 ].push(uvs);
+ 		scope.faceVertexUvs[ 0 ].push( uvs );
+
 	}
 
 };
@@ -666,7 +693,8 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
 
 
 THREE.ExtrudeGeometry.WorldUVGenerator = {
-	generateTopUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC) {
+
+	generateTopUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC ) {
 		var ax = geometry.vertices[ indexA ].x,
 			ay = geometry.vertices[ indexA ].y,
 
@@ -675,16 +703,19 @@ THREE.ExtrudeGeometry.WorldUVGenerator = {
 
 			cx = geometry.vertices[ indexC ].x,
 			cy = geometry.vertices[ indexC ].y;
-			
+
 		return [
-			new THREE.UV( ax, 1 - ay ),
-			new THREE.UV( bx, 1 - by ),
-			new THREE.UV( cx, 1 - cy )
+			new THREE.UV( ax, ay ),
+			new THREE.UV( bx, by ),
+			new THREE.UV( cx, cy )
 		];
+
 	},
 
-	generateBottomUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC) {
+	generateBottomUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC ) {
+
 		return this.generateTopUV( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC );
+
 	},
 
 	generateSideWallUV: function( geometry, extrudedShape, wallContour, extrudeOptions,
@@ -705,20 +736,20 @@ THREE.ExtrudeGeometry.WorldUVGenerator = {
 			dx = geometry.vertices[ indexD ].x,
 			dy = geometry.vertices[ indexD ].y,
 			dz = geometry.vertices[ indexD ].z;
-		
+
 		if ( Math.abs( ay - by ) < 0.01 ) {
 			return [
-				new THREE.UV( ax, az ),
-				new THREE.UV( bx, bz ),
-				new THREE.UV( cx, cz ),
-				new THREE.UV( dx, dz )
+				new THREE.UV( ax, 1 - az ),
+				new THREE.UV( bx, 1 - bz ),
+				new THREE.UV( cx, 1 - cz ),
+				new THREE.UV( dx, 1 - dz )
 			];
 		} else {
 			return [
-				new THREE.UV( ay, az ),
-				new THREE.UV( by, bz ),
-				new THREE.UV( cy, cz ),
-				new THREE.UV( dy, dz )
+				new THREE.UV( ay, 1 - az ),
+				new THREE.UV( by, 1 - bz ),
+				new THREE.UV( cy, 1 - cz ),
+				new THREE.UV( dy, 1 - dz )
 			];
 		}
 	}