CmdSetScale.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param newScale THREE.Vector3
  7. * @param optionalOldScale THREE.Vector3
  8. * @constructor
  9. */
  10. CmdSetScale = function ( object, newScale, optionalOldScale ) {
  11. Cmd.call( this );
  12. this.type = 'CmdSetScale';
  13. this.name = 'Set Scale';
  14. this.updatable = true;
  15. this.object = object;
  16. if ( object !== undefined && newScale !== undefined ) {
  17. this.oldScale = object.scale.clone();
  18. this.newScale = newScale.clone();
  19. }
  20. if ( optionalOldScale !== undefined ) {
  21. this.oldScale = optionalOldScale.clone();
  22. }
  23. };
  24. CmdSetScale.prototype = {
  25. execute: function () {
  26. this.object.scale.copy( this.newScale );
  27. this.object.updateMatrixWorld( true );
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. },
  30. undo: function () {
  31. this.object.scale.copy( this.oldScale );
  32. this.object.updateMatrixWorld( true );
  33. this.editor.signals.objectChanged.dispatch( this.object );
  34. },
  35. update: function ( command ) {
  36. this.newScale.copy( command.newScale );
  37. },
  38. toJSON: function () {
  39. var output = Cmd.prototype.toJSON.call( this );
  40. output.objectUuid = this.object.uuid;
  41. output.oldScale = this.oldScale.toArray();
  42. output.newScale = this.newScale.toArray();
  43. return output;
  44. },
  45. fromJSON: function ( json ) {
  46. Cmd.prototype.fromJSON.call( this, json );
  47. this.object = this.editor.objectByUuid( json.objectUuid );
  48. this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
  49. this.newScale = new THREE.Vector3().fromArray( json.newScale );
  50. }
  51. };