UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

35 lines (34 loc) 1.24 kB
import {TypedGlNode} from "./_Base"; import {ThreeToGl as ThreeToGl2} 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 ParamsConfig2 = new RandomGlParamsConfig(); export class RandomGlNode extends TypedGlNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; } static type() { return "random"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT) ]); } set_lines(shaders_collection_controller) { const input_name = this.io.inputs.named_input_connection_points[0].name(); const value = ThreeToGl2.vector2(this.variable_for_input(input_name)); const float = this.gl_var_name(OUTPUT_NAME); const body_line = `float ${float} = rand(${value})`; shaders_collection_controller.add_body_lines(this, [body_line]); } }