CmdSetRotation.js 1.6 KB

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