CmdSetMaterialColor.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.attributeName = attributeName;
  11. this.oldValue = ( object !== undefined ) ? this.object.material[ this.attributeName ].getHex() : undefined;
  12. this.newValue = newValue;
  13. };
  14. CmdSetMaterialColor.prototype = {
  15. execute: function () {
  16. this.object.material[ this.attributeName ].setHex( this.newValue );
  17. this.editor.signals.materialChanged.dispatch( this.object.material );
  18. },
  19. undo: function () {
  20. this.object.material[ this.attributeName ].setHex( this.oldValue );
  21. this.editor.signals.materialChanged.dispatch( this.object.material );
  22. },
  23. update: function ( cmd ) {
  24. this.newValue = cmd.newValue;
  25. },
  26. toJSON: function () {
  27. var output = Cmd.prototype.toJSON.call( this );
  28. output.objectUuid = this.object.uuid;
  29. output.attributeName = this.attributeName;
  30. output.oldValue = this.oldValue;
  31. output.newValue = this.newValue;
  32. return output;
  33. },
  34. fromJSON: function ( json ) {
  35. Cmd.prototype.fromJSON.call( this, json );
  36. this.object = this.editor.objectByUuid( json.objectUuid );
  37. this.attributeName = json.attributeName;
  38. this.oldValue = json.oldValue;
  39. this.newValue = json.newValue;
  40. }
  41. };