UNPKG

@polygonjs/polygonjs

Version:

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

46 lines (45 loc) 1.91 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 { isBooleanTrue } from "../../../core/Type"; import { GlType } from "../../poly/registers/nodes/types/Gl"; const OUTPUT_NAME = "p"; class SDFElongateGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.center = ParamConfig.VECTOR3([0, 0, 0]); this.mult = ParamConfig.VECTOR3([0, 0, 0]); this.fast = ParamConfig.BOOLEAN(1); } } const ParamsConfig = new SDFElongateGlParamsConfig(); export class SDFElongateGlNode extends BaseSDFGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.SDF_ELONGATE; } initializeNode() { super.initializeNode(); this.io.connection_points.spare_params.setInputlessParamNames(["fast"]); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC3) ]); } setLines(shadersCollectionController) { const position = this.position(); const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center)); const mult = ThreeToGl.vector3(this.variableForInputParam(this.p.mult)); const out = this.glVarName(OUTPUT_NAME); const functionName = isBooleanTrue(this.pv.fast) ? "SDFElongateFast" : "SDFElongateSlow"; const suffix = isBooleanTrue(this.pv.fast) ? ".xyz" : ".xyz"; const bodyLine = `vec3 ${out} = ${functionName}(${position} - ${center}, ${mult})${suffix}`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDFMethods(shadersCollectionController); } }