فهرست منبع

Editor: Object rotation in degrees.

Mr.doob 9 سال پیش
والد
کامیت
96aecf6567
2فایلهای تغییر یافته به همراه22 افزوده شده و 36 حذف شده
  1. 7 7
      editor/js/Sidebar.Object.js
  2. 15 29
      editor/js/libs/ui.js

+ 7 - 7
editor/js/Sidebar.Object.js

@@ -109,9 +109,9 @@ Sidebar.Object = function ( editor ) {
 	// rotation
 
 	var objectRotationRow = new UI.Row();
-	var objectRotationX = new UI.Number().setWidth( '50px' ).onChange( update );
-	var objectRotationY = new UI.Number().setWidth( '50px' ).onChange( update );
-	var objectRotationZ = new UI.Number().setWidth( '50px' ).onChange( update );
+	var objectRotationX = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
+	var objectRotationY = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
+	var objectRotationZ = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
 
 	objectRotationRow.add( new UI.Text( 'Rotation' ).setWidth( '90px' ) );
 	objectRotationRow.add( objectRotationX, objectRotationY, objectRotationZ );
@@ -355,7 +355,7 @@ Sidebar.Object = function ( editor ) {
 
 			}
 
-			var newRotation = new THREE.Euler( objectRotationX.getValue(), objectRotationY.getValue(), objectRotationZ.getValue() );
+			var newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.Math.DEG2RAD, objectRotationY.getValue() * THREE.Math.DEG2RAD, objectRotationZ.getValue() * THREE.Math.DEG2RAD );
 			if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
 
 				editor.execute( new SetRotationCommand( object, newRotation ) );
@@ -567,9 +567,9 @@ Sidebar.Object = function ( editor ) {
 		objectPositionY.setValue( object.position.y );
 		objectPositionZ.setValue( object.position.z );
 
-		objectRotationX.setValue( object.rotation.x );
-		objectRotationY.setValue( object.rotation.y );
-		objectRotationZ.setValue( object.rotation.z );
+		objectRotationX.setValue( object.rotation.x * THREE.Math.RAD2DEG );
+		objectRotationY.setValue( object.rotation.y * THREE.Math.RAD2DEG );
+		objectRotationZ.setValue( object.rotation.z * THREE.Math.RAD2DEG );
 
 		objectScaleX.setValue( object.scale.x );
 		objectScaleY.setValue( object.scale.y );

+ 15 - 29
editor/js/libs/ui.js

@@ -684,6 +684,7 @@ UI.Number = function ( number ) {
 
 	this.precision = 2;
 	this.step = 1;
+	this.unit = '';
 
 	this.dom = dom;
 
@@ -751,19 +752,7 @@ UI.Number = function ( number ) {
 
 	function onChange( event ) {
 
-		var value = 0;
-
-		try {
-
-			value = eval( dom.value );
-
-		} catch ( error ) {
-
-			console.error( error.message );
-
-		}
-
-		scope.setValue( value );
+		scope.setValue( dom.value );
 
 	}
 
@@ -811,7 +800,7 @@ UI.Number.prototype.setValue = function ( value ) {
 		if ( value > this.max ) value = this.max;
 
 		this.value = value;
-		this.dom.value = value.toFixed( this.precision );
+		this.dom.value = value.toFixed( this.precision ) + ' ' + this.unit;
 
 	}
 
@@ -836,6 +825,13 @@ UI.Number.prototype.setPrecision = function ( precision ) {
 
 };
 
+UI.Number.prototype.setUnit = function ( unit ) {
+
+	this.unit = unit;
+
+	return this;
+
+};
 
 // Integer
 
@@ -928,19 +924,7 @@ UI.Integer = function ( number ) {
 
 	function onChange( event ) {
 
-		var value = 0;
-
-		try {
-
-			value = eval( dom.value );
-
-		} catch ( error ) {
-
-			console.error( error.message );
-
-		}
-
-		scope.setValue( value );
+		scope.setValue( dom.value );
 
 	}
 
@@ -982,8 +966,10 @@ UI.Integer.prototype.setValue = function ( value ) {
 
 	if ( value !== undefined ) {
 
-		this.value = value | 0;
-		this.dom.value = value | 0;
+		value = parseInt( value );
+
+		this.value = value;
+		this.dom.value = value;
 
 	}