AddObjectCommand.js 1.2 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. import { Command } from '../Command.js';
  6. import { ObjectLoader } from '../../../build/three.module.js';
  7. /**
  8. * @param editor Editor
  9. * @param object THREE.Object3D
  10. * @constructor
  11. */
  12. var AddObjectCommand = function ( editor, object ) {
  13. Command.call( this, editor );
  14. this.type = 'AddObjectCommand';
  15. this.object = object;
  16. if ( object !== undefined ) {
  17. this.name = 'Add Object: ' + object.name;
  18. }
  19. };
  20. AddObjectCommand.prototype = {
  21. execute: function () {
  22. this.editor.addObject( this.object );
  23. this.editor.select( this.object );
  24. },
  25. undo: function () {
  26. this.editor.removeObject( this.object );
  27. this.editor.deselect();
  28. },
  29. toJSON: function () {
  30. var output = Command.prototype.toJSON.call( this );
  31. output.object = this.object.toJSON();
  32. return output;
  33. },
  34. fromJSON: function ( json ) {
  35. Command.prototype.fromJSON.call( this, json );
  36. this.object = this.editor.objectByUuid( json.object.object.uuid );
  37. if ( this.object === undefined ) {
  38. var loader = new ObjectLoader();
  39. this.object = loader.parse( json.object );
  40. }
  41. }
  42. };
  43. export { AddObjectCommand };