UNPKG

@polygonjs/polygonjs

Version:

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

50 lines (49 loc) 2.19 kB
"use strict"; import { BaseSDFGlNode } from "./_BaseSDF"; import { ThreeToGl } from "../../../../src/core/ThreeToGl"; import GL_CODE from "./gl/raymarching/sdfRhombus.glsl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; import { FunctionGLDefinition } from "./utils/GLDefinition"; import { GlType } from "../../poly/registers/nodes/types/Gl"; const OUTPUT_NAME = "float"; class SDFRhombusGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.center = ParamConfig.VECTOR3([0, 0, 0]); this.length1 = ParamConfig.FLOAT(1); this.length2 = ParamConfig.FLOAT(0.5); this.height = ParamConfig.FLOAT(0.2); this.radius = ParamConfig.FLOAT(0.05); } } const ParamsConfig = new SDFRhombusGlParamsConfig(); export class SDFRhombusGlNode extends BaseSDFGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.SDF_RHOMBUS; } 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 length1 = ThreeToGl.float(this.variableForInputParam(this.p.length1)); const length2 = ThreeToGl.float(this.variableForInputParam(this.p.length2)); const height = ThreeToGl.float(this.variableForInputParam(this.p.height)); const radius = ThreeToGl.float(this.variableForInputParam(this.p.radius)); const float = this.glVarName(OUTPUT_NAME); const bodyLine = `float ${float} = sdRhombus(${position} - ${center}, ${length1}, ${length2}, ${height}, ${radius})`; shadersCollectionController.addBodyLines(this, [bodyLine]); this._addSDFMethods(shadersCollectionController); shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, GL_CODE)]); } }