CmdSetGeometry.js 1.6 KB

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