Skip to content

Commit 96aecf6

Browse files
committed
Editor: Object rotation in degrees.
1 parent 70c63d2 commit 96aecf6

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

editor/js/Sidebar.Object.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ Sidebar.Object = function ( editor ) {
109109
// rotation
110110

111111
var objectRotationRow = new UI.Row();
112-
var objectRotationX = new UI.Number().setWidth( '50px' ).onChange( update );
113-
var objectRotationY = new UI.Number().setWidth( '50px' ).onChange( update );
114-
var objectRotationZ = new UI.Number().setWidth( '50px' ).onChange( update );
112+
var objectRotationX = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
113+
var objectRotationY = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
114+
var objectRotationZ = new UI.Number().setUnit( '°' ).setWidth( '50px' ).onChange( update );
115115

116116
objectRotationRow.add( new UI.Text( 'Rotation' ).setWidth( '90px' ) );
117117
objectRotationRow.add( objectRotationX, objectRotationY, objectRotationZ );
@@ -355,7 +355,7 @@ Sidebar.Object = function ( editor ) {
355355

356356
}
357357

358-
var newRotation = new THREE.Euler( objectRotationX.getValue(), objectRotationY.getValue(), objectRotationZ.getValue() );
358+
var newRotation = new THREE.Euler( objectRotationX.getValue() * THREE.Math.DEG2RAD, objectRotationY.getValue() * THREE.Math.DEG2RAD, objectRotationZ.getValue() * THREE.Math.DEG2RAD );
359359
if ( object.rotation.toVector3().distanceTo( newRotation.toVector3() ) >= 0.01 ) {
360360

361361
editor.execute( new SetRotationCommand( object, newRotation ) );
@@ -567,9 +567,9 @@ Sidebar.Object = function ( editor ) {
567567
objectPositionY.setValue( object.position.y );
568568
objectPositionZ.setValue( object.position.z );
569569

570-
objectRotationX.setValue( object.rotation.x );
571-
objectRotationY.setValue( object.rotation.y );
572-
objectRotationZ.setValue( object.rotation.z );
570+
objectRotationX.setValue( object.rotation.x * THREE.Math.RAD2DEG );
571+
objectRotationY.setValue( object.rotation.y * THREE.Math.RAD2DEG );
572+
objectRotationZ.setValue( object.rotation.z * THREE.Math.RAD2DEG );
573573

574574
objectScaleX.setValue( object.scale.x );
575575
objectScaleY.setValue( object.scale.y );

editor/js/libs/ui.js

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ UI.Number = function ( number ) {
684684

685685
this.precision = 2;
686686
this.step = 1;
687+
this.unit = '';
687688

688689
this.dom = dom;
689690

@@ -751,19 +752,7 @@ UI.Number = function ( number ) {
751752

752753
function onChange( event ) {
753754

754-
var value = 0;
755-
756-
try {
757-
758-
value = eval( dom.value );
759-
760-
} catch ( error ) {
761-
762-
console.error( error.message );
763-
764-
}
765-
766-
scope.setValue( value );
755+
scope.setValue( dom.value );
767756

768757
}
769758

@@ -811,7 +800,7 @@ UI.Number.prototype.setValue = function ( value ) {
811800
if ( value > this.max ) value = this.max;
812801

813802
this.value = value;
814-
this.dom.value = value.toFixed( this.precision );
803+
this.dom.value = value.toFixed( this.precision ) + ' ' + this.unit;
815804

816805
}
817806

@@ -836,6 +825,13 @@ UI.Number.prototype.setPrecision = function ( precision ) {
836825

837826
};
838827

828+
UI.Number.prototype.setUnit = function ( unit ) {
829+
830+
this.unit = unit;
831+
832+
return this;
833+
834+
};
839835

840836
// Integer
841837

@@ -928,19 +924,7 @@ UI.Integer = function ( number ) {
928924

929925
function onChange( event ) {
930926

931-
var value = 0;
932-
933-
try {
934-
935-
value = eval( dom.value );
936-
937-
} catch ( error ) {
938-
939-
console.error( error.message );
940-
941-
}
942-
943-
scope.setValue( value );
927+
scope.setValue( dom.value );
944928

945929
}
946930

@@ -982,8 +966,10 @@ UI.Integer.prototype.setValue = function ( value ) {
982966

983967
if ( value !== undefined ) {
984968

985-
this.value = value | 0;
986-
this.dom.value = value | 0;
969+
value = parseInt( value );
970+
971+
this.value = value;
972+
this.dom.value = value;
987973

988974
}
989975

0 commit comments

Comments
 (0)