CmdSetMaterialValue.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetMaterialValue = function ( object, attributeName, newValue ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetMaterialValue';
  7. this.object = object;
  8. this.attributeName = attributeName;
  9. this.oldValue = object !== undefined ? object.material[ attributeName ] : undefined;
  10. this.newValue = newValue;
  11. this.objectUuid = object !== undefined ? object.uuid : undefined;
  12. };
  13. CmdSetMaterialValue.prototype = {
  14. execute: function () {
  15. this.object.material[ this.attributeName ] = this.newValue;
  16. this.editor.signals.objectChanged.dispatch( this.object );
  17. this.editor.signals.sceneGraphChanged.dispatch();
  18. },
  19. undo: function () {
  20. this.object.material[ this.attributeName ] = this.oldValue;
  21. this.editor.signals.objectChanged.dispatch( this.object );
  22. this.editor.signals.sceneGraphChanged.dispatch();
  23. },
  24. toJSON: function () {
  25. var output = Cmd.prototype.toJSON.call( this );
  26. output.objectUuid = this.objectUuid;
  27. output.attributeName = this.attributeName;
  28. output.oldValue = this.oldValue;
  29. output.newValue = this.newValue;
  30. return output;
  31. },
  32. fromJSON: function ( json ) {
  33. Cmd.prototype.fromJSON.call( this, json );
  34. this.objectUuid = json.objectUuid;
  35. this.attributeName = json.attributeName;
  36. this.oldValue = json.oldValue;
  37. this.newValue = json.newValue;
  38. this.object = this.editor.objectByUuid( json.objectUuid );
  39. }
  40. };