2
0

SetScaleCommand.js 1.7 KB

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