@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
52 lines (51 loc) • 2.04 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 SDF2DCrossJsParamsConfig 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.width = ParamConfig.FLOAT(0.3);
this.radius = ParamConfig.FLOAT(0, {
range: [-1, 1]
});
}
}
const ParamsConfig = new SDF2DCrossJsParamsConfig();
export class SDF2DCrossJsNode extends BaseSDF2DJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SDF_2D_CROSS;
}
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 width = this.variableForInputParam(shadersCollectionController, this.p.width);
const radius = this.variableForInputParam(shadersCollectionController, this.p.radius);
const float = this.jsVarName(OUTPUT_NAME);
const func = Poly.namedFunctionsRegister.getFunction("SDF2DCross", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.FLOAT,
varName: float,
value: func.asString(position, center, length, width, radius)
}
]);
}
}