SetRotationCommand.js 1.8 KB

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