CmdSetMaterialValue.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.name = 'Set Material.' + attributeName;
  8. this.updatable = true;
  9. this.object = object;
  10. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  11. this.oldValue = ( object !== undefined ) ? object.material[ attributeName ] : undefined;
  12. this.newValue = newValue;
  13. this.attributeName = attributeName;
  14. };
  15. CmdSetMaterialValue.prototype = {
  16. init: function () {
  17. if ( this.object === undefined ) {
  18. this.object = this.editor.objectByUuid( this.objectUuid );
  19. }
  20. },
  21. execute: function () {
  22. this.init();
  23. this.object.material[ this.attributeName ] = this.newValue;
  24. this.object.material.needsUpdate = true;
  25. this.editor.signals.materialChanged.dispatch( this.object.material );
  26. },
  27. undo: function () {
  28. this.init();
  29. this.object.material[ this.attributeName ] = this.oldValue;
  30. this.object.material.needsUpdate = true;
  31. this.editor.signals.materialChanged.dispatch( this.object.material );
  32. },
  33. update: function ( cmd ) {
  34. this.newValue = cmd.newValue;
  35. },
  36. toJSON: function () {
  37. var output = Cmd.prototype.toJSON.call( this );
  38. output.objectUuid = this.objectUuid;
  39. output.attributeName = this.attributeName;
  40. output.oldValue = this.oldValue;
  41. output.newValue = this.newValue;
  42. return output;
  43. },
  44. fromJSON: function ( json ) {
  45. Cmd.prototype.fromJSON.call( this, json );
  46. this.objectUuid = json.objectUuid;
  47. this.attributeName = json.attributeName;
  48. this.oldValue = json.oldValue;
  49. this.newValue = json.newValue;
  50. }
  51. };