浏览代码

Simplified LatheGeometry.

Mr.doob 9 年之前
父节点
当前提交
e61cf3b89f

+ 14 - 14
editor/js/Menubar.Add.js

@@ -249,24 +249,24 @@ Menubar.Add = function ( editor ) {
 	option.setTextContent( 'Lathe' );
 	option.onClick( function() {
 
-		var points = [];
+		var points = [
+			new THREE.Vector2( 0, 0 ),
+			new THREE.Vector2( 4, 0 ),
+			new THREE.Vector2( 3.5, 0.5 ),
+			new THREE.Vector2( 1, 0.75 ),
+			new THREE.Vector2( 0.8, 1 ),
+			new THREE.Vector2( 0.8, 4 ),
+			new THREE.Vector2( 1, 4.2 ),
+			new THREE.Vector2( 1.4, 4.8 ),
+			new THREE.Vector2( 2, 5 ),
+			new THREE.Vector2( 2.5, 5.4 ),
+			new THREE.Vector2( 3, 12 )
+		];
 		var segments = 20;
 		var phiStart = 0;
 		var phiLength = 2 * Math.PI;
 
-		points.push( new THREE.Vector2( 0, 0 ) );
-		points.push( new THREE.Vector2( 4, 0 ) );
-		points.push( new THREE.Vector2( 3.5, 0.5 ) );
-		points.push( new THREE.Vector2( 1, 0.75 ) );
-		points.push( new THREE.Vector2( 0.8, 1 ) );
-		points.push( new THREE.Vector2( 0.8, 4 ) );
-		points.push( new THREE.Vector2( 1, 4.2 ) );
-		points.push( new THREE.Vector2( 1.4, 4.8 ) );
-		points.push( new THREE.Vector2( 2, 5 ) );
-		points.push( new THREE.Vector2( 2.5, 5.4 ) );
-		points.push( new THREE.Vector2( 3, 12 ) );
-
-		var geometry = new THREE.LatheGeometry( points, segments, phiStart, phiLength, 'Y' );
+		var geometry = new THREE.LatheGeometry( points, segments, phiStart, phiLength );
 		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
 		mesh.name = 'Lathe ' + ( ++ meshCount );
 

+ 1 - 12
editor/js/Sidebar.Geometry.LatheGeometry.js

@@ -40,16 +40,6 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 
 	container.add( phiLengthRow );
 
-	// axe
-
-	var axeRow = new UI.Row();
-	var axe = new UI.Input( parameters.axe ).setWidth( '10px' ).onChange( update );
-
-	axeRow.add( new UI.Text( 'Axe' ).setWidth( '90px' ) );
-	axeRow.add( axe );
-
-	container.add( axeRow );
-
 	// points
 
 	var lastPointIdx = 0;
@@ -139,8 +129,7 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 			points,
 			segments.getValue(),
 			phiStart.getValue() / 180 * Math.PI,
-			phiLength.getValue() / 180 * Math.PI,
-			axe.getValue()
+			phiLength.getValue() / 180 * Math.PI
 		);
 
 		editor.execute( new SetGeometryCommand( object, geometry ) );

+ 13 - 48
src/extras/geometries/LatheGeometry.js

@@ -10,78 +10,43 @@
 // phiStart - the starting radian
 // phiLength - the radian (0 to 2*PI) range of the lathed section
 //    2*pi is a closed lathe, less than 2PI is a portion.
-// axe - the axis of revolution ('X', 'Y' or 'Z')
 
-THREE.LatheGeometry = function( points, segments, phiStart, phiLength, axe ) {
-
-	var thePoints = points;
-	if ( points.length && points[ 0 ] instanceof THREE.Vector3 ) {
-
-		console.warn( 'THREE.LatheGeometry has been updated. Use an array of THREE.Vector2 as first parameter.' );
-
-		thePoints = [];
-		axe = 'Z';
-		for ( var i = 0; i < points.length; i ++ ) {
-
-			var pt = points[ i ];
-			thePoints.push( new THREE.Vector2( Math.sqrt( pt.x * pt.x + pt.y * pt.y ), pt.z ) );
-
-		}
-
-	}
+THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
 
 	THREE.Geometry.call( this );
 
 	this.type = 'LatheGeometry';
 
 	this.parameters = {
-		points: thePoints,
+		points: points,
 		segments: segments,
 		phiStart: phiStart,
-		phiLength: phiLength,
-		axe: axe
+		phiLength: phiLength
 	};
 
 	segments = segments || 12;
 	phiStart = phiStart || 0;
 	phiLength = phiLength || 2 * Math.PI;
-	axe = axe || 'Y';
 
-	var inversePointLength = 1.0 / ( thePoints.length - 1 );
+	var inversePointLength = 1.0 / ( points.length - 1 );
 	var inverseSegments = 1.0 / segments;
 
 	for ( var i = 0, il = segments; i <= il; i ++ ) {
 
 		var phi = phiStart + i * inverseSegments * phiLength;
 
-		var c = Math.cos( phi ),
-			s = Math.sin( phi );
+		var sin = Math.sin( phi );
+		var cos = Math.cos( phi );
 
-		for ( var j = 0, jl = thePoints.length; j < jl; j ++ ) {
+		for ( var j = 0, jl = points.length; j < jl; j ++ ) {
 
-			var pt = thePoints[ j ];
+			var point = points[ j ];
 
 			var vertex = new THREE.Vector3();
 
-			if ( axe === 'Z' ) {
-
-				vertex.x = c * pt.x;
-				vertex.y = s * pt.x;
-				vertex.z = pt.y;
-
-			} else if ( axe === 'X' ) {
-
-				vertex.y = c * pt.x;
-				vertex.z = s * pt.x;
-				vertex.x = pt.y;
-
-			} else {
-
-				vertex.z = c * pt.x;
-				vertex.x = s * pt.x;
-				vertex.y = pt.y;
-
-			}
+			vertex.x = point.x * cos;
+			vertex.y = point.y;
+			vertex.z = point.x * sin;
 
 			this.vertices.push( vertex );
 
@@ -89,11 +54,11 @@ THREE.LatheGeometry = function( points, segments, phiStart, phiLength, axe ) {
 
 	}
 
-	var np = thePoints.length;
+	var np = points.length;
 
 	for ( var i = 0, il = segments; i < il; i ++ ) {
 
-		for ( var j = 0, jl = thePoints.length - 1; j < jl; j ++ ) {
+		for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
 
 			var base = j + np * i;
 			var a = base;

+ 1 - 2
src/loaders/ObjectLoader.js

@@ -263,8 +263,7 @@ THREE.ObjectLoader.prototype = {
 							data.points,
 							data.segments,
 							data.phiStart,
-							data.phiLength,
-							data.axe
+							data.phiLength
 						);
 
 						break;