@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
48 lines (47 loc) • 1.89 kB
JavaScript
"use strict";
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 SDF2DRoundedXJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR2([0, 0], { hidden: true });
this.center = ParamConfig.VECTOR2([0, 0]);
this.length = ParamConfig.FLOAT(1);
this.radius = ParamConfig.FLOAT(0.1);
}
}
const ParamsConfig = new SDF2DRoundedXJsParamsConfig();
export class SDF2DRoundedXJsNode extends BaseSDF2DJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_2D_ROUNDED_X;
}
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 length = this.variableForInputParam(shadersCollectionController, this.p.length);
const radius = this.variableForInputParam(shadersCollectionController, this.p.radius);
const float = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDF2DRoundedX", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: float,
value: func.asString(position, center, length, radius)
}
]);
}
}