How to stop NodeMaterial from generating same effects when not needed and save compilation time

Alright people!!

The next nightly (will be live in less than a hour) will let you do this:

 BABYLON.NodeMaterial.ParseFromSnippetAsync("#PX0637", scene).then(nme_mat => {
        var texture_block = nme_mat.getTextureBlocks()[0];
        texture_block.texture = new BABYLON.Texture("/textures/grass.png");
        box.material = nme_mat;

        var clone = nme_mat.clone("mat2", true);
        box2.material = clone;

        texture_block = clone.getTextureBlocks()[0];
        texture_block.texture = new BABYLON.Texture("/textures/crate.png");
    });

The only difference is the 2nd parameter for the clone function. When set to true, it will let you reuse the same effect (until you call build again of course).

So this PG will work (when the PR will be live): Local Reflection Texture Test | Babylon.js Playground

Link to the PR: Nightly by deltakosh · Pull Request #10230 · BabylonJS/Babylon.js (github.com)

Enjoy!

4 Likes