UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

46 lines (45 loc) 1.73 kB
"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 SDF2DBoxJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR2([0, 0], { hidden: true }); this.center = ParamConfig.VECTOR2([0, 0]); this.sizes = ParamConfig.VECTOR2([1, 1]); } } const ParamsConfig = new SDF2DBoxJsParamsConfig(); export class SDF2DBoxJsNode extends BaseSDF2DJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.SDF_2D_BOX; } 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 sizes = this.variableForInputParam(shadersCollectionController, this.p.sizes); const float = this.jsVarName(OUTPUT_NAME); const func = Poly.namedFunctionsRegister.getFunction("SDF2DBox", this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.FLOAT, varName: float, value: func.asString(position, center, sizes) } ]); } }