I created a custom node like below, It means Blending some textures to diffuse color, and running at postprocessing. the method .textures
can update textures of the node. After size of textures is changed, .setup
is supposed to rerun to update the code of node. But I found .steup
only run once and never update again. How can I trigger the method .setup
of a node? I’ve tried setting .needsUpdate
is true or recreate the node, but both of them didn’t work.
class AddTexturesNode extends Node {
constructor(colorNode, textures) {
super('vec4');
this._colorNode = colorNode;
this._textures = textures || [];
}
setup(builder) {
const addTextureColor = tslFn(([oldColor, map]) => {
const transformUV = uv();
let color = oldColor.toVar('finalColor');
const sampleColor = map.uv(transformUV);
color.assign(vec4(mix(sampleColor.rgb, color.rgb, sampleColor.a.oneMinus()),
add(color.a, sampleColor.a)));
return color;
});
const texturesCount = this._textures.length;
for (let i = 0; i < texturesCount; ++i) {
this['texture' + i] = texture(this._textures[i]);
}
const addTextures = tslFn(() => {
let color = this._colorNode;
if (texturesCount > 0) {
color = addTextureColor(color, this.texture0);
}
if (texturesCount > 1) {
color = addTextureColor(color, this.texture1);
}
return color;
});
return addTextures();
}
textures(textures) {
const oldTextureCount = this._textures.length;
const newTextureCount = textures.length;
if (this._inited && oldTextureCount === newTextureCount) {
for (let i = 0; i < newTextureCount; ++i) {
if (this['texture' + i]) {
this['texture' + i].value = textures[i];
}
}
}
else {
this.needsUpdate = true;
}
this._textures = textures || [];
return this;
}
}
export const addTextures = (node, textures, textureInfos) => nodeObject(
new AddTexturesNode(nodeObject(node).toTexture(), textures, textureInfos));