@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
45 lines (44 loc) • 1.83 kB
JavaScript
;
import { BaseSDFGlNode } from "./_BaseSDF";
import { ThreeToGl } from "../../../core/ThreeToGl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { GlType } from "../../poly/registers/nodes/types/Gl";
const OUTPUT_NAME = "float";
class SDFBoxRoundGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.size = ParamConfig.FLOAT(1);
this.sizes = ParamConfig.VECTOR3([1, 1, 1]);
this.radius = ParamConfig.FLOAT(0.1);
}
}
const ParamsConfig = new SDFBoxRoundGlParamsConfig();
export class SDFBoxRoundGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_BOX_ROUND;
}
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 size = ThreeToGl.float(this.variableForInputParam(this.p.size));
const sizes = ThreeToGl.vector3(this.variableForInputParam(this.p.sizes));
const radius = ThreeToGl.float(this.variableForInputParam(this.p.radius));
const float = this.glVarName(OUTPUT_NAME);
const bodyLine = `float ${float} = sdRoundBox(${position} - ${center}, ${sizes}*${size}, ${radius})`;
shadersCollectionController.addBodyLines(this, [bodyLine]);
this._addSDFMethods(shadersCollectionController);
}
}