SetScaleCommand.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. import { Command } from '../Command.js';
  6. import { Vector3 } from '../../../build/three.module.js';
  7. /**
  8. * @param editor Editor
  9. * @param object THREE.Object3D
  10. * @param newScale THREE.Vector3
  11. * @param optionalOldScale THREE.Vector3
  12. * @constructor
  13. */
  14. var SetScaleCommand = function ( editor, object, newScale, optionalOldScale ) {
  15. Command.call( this, editor );
  16. this.type = 'SetScaleCommand';
  17. this.name = 'Set Scale';
  18. this.updatable = true;
  19. this.object = object;
  20. if ( object !== undefined && newScale !== undefined ) {
  21. this.oldScale = object.scale.clone();
  22. this.newScale = newScale.clone();
  23. }
  24. if ( optionalOldScale !== undefined ) {
  25. this.oldScale = optionalOldScale.clone();
  26. }
  27. };
  28. SetScaleCommand.prototype = {
  29. execute: function () {
  30. this.object.scale.copy( this.newScale );
  31. this.object.updateMatrixWorld( true );
  32. this.editor.signals.objectChanged.dispatch( this.object );
  33. },
  34. undo: function () {
  35. this.object.scale.copy( this.oldScale );
  36. this.object.updateMatrixWorld( true );
  37. this.editor.signals.objectChanged.dispatch( this.object );
  38. },
  39. update: function ( command ) {
  40. this.newScale.copy( command.newScale );
  41. },
  42. toJSON: function () {
  43. var output = Command.prototype.toJSON.call( this );
  44. output.objectUuid = this.object.uuid;
  45. output.oldScale = this.oldScale.toArray();
  46. output.newScale = this.newScale.toArray();
  47. return output;
  48. },
  49. fromJSON: function ( json ) {
  50. Command.prototype.fromJSON.call( this, json );
  51. this.object = this.editor.objectByUuid( json.objectUuid );
  52. this.oldScale = new Vector3().fromArray( json.oldScale );
  53. this.newScale = new Vector3().fromArray( json.newScale );
  54. }
  55. };
  56. export { SetScaleCommand };