CmdAddObject.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if ( object.geometry !== undefined ) {
  18. this.objectJSON.geometries = [];
  19. this.objectJSON.geometries.push( object.geometry.toJSON( meta ) );
  20. }
  21. if ( object.material !== undefined ) {
  22. this.objectJSON.materials = [];
  23. this.objectJSON.materials.push( object.material.toJSON( meta ) );
  24. }
  25. }
  26. };
  27. CmdAddObject.prototype = {
  28. execute: function () {
  29. this.editor.addObject( this.object );
  30. },
  31. undo: function () {
  32. this.editor.removeObject( this.object );
  33. this.editor.deselect();
  34. },
  35. toJSON: function () {
  36. var output = Cmd.prototype.toJSON.call( this );
  37. output.object = this.objectJSON;
  38. return output;
  39. },
  40. fromJSON: function ( json ) {
  41. Cmd.prototype.fromJSON.call( this, json );
  42. this.objectJSON = json.object;
  43. this.object = this.editor.objectByUuid( json.object.object.uuid );
  44. if ( this.object === undefined ) {
  45. var loader = new THREE.ObjectLoader();
  46. this.object = loader.parse( json.object );
  47. }
  48. }
  49. };