CmdSetMaterialValue.js 1.5 KB

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