Przeglądaj źródła

Compiled lib with new Cylinder.

Mr.doob 14 lat temu
rodzic
commit
c986eef0f9
3 zmienionych plików z 57 dodań i 47 usunięć
  1. 1 1
      build/Three.js
  2. 1 1
      build/custom/ThreeExtras.js
  3. 55 45
      src/extras/geometries/Cylinder.js

+ 1 - 1
build/Three.js

@@ -336,7 +336,7 @@ za*X+ca,J+za*(X+1)+ca,J+1+za*(X+1)+ca,J+1+za*X+ca,null,N));t.uvs.push([new THREE
 k[B]);this.sides.px&&m("z","y",1*j,-1,b,c,-w,this.materials[0]);this.sides.nx&&m("z","y",-1*j,-1,b,c,w,this.materials[1]);this.sides.py&&m("x","z",1*j,1,a,b,u,this.materials[2]);this.sides.ny&&m("x","z",1*j,-1,a,b,-u,this.materials[3]);this.sides.pz&&m("x","y",1*j,-1,a,c,o,this.materials[4]);this.sides.nz&&m("x","y",-1*j,-1,a,c,-o,this.materials[5]);(function(){for(var F=[],x=[],G=0,y=t.vertices.length;G<y;G++){for(var L=t.vertices[G],J=!1,Y=0,N=F.length;Y<N;Y++){var f=F[Y];if(L.position.x==f.position.x&&
 L.position.y==f.position.y&&L.position.z==f.position.z){x[G]=Y;J=!0;break}}if(!J){x[G]=F.length;F.push(new THREE.Vertex(L.position.clone()))}}G=0;for(y=t.faces.length;G<y;G++){L=t.faces[G];L.a=x[L.a];L.b=x[L.b];L.c=x[L.c];L.d=x[L.d]}t.vertices=F})();this.computeCentroids();this.computeFaceNormals()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
 var Cylinder=function(a,c,b,d,e,g){function h(t,w,u){j.vertices.push(new THREE.Vertex(new THREE.Vector3(t,w,u)))}THREE.Geometry.call(this);var j=this,k=Math.PI,m=d/2;for(d=0;d<a;d++)h(Math.sin(2*k*d/a)*c,Math.cos(2*k*d/a)*c,-m);for(d=0;d<a;d++)h(Math.sin(2*k*d/a)*b,Math.cos(2*k*d/a)*b,m);for(d=0;d<a;d++)j.faces.push(new THREE.Face4(d,d+a,a+(d+1)%a,(d+1)%a));if(b>0){h(0,0,-m-(g||0));for(d=a;d<a+a/2;d++)j.faces.push(new THREE.Face4(2*a,(2*d-2*a)%a,(2*d-2*a+1)%a,(2*d-2*a+2)%a))}if(c>0){h(0,0,m+(e||0));
-for(d=a+a/2;d<2*a;d++)j.faces.push(new THREE.Face4((2*d-2*a+2)%a+a,(2*d-2*a+1)%a+a,(2*d-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
+for(d=a+a/2;d<2*a;d++)j.faces.push(new THREE.Face4(2*a+1,(2*d-2*a+2)%a+a,(2*d-2*a+1)%a+a,(2*d-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
 var Icosahedron=function(a){function c(w,u,o){var v=Math.sqrt(w*w+u*u+o*o);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(w/v,u/v,o/v)))-1}function b(w,u,o,v){v.faces.push(new THREE.Face3(w,u,o))}function d(w,u){var o=e.vertices[w].position,v=e.vertices[u].position;return c((o.x+v.x)/2,(o.y+v.y)/2,(o.z+v.z)/2)}var e=this,g=new THREE.Geometry,h;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;c(-1,a,0);c(1,a,0);c(-1,-a,0);c(1,-a,0);c(0,-1,a);c(0,1,a);c(0,-1,-a);c(0,
 1,-a);c(a,0,-1);c(a,0,1);c(-a,0,-1);c(-a,0,1);b(0,11,5,g);b(0,5,1,g);b(0,1,7,g);b(0,7,10,g);b(0,10,11,g);b(1,5,9,g);b(5,11,4,g);b(11,10,2,g);b(10,7,6,g);b(7,1,8,g);b(3,9,4,g);b(3,4,2,g);b(3,2,6,g);b(3,6,8,g);b(3,8,9,g);b(4,9,5,g);b(2,4,11,g);b(6,2,10,g);b(8,6,7,g);b(9,8,1,g);for(a=0;a<this.subdivisions;a++){h=new THREE.Geometry;for(var j in g.faces){var k=d(g.faces[j].a,g.faces[j].b),m=d(g.faces[j].b,g.faces[j].c),t=d(g.faces[j].c,g.faces[j].a);b(g.faces[j].a,k,t,h);b(g.faces[j].b,m,k,h);b(g.faces[j].c,
 t,m,h);b(k,m,t,h)}g.faces=h.faces}e.faces=g.faces;delete g;delete h;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Icosahedron.prototype=new THREE.Geometry;Icosahedron.prototype.constructor=Icosahedron;

+ 1 - 1
build/custom/ThreeExtras.js

@@ -44,7 +44,7 @@ var Cube=function(a,d,b,c,g,e,f,h,j){function l(z,w,x,o,D,A,I,C){var E,F,J=c||1,
 l("z","y",1*h,-1,b,d,-t,this.materials[0]);this.sides.nx&&l("z","y",-1*h,-1,b,d,t,this.materials[1]);this.sides.py&&l("x","z",1*h,1,a,b,n,this.materials[2]);this.sides.ny&&l("x","z",1*h,-1,a,b,-n,this.materials[3]);this.sides.pz&&l("x","y",1*h,-1,a,d,m,this.materials[4]);this.sides.nz&&l("x","y",-1*h,-1,a,d,-m,this.materials[5]);(function(){for(var z=[],w=[],x=0,o=k.vertices.length;x<o;x++){for(var D=k.vertices[x],A=!1,I=0,C=z.length;I<C;I++){var E=z[I];if(D.position.x==E.position.x&&D.position.y==
 E.position.y&&D.position.z==E.position.z){w[x]=I;A=!0;break}}if(!A){w[x]=z.length;z.push(new THREE.Vertex(D.position.clone()))}}x=0;for(o=k.faces.length;x<o;x++){D=k.faces[x];D.a=w[D.a];D.b=w[D.b];D.c=w[D.c];D.d=w[D.d]}k.vertices=z})();this.computeCentroids();this.computeFaceNormals()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
 var Cylinder=function(a,d,b,c,g,e){function f(k,t,n){h.vertices.push(new THREE.Vertex(new THREE.Vector3(k,t,n)))}THREE.Geometry.call(this);var h=this,j=Math.PI,l=c/2;for(c=0;c<a;c++)f(Math.sin(2*j*c/a)*d,Math.cos(2*j*c/a)*d,-l);for(c=0;c<a;c++)f(Math.sin(2*j*c/a)*b,Math.cos(2*j*c/a)*b,l);for(c=0;c<a;c++)h.faces.push(new THREE.Face4(c,c+a,a+(c+1)%a,(c+1)%a));if(b>0){f(0,0,-l-(e||0));for(c=a;c<a+a/2;c++)h.faces.push(new THREE.Face4(2*a,(2*c-2*a)%a,(2*c-2*a+1)%a,(2*c-2*a+2)%a))}if(d>0){f(0,0,l+(g||0));
-for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4((2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
+for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4(2*a+1,(2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
 var Icosahedron=function(a){function d(t,n,m){var p=Math.sqrt(t*t+n*n+m*m);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(t/p,n/p,m/p)))-1}function b(t,n,m,p){p.faces.push(new THREE.Face3(t,n,m))}function c(t,n){var m=g.vertices[t].position,p=g.vertices[n].position;return d((m.x+p.x)/2,(m.y+p.y)/2,(m.z+p.z)/2)}var g=this,e=new THREE.Geometry,f;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;d(-1,a,0);d(1,a,0);d(-1,-a,0);d(1,-a,0);d(0,-1,a);d(0,1,a);d(0,-1,-a);d(0,
 1,-a);d(a,0,-1);d(a,0,1);d(-a,0,-1);d(-a,0,1);b(0,11,5,e);b(0,5,1,e);b(0,1,7,e);b(0,7,10,e);b(0,10,11,e);b(1,5,9,e);b(5,11,4,e);b(11,10,2,e);b(10,7,6,e);b(7,1,8,e);b(3,9,4,e);b(3,4,2,e);b(3,2,6,e);b(3,6,8,e);b(3,8,9,e);b(4,9,5,e);b(2,4,11,e);b(6,2,10,e);b(8,6,7,e);b(9,8,1,e);for(a=0;a<this.subdivisions;a++){f=new THREE.Geometry;for(var h in e.faces){var j=c(e.faces[h].a,e.faces[h].b),l=c(e.faces[h].b,e.faces[h].c),k=c(e.faces[h].c,e.faces[h].a);b(e.faces[h].a,j,k,f);b(e.faces[h].b,l,j,f);b(e.faces[h].c,
 k,l,f);b(j,l,k,f)}e.faces=f.faces}g.faces=e.faces;delete e;delete f;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Icosahedron.prototype=new THREE.Geometry;Icosahedron.prototype.constructor=Icosahedron;

+ 55 - 45
src/extras/geometries/Cylinder.js

@@ -1,89 +1,99 @@
 /**
  * @author kile / http://kile.stravaganza.org/
- * @author mr.doob / http://mrdoob.com/ 
+ * @author mr.doob / http://mrdoob.com/
+ * @author fuzzthink
  */
 
 var Cylinder = function ( numSegs, topRad, botRad, height, topOffset, botOffset ) {
 
-  THREE.Geometry.call( this );
+	THREE.Geometry.call( this );
 
-  var scope = this, i, pi = Math.PI, halfHeight = height / 2;
+	var scope = this, i, pi = Math.PI, halfHeight = height / 2;
 
-  // Top circle vertices
+	// Top circle vertices
 
-  for ( i = 0; i < numSegs; i ++ ) {
+	for ( i = 0; i < numSegs; i ++ ) {
 
-    v( Math.sin( 2 * pi * i / numSegs ) * topRad, Math.cos( 2 * pi * i / numSegs ) * topRad, - halfHeight );
+		v( Math.sin( 2 * pi * i / numSegs ) * topRad, Math.cos( 2 * pi * i / numSegs ) * topRad, - halfHeight );
 
-  }
+	}
 
-  // Bottom circle vertices
+	// Bottom circle vertices
 
-  for ( i = 0; i < numSegs; i ++ ) {
+	for ( i = 0; i < numSegs; i ++ ) {
 
-    v( Math.sin( 2 * pi * i / numSegs ) * botRad, Math.cos( 2 * pi * i / numSegs ) * botRad, halfHeight );
+		v( Math.sin( 2 * pi * i / numSegs ) * botRad, Math.cos( 2 * pi * i / numSegs ) * botRad, halfHeight );
 
-  }
+	}
 
-  // Body faces
+	// Body faces
 
-  for ( i = 0; i < numSegs; i++ ) {
+	for ( i = 0; i < numSegs; i++ ) {
 
-    f4( i, i + numSegs, numSegs + ( i + 1 ) % numSegs, ( i + 1 ) % numSegs );
+		f4(
+			i,
+			i + numSegs,
+			numSegs + ( i + 1 ) % numSegs,
+			( i + 1 ) % numSegs
+		);
 
-  }
+	}
 
-  // Bottom circle faces
+	// Bottom circle faces
 
-  if ( botRad > 0 ) {
+	if ( botRad > 0 ) {
 
-    v( 0, 0, - halfHeight - ( botOffset || 0 ) );
+		v( 0, 0, - halfHeight - ( botOffset || 0 ) );
 
-    for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) {
+		for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) {
 
-      f4(  2 * numSegs, 
-         ( 2 * i - 2 * numSegs     ) % numSegs, 
-         ( 2 * i - 2 * numSegs + 1 ) % numSegs, 
-         ( 2 * i - 2 * numSegs + 2 ) % numSegs );
+			f4(
+				2 * numSegs,
+				( 2 * i - 2 * numSegs ) % numSegs,
+				( 2 * i - 2 * numSegs + 1 ) % numSegs,
+				( 2 * i - 2 * numSegs + 2 ) % numSegs
+			);
 
-    }
+		}
 
-  }
+	}
 
-  // Top circle faces
+	// Top circle faces
 
-  if ( topRad > 0 ) {
+	if ( topRad > 0 ) {
 
-    v( 0, 0, halfHeight + ( topOffset || 0 ) );
+		v( 0, 0, halfHeight + ( topOffset || 0 ) );
 
-    for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) {
+		for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) {
 
-      f4(  2 * numSegs + 1,
-         ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, 
-         ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, 
-         ( 2 * i - 2 * numSegs     ) % numSegs + numSegs );
+			f4(
+				2 * numSegs + 1,
+				( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs,
+				( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs,
+				( 2 * i - 2 * numSegs ) % numSegs + numSegs
+			);
 
-    }
+		}
 
-  }
+	}
 
-  this.computeCentroids();
-  this.computeFaceNormals();
-  //this.computeVertexNormals();
+	this.computeCentroids();
+	this.computeFaceNormals();
+	// this.computeVertexNormals();
 
-  function v( x, y, z ) {
+	function v( x, y, z ) {
 
-    scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
+		scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
 
-  }
+	}
 
-  function f4( a, b, c, d ) {
+	function f4( a, b, c, d ) {
 
-    scope.faces.push( new THREE.Face4( a, b, c, d ) );
+		scope.faces.push( new THREE.Face4( a, b, c, d ) );
 
-  }
+	}
 
 };
 
 Cylinder.prototype = new THREE.Geometry();
-Cylinder.prototype.constructor = Cylinder;
+Cylinder.prototype.constructor = Cylinder;