PowerEditor.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { LabelElement, NumberInput } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, UniformNode } from 'three/nodes';
  4. export class PowerEditor extends BaseNode {
  5. constructor() {
  6. const NULL_VALUE = new UniformNode( 0 );
  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. }