CmdSetScale.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. execute: function () {
  21. this.object.scale.copy( this.newScale );
  22. this.object.updateMatrixWorld( true );
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. },
  25. undo: function () {
  26. this.object.scale.copy( this.oldScale );
  27. this.object.updateMatrixWorld( true );
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. },
  30. update: function ( command ) {
  31. this.newScale.copy( command.newScale );
  32. },
  33. toJSON: function () {
  34. var output = Cmd.prototype.toJSON.call( this );
  35. output.objectUuid = this.objectUuid;
  36. output.oldScale = this.oldScale.toArray();
  37. output.newScale = this.newScale.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.oldScale = new THREE.Vector3().fromArray(json.oldScale);
  45. this.newScale = new THREE.Vector3().fromArray(json.newScale);
  46. }
  47. };