SetGeometryValueCommand.js 1.7 KB

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