OperatorEditor.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Element, LabelElement, NumberInput, SelectInput } from '../../libs/flow.module.js';
  2. import { UniformNode, OperatorNode } from 'three-nodes/Nodes.js';
  3. import { BaseNode } from '../core/BaseNode.js';
  4. export class OperatorEditor extends BaseNode {
  5. constructor() {
  6. const NULL_VALUE = new UniformNode( 0 );
  7. const node = new OperatorNode( '+', NULL_VALUE, NULL_VALUE );
  8. super( 'Operator', 1, node, 150 );
  9. const opInput = new SelectInput( [
  10. { name: 'Addition ( + )', value: '+' },
  11. { name: 'Subtraction ( - )', value: '-' },
  12. { name: 'Multiplication ( * )', value: '*' },
  13. { name: 'Division ( / )', value: '/' }
  14. ], '+' );
  15. opInput.onChange( ( data ) => {
  16. node.op = data.getValue();
  17. this.invalidate();
  18. } );
  19. const aElement = new LabelElement( 'A' ).setInput( 3 );
  20. const bElement = new LabelElement( 'B' ).setInput( 3 );
  21. aElement.add( new NumberInput().onChange( ( field ) => {
  22. node.aNode.value = field.getValue();
  23. } ) ).onConnect( ( elmt ) => {
  24. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  25. node.aNode = elmt.getLinkedObject() || NULL_VALUE;
  26. } );
  27. bElement.add( new NumberInput().onChange( ( field ) => {
  28. node.bNode.value = field.getValue();
  29. } ) ).onConnect( ( elmt ) => {
  30. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  31. node.bNode = elmt.getLinkedObject() || NULL_VALUE;
  32. } );
  33. this.add( new Element().add( opInput ) )
  34. .add( aElement )
  35. .add( bElement );
  36. }
  37. }