@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
50 lines (49 loc) • 2.12 kB
JavaScript
;
import { BaseSDFGlNode } from "./_BaseSDF";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import GL_CODE from "./gl/raymarching/sdfRhombusTriacontahedron.glsl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { FunctionGLDefinition } from "./utils/GLDefinition";
import { GlType } from "../../poly/registers/nodes/types/Gl";
const OUTPUT_NAME = "float";
class SDFRhombusTriacontahedronGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.m1 = ParamConfig.FLOAT(0.2);
this.m2 = ParamConfig.FLOAT(0.75);
this.f = ParamConfig.FLOAT(2, {
range: [0, 4]
});
}
}
const ParamsConfig = new SDFRhombusTriacontahedronGlParamsConfig();
export class SDFRhombusTriacontahedronGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_RHOMBUS_TRIACONTAHEDRON;
}
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 m1 = ThreeToGl.float(this.variableForInputParam(this.p.m1));
const m2 = ThreeToGl.float(this.variableForInputParam(this.p.m2));
const f = ThreeToGl.float(this.variableForInputParam(this.p.f));
const float = this.glVarName(OUTPUT_NAME);
const bodyLine = `float ${float} = sdRhombusTriacontahedron(${position} - ${center}, ${m1}, ${m2}, ${f})`;
shadersCollectionController.addBodyLines(this, [bodyLine]);
this._addSDFMethods(shadersCollectionController);
shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, GL_CODE)]);
}
}