CmdSetScale.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.updatable = true;
  8. this.object = object;
  9. this.objectUuid = object !== undefined ? object.uuid : undefined;
  10. if ( object !== undefined && newScaleVector !== undefined ) {
  11. this.oldScale = object.scale.clone();
  12. this.newScale = newScaleVector.clone();
  13. }
  14. if ( oldScaleVector !== undefined ) {
  15. this.oldScale = oldScaleVector.clone();
  16. }
  17. };
  18. CmdSetScale.prototype = {
  19. execute: function () {
  20. this.object.scale.copy( this.newScale );
  21. this.object.updateMatrix();
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. },
  24. undo: function () {
  25. this.object.scale.copy( this.oldScale );
  26. this.object.updateMatrix();
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. },
  29. update: function ( command ) {
  30. this.newScale.copy( command.newScale );
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.objectUuid;
  35. output.oldScale = this.oldScale.toArray();
  36. output.newScale = this.newScale.toArray();
  37. return output;
  38. },
  39. fromJSON: function ( json ) {
  40. Cmd.prototype.fromJSON.call( this, json );
  41. this.object = this.editor.objectByUuid( json.objectUuid );
  42. this.objectUuid = json.objectUuid;
  43. this.oldScale = new THREE.Vector3().fromArray(json.oldScale);
  44. this.newScale = new THREE.Vector3().fromArray(json.newScale);
  45. }
  46. };