CmdSetScale.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Created by Daniel on 23.07.15.
  3. */
  4. CmdSetScale = function ( object, newScaleVector, oldScaleVector ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetScale';
  7. this.name = 'Set Scale';
  8. this.updatable = true;
  9. this.object = object;
  10. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  11. if ( object !== undefined && newScaleVector !== undefined ) {
  12. this.oldScale = object.scale.clone();
  13. this.newScale = newScaleVector.clone();
  14. }
  15. if ( oldScaleVector !== undefined ) {
  16. this.oldScale = oldScaleVector.clone();
  17. }
  18. };
  19. CmdSetScale.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.scale.copy( this.newScale );
  28. this.object.updateMatrixWorld( true );
  29. this.editor.signals.objectChanged.dispatch( this.object );
  30. },
  31. undo: function () {
  32. this.init();
  33. this.object.scale.copy( this.oldScale );
  34. this.object.updateMatrixWorld( true );
  35. this.editor.signals.objectChanged.dispatch( this.object );
  36. },
  37. update: function ( command ) {
  38. this.newScale.copy( command.newScale );
  39. },
  40. toJSON: function () {
  41. var output = Cmd.prototype.toJSON.call( this );
  42. output.objectUuid = this.objectUuid;
  43. output.oldScale = this.oldScale.toArray();
  44. output.newScale = this.newScale.toArray();
  45. return output;
  46. },
  47. fromJSON: function ( json ) {
  48. Cmd.prototype.fromJSON.call( this, json );
  49. this.objectUuid = json.objectUuid;
  50. this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
  51. this.newScale = new THREE.Vector3().fromArray( json.newScale );
  52. }
  53. };