UNPKG

@polygonjs/polygonjs

Version:

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

41 lines (40 loc) 1.66 kB
"use strict"; import { ThreeToGl } from "../../../core/ThreeToGl"; import GET_UV from "./gl/geometryAttributes/geometryAttributesLookupUv.glsl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; import { FunctionGLDefinition } from "./utils/GLDefinition"; import { TypedGlNode } from "./_Base"; const OUTPUT_NAME = "uv"; class GeometryAttributeLookupUvGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.id = ParamConfig.FLOAT(0); this.textureSize = ParamConfig.VECTOR2([1, 1]); } } const ParamsConfig = new GeometryAttributeLookupUvGlParamsConfig(); export class GeometryAttributeLookupUvGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "geometryAttributeLookupUv"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC2) ]); } setLines(shadersCollectionController) { const id = ThreeToGl.float(this.variableForInputParam(this.p.id)); const textureSize = ThreeToGl.vector2(this.variableForInputParam(this.p.textureSize)); const uv = this.glVarName(OUTPUT_NAME); const functionCall = `geometryAttributesLookupUv(${id},${textureSize})`; const bodyLine = `vec2 ${uv} = ${functionCall}`; shadersCollectionController.addBodyLines(this, [bodyLine]); shadersCollectionController.addDefinitions(this, [new FunctionGLDefinition(this, GET_UV)]); } }