@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
48 lines (47 loc) • 1.74 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 SDFBoxJsParamsConfig 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]);
}
}
const ParamsConfig = new SDFBoxJsParamsConfig();
export class SDFBoxJsNode extends BaseSDFJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_BOX;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.FLOAT)
]);
}
setLines(linesController) {
const position = this.position(linesController);
const center = this.variableForInputParam(linesController, this.p.center);
const size = this.variableForInputParam(linesController, this.p.size);
const sizes = this.variableForInputParam(linesController, this.p.sizes);
const float = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDFBox", this, linesController);
linesController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: float,
value: func.asString(position, center, sizes, size)
}
]);
}
}