SplitEditor.js 882 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { SelectInput, Element } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { SplitNode, UniformNode } from 'three/nodes';
  4. const NULL_VALUE = new UniformNode( 0 );
  5. export class SplitEditor extends BaseNode {
  6. constructor() {
  7. const node = new SplitNode( NULL_VALUE, 'x' );
  8. super( 'Split', 1, node, 175 );
  9. const componentsField = new SelectInput( [
  10. { name: 'X | R', value: 'x' },
  11. { name: 'Y | G', value: 'y' },
  12. { name: 'Z | B', value: 'z' },
  13. { name: 'W | A', value: 'w' }
  14. ], node.components ).onChange( () => {
  15. node.components = componentsField.getValue();
  16. this.invalidate();
  17. } );
  18. const componentsElement = new Element().add( componentsField ).setInput( 1 )
  19. .onConnect( () => {
  20. node.node = componentsElement.getLinkedObject() || NULL_VALUE;
  21. } );
  22. this.add( componentsElement );
  23. }
  24. }