SetShadowValueCommand.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Command } from '../Command.js';
  2. /**
  3. * @param editor Editor
  4. * @param object THREE.Object3D
  5. * @param attributeName string
  6. * @param newValue number, string, boolean or object
  7. * @constructor
  8. */
  9. class SetShadowValueCommand extends Command {
  10. constructor( editor, object = null, attributeName = '', newValue = null ) {
  11. super( editor );
  12. this.type = 'SetShadowValueCommand';
  13. this.name = editor.strings.getKey( 'command/SetShadowValue' ) + ': ' + attributeName;
  14. this.object = object;
  15. this.attributeName = attributeName;
  16. this.oldValue = ( object !== null ) ? object.shadow[ attributeName ] : null;
  17. this.newValue = newValue;
  18. }
  19. execute() {
  20. this.object.shadow[ this.attributeName ] = this.newValue;
  21. this.editor.signals.objectChanged.dispatch( this.object );
  22. }
  23. undo() {
  24. this.object.shadow[ this.attributeName ] = this.oldValue;
  25. this.editor.signals.objectChanged.dispatch( this.object );
  26. }
  27. toJSON() {
  28. const output = super.toJSON( this );
  29. output.objectUuid = this.object.uuid;
  30. output.attributeName = this.attributeName;
  31. output.oldValue = this.oldValue;
  32. output.newValue = this.newValue;
  33. return output;
  34. }
  35. fromJSON( json ) {
  36. super.fromJSON( json );
  37. this.object = this.editor.objectByUuid( json.objectUuid );
  38. this.attributeName = json.attributeName;
  39. this.oldValue = json.oldValue;
  40. this.newValue = json.newValue;
  41. }
  42. }
  43. export { SetShadowValueCommand };