@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
46 lines (45 loc) • 1.69 kB
JavaScript
;
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPointType, JsConnectionPoint } from "../utils/io/connections/Js";
import { BaseSDFJsNode } from "./_BaseSDF";
import { Poly } from "../../Poly";
import { JsType } from "../../poly/registers/nodes/types/Js";
const OUTPUT_NAME = "float";
class SDFTubeJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.radius = ParamConfig.FLOAT(0.5);
}
}
const ParamsConfig = new SDFTubeJsParamsConfig();
export class SDFTubeJsNode extends BaseSDFJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_TUBE;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const position = this.position(shadersCollectionController);
const center = this.variableForInputParam(shadersCollectionController, this.p.center);
const radius = this.variableForInputParam(shadersCollectionController, this.p.radius);
const out = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDFTube", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: out,
value: func.asString(position, center, radius)
}
]);
}
}