CmdSetGeometryValue.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. */
  4. /**
  5. * @param object THREE.Object3D
  6. * @param attributeName string
  7. * @param newValue number, string, boolean or object
  8. * @constructor
  9. */
  10. CmdSetGeometryValue = function ( object, attributeName, newValue ) {
  11. Cmd.call( this );
  12. this.type = 'CmdSetGeometryValue';
  13. this.name = 'Set Geometry.' + attributeName;
  14. this.object = object;
  15. this.attributeName = attributeName;
  16. this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
  17. this.newValue = newValue;
  18. };
  19. CmdSetGeometryValue.prototype = {
  20. execute: function () {
  21. this.object.geometry[ this.attributeName ] = this.newValue;
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. this.editor.signals.geometryChanged.dispatch();
  24. this.editor.signals.sceneGraphChanged.dispatch();
  25. },
  26. undo: function () {
  27. this.object.geometry[ this.attributeName ] = this.oldValue;
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. this.editor.signals.geometryChanged.dispatch();
  30. this.editor.signals.sceneGraphChanged.dispatch();
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.object.uuid;
  35. output.attributeName = this.attributeName;
  36. output.oldValue = this.oldValue;
  37. output.newValue = this.newValue;
  38. return output;
  39. },
  40. fromJSON: function ( json ) {
  41. Cmd.prototype.fromJSON.call( this, json );
  42. this.object = this.editor.objectByUuid( json.objectUuid );
  43. this.attributeName = json.attributeName;
  44. this.oldValue = json.oldValue;
  45. this.newValue = json.newValue;
  46. }
  47. };