@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
44 lines (43 loc) • 1.59 kB
JavaScript
;
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPointType, JsConnectionPoint } from "../utils/io/connections/Js";
import { BaseSDF2DJsNode } from "./_BaseSDF2D";
import { Poly } from "../../Poly";
import { JsType } from "../../poly/registers/nodes/types/Js";
const OUTPUT_NAME = "float";
class SDF2DHeartJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR2([0, 0], { hidden: true });
this.center = ParamConfig.VECTOR2([0, 0]);
}
}
const ParamsConfig = new SDF2DHeartJsParamsConfig();
export class SDF2DHeartJsNode extends BaseSDF2DJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_2D_HEART;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const position = this.variableForInputParam(shadersCollectionController, this.p.position);
const center = this.variableForInputParam(shadersCollectionController, this.p.center);
const float = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDF2DHeart", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: float,
value: func.asString(position, center)
}
]);
}
}