Browse Source

Merge remote branch 'remotes/upstream/master'

alteredq 14 years ago
parent
commit
5273e091d1
2 changed files with 46 additions and 1 deletions
  1. 1 1
      examples/geometry_birds.html
  2. 45 0
      src/extras/primitives/LathedObject.js

+ 1 - 1
examples/geometry_birds.html

@@ -19,7 +19,7 @@
 				top: 0px; width: 100%;
 				top: 0px; width: 100%;
 				padding: 5px;
 				padding: 5px;
 			}
 			}
-		</style
+                </style>
 	</head>
 	</head>
 	<body>
 	<body>
 
 

+ 45 - 0
src/extras/primitives/LathedObject.js

@@ -0,0 +1,45 @@
+/**
+ * @author astrodud / http://astrodud.isgreat.org/
+ */
+
+function LathedObject( verts, nsteps, latheAngle ) {
+   THREE.Geometry.call( this );
+   nsteps = nsteps || 12;
+   latheAngle = latheAngle || 2 * Math.PI;
+   var stepSize = latheAngle / nsteps;
+   var newV = [], oldInds = [], newInds = [], startInds = [];
+   for ( var j = 0; j < verts.length; j ++ ) {
+      this.vertices.push( new THREE.Vertex( verts[ j ] ) );
+      oldInds[ j ] = this.vertices.length - 1;
+      newV[ j ] = new THREE.Vector3( verts[ j ].x, verts[ j ].y, verts[ j ].z );
+   }
+   var m = THREE.Matrix4.rotationZMatrix( stepSize );
+   for ( var r = 0; r <= latheAngle + 0.001; r += stepSize ) { // need the +0.001 to it go up to latheAngle
+      for ( var j = 0; j < newV.length; j ++ ) {
+	 if ( r < latheAngle ) {
+	    newV[ j ] = transformVector3( newV[ j ], m );
+	    this.vertices.push( new THREE.Vertex( newV[ j ] ) );
+	    newInds[ j ] = this.vertices.length - 1;
+	 } else {
+	    newInds = startInds; // wrap it up!
+	 }
+      }
+      if ( r == 0 ) startInds = oldInds;
+      for ( var j = 0; j < oldInds.length - 1; j ++ ) {
+	 this.faces.push( new THREE.Face4( newInds[ j ], newInds[ j + 1 ], oldInds[ j + 1 ], oldInds[ j ] ) );
+	 this.uvs.push( [ new THREE.UV( r / latheAngle, j / verts.length ),
+			  new THREE.UV( r / latheAngle, ( j + 1 ) / verts.length ),
+			  new THREE.UV( ( r - stepSize ) / latheAngle, ( j + 1 ) / verts.length ),
+			  new THREE.UV( ( r - stepSize ) / latheAngle, j / verts.length ) ] );
+      }
+      oldInds = newInds;
+      newInds = [];
+   }
+   this.computeCentroids();
+   this.computeFaceNormals();
+   this.computeVertexNormals();
+   this.sortFacesByMaterial();
+};
+
+LathedObject.prototype = new THREE.Geometry();
+LathedObject.prototype.constructor = LathedObject;