BlendEditor.js 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { LabelElement } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { MathNode, UniformNode } from 'three/nodes';
  4. const NULL_VALUE = new UniformNode( 0 );
  5. const ONE_VALUE = new UniformNode( 1 );
  6. export class BlendEditor extends BaseNode {
  7. constructor() {
  8. const node = new MathNode( MathNode.MIX, NULL_VALUE, NULL_VALUE, ONE_VALUE );
  9. super( 'Blend', 3, node, 200 );
  10. const aElement = new LabelElement( 'Base' ).setInput( 3 );
  11. const bElement = new LabelElement( 'Blend' ).setInput( 3 );
  12. const cElement = new LabelElement( 'Opacity' ).setInput( 1 );
  13. aElement.onConnect( () => {
  14. node.aNode = aElement.getLinkedObject() || NULL_VALUE;
  15. } );
  16. bElement.onConnect( () => {
  17. node.bNode = bElement.getLinkedObject() || NULL_VALUE;
  18. } );
  19. cElement.onConnect( () => {
  20. node.cNode = cElement.getLinkedObject() || ONE_VALUE;
  21. } );
  22. this.add( aElement )
  23. .add( bElement )
  24. .add( cElement );
  25. }
  26. }