UNPKG

@polygonjs/polygonjs

Version:

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

41 lines (40 loc) 1.56 kB
"use strict"; import { ThreeToGl } from "../../../../src/core/ThreeToGl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; import { BaseSDF2DGlNode } from "./_BaseSDF2D"; import { GlType } from "../../poly/registers/nodes/types/Gl"; const OUTPUT_NAME = "float"; class SDF2DBoxGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR2([0, 0], { hidden: true }); this.center = ParamConfig.VECTOR2([0, 0]); this.size = ParamConfig.VECTOR2([1, 1]); } } const ParamsConfig = new SDF2DBoxGlParamsConfig(); export class SDF2DBoxGlNode extends BaseSDF2DGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.SDF_2D_BOX; } 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 size = ThreeToGl.vector2(this.variableForInputParam(this.p.size)); const float = this.glVarName(OUTPUT_NAME); const bodyLine = `float ${float} = sdBox(${position} - ${center}, ${size})`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDF2DMethods(shadersCollectionController); } }