2
0

OscillatorEditor.js 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { SelectInput, LabelElement, Element } from '../../libs/flow.module.js';
  2. import { BaseNode } from '../core/BaseNode.js';
  3. import { OscNode, UniformNode } from 'three/nodes';
  4. const NULL_VALUE = new UniformNode( 0 );
  5. export class OscillatorEditor extends BaseNode {
  6. constructor() {
  7. const node = new OscNode( OscNode.SINE, NULL_VALUE );
  8. super( 'Oscillator', 1, node, 175 );
  9. const methodInput = new SelectInput( [
  10. { name: 'Sine', value: OscNode.SINE },
  11. { name: 'Square', value: OscNode.SQUARE },
  12. { name: 'Triangle', value: OscNode.TRIANGLE },
  13. { name: 'Sawtooth', value: OscNode.SAWTOOTH }
  14. ], OscNode.SINE );
  15. methodInput.onChange( () => {
  16. node.method = methodInput.getValue();
  17. this.invalidate();
  18. } );
  19. const timeElement = new LabelElement( 'Time' ).setInput( 1 );
  20. timeElement.onConnect( () => {
  21. node.timeNode = timeElement.getLinkedObject() || NULL_VALUE;
  22. } );
  23. this.add( new Element().add( methodInput ) )
  24. .add( timeElement );
  25. }
  26. }