SetGeometryValueCommand.js 1.7 KB

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