CmdSetRotation.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param newRotation THREE.Euler
  7. * @param optionalOldRotation THREE.Euler
  8. * @constructor
  9. */
  10. CmdSetRotation = function ( object, newRotation, optionalOldRotation ) {
  11. Cmd.call( this );
  12. this.type = 'CmdSetRotation';
  13. this.name = 'Set Rotation';
  14. this.updatable = true;
  15. this.object = object;
  16. if ( object !== undefined && newRotation !== undefined ) {
  17. this.oldRotation = object.rotation.clone();
  18. this.newRotation = newRotation.clone();
  19. }
  20. if ( optionalOldRotation !== undefined ) {
  21. this.oldRotation = optionalOldRotation.clone();
  22. }
  23. };
  24. CmdSetRotation.prototype = {
  25. execute: function () {
  26. this.object.rotation.copy( this.newRotation );
  27. this.object.updateMatrixWorld( true );
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. },
  30. undo: function () {
  31. this.object.rotation.copy( this.oldRotation );
  32. this.object.updateMatrixWorld( true );
  33. this.editor.signals.objectChanged.dispatch( this.object );
  34. },
  35. update: function ( command ) {
  36. this.newRotation.copy( command.newRotation );
  37. },
  38. toJSON: function () {
  39. var output = Cmd.prototype.toJSON.call( this );
  40. output.objectUuid = this.object.uuid;
  41. output.oldRotation = this.oldRotation.toArray();
  42. output.newRotation = this.newRotation.toArray();
  43. return output;
  44. },
  45. fromJSON: function ( json ) {
  46. Cmd.prototype.fromJSON.call( this, json );
  47. this.object = this.editor.objectByUuid( json.objectUuid );
  48. this.oldRotation = new THREE.Euler().fromArray( json.oldRotation );
  49. this.newRotation = new THREE.Euler().fromArray( json.newRotation );
  50. }
  51. };