CmdSetRotation.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.updatable = true;
  8. this.object = object;
  9. this.objectUuid = object !== undefined ? object.uuid : undefined;
  10. if ( object !== undefined && newRotationEuler !== undefined) {
  11. this.oldRotation = object.rotation.clone();
  12. this.newRotation = newRotationEuler.clone();
  13. }
  14. if ( oldRotationEuler !== undefined ) {
  15. this.oldRotation = oldRotationEuler.clone();
  16. }
  17. };
  18. CmdSetRotation.prototype = {
  19. execute: function () {
  20. this.object.rotation.copy( this.newRotation );
  21. this.object.updateMatrix();
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. },
  24. undo: function () {
  25. this.object.rotation.copy( this.oldRotation );
  26. this.object.updateMatrix();
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. },
  29. update: function ( command ) {
  30. this.newRotation.copy( command.newRotation );
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.objectUuid;
  35. output.oldRotation = this.oldRotation.toArray();
  36. output.newRotation = this.newRotation.toArray();
  37. return output;
  38. },
  39. fromJSON: function ( json ) {
  40. Cmd.prototype.fromJSON.call( this, json );
  41. this.object = this.editor.objectByUuid( json.objectUuid );
  42. this.objectUuid = json.objectUuid;
  43. this.oldRotation = new THREE.Euler().fromArray(json.oldRotation);
  44. this.newRotation = new THREE.Euler().fromArray(json.newRotation);
  45. }
  46. };