2
0
Эх сурвалжийг харах

Editor: Lather code clean up.

Mr.doob 9 жил өмнө
parent
commit
a6b93c1cca

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

@@ -246,7 +246,7 @@ Menubar.Add = function ( editor ) {
 
 	var option = new UI.Row();
 	option.setClass( 'option' );
-	option.setTextContent( 'Lathe geometry' );
+	option.setTextContent( 'Lathe' );
 	option.onClick( function() {
 
 		var points = [];
@@ -268,7 +268,7 @@ Menubar.Add = function ( editor ) {
 
 		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 );
+		mesh.name = 'Lathe ' + ( ++ meshCount );
 
 		editor.execute( new AddObjectCommand( mesh ) );
 

+ 30 - 23
editor/js/Sidebar.Geometry.LatheGeometry.js

@@ -45,32 +45,40 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 	var lastPointIdx = 0;
 	var pointsUI = [];
 
-	var pointsDiv = new UI.Div();
-	var point;
+	var pointsRow = new UI.Row();
+	pointsRow.add( new UI.Text( 'Points' ).setWidth( '90px' ) );
+
+	var points = new UI.Span().setDisplay( 'inline-block' );
+	pointsRow.add( points );
+
+	var pointsList = new UI.Div();
+	points.add( pointsList );
+
 	for ( var i = 0; i < parameters.points.length; i ++ ) {
 
-		point = parameters.points[ i ];
-		pointsDiv.add( createPointRow( point.x, point.z ) );
+		var point = parameters.points[ i ];
+		pointsList.add( createPointRow( point.x, point.z ) );
 
 	}
 
-	var pointsRow = new UI.Row().setDisplay( 'flex' );
+	var addPointButton = new UI.Button( '+' ).onClick( function() {
+
+		var point = pointsUI[ pointsUI.length - 1 ];
 
-	var btnAdd = new UI.Button( '+' ).setMarginRight( '15px' ).onClick( function() {
+		pointsList.add( createPointRow( point.x.getValue(), point.y.getValue() ) );
 
-		pointsDiv.add( createPointRow( 0, 0 ) );
 		update();
 
 	} );
+	points.add( addPointButton );
 
-	pointsRow.add( new UI.Text( 'Points' ).setWidth( '50px' ), btnAdd, pointsDiv );
 	container.add( pointsRow );
 
 	//
 
 	function createPointRow( x, y ) {
 
-		var pointRow = new UI.Row();
+		var pointRow = new UI.Div();
 		var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
 		var txtX = new UI.Number( x ).setRange( 0, Infinity ).setWidth( '40px' ).onChange( update );
 		var txtY = new UI.Number( y ).setWidth( '40px' ).onChange( update );
@@ -93,7 +101,7 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 
 		if ( ! pointsUI[ idx ] ) return;
 
-		pointsDiv.remove( pointsUI[ idx ].row );
+		pointsList.remove( pointsUI[ idx ].row );
 		pointsUI[ idx ] = null;
 
 		update();
@@ -104,15 +112,12 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 
 		var points = [];
 		var count = 0;
-		var pointUI;
-		for ( var i = 0; i < pointsUI.length; i ++ ) {
 
-			pointUI = pointsUI[ i ];
-			if ( ! pointUI ) {
+		for ( var i = 0; i < pointsUI.length; i ++ ) {
 
-				continue;
+			var pointUI = pointsUI[ i ];
 
-			}
+			if ( ! pointUI ) continue;
 
 			points.push( new THREE.Vector3( pointUI.x.getValue(), 0, pointUI.y.getValue() ) );
 			count ++;
@@ -120,15 +125,17 @@ Sidebar.Geometry.LatheGeometry = function( editor, object ) {
 
 		}
 
-		editor.execute( new SetGeometryCommand( object, new THREE.LatheGeometry(
-					points,
-					segments.getValue(),
-					phiStart.getValue() / 180 * Math.PI,
-					phiLength.getValue() / 180 * Math.PI
-				) ) );
+		var geometry = new THREE.LatheGeometry(
+			points,
+			segments.getValue(),
+			phiStart.getValue() / 180 * Math.PI,
+			phiLength.getValue() / 180 * Math.PI
+		);
+
+		editor.execute( new SetGeometryCommand( object, geometry ) );
 
 	}
 
 	return container;
 
-}
+};