CmdSetGeometry.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetGeometry = function ( object, newGeometry ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetGeometry';
  7. this.name = 'Set geometry';
  8. this.updatable = true;
  9. this.object = object;
  10. this.objectUuid = object !== undefined ? object.uuid : undefined;
  11. this.oldGeometry = object !== undefined ? object.geometry : undefined;
  12. this.newGeometry = newGeometry;
  13. this.oldGeometryJSON = object !== undefined ? object.geometry.toJSON() : undefined;
  14. this.newGeometryJSON = newGeometry !== undefined ? newGeometry.toJSON() : undefined;
  15. };
  16. CmdSetGeometry.prototype = {
  17. execute: function () {
  18. this.object.geometry.dispose();
  19. this.object.geometry = this.newGeometry;
  20. this.object.geometry.computeBoundingSphere();
  21. this.editor.signals.geometryChanged.dispatch( this.object );
  22. this.editor.signals.sceneGraphChanged.dispatch();
  23. },
  24. undo: function () {
  25. this.object.geometry.dispose();
  26. this.object.geometry = this.oldGeometry;
  27. this.object.geometry.computeBoundingSphere();
  28. this.editor.signals.geometryChanged.dispatch( this.object );
  29. this.editor.signals.sceneGraphChanged.dispatch();
  30. },
  31. update: function ( cmd ) {
  32. this.newGeometry = cmd.newGeometry;
  33. this.newGeometryJSON = cmd.newGeometry.toJSON();
  34. },
  35. toJSON: function () {
  36. var output = Cmd.prototype.toJSON.call( this );
  37. output.objectUuid = this.objectUuid;
  38. output.oldGeometryJSON = this.oldGeometryJSON;
  39. output.newGeometryJSON = this.newGeometryJSON;
  40. return output;
  41. },
  42. fromJSON: function ( json ) {
  43. Cmd.prototype.fromJSON.call( this, json );
  44. this.object = this.editor.objectByUuid( json.objectUuid );
  45. this.objectUuid = json.objectUuid;
  46. this.oldGeometryJSON = json.oldGeometryJSON;
  47. this.newGeometryJSON = json.newGeometryJSON;
  48. this.oldGeometry = parseGeometry( this.oldGeometryJSON );
  49. this.newGeometry = parseGeometry( this.newGeometryJSON );
  50. function parseGeometry ( data ) {
  51. var loader = new THREE.ObjectLoader();
  52. return loader.parseGeometries( [ data ] )[ data.uuid ];
  53. }
  54. }
  55. };