@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
38 lines (37 loc) • 1.37 kB
JavaScript
;
import { TypedGlNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { ShaderName } from "../utils/shaders/ShaderName";
import { ThreeToGl } from "../../../core/ThreeToGl";
const OUTPUT_NAME = "mvMult";
class ModelViewMatrixMultGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.vector = ParamConfig.VECTOR3([0, 0, 0]);
}
}
const ParamsConfig = new ModelViewMatrixMultGlParamsConfig();
export class ModelViewMatrixMultGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "modelViewMatrixMult";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC4)
]);
}
setLines(linesController) {
if (linesController.currentShaderName() == ShaderName.VERTEX) {
const input = ThreeToGl.vector3(this.variableForInputParam(this.p.vector));
const outValue = this.glVarName(OUTPUT_NAME);
const bodyLine = `vec4 ${outValue} = modelViewMatrix * vec4(${input}, 1.0)`;
linesController.addBodyLines(this, [bodyLine], ShaderName.VERTEX);
}
}
}