AddObjectCommand.js 1.1 KB

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