SetUuidCommand.js 1.4 KB

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