UNPKG

@polygonjs/polygonjs

Version:

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

83 lines (82 loc) 2.74 kB
"use strict"; import { BaseSDFJsNode } from "./_BaseSDF"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPointType, JsConnectionPoint } from "../utils/io/connections/Js"; import { TypeAssert } from "../../poly/Assert"; import { Vector2 } from "three"; import { Poly } from "../../Poly"; import { JsType } from "../../poly/registers/nodes/types/Js"; var SDFRevolutionJsAxis = /* @__PURE__ */ ((SDFRevolutionJsAxis2) => { SDFRevolutionJsAxis2["X"] = "X"; SDFRevolutionJsAxis2["Y"] = "Y"; SDFRevolutionJsAxis2["Z"] = "Z"; return SDFRevolutionJsAxis2; })(SDFRevolutionJsAxis || {}); const SDF_REVOLUTION_AXISES = [ "X" /* X */, "Y" /* Y */, "Z" /* Z */ ]; const OUTPUT_NAME = "p"; class SDFRevolutionJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.center = ParamConfig.VECTOR3([0, 0, 0]); this.radius = ParamConfig.FLOAT(1); this.axis = ParamConfig.INTEGER(SDF_REVOLUTION_AXISES.indexOf("Y" /* Y */), { menu: { entries: SDF_REVOLUTION_AXISES.map((name, value) => ({ name, value })) } }); } } const ParamsConfig = new SDFRevolutionJsParamsConfig(); export class SDFRevolutionJsNode extends BaseSDFJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.SDF_REVOLUTION; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR2) ]); } setAxis(axis) { this.p.axis.set(SDF_REVOLUTION_AXISES.indexOf(axis)); } setLines(linesController) { const position = this.position(linesController); const center = this.variableForInputParam(linesController, this.p.center); const radius = this.variableForInputParam(linesController, this.p.radius); const out = this.jsVarName(OUTPUT_NAME); const tmpVarName = linesController.addVariable(this, new Vector2()); const func = Poly.namedFunctionsRegister.getFunction(this._functionName(), this, linesController); linesController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.VECTOR2, varName: out, value: func.asString(position, center, radius, tmpVarName) } ]); } _functionName() { const axis = SDF_REVOLUTION_AXISES[this.pv.axis]; switch (axis) { case "X" /* X */: { return "SDFRevolutionX"; } case "Y" /* Y */: { return "SDFRevolutionY"; } case "Z" /* Z */: { return "SDFRevolutionZ"; } } TypeAssert.unreachable(axis); } }