mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 04:56:01 +10:00
Fixed Lathe Geometry.
This commit is contained in:
@@ -55,7 +55,6 @@
|
||||
light.position.z = - 1;
|
||||
scene.addLight( light );
|
||||
|
||||
|
||||
material = [
|
||||
new THREE.MeshLambertMaterial( { color: 0xffffff } ),
|
||||
new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, opacity: 0.1 } )
|
||||
@@ -66,7 +65,7 @@
|
||||
object.position.z = 200;
|
||||
scene.addObject( object );
|
||||
|
||||
object = new THREE.Mesh( new Cylinder( 50, 75, 75, 100 ), material );
|
||||
object = new THREE.Mesh( new Cylinder( 50, 25, 75, 100 ), material );
|
||||
object.position.z = 200;
|
||||
scene.addObject( object );
|
||||
|
||||
@@ -83,10 +82,23 @@
|
||||
object = new THREE.Mesh( new Sphere( 75, 20, 10 ), material );
|
||||
scene.addObject( object );
|
||||
|
||||
object = new THREE.Mesh( new Torus( 50, 20, 20, 20 ), material );
|
||||
var points = [];
|
||||
|
||||
for ( var i = 0; i < 50; i ++ ) {
|
||||
|
||||
points.push( new THREE.Vector3( Math.sin( i * 0.2 ) * 15 + 50, 0, ( i - 5 ) * 2 ) );
|
||||
|
||||
}
|
||||
|
||||
object = new THREE.Mesh( new Lathe( points, 20 ), material );
|
||||
object.position.x = 200;
|
||||
scene.addObject( object );
|
||||
|
||||
object = new THREE.Mesh( new Torus( 50, 20, 20, 20 ), material );
|
||||
object.position.x = - 200;
|
||||
object.position.z = - 200;
|
||||
scene.addObject( object );
|
||||
|
||||
object = new THREE.Mesh( new TorusKnot( 50, 10, 50, 20 ), material );
|
||||
object.position.z = - 200;
|
||||
scene.addObject( object );
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @author astrodud / http://astrodud.isgreat.org/
|
||||
*/
|
||||
|
||||
function Lathe( vertices, steps, angle ) {
|
||||
function Lathe( points, steps, angle ) {
|
||||
|
||||
THREE.Geometry.call( this );
|
||||
|
||||
@@ -13,21 +13,22 @@ function Lathe( vertices, steps, angle ) {
|
||||
|
||||
var newV = [], oldInds = [], newInds = [], startInds = [];
|
||||
|
||||
for ( var j = 0; j < vertices.length; j ++ ) {
|
||||
for ( var j = 0; j < points.length; j ++ ) {
|
||||
|
||||
this.vertices.push( new THREE.Vertex( vertices[ j ] ) );
|
||||
this.vertices.push( new THREE.Vertex( points[ j ] ) );
|
||||
|
||||
newV[ j ] = points[ j ].clone();
|
||||
oldInds[ j ] = this.vertices.length - 1;
|
||||
newV[ j ] = new THREE.Vector3( vertices[ j ].x, vertices[ j ].y, vertices[ j ].z );
|
||||
|
||||
}
|
||||
|
||||
var matrix = new THREE.Matrix4().setRotationZ( this.stepSize );
|
||||
var matrix = new THREE.Matrix4().setRotationZ( stepSize );
|
||||
|
||||
for ( var r = 0; r <= this.angle + 0.001; r += this.stepSize ) { // need the +0.001 for it go up to angle
|
||||
for ( var r = 0; r <= this.angle + 0.001; r += stepSize ) { // need the +0.001 for it go up to angle
|
||||
|
||||
for ( var j = 0; j < newV.length; j ++ ) {
|
||||
|
||||
if ( r < angle ) {
|
||||
if ( r < this.angle ) {
|
||||
|
||||
newV[ j ] = matrix.multiplyVector3( newV[ j ].clone() );
|
||||
this.vertices.push( new THREE.Vertex( newV[ j ] ) );
|
||||
@@ -48,10 +49,10 @@ function Lathe( vertices, steps, angle ) {
|
||||
this.faces.push( new THREE.Face4( newInds[ j ], newInds[ j + 1 ], oldInds[ j + 1 ], oldInds[ j ] ) );
|
||||
this.uvs.push( [
|
||||
|
||||
new THREE.UV( r / angle, j / vertices.length ),
|
||||
new THREE.UV( r / angle, ( j + 1 ) / vertices.length ),
|
||||
new THREE.UV( ( r - stepSize ) / angle, ( j + 1 ) / vertices.length ),
|
||||
new THREE.UV( ( r - stepSize ) / angle, j / vertices.length )
|
||||
new THREE.UV( r / angle, j / points.length ),
|
||||
new THREE.UV( r / angle, ( j + 1 ) / points.length ),
|
||||
new THREE.UV( ( r - stepSize ) / angle, ( j + 1 ) / points.length ),
|
||||
new THREE.UV( ( r - stepSize ) / angle, j / points.length )
|
||||
|
||||
] );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user