SetUuidCommand.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import { Command } from '../Command.js';
  6. /**
  7. * @param editor Editor
  8. * @param object THREE.Object3D
  9. * @param newUuid string
  10. * @constructor
  11. */
  12. var SetUuidCommand = function ( editor, object, newUuid ) {
  13. Command.call( this, editor );
  14. this.type = 'SetUuidCommand';
  15. this.name = 'Update UUID';
  16. this.object = object;
  17. this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
  18. this.newUuid = newUuid;
  19. };
  20. SetUuidCommand.prototype = {
  21. execute: function () {
  22. this.object.uuid = this.newUuid;
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. this.editor.signals.sceneGraphChanged.dispatch();
  25. },
  26. undo: function () {
  27. this.object.uuid = this.oldUuid;
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. this.editor.signals.sceneGraphChanged.dispatch();
  30. },
  31. toJSON: function () {
  32. var output = Command.prototype.toJSON.call( this );
  33. output.oldUuid = this.oldUuid;
  34. output.newUuid = this.newUuid;
  35. return output;
  36. },
  37. fromJSON: function ( json ) {
  38. Command.prototype.fromJSON.call( this, json );
  39. this.oldUuid = json.oldUuid;
  40. this.newUuid = json.newUuid;
  41. this.object = this.editor.objectByUuid( json.oldUuid );
  42. if ( this.object === undefined ) {
  43. this.object = this.editor.objectByUuid( json.newUuid );
  44. }
  45. }
  46. };
  47. export { SetUuidCommand };