CmdSetGeometry.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.updatable = true;
  8. this.object = object;
  9. this.objectUuid = object !== undefined ? object.uuid : undefined;
  10. this.oldGeometry = object !== undefined ? object.geometry : undefined;
  11. this.newGeometry = newGeometry;
  12. this.oldGeometryJSON = object !== undefined ? object.geometry.toJSON() : undefined;
  13. this.newGeometryJSON = newGeometry !== undefined ? newGeometry.toJSON() : undefined;
  14. };
  15. CmdSetGeometry.prototype = {
  16. execute: function () {
  17. this.object.geometry.dispose();
  18. this.object.geometry = this.newGeometry;
  19. this.object.geometry.computeBoundingSphere();
  20. this.editor.signals.geometryChanged.dispatch( this.object );
  21. this.editor.signals.sceneGraphChanged.dispatch();
  22. },
  23. undo: function () {
  24. this.object.geometry.dispose();
  25. this.object.geometry = this.oldGeometry;
  26. this.object.geometry.computeBoundingSphere();
  27. this.editor.signals.geometryChanged.dispatch( this.object );
  28. this.editor.signals.sceneGraphChanged.dispatch();
  29. },
  30. update: function ( cmd ) {
  31. this.newGeometry = cmd.newGeometry;
  32. this.newGeometryJSON = cmd.newGeometry.toJSON();
  33. },
  34. toJSON: function () {
  35. var output = Cmd.prototype.toJSON.call( this );
  36. output.objectUuid = this.objectUuid;
  37. output.oldGeometryJSON = this.oldGeometryJSON;
  38. output.newGeometryJSON = this.newGeometryJSON;
  39. return output;
  40. },
  41. fromJSON: function ( json ) {
  42. Cmd.prototype.fromJSON.call( this, json );
  43. this.object = this.editor.objectByUuid( json.objectUuid );
  44. this.objectUuid = json.objectUuid;
  45. this.oldGeometryJSON = json.oldGeometryJSON;
  46. this.newGeometryJSON = json.newGeometryJSON;
  47. this.oldGeometry = parseGeometry( this.oldGeometryJSON );
  48. this.newGeometry = parseGeometry( this.newGeometryJSON );
  49. function parseGeometry ( data ) {
  50. var loader = new THREE.ObjectLoader();
  51. return loader.parseGeometries( [ data ] )[ data.uuid ];
  52. }
  53. }
  54. };