CmdSetUuid.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param newUuid string
  7. * @constructor
  8. */
  9. CmdSetUuid = function ( object, newUuid ) {
  10. Cmd.call( this );
  11. this.type = 'CmdSetUuid';
  12. this.name = 'Update UUID';
  13. this.object = object;
  14. this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
  15. this.newUuid = newUuid;
  16. };
  17. CmdSetUuid.prototype = {
  18. execute: function () {
  19. this.object.uuid = this.newUuid;
  20. this.editor.signals.objectChanged.dispatch( this.object );
  21. this.editor.signals.sceneGraphChanged.dispatch();
  22. },
  23. undo: function () {
  24. this.object.uuid = this.oldUuid;
  25. this.editor.signals.objectChanged.dispatch( this.object );
  26. this.editor.signals.sceneGraphChanged.dispatch();
  27. },
  28. toJSON: function () {
  29. var output = Cmd.prototype.toJSON.call( this );
  30. output.oldUuid = this.oldUuid;
  31. output.newUuid = this.newUuid;
  32. return output;
  33. },
  34. fromJSON: function ( json ) {
  35. Cmd.prototype.fromJSON.call( this, json );
  36. this.oldUuid = json.oldUuid;
  37. this.newUuid = json.newUuid;
  38. this.object = this.editor.objectByUuid( json.oldUuid );
  39. if ( this.object === undefined ) {
  40. this.object = this.editor.objectByUuid( json.newUuid );
  41. }
  42. }
  43. };