SetMaterialVectorCommand.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.material = this.editor.getObjectMaterial( object, materialSlot );
  10. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].toArray() : undefined;
  11. this.newValue = newValue;
  12. this.attributeName = attributeName;
  13. }
  14. execute() {
  15. this.material[ this.attributeName ].fromArray( this.newValue );
  16. this.editor.signals.materialChanged.dispatch( this.material );
  17. }
  18. undo() {
  19. this.material[ this.attributeName ].fromArray( this.oldValue );
  20. this.editor.signals.materialChanged.dispatch( this.material );
  21. }
  22. update( cmd ) {
  23. this.newValue = cmd.newValue;
  24. }
  25. toJSON() {
  26. const output = super.toJSON( 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( json ) {
  34. super.fromJSON( 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 };