SetScaleCommand.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  6. * @param object THREE.Object3D
  7. * @param newScale THREE.Vector3
  8. * @param optionalOldScale THREE.Vector3
  9. * @constructor
  10. */
  11. var SetScaleCommand = function ( object, newScale, optionalOldScale ) {
  12. Command.call( this );
  13. this.type = 'SetScaleCommand';
  14. this.name = 'Set Scale';
  15. this.updatable = true;
  16. this.object = object;
  17. if ( object !== undefined && newScale !== undefined ) {
  18. this.oldScale = object.scale.clone();
  19. this.newScale = newScale.clone();
  20. }
  21. if ( optionalOldScale !== undefined ) {
  22. this.oldScale = optionalOldScale.clone();
  23. }
  24. };
  25. SetScaleCommand.prototype = {
  26. execute: function () {
  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.object.scale.copy( this.oldScale );
  33. this.object.updateMatrixWorld( true );
  34. this.editor.signals.objectChanged.dispatch( this.object );
  35. },
  36. update: function ( command ) {
  37. this.newScale.copy( command.newScale );
  38. },
  39. toJSON: function () {
  40. var output = Command.prototype.toJSON.call( this );
  41. output.objectUuid = this.object.uuid;
  42. output.oldScale = this.oldScale.toArray();
  43. output.newScale = this.newScale.toArray();
  44. return output;
  45. },
  46. fromJSON: function ( json ) {
  47. Command.prototype.fromJSON.call( this, json );
  48. this.object = this.editor.objectByUuid( json.objectUuid );
  49. this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
  50. this.newScale = new THREE.Vector3().fromArray( json.newScale );
  51. }
  52. };