Parcourir la source

More useful UVs for Cylinder caps.

Mr.doob il y a 14 ans
Parent
commit
93e446e805
3 fichiers modifiés avec 11 ajouts et 11 suppressions
  1. 2 2
      build/Three.js
  2. 2 2
      build/custom/ThreeExtras.js
  3. 7 7
      src/extras/geometries/CylinderGeometry.js

+ 2 - 2
build/Three.js

@@ -474,8 +474,8 @@ t[y]);this.sides.px&&u("z","y",1*n,-1,e,c,-v,this.materials[0]);this.sides.nx&&u
 h.position.y==t.position.y&&h.position.z==t.position.z){c[e]=m;k=!0;break}}if(!k)c[e]=b.length,b.push(new THREE.Vertex(h.position.clone()))}e=0;for(f=p.faces.length;e<f;e++)h=p.faces[e],h.a=c[h.a],h.b=c[h.b],h.c=c[h.c],h.d=c[h.d];p.vertices=b})();this.computeCentroids();this.computeFaceNormals()};THREE.CubeGeometry.prototype=new THREE.Geometry;THREE.CubeGeometry.prototype.constructor=THREE.CubeGeometry;
 THREE.CylinderGeometry=function(b,c,e,f,k){THREE.Geometry.call(this);var b=b!=null?b:20,c=c!=null?c:20,e=e||100,m=e/2,f=f||8,k=k||1,h,n,t=[],u=[];for(n=0;n<=k;n++){var p=[],v=[],x=n/k,w=x*(c-b)+b;for(h=0;h<=f;h++){var z=h/f;this.vertices.push(new THREE.Vertex(new THREE.Vector3(w*Math.sin(z*Math.PI*2),-x*e+m,w*Math.cos(z*Math.PI*2))));p.push(this.vertices.length-1);v.push(new THREE.UV(z,x))}t.push(p);u.push(v)}for(n=0;n<k;n++)for(h=0;h<f;h++){var e=t[n][h],p=t[n+1][h],v=t[n+1][h+1],x=t[n][h+1],w=this.vertices[e].position.clone().setY(0).normalize(),
 z=this.vertices[p].position.clone().setY(0).normalize(),y=this.vertices[v].position.clone().setY(0).normalize(),B=this.vertices[x].position.clone().setY(0).normalize(),D=u[n][h].clone(),G=u[n+1][h].clone(),H=u[n+1][h+1].clone(),E=u[n][h+1].clone();this.faces.push(new THREE.Face4(e,p,v,x,[w,z,y,B]));this.faceVertexUvs[0].push([D,G,H,E])}if(b>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,m,0)));for(h=0;h<f;h++)e=t[0][h],p=t[0][h+1],v=this.vertices.length-1,w=new THREE.Vector3(0,1,0),z=
-new THREE.Vector3(0,1,0),y=new THREE.Vector3(0,1,0),D=u[0][h].clone(),G=u[0][h+1].clone(),H=new THREE.UV,this.faces.push(new THREE.Face3(e,p,v,[w,z,y])),this.faceVertexUvs[0].push([D,G,H])}if(c>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-m,0)));for(h=0;h<f;h++)e=t[n][h],p=this.vertices.length-1,v=t[n][h+1],w=new THREE.Vector3(0,-1,0),z=new THREE.Vector3(0,-1,0),y=new THREE.Vector3(0,-1,0),D=u[n][h].clone(),G=new THREE.UV(1,1),H=u[n][h+1].clone(),this.faces.push(new THREE.Face3(e,p,
-v,[w,z,y])),this.faceVertexUvs[0].push([D,G,H])}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;THREE.ExtrudeGeometry=function(b,c){if(typeof b!="undefined"){THREE.Geometry.call(this);var b=b instanceof Array?b:[b],e,f=b.length,k;this.shapebb=b[f-1].getBoundingBox();for(e=0;e<f;e++)k=b[e],this.addShape(k,c);this.computeCentroids();this.computeFaceNormals()}};
+new THREE.Vector3(0,1,0),y=new THREE.Vector3(0,1,0),D=u[0][h].clone(),G=u[0][h+1].clone(),H=new THREE.UV(G.u,0),this.faces.push(new THREE.Face3(e,p,v,[w,z,y])),this.faceVertexUvs[0].push([D,G,H])}if(c>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-m,0)));for(h=0;h<f;h++)e=t[n][h+1],p=t[n][h],v=this.vertices.length-1,w=new THREE.Vector3(0,-1,0),z=new THREE.Vector3(0,-1,0),y=new THREE.Vector3(0,-1,0),D=u[n][h+1].clone(),G=u[n][h].clone(),H=new THREE.UV(G.u,1),this.faces.push(new THREE.Face3(e,
+p,v,[w,z,y])),this.faceVertexUvs[0].push([D,G,H])}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;THREE.ExtrudeGeometry=function(b,c){if(typeof b!="undefined"){THREE.Geometry.call(this);var b=b instanceof Array?b:[b],e,f=b.length,k;this.shapebb=b[f-1].getBoundingBox();for(e=0;e<f;e++)k=b[e],this.addShape(k,c);this.computeCentroids();this.computeFaceNormals()}};
 THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
 THREE.ExtrudeGeometry.prototype.addShape=function(b,c){function e(b,c,e){c||console.log("die");return c.clone().multiplyScalar(e).addSelf(b)}function f(b,c,e){var f=THREE.ExtrudeGeometry.__v1,h=THREE.ExtrudeGeometry.__v2,k=THREE.ExtrudeGeometry.__v3,m=THREE.ExtrudeGeometry.__v4,n=THREE.ExtrudeGeometry.__v5,o=THREE.ExtrudeGeometry.__v6;f.set(b.x-c.x,b.y-c.y);h.set(b.x-e.x,b.y-e.y);f=f.normalize();h=h.normalize();k.set(-f.y,f.x);m.set(h.y,-h.x);n.copy(b).addSelf(k);o.copy(b).addSelf(m);if(n.equals(o))return m.clone();
 n.copy(c).addSelf(k);o.copy(e).addSelf(m);k=f.dot(m);m=o.subSelf(n).dot(m);k==0&&(console.log("Either infinite or no solutions!"),m==0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));m/=k;if(m<0)return c=Math.atan2(c.y-b.y,c.x-b.x),b=Math.atan2(e.y-b.y,e.x-b.x),c>b&&(b+=Math.PI*2),anglec=(c+b)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return f.multiplyScalar(m).addSelf(n).subSelf(b).clone()}function k(b){for(L=b.length;--L>=0;){ga=L;da=L-1;da<0&&(da=b.length-

+ 2 - 2
build/custom/ThreeExtras.js

@@ -134,8 +134,8 @@ l[v]);this.sides.px&&m("z","y",1*k,-1,c,b,-o,this.materials[0]);this.sides.nx&&m
 f.position.y==l.position.y&&f.position.z==l.position.z){c[b]=h;g=!0;break}}if(!g)c[b]=a.length,a.push(new THREE.Vertex(f.position.clone()))}b=0;for(e=n.faces.length;b<e;b++)f=n.faces[b],f.a=c[f.a],f.b=c[f.b],f.c=c[f.c],f.d=c[f.d];n.vertices=a})();this.computeCentroids();this.computeFaceNormals()};THREE.CubeGeometry.prototype=new THREE.Geometry;THREE.CubeGeometry.prototype.constructor=THREE.CubeGeometry;
 THREE.CylinderGeometry=function(a,b,c,e,h){THREE.Geometry.call(this);var a=a!=null?a:20,b=b!=null?b:20,c=c||100,g=c/2,e=e||8,h=h||1,f,k,l=[],m=[];for(k=0;k<=h;k++){var n=[],o=[],p=k/h,t=p*(b-a)+a;for(f=0;f<=e;f++){var x=f/e;this.vertices.push(new THREE.Vertex(new THREE.Vector3(t*Math.sin(x*Math.PI*2),-p*c+g,t*Math.cos(x*Math.PI*2))));n.push(this.vertices.length-1);o.push(new THREE.UV(x,p))}l.push(n);m.push(o)}for(k=0;k<h;k++)for(f=0;f<e;f++){var c=l[k][f],n=l[k+1][f],o=l[k+1][f+1],p=l[k][f+1],t=this.vertices[c].position.clone().setY(0).normalize(),
 x=this.vertices[n].position.clone().setY(0).normalize(),v=this.vertices[o].position.clone().setY(0).normalize(),u=this.vertices[p].position.clone().setY(0).normalize(),z=m[k][f].clone(),y=m[k+1][f].clone(),w=m[k+1][f+1].clone(),A=m[k][f+1].clone();this.faces.push(new THREE.Face4(c,n,o,p,[t,x,v,u]));this.faceVertexUvs[0].push([z,y,w,A])}if(a>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,g,0)));for(f=0;f<e;f++)c=l[0][f],n=l[0][f+1],o=this.vertices.length-1,t=new THREE.Vector3(0,1,0),x=
-new THREE.Vector3(0,1,0),v=new THREE.Vector3(0,1,0),z=m[0][f].clone(),y=m[0][f+1].clone(),w=new THREE.UV,this.faces.push(new THREE.Face3(c,n,o,[t,x,v])),this.faceVertexUvs[0].push([z,y,w])}if(b>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-g,0)));for(f=0;f<e;f++)c=l[k][f],n=this.vertices.length-1,o=l[k][f+1],t=new THREE.Vector3(0,-1,0),x=new THREE.Vector3(0,-1,0),v=new THREE.Vector3(0,-1,0),z=m[k][f].clone(),y=new THREE.UV(1,1),w=m[k][f+1].clone(),this.faces.push(new THREE.Face3(c,n,
-o,[t,x,v])),this.faceVertexUvs[0].push([z,y,w])}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;THREE.ExtrudeGeometry=function(a,b){if(typeof a!="undefined"){THREE.Geometry.call(this);var a=a instanceof Array?a:[a],c,e=a.length,h;this.shapebb=a[e-1].getBoundingBox();for(c=0;c<e;c++)h=a[c],this.addShape(h,b);this.computeCentroids();this.computeFaceNormals()}};
+new THREE.Vector3(0,1,0),v=new THREE.Vector3(0,1,0),z=m[0][f].clone(),y=m[0][f+1].clone(),w=new THREE.UV(y.u,0),this.faces.push(new THREE.Face3(c,n,o,[t,x,v])),this.faceVertexUvs[0].push([z,y,w])}if(b>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-g,0)));for(f=0;f<e;f++)c=l[k][f+1],n=l[k][f],o=this.vertices.length-1,t=new THREE.Vector3(0,-1,0),x=new THREE.Vector3(0,-1,0),v=new THREE.Vector3(0,-1,0),z=m[k][f+1].clone(),y=m[k][f].clone(),w=new THREE.UV(y.u,1),this.faces.push(new THREE.Face3(c,
+n,o,[t,x,v])),this.faceVertexUvs[0].push([z,y,w])}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;THREE.ExtrudeGeometry=function(a,b){if(typeof a!="undefined"){THREE.Geometry.call(this);var a=a instanceof Array?a:[a],c,e=a.length,h;this.shapebb=a[e-1].getBoundingBox();for(c=0;c<e;c++)h=a[c],this.addShape(h,b);this.computeCentroids();this.computeFaceNormals()}};
 THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
 THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,c,b){c||console.log("die");return c.clone().multiplyScalar(b).addSelf(a)}function e(a,c,b){var e=THREE.ExtrudeGeometry.__v1,f=THREE.ExtrudeGeometry.__v2,g=THREE.ExtrudeGeometry.__v3,h=THREE.ExtrudeGeometry.__v4,k=THREE.ExtrudeGeometry.__v5,l=THREE.ExtrudeGeometry.__v6;e.set(a.x-c.x,a.y-c.y);f.set(a.x-b.x,a.y-b.y);e=e.normalize();f=f.normalize();g.set(-e.y,e.x);h.set(f.y,-f.x);k.copy(a).addSelf(g);l.copy(a).addSelf(h);if(k.equals(l))return h.clone();
 k.copy(c).addSelf(g);l.copy(b).addSelf(h);g=e.dot(h);h=l.subSelf(k).dot(h);g==0&&(console.log("Either infinite or no solutions!"),h==0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));h/=g;if(h<0)return c=Math.atan2(c.y-a.y,c.x-a.x),a=Math.atan2(b.y-a.y,b.x-a.x),c>a&&(a+=Math.PI*2),anglec=(c+a)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return e.multiplyScalar(h).addSelf(k).subSelf(a).clone()}function h(a){for(B=a.length;--B>=0;){T=B;R=B-1;R<0&&(R=a.length-

+ 7 - 7
src/extras/geometries/CylinderGeometry.js

@@ -87,7 +87,7 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRad
 
 			var uv1 = uvs[ 0 ][ x ].clone();
 			var uv2 = uvs[ 0 ][ x + 1 ].clone();
-			var uv3 = new THREE.UV();
+			var uv3 = new THREE.UV( uv2.u, 0 );
 
 			this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
 			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
@@ -104,17 +104,17 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRad
 
 		for ( x = 0; x < segmentsX; x ++ ) {
 
-			var v1 = vertices[ y ][ x ];
-			var v2 = this.vertices.length - 1;
-			var v3 = vertices[ y ][ x + 1 ];
+			var v1 = vertices[ y ][ x + 1 ];
+			var v2 = vertices[ y ][ x ];
+			var v3 = this.vertices.length - 1;
 
 			var n1 = new THREE.Vector3( 0, - 1, 0 );
 			var n2 = new THREE.Vector3( 0, - 1, 0 );
 			var n3 = new THREE.Vector3( 0, - 1, 0 );
 
-			var uv1 = uvs[ y ][ x ].clone();
-			var uv2 = new THREE.UV( 1, 1 );
-			var uv3 = uvs[ y ][ x + 1 ].clone();
+			var uv1 = uvs[ y ][ x + 1 ].clone();
+			var uv2 = uvs[ y ][ x ].clone();
+			var uv3 = new THREE.UV( uv2.u, 1 );
 
 			this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
 			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );