UNPKG

@polygonjs/polygonjs

Version:

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

62 lines (61 loc) 2.29 kB
"use strict"; import { BaseSDFGlNode } from "./_BaseSDF"; import { ThreeToGl } from "../../../../src/core/ThreeToGl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; var SDFExtrudeAxis = /* @__PURE__ */ ((SDFExtrudeAxis2) => { SDFExtrudeAxis2["X"] = "X"; SDFExtrudeAxis2["Y"] = "Y"; SDFExtrudeAxis2["Z"] = "Z"; return SDFExtrudeAxis2; })(SDFExtrudeAxis || {}); const SDF_Extrude_AXISES = ["X" /* X */, "Y" /* Y */, "Z" /* Z */]; const OUTPUT_NAME = "d"; class SDFExtrudeGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.center = ParamConfig.VECTOR3([0, 0, 0]); this.height = ParamConfig.FLOAT(1); this.d = ParamConfig.FLOAT(1); this.axis = ParamConfig.INTEGER(SDF_Extrude_AXISES.indexOf("Z" /* Z */), { menu: { entries: SDF_Extrude_AXISES.map((name, value) => ({ name, value })) } }); } } const ParamsConfig = new SDFExtrudeGlParamsConfig(); export class SDFExtrudeGlNode extends BaseSDFGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "SDFExtrude"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT) ]); } setAxis(axis) { this.p.axis.set(SDF_Extrude_AXISES.indexOf(axis)); } setLines(shadersCollectionController) { const position = this.position(); const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center)); const height = ThreeToGl.float(this.variableForInputParam(this.p.height)); const d = ThreeToGl.float(this.variableForInputParam(this.p.d)); const out = this.glVarName(OUTPUT_NAME); const functionName = this._functionName(); const bodyLine = `float ${out} = ${functionName}(${position} - ${center}, ${d}, ${height})`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDFMethods(shadersCollectionController); } _functionName() { const axis = SDF_Extrude_AXISES[this.pv.axis]; return `SDFExtrude${axis}`; } }