AddObjectCommand.js 1.1 KB

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