UNPKG

@polygonjs/polygonjs

Version:

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

45 lines (44 loc) 1.84 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"; const OUTPUT_NAME = "float"; class SDFLinkGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.center = ParamConfig.VECTOR3([0, 0, 0]); this.halfLength = ParamConfig.FLOAT(1); this.radius1 = ParamConfig.FLOAT(0.5); this.radius2 = ParamConfig.FLOAT(0.2); } } const ParamsConfig = new SDFLinkGlParamsConfig(); export class SDFLinkGlNode extends BaseSDFGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.SDF_LINK; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT) ]); } setLines(shadersCollectionController) { const position = this.position(); const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center)); const halfLength = ThreeToGl.float(this.variableForInputParam(this.p.halfLength)); const radius1 = ThreeToGl.float(this.variableForInputParam(this.p.radius1)); const radius2 = ThreeToGl.float(this.variableForInputParam(this.p.radius2)); const float = this.glVarName(OUTPUT_NAME); const bodyLine = `float ${float} = sdLink(${position} - ${center}, ${halfLength}, ${radius1}, ${radius2})`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDFMethods(shadersCollectionController); } }