CmdSetRotation.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. init: function () {
  21. if ( this.object === undefined ) {
  22. this.object = this.editor.objectByUuid( this.objectUuid );
  23. }
  24. },
  25. execute: function () {
  26. this.init();
  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.init();
  33. this.object.rotation.copy( this.oldRotation );
  34. this.object.updateMatrixWorld( true );
  35. this.editor.signals.objectChanged.dispatch( this.object );
  36. },
  37. update: function ( command ) {
  38. this.newRotation.copy( command.newRotation );
  39. },
  40. toJSON: function () {
  41. var output = Cmd.prototype.toJSON.call( this );
  42. output.objectUuid = this.objectUuid;
  43. output.oldRotation = this.oldRotation.toArray();
  44. output.newRotation = this.newRotation.toArray();
  45. return output;
  46. },
  47. fromJSON: function ( json ) {
  48. Cmd.prototype.fromJSON.call( this, json );
  49. this.objectUuid = json.objectUuid;
  50. this.oldRotation = new THREE.Euler().fromArray(json.oldRotation);
  51. this.newRotation = new THREE.Euler().fromArray(json.newRotation);
  52. }
  53. };
粤ICP备19079148号