SetGeometryValueCommand.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  7. * @param editor Editor
  8. * @param object THREE.Object3D
  9. * @param attributeName string
  10. * @param newValue number, string, boolean or object
  11. * @constructor
  12. */
  13. var SetGeometryValueCommand = function ( editor, object, attributeName, newValue ) {
  14. Command.call( this, editor );
  15. this.type = 'SetGeometryValueCommand';
  16. this.name = 'Set Geometry.' + attributeName;
  17. this.object = object;
  18. this.attributeName = attributeName;
  19. this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
  20. this.newValue = newValue;
  21. };
  22. SetGeometryValueCommand.prototype = {
  23. execute: function () {
  24. this.object.geometry[ this.attributeName ] = this.newValue;
  25. this.editor.signals.objectChanged.dispatch( this.object );
  26. this.editor.signals.geometryChanged.dispatch();
  27. this.editor.signals.sceneGraphChanged.dispatch();
  28. },
  29. undo: function () {
  30. this.object.geometry[ this.attributeName ] = this.oldValue;
  31. this.editor.signals.objectChanged.dispatch( this.object );
  32. this.editor.signals.geometryChanged.dispatch();
  33. this.editor.signals.sceneGraphChanged.dispatch();
  34. },
  35. toJSON: function () {
  36. var output = Command.prototype.toJSON.call( this );
  37. output.objectUuid = this.object.uuid;
  38. output.attributeName = this.attributeName;
  39. output.oldValue = this.oldValue;
  40. output.newValue = this.newValue;
  41. return output;
  42. },
  43. fromJSON: function ( json ) {
  44. Command.prototype.fromJSON.call( this, json );
  45. this.object = this.editor.objectByUuid( json.objectUuid );
  46. this.attributeName = json.attributeName;
  47. this.oldValue = json.oldValue;
  48. this.newValue = json.newValue;
  49. }
  50. };
  51. export { SetGeometryValueCommand };