SetUuidCommand.js 1.3 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. function SetUuidCommand( editor, object, newUuid ) {
  9. Command.call( this, editor );
  10. this.type = 'SetUuidCommand';
  11. this.name = 'Update UUID';
  12. this.object = object;
  13. this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
  14. this.newUuid = newUuid;
  15. }
  16. SetUuidCommand.prototype = {
  17. execute: function () {
  18. this.object.uuid = this.newUuid;
  19. this.editor.signals.objectChanged.dispatch( this.object );
  20. this.editor.signals.sceneGraphChanged.dispatch();
  21. },
  22. undo: function () {
  23. this.object.uuid = this.oldUuid;
  24. this.editor.signals.objectChanged.dispatch( this.object );
  25. this.editor.signals.sceneGraphChanged.dispatch();
  26. },
  27. toJSON: function () {
  28. var output = Command.prototype.toJSON.call( this );
  29. output.oldUuid = this.oldUuid;
  30. output.newUuid = this.newUuid;
  31. return output;
  32. },
  33. fromJSON: function ( json ) {
  34. Command.prototype.fromJSON.call( this, 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 };