SetRotationCommand.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. import { Command } from '../Command.js';
  6. import { Euler } from '../../../build/three.module.js';
  7. /**
  8. * @param editor Editor
  9. * @param object THREE.Object3D
  10. * @param newRotation THREE.Euler
  11. * @param optionalOldRotation THREE.Euler
  12. * @constructor
  13. */
  14. var SetRotationCommand = function ( editor, object, newRotation, optionalOldRotation ) {
  15. Command.call( this, editor );
  16. this.type = 'SetRotationCommand';
  17. this.name = 'Set Rotation';
  18. this.updatable = true;
  19. this.object = object;
  20. if ( object !== undefined && newRotation !== undefined ) {
  21. this.oldRotation = object.rotation.clone();
  22. this.newRotation = newRotation.clone();
  23. }
  24. if ( optionalOldRotation !== undefined ) {
  25. this.oldRotation = optionalOldRotation.clone();
  26. }
  27. };
  28. SetRotationCommand.prototype = {
  29. execute: function () {
  30. this.object.rotation.copy( this.newRotation );
  31. this.object.updateMatrixWorld( true );
  32. this.editor.signals.objectChanged.dispatch( this.object );
  33. },
  34. undo: function () {
  35. this.object.rotation.copy( this.oldRotation );
  36. this.object.updateMatrixWorld( true );
  37. this.editor.signals.objectChanged.dispatch( this.object );
  38. },
  39. update: function ( command ) {
  40. this.newRotation.copy( command.newRotation );
  41. },
  42. toJSON: function () {
  43. var output = Command.prototype.toJSON.call( this );
  44. output.objectUuid = this.object.uuid;
  45. output.oldRotation = this.oldRotation.toArray();
  46. output.newRotation = this.newRotation.toArray();
  47. return output;
  48. },
  49. fromJSON: function ( json ) {
  50. Command.prototype.fromJSON.call( this, json );
  51. this.object = this.editor.objectByUuid( json.objectUuid );
  52. this.oldRotation = new Euler().fromArray( json.oldRotation );
  53. this.newRotation = new Euler().fromArray( json.newRotation );
  54. }
  55. };
  56. export { SetRotationCommand };