@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
48 lines (47 loc) • 1.84 kB
JavaScript
"use strict";
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 SDFTorusJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.radius1 = ParamConfig.FLOAT(1);
this.radius2 = ParamConfig.FLOAT(0.5);
}
}
const ParamsConfig = new SDFTorusJsParamsConfig();
export class SDFTorusJsNode extends BaseSDFJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_TORUS;
}
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 radius1 = this.variableForInputParam(shadersCollectionController, this.p.radius1);
const radius2 = this.variableForInputParam(shadersCollectionController, this.p.radius2);
const out = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDFTorus", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: out,
value: func.asString(position, center, radius1, radius2)
}
]);
}
}