UNPKG

@polygonjs/polygonjs

Version:

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

50 lines (49 loc) 1.85 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 = "subtract"; class SDFSubtractJsParamsConfig 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 SDFSubtractJsParamsConfig(); export class SDFSubtractJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "SDFSubtract"; } 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) ? "SDFSmoothSubtract" : "SDFSubtract"; const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); const float = this.jsVarName(OUTPUT_NAME); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.FLOAT, varName: float, value: func.asString(sdf0, sdf1, smoothFactor) } ]); } }