@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
56 lines (55 loc) • 2.07 kB
JavaScript
"use strict";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import WAVES from "./gl/waves.glsl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
import { TypedGlNode } from "./_Base";
const OUTPUT_NAME = "h";
class WavesGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR2([0, 0]);
this.time = ParamConfig.FLOAT(0);
this.freq = ParamConfig.FLOAT(6, {
range: [0, 10],
rangeLocked: [false, false]
});
this.freqMult = ParamConfig.FLOAT(1.18, {
range: [0, 2],
rangeLocked: [false, false]
});
this.speedMult = ParamConfig.FLOAT(1.07, {
range: [0, 2],
rangeLocked: [false, false]
});
}
}
const ParamsConfig = new WavesGlParamsConfig();
export class WavesGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "waves";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
setLines(linesController) {
const position = ThreeToGl.vector3(this.variableForInputParam(this.p.position));
const time = ThreeToGl.float(this.variableForInputParam(this.p.time));
const freq = ThreeToGl.float(this.variableForInputParam(this.p.freq));
const freqMult = ThreeToGl.float(this.variableForInputParam(this.p.freqMult));
const speedMult = ThreeToGl.float(this.variableForInputParam(this.p.speedMult));
const float = this.glVarName(OUTPUT_NAME);
const args = [position, time, freq, freqMult, speedMult];
const bodyLine = `float ${float} = getwaves(${args.join(",")})`;
linesController.addBodyLines(this, [bodyLine]);
linesController.addDefinitions(this, [new FunctionGLDefinition(this, WAVES)]);
}
}