@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
40 lines (39 loc) • 1.33 kB
JavaScript
;
import { TypedGlNode } from "./_Base";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPoint, GlConnectionPointType } from "../utils/io/connections/Gl";
const OUTPUT_NAME = "rand";
class RandomGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.seed = ParamConfig.VECTOR2([1, 1]);
}
}
const ParamsConfig = new RandomGlParamsConfig();
export class RandomGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "random";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
setLines(shaders_collection_controller) {
const connectionPoints = this.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
const input_name = connectionPoints[0].name();
const value = ThreeToGl.vector2(this.variableForInput(input_name));
const float = this.glVarName(OUTPUT_NAME);
const body_line = `float ${float} = rand(${value})`;
shaders_collection_controller.addBodyLines(this, [body_line]);
}
}