SetMaterialVectorCommand.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. import { Command } from '../Command.js';
  6. var SetMaterialVectorCommand = function ( editor, object, attributeName, newValue, materialSlot ) {
  7. Command.call( this, editor );
  8. this.type = 'SetMaterialColorCommand';
  9. this.name = 'Set Material.' + attributeName;
  10. this.updatable = true;
  11. this.object = object;
  12. this.material = this.editor.getObjectMaterial( object, materialSlot );
  13. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].toArray() : undefined;
  14. this.newValue = newValue;
  15. this.attributeName = attributeName;
  16. };
  17. SetMaterialVectorCommand.prototype = {
  18. execute: function () {
  19. this.material[ this.attributeName ].fromArray( this.newValue );
  20. this.editor.signals.materialChanged.dispatch( this.material );
  21. },
  22. undo: function () {
  23. this.material[ this.attributeName ].fromArray( this.oldValue );
  24. this.editor.signals.materialChanged.dispatch( this.material );
  25. },
  26. update: function ( cmd ) {
  27. this.newValue = cmd.newValue;
  28. },
  29. toJSON: function () {
  30. var output = Command.prototype.toJSON.call( this );
  31. output.objectUuid = this.object.uuid;
  32. output.attributeName = this.attributeName;
  33. output.oldValue = this.oldValue;
  34. output.newValue = this.newValue;
  35. return output;
  36. },
  37. fromJSON: function ( json ) {
  38. Command.prototype.fromJSON.call( this, json );
  39. this.object = this.editor.objectByUuid( json.objectUuid );
  40. this.attributeName = json.attributeName;
  41. this.oldValue = json.oldValue;
  42. this.newValue = json.newValue;
  43. }
  44. };
  45. export { SetMaterialVectorCommand };