UNPKG

@polygonjs/polygonjs

Version:

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

44 lines (43 loc) 1.47 kB
"use strict"; import { TypedJsNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { Poly } from "../../Poly"; import { JsType } from "../../poly/registers/nodes/types/Js"; import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js"; const OUTPUT_NAME = "onion"; class SDFOnionJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.sdf = ParamConfig.FLOAT(0); this.thickness = ParamConfig.FLOAT(0.1); } } const ParamsConfig = new SDFOnionJsParamsConfig(); export class SDFOnionJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.SDF_ONION; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.FLOAT) ]); } setLines(linesController) { const sdf = this.variableForInputParam(linesController, this.p.sdf); const thickness = this.variableForInputParam(linesController, this.p.thickness); const out = this.jsVarName(OUTPUT_NAME); const func = Poly.namedFunctionsRegister.getFunction("SDFOnion", this, linesController); linesController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.FLOAT, varName: out, value: func.asString(sdf, thickness) } ]); } }