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. class SetGeometryValueCommand extends Command {
  10. constructor( editor, object = null, attributeName = '', newValue = null ) {
  11. super( editor );
  12. this.type = 'SetGeometryValueCommand';
  13. this.name = editor.strings.getKey( 'command/SetGeometryValue' ) + ': ' + attributeName;
  14. this.object = object;
  15. this.attributeName = attributeName;
  16. this.oldValue = ( object !== null ) ? object.geometry[ attributeName ] : null;
  17. this.newValue = newValue;
  18. }
  19. execute() {
  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() {
  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() {
  32. const output = super.toJSON( 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( json ) {
  40. super.fromJSON( 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 };