2
0

CmdSetScale.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. if ( object !== undefined && newScaleVector !== undefined ) {
  11. this.oldScale = object.scale.clone();
  12. this.newScale = newScaleVector.clone();
  13. }
  14. if ( oldScaleVector !== undefined ) {
  15. this.oldScale = oldScaleVector.clone();
  16. }
  17. };
  18. CmdSetScale.prototype = {
  19. execute: function () {
  20. this.object.scale.copy( this.newScale );
  21. this.object.updateMatrixWorld( true );
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. },
  24. undo: function () {
  25. this.object.scale.copy( this.oldScale );
  26. this.object.updateMatrixWorld( true );
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. },
  29. update: function ( command ) {
  30. this.newScale.copy( command.newScale );
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.object.uuid;
  35. output.oldScale = this.oldScale.toArray();
  36. output.newScale = this.newScale.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.oldScale = new THREE.Vector3().fromArray( json.oldScale );
  43. this.newScale = new THREE.Vector3().fromArray( json.newScale );
  44. }
  45. };