@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
99 lines (98 loc) • 4.96 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, UNIFORM_TEXTURE_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 ClothSolverPositionOutputName = /* @__PURE__ */ ((ClothSolverPositionOutputName2) => {
ClothSolverPositionOutputName2["POSITION"] = "position";
ClothSolverPositionOutputName2["NORMAL"] = "normal";
return ClothSolverPositionOutputName2;
})(ClothSolverPositionOutputName || {});
class ClothSolverPositionGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.id = ParamConfig.FLOAT(0);
this.size = ParamConfig.STRING(ClothSolverUniformName.SIZE);
this.position0 = ParamConfig.STRING(ClothSolverUniformName.POSITION0);
this.position1 = ParamConfig.STRING(ClothSolverUniformName.POSITION1);
this.normal = ParamConfig.STRING(ClothSolverUniformName.NORMAL);
}
}
const ParamsConfig = new ClothSolverPositionGlParamsConfig();
export class ClothSolverPositionGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "clothSolverPosition";
}
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("position" /* POSITION */, GlConnectionPointType.VEC3),
new GlConnectionPoint("normal" /* NORMAL */, GlConnectionPointType.VEC3)
]);
}
setLines(shaders_collection_controller) {
const id = ThreeToGl.vector2(this.variableForInputParam(this.p.id));
const uv = this.glVarName("clothSolverUv");
const position = this.glVarName("position" /* POSITION */);
const normal = this.glVarName("normal" /* NORMAL */);
const uniformSize = this.uniformNameSize();
const uniformPosition0 = this.uniformNamePosition0();
const uniformPosition1 = this.uniformNamePosition1();
const uniformNormal = this.uniformNameNormal();
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})`);
bodyLines.push(`vec3 ${position} = clothSolverPosition(${uniformPosition0}, ${uniformPosition1}, ${uv})`);
bodyLines.push(`vec3 ${normal} = clothSolverNormal(${uniformNormal}, ${uv})`);
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());
const position0 = new GlParamConfig(ParamType.NODE_PATH, this.pv.position0, "", this.uniformNamePosition0());
const position1 = new GlParamConfig(ParamType.NODE_PATH, this.pv.position1, "", this.uniformNamePosition1());
const normal = new GlParamConfig(ParamType.NODE_PATH, this.pv.normal, "", this.uniformNameNormal());
this._param_configs_controller.push(size);
this._param_configs_controller.push(position0);
this._param_configs_controller.push(position1);
this._param_configs_controller.push(normal);
}
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}`;
}
}