PowerEditor.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { LabelElement, NumberInput } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, FloatNode } from 'three-nodes/Nodes.js';
  4. export class PowerEditor extends BaseNode {
  5. constructor() {
  6. const NULL_VALUE = new FloatNode();
  7. const node = new MathNode( MathNode.POW, NULL_VALUE, NULL_VALUE );
  8. super( 'Power', 1, node, 175 );
  9. const aElement = new LabelElement( 'A' ).setInput( 1 );
  10. const bElement = new LabelElement( 'B' ).setInput( 1 );
  11. aElement.add( new NumberInput().onChange( ( field ) => {
  12. node.aNode.value = field.getValue();
  13. } ) ).onConnect( ( elmt ) => {
  14. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  15. node.aNode = elmt.getLinkedObject() || NULL_VALUE;
  16. } );
  17. bElement.add( new NumberInput().onChange( ( field ) => {
  18. node.bNode.value = field.getValue();
  19. } ) ).onConnect( ( elmt ) => {
  20. elmt.setEnabledInputs( ! elmt.getLinkedObject() );
  21. node.bNode = elmt.getLinkedObject() || NULL_VALUE;
  22. } );
  23. this.add( aElement )
  24. .add( bElement );
  25. }
  26. }