2
0

SetMaterialVectorCommand.js 1.5 KB

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