CmdSetMaterialColor.js 1.5 KB

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