123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import Node, { addNodeClass } from '../core/Node.js';
- import { timerLocal } from './TimerNode.js';
- import { nodeObject, nodeProxy } from '../shadernode/ShaderNode.js';
- class OscNode extends Node {
- constructor( method = OscNode.SINE, timeNode = timerLocal() ) {
- super();
- this.method = method;
- this.timeNode = timeNode;
- }
- getNodeType( builder ) {
- return this.timeNode.getNodeType( builder );
- }
- setup() {
- const method = this.method;
- const timeNode = nodeObject( this.timeNode );
- let outputNode = null;
- if ( method === OscNode.SINE ) {
- outputNode = timeNode.add( 0.75 ).mul( Math.PI * 2 ).sin().mul( 0.5 ).add( 0.5 );
- } else if ( method === OscNode.SQUARE ) {
- outputNode = timeNode.fract().round();
- } else if ( method === OscNode.TRIANGLE ) {
- outputNode = timeNode.add( 0.5 ).fract().mul( 2 ).sub( 1 ).abs();
- } else if ( method === OscNode.SAWTOOTH ) {
- outputNode = timeNode.fract();
- }
- return outputNode;
- }
- serialize( data ) {
- super.serialize( data );
- data.method = this.method;
- }
- deserialize( data ) {
- super.deserialize( data );
- this.method = data.method;
- }
- }
- OscNode.SINE = 'sine';
- OscNode.SQUARE = 'square';
- OscNode.TRIANGLE = 'triangle';
- OscNode.SAWTOOTH = 'sawtooth';
- export default OscNode;
- export const oscSine = nodeProxy( OscNode, OscNode.SINE );
- export const oscSquare = nodeProxy( OscNode, OscNode.SQUARE );
- export const oscTriangle = nodeProxy( OscNode, OscNode.TRIANGLE );
- export const oscSawtooth = nodeProxy( OscNode, OscNode.SAWTOOTH );
- addNodeClass( 'OscNode', OscNode );
|