SetUuidCommand.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Command } from '../Command.js';
  2. /**
  3. * @param editor Editor
  4. * @param object THREE.Object3D
  5. * @param newUuid string
  6. * @constructor
  7. */
  8. class SetUuidCommand extends Command {
  9. constructor( editor, object = null, newUuid = null ) {
  10. super( editor );
  11. this.type = 'SetUuidCommand';
  12. this.name = editor.strings.getKey( 'command/SetUuid' );
  13. this.object = object;
  14. this.oldUuid = ( object !== null ) ? object.uuid : null;
  15. this.newUuid = newUuid;
  16. }
  17. execute() {
  18. this.object.uuid = this.newUuid;
  19. this.editor.signals.objectChanged.dispatch( this.object );
  20. this.editor.signals.sceneGraphChanged.dispatch();
  21. }
  22. undo() {
  23. this.object.uuid = this.oldUuid;
  24. this.editor.signals.objectChanged.dispatch( this.object );
  25. this.editor.signals.sceneGraphChanged.dispatch();
  26. }
  27. toJSON() {
  28. const output = super.toJSON( this );
  29. output.oldUuid = this.oldUuid;
  30. output.newUuid = this.newUuid;
  31. return output;
  32. }
  33. fromJSON( json ) {
  34. super.fromJSON( json );
  35. this.oldUuid = json.oldUuid;
  36. this.newUuid = json.newUuid;
  37. this.object = this.editor.objectByUuid( json.oldUuid );
  38. if ( this.object === undefined ) {
  39. this.object = this.editor.objectByUuid( json.newUuid );
  40. }
  41. }
  42. }
  43. export { SetUuidCommand };