UNPKG

@polygonjs/polygonjs

Version:

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

38 lines (37 loc) 1.41 kB
"use strict"; import { TypedGlNode } from "./_Base"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; import { ThreeToGl } from "../../../core/ThreeToGl"; import { ParamConfig, NodeParamsConfig } from "../utils/params/ParamsConfig"; import { FunctionGLDefinition } from "./utils/GLDefinition"; import PolarGlslLib from "./gl/polar.glsl"; const OUTPUT_NAME = "xyz"; class PolarToCartesianGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.polar = ParamConfig.VECTOR3([1, 1, 1]); } } const ParamsConfig = new PolarToCartesianGlParamsConfig(); export class PolarToCartesianGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "polarToCartesian"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC3) ]); } setLines(shadersCollectionController) { const out = this.glVarName(OUTPUT_NAME); const polar = ThreeToGl.vector3(this.variableForInputParam(this.p.polar)); const bodyLine = `vec3 ${out} = polarToCartesian(${polar})`; shadersCollectionController.addBodyLines(this, [bodyLine]); shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, PolarGlslLib)]); } }