InvertEditor.js 914 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { SelectInput, LabelElement } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, UniformNode } from 'three/nodes';
  4. const DEFAULT_VALUE = new UniformNode( 0 );
  5. export class InvertEditor extends BaseNode {
  6. constructor() {
  7. const node = new MathNode( MathNode.INVERT, DEFAULT_VALUE );
  8. super( 'Invert / Negate', 1, node, 175 );
  9. const optionsField = new SelectInput( [
  10. { name: 'Invert ( 1 - Source )', value: MathNode.INVERT },
  11. { name: 'Negate ( - Source )', value: MathNode.NEGATE }
  12. ], MathNode.INVERT ).onChange( () => {
  13. node.method = optionsField.getValue();
  14. this.invalidate();
  15. } );
  16. const input = new LabelElement( 'Source' ).setInput( 1 );
  17. input.onConnect( () => {
  18. node.aNode = input.getLinkedObject() || DEFAULT_VALUE;
  19. } );
  20. this.add( new LabelElement( 'Method' ).add( optionsField ) )
  21. .add( input );
  22. }
  23. }