LimiterEditor.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { SelectInput, LabelElement, Element, NumberInput } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, UniformNode } from 'three/nodes';
  4. export class LimiterEditor extends BaseNode {
  5. constructor() {
  6. const NULL_VALUE = new UniformNode( 0 );
  7. const node = new MathNode( MathNode.MIN, NULL_VALUE, NULL_VALUE );
  8. super( 'Limiter', 1, node, 175 );
  9. const methodInput = new SelectInput( [
  10. { name: 'Min', value: MathNode.MIN },
  11. { name: 'Max', value: MathNode.MAX },
  12. // { name: 'Clamp', value: MathNode.CLAMP }
  13. { name: 'Saturate', value: MathNode.SATURATE }
  14. ], MathNode.MIN );
  15. methodInput.onChange( ( data ) => {
  16. node.method = data.getValue();
  17. bElement.setVisible( data.getValue() !== MathNode.SATURATE );
  18. this.invalidate();
  19. } );
  20. const aElement = new LabelElement( 'A' ).setInput( 1 );
  21. const bElement = new LabelElement( 'B' ).setInput( 1 );
  22. aElement.add( new NumberInput().onChange( ( field ) => {
  23. node.aNode.value = field.getValue();
  24. } ) ).onConnect( ( elmt ) => {
  25. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  26. node.aNode = elmt.getLinkedObject() || NULL_VALUE;
  27. } );
  28. bElement.add( new NumberInput().onChange( ( field ) => {
  29. node.bNode.value = field.getValue();
  30. } ) ).onConnect( ( elmt ) => {
  31. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  32. node.bNode = elmt.getLinkedObject() || NULL_VALUE;
  33. } );
  34. this.add( new Element().add( methodInput ) )
  35. .add( aElement )
  36. .add( bElement );
  37. }
  38. }