UNPKG

@polygonjs/polygonjs

Version:

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

50 lines (49 loc) 1.83 kB
"use strict"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPointType, JsConnectionPoint } from "../utils/io/connections/Js"; import { TypedJsNode } from "./_Base"; import { isBooleanTrue } from "../../../core/Type"; import { Poly } from "../../Poly"; const OUTPUT_NAME = "union"; class SDFUnionJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.sdf0 = ParamConfig.FLOAT(1); this.sdf1 = ParamConfig.FLOAT(1); this.smooth = ParamConfig.BOOLEAN(1); this.smoothFactor = ParamConfig.FLOAT(1, { visibleIf: { smooth: 1 } }); } } const ParamsConfig = new SDFUnionJsParamsConfig(); export class SDFUnionJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "SDFUnion"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.FLOAT) ]); } setLines(shadersCollectionController) { const sdf0 = this.variableForInputParam(shadersCollectionController, this.p.sdf0); const sdf1 = this.variableForInputParam(shadersCollectionController, this.p.sdf1); const smoothFactor = this.variableForInputParam(shadersCollectionController, this.p.smoothFactor); const functionName = isBooleanTrue(this.pv.smooth) ? "SDFSmoothUnion" : "SDFUnion"; const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); const out = this.jsVarName(OUTPUT_NAME); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.FLOAT, varName: out, value: func.asString(sdf0, sdf1, smoothFactor) } ]); } }