SetGeometryValueCommand.js 1.6 KB

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