CmdSetGeometry.js 1.7 KB

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