@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
81 lines (80 loc) • 3.57 kB
JavaScript
"use strict";
import { TypedGlNode } from "./_Base";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { ThreeToGl } from "../../../core/ThreeToGl";
import { FunctionGLDefinition, UniformGLDefinition } from "./utils/GLDefinition";
import { ParamConfigsController } from "../utils/code/controllers/ParamConfigsController";
import { ParamType } from "../../poly/ParamType";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlParamConfig } from "./code/utils/GLParamConfig";
import { UNIFORM_PARAM_PREFIX } from "../../../core/material/uniform";
import GET_UV from "../../../core/cloth/glsl/common/getUV.glsl";
import CLOTH_SOLVER_POSITION from "../../../core/cloth/glsl/render/ClothSolverPosition.glsl";
import { ClothSolverUniformName } from "../../../core/cloth/ClothAttribute";
var ClothSolverUvOutputName = /* @__PURE__ */ ((ClothSolverUvOutputName2) => {
ClothSolverUvOutputName2["UV"] = "uv";
return ClothSolverUvOutputName2;
})(ClothSolverUvOutputName || {});
class ClothSolverUvGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.id = ParamConfig.FLOAT(0);
this.size = ParamConfig.STRING(ClothSolverUniformName.SIZE);
}
}
const ParamsConfig = new ClothSolverUvGlParamsConfig();
export class ClothSolverUvGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "clothSolverUv";
}
initializeNode() {
this.addPostDirtyHook("_setMatToRecompile", this._setMatToRecompile.bind(this));
this.lifecycle.onAfterAdded(this._setMatToRecompile.bind(this));
this.lifecycle.onBeforeDeleted(this._setMatToRecompile.bind(this));
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint("uv" /* UV */, GlConnectionPointType.VEC2)
]);
}
setLines(shaders_collection_controller) {
const id = ThreeToGl.vector2(this.variableForInputParam(this.p.id));
const uv = this.glVarName("uv" /* UV */);
const uniformSize = this.uniformNameSize();
const definitions = [
new UniformGLDefinition(this, GlConnectionPointType.VEC2, uniformSize),
// new UniformGLDefinition(this, GlConnectionPointType.SAMPLER_2D, uniformPosition0),
// new UniformGLDefinition(this, GlConnectionPointType.SAMPLER_2D, uniformPosition1),
// new UniformGLDefinition(this, GlConnectionPointType.SAMPLER_2D, uniformNormal),
new FunctionGLDefinition(this, GET_UV),
new FunctionGLDefinition(this, CLOTH_SOLVER_POSITION)
];
const bodyLines = [];
bodyLines.push(`vec2 ${uv} = getClothSolverUV(${id}, ${uniformSize})`);
shaders_collection_controller.addDefinitions(this, definitions);
shaders_collection_controller.addBodyLines(this, bodyLines);
}
paramsGenerating() {
return true;
}
setParamConfigs() {
this._param_configs_controller = this._param_configs_controller || new ParamConfigsController();
this._param_configs_controller.reset();
const size = new GlParamConfig(ParamType.VECTOR2, this.pv.size, [1, 1], this.uniformNameSize());
this._param_configs_controller.push(size);
}
uniformNameSize() {
return `${UNIFORM_PARAM_PREFIX}${this.pv.size}`;
}
// uniformNamePosition0() {
// return `${UNIFORM_TEXTURE_PREFIX}${this.pv.position0}`;
// }
// uniformNamePosition1() {
// return `${UNIFORM_TEXTURE_PREFIX}${this.pv.position1}`;
// }
// uniformNameNormal() {
// return `${UNIFORM_TEXTURE_PREFIX}${this.pv.normal}`;
// }
}