JoinEditor.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { LabelElement } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { JoinNode, UniformNode } from 'three/nodes';
  4. const NULL_VALUE = new UniformNode( 0 );
  5. export class JoinEditor extends BaseNode {
  6. constructor() {
  7. const node = new JoinNode();
  8. super( 'Join', 1, node, 175 );
  9. const update = () => {
  10. const values = [
  11. xElement.getLinkedObject(),
  12. yElement.getLinkedObject(),
  13. zElement.getLinkedObject(),
  14. wElement.getLinkedObject()
  15. ];
  16. let length = 1;
  17. if ( values[ 3 ] !== null ) length = 4;
  18. else if ( values[ 2 ] !== null ) length = 3;
  19. else if ( values[ 1 ] !== null ) length = 2;
  20. const nodes = [];
  21. for ( let i = 0; i < length; i ++ ) {
  22. nodes.push( values[ i ] || NULL_VALUE );
  23. }
  24. node.nodes = nodes;
  25. this.invalidate();
  26. };
  27. const xElement = new LabelElement( 'X | R' ).setInput( 1 ).onConnect( update );
  28. const yElement = new LabelElement( 'Y | G' ).setInput( 1 ).onConnect( update );
  29. const zElement = new LabelElement( 'Z | B' ).setInput( 1 ).onConnect( update );
  30. const wElement = new LabelElement( 'W | A' ).setInput( 1 ).onConnect( update );
  31. this.add( xElement )
  32. .add( yElement )
  33. .add( zElement )
  34. .add( wElement );
  35. update();
  36. }
  37. }