SetUuidCommand.js 1.3 KB

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