SetMaterialVectorCommand.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Command } from '../Command.js';
  2. function SetMaterialVectorCommand( editor, object, attributeName, newValue, materialSlot ) {
  3. Command.call( this, editor );
  4. this.type = 'SetMaterialColorCommand';
  5. this.name = 'Set Material.' + attributeName;
  6. this.updatable = true;
  7. this.object = object;
  8. this.material = this.editor.getObjectMaterial( object, materialSlot );
  9. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].toArray() : undefined;
  10. this.newValue = newValue;
  11. this.attributeName = attributeName;
  12. }
  13. SetMaterialVectorCommand.prototype = {
  14. execute: function () {
  15. this.material[ this.attributeName ].fromArray( this.newValue );
  16. this.editor.signals.materialChanged.dispatch( this.material );
  17. },
  18. undo: function () {
  19. this.material[ this.attributeName ].fromArray( this.oldValue );
  20. this.editor.signals.materialChanged.dispatch( this.material );
  21. },
  22. update: function ( cmd ) {
  23. this.newValue = cmd.newValue;
  24. },
  25. toJSON: function () {
  26. var output = Command.prototype.toJSON.call( this );
  27. output.objectUuid = this.object.uuid;
  28. output.attributeName = this.attributeName;
  29. output.oldValue = this.oldValue;
  30. output.newValue = this.newValue;
  31. return output;
  32. },
  33. fromJSON: function ( json ) {
  34. Command.prototype.fromJSON.call( this, json );
  35. this.object = this.editor.objectByUuid( json.objectUuid );
  36. this.attributeName = json.attributeName;
  37. this.oldValue = json.oldValue;
  38. this.newValue = json.newValue;
  39. }
  40. };
  41. export { SetMaterialVectorCommand };