UNPKG

@polygonjs/polygonjs

Version:

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

115 lines (114 loc) 4.54 kB
"use strict"; import { TypedGlNode } from "./_Base"; import { ThreeToGl } from "../../../core/ThreeToGl"; import VERTEX_ANIMATION_TEXTURE from "./gl/vertexAnimationTexture.glsl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { FunctionGLDefinition, UniformGLDefinition } from "./utils/GLDefinition"; import { GlConnectionPoint, GlConnectionPointType } from "../utils/io/connections/Gl"; import { ParamConfigsController } from "../utils/code/controllers/ParamConfigsController"; import { GlParamConfig } from "./code/utils/GLParamConfig"; import { ParamType } from "../../poly/ParamType"; import { GlType } from "../../poly/registers/nodes/types/Gl"; const OUTPUT = { P: "position", N: "normal" }; class VertexAnimationTextureGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.frame = ParamConfig.FLOAT(0); this.framesCount = ParamConfig.FLOAT(100); this.uv = ParamConfig.VECTOR2([0, 0]); this.paddedRatio = ParamConfig.VECTOR2([1, 1]); this.textureP = ParamConfig.STRING("textureP"); this.textureP2 = ParamConfig.STRING("textureP2"); this.textureN = ParamConfig.STRING("textureN"); } } const ParamsConfig = new VertexAnimationTextureGlParamsConfig(); export class VertexAnimationTextureGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return GlType.VERTEX_ANIMATION_TEXTURE; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT.P, GlConnectionPointType.VEC3), new GlConnectionPoint(OUTPUT.N, GlConnectionPointType.VEC3) ]); } setLines(shadersCollectionController) { const functionDeclarationLines = []; const bodyLines = []; functionDeclarationLines.push(new FunctionGLDefinition(this, VERTEX_ANIMATION_TEXTURE)); const frame = ThreeToGl.float(this.variableForInputParam(this.p.frame)); const framesCount = ThreeToGl.float(this.variableForInputParam(this.p.framesCount)); const uv = ThreeToGl.vector2(this.variableForInputParam(this.p.uv)); const paddedRatio = ThreeToGl.vector2(this.variableForInputParam(this.p.paddedRatio)); const mapP = this._uniformName(this.pv.textureP); const mapP2 = this._uniformName(this.pv.textureP2); const mapN = this._uniformName(this.pv.textureN); const VATInfo = this.glVarName("VATInfo"); const VATDataResult = this.glVarName("VATDataResultTmp"); const outP = this.glVarName(OUTPUT.P); const outN = this.glVarName(OUTPUT.N); bodyLines.push( `VATDataInfoBasic ${VATInfo} = VATDataInfoBasic(${frame}, ${framesCount}, ${paddedRatio}, ${uv});` ); bodyLines.push(`VATDataResult ${VATDataResult} = VATData(${VATInfo}, ${mapP}, ${mapP2}, ${mapN})`); bodyLines.push(`vec3 ${outP} = ${VATDataResult}.P;`); bodyLines.push(`vec3 ${outN} = ${VATDataResult}.N;`); shadersCollectionController.addDefinitions(this, functionDeclarationLines); shadersCollectionController.addBodyLines(this, bodyLines); const definitionP = new UniformGLDefinition( this, GlConnectionPointType.SAMPLER_2D, this._uniformName(this.pv.textureP) ); const definitionP2 = new UniformGLDefinition( this, GlConnectionPointType.SAMPLER_2D, this._uniformName(this.pv.textureP2) ); const definitionN = new UniformGLDefinition( this, GlConnectionPointType.SAMPLER_2D, this._uniformName(this.pv.textureN) ); shadersCollectionController.addDefinitions(this, [definitionP, definitionP2, definitionN]); } paramsGenerating() { return true; } setParamConfigs() { this._param_configs_controller = this._param_configs_controller || new ParamConfigsController(); this._param_configs_controller.reset(); const paramConfigP = new GlParamConfig( ParamType.NODE_PATH, this.pv.textureP, "", this._uniformName(this.pv.textureP) ); const paramConfigP2 = new GlParamConfig( ParamType.NODE_PATH, this.pv.textureP2, "", this._uniformName(this.pv.textureP2) ); const paramConfigN = new GlParamConfig( ParamType.NODE_PATH, this.pv.textureN, "", this._uniformName(this.pv.textureN) ); this._param_configs_controller.push(paramConfigP); this._param_configs_controller.push(paramConfigP2); this._param_configs_controller.push(paramConfigN); } _uniformName(name) { return this.glVarName(name); } }