@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
49 lines (48 loc) • 2.05 kB
JavaScript
"use strict";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { BaseSDFGlNode } from "./_BaseSDF";
import { GlType } from "../../poly/registers/nodes/types/Gl";
const OUTPUT_NAME = "float";
class SDFQuadGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.a = ParamConfig.VECTOR3([0, 0, 0]);
this.b = ParamConfig.VECTOR3([0, 1, 0]);
this.c = ParamConfig.VECTOR3([0, 1, 1]);
this.d = ParamConfig.VECTOR3([0, 0, 1]);
this.thickness = ParamConfig.FLOAT(0.1);
}
}
const ParamsConfig = new SDFQuadGlParamsConfig();
export class SDFQuadGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_QUAD;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const position = this.position();
const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center));
const a = ThreeToGl.float(this.variableForInputParam(this.p.a));
const b = ThreeToGl.float(this.variableForInputParam(this.p.b));
const c = ThreeToGl.float(this.variableForInputParam(this.p.c));
const d = ThreeToGl.float(this.variableForInputParam(this.p.d));
const thickness = ThreeToGl.float(this.variableForInputParam(this.p.thickness));
const float = this.glVarName(OUTPUT_NAME);
const bodyLine = `float ${float} = udQuad(${position} - ${center}, ${a}, ${b}, ${c}, ${d}, ${thickness})`;
shadersCollectionController.addBodyLines(this, [bodyLine]);
this._addSDFMethods(shadersCollectionController);
}
}