CmdAddObject.js 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdAddObject = function ( object ) {
  5. Cmd.call( this );
  6. this.type = 'CmdAddObject';
  7. this.object = object;
  8. if ( object !== undefined ) {
  9. object.updateMatrixWorld( true );
  10. meta = {
  11. geometries: {},
  12. materials: {},
  13. textures: {},
  14. images: {}
  15. };
  16. this.objectJSON = object.toJSON( meta );
  17. }
  18. };
  19. CmdAddObject.prototype = {
  20. execute: function () {
  21. this.editor.addObject( this.object );
  22. },
  23. undo: function () {
  24. this.editor.removeObject( this.object );
  25. this.editor.deselect();
  26. },
  27. toJSON: function () {
  28. var output = Cmd.prototype.toJSON.call( this );
  29. output.object = this.objectJSON;
  30. return output;
  31. },
  32. fromJSON: function ( json ) {
  33. Cmd.prototype.fromJSON.call( this, json );
  34. this.objectJSON = json.object;
  35. this.object = this.editor.objectByUuid( json.object.object.uuid );
  36. if ( this.object === undefined ) {
  37. var loader = new THREE.ObjectLoader();
  38. this.object = loader.parse( json.object );
  39. }
  40. }
  41. };