CmdSetMaterialValue.js 1.4 KB

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