LimiterEditor.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { SelectInput, LabelElement, Element } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, FloatNode } from '../../renderers/nodes/Nodes.js';
  4. const NULL_VALUE = new FloatNode();
  5. export class LimiterEditor extends BaseNode {
  6. constructor() {
  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. ], MathNode.MIN );
  13. methodInput.onChange( ( data ) => {
  14. node.method = data.getValue();
  15. this.invalidate();
  16. } );
  17. const aElement = new LabelElement( 'A' ).setInput( 1 );
  18. const bElement = new LabelElement( 'B' ).setInput( 1 );
  19. aElement.onConnect( () => {
  20. node.aNode = aElement.getLinkedObject() || NULL_VALUE;
  21. } );
  22. bElement.onConnect( () => {
  23. node.bNode = bElement.getLinkedObject() || NULL_VALUE;
  24. } );
  25. this.add( new Element().add( methodInput ) )
  26. .add( aElement )
  27. .add( bElement );
  28. }
  29. }