AddObjectCommand.js 1.1 KB

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