UNPKG

@polygonjs/polygonjs

Version:

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

65 lines (64 loc) 2.32 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"; import { GlType } from "../../poly/registers/nodes/types/Gl"; var SDFRevolutionGlAxis = /* @__PURE__ */ ((SDFRevolutionGlAxis2) => { SDFRevolutionGlAxis2["X"] = "X"; SDFRevolutionGlAxis2["Y"] = "Y"; SDFRevolutionGlAxis2["Z"] = "Z"; return SDFRevolutionGlAxis2; })(SDFRevolutionGlAxis || {}); const SDF_REVOLUTION_AXISES = [ "X" /* X */, "Y" /* Y */, "Z" /* Z */ ]; const OUTPUT_NAME = "p"; class SDFRevolutionGlParamsConfig 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 SDFRevolutionGlParamsConfig(); export class SDFRevolutionGlNode extends BaseSDFGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.SDF_REVOLUTION; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC2) ]); } setAxis(axis) { this.p.axis.set(SDF_REVOLUTION_AXISES.indexOf(axis)); } setLines(shadersCollectionController) { const position = this.position(); const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center)); const radius = ThreeToGl.float(this.variableForInputParam(this.p.radius)); const out = this.glVarName(OUTPUT_NAME); const functionName = this._functionName(); const bodyLine = `vec2 ${out} = ${functionName}(${position} - ${center}, ${radius})`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDFMethods(shadersCollectionController); } _functionName() { const axis = SDF_REVOLUTION_AXISES[this.pv.axis]; return `SDFRevolution${axis}`; } }