CmdAddObject.js 1.2 KB

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