Change image texture based on condition

Hello guys!

It’s my first time using the NME and its my first time using nodes to program in general. I’m more used to code using real line of codes.

So basically I need like to do something quite simple. I would like to switch the main texture image based on the player input. For example, if a value is equal to zero, change the image to a specific to another one, if a value is equal top 1, change the image to another image, if a value is equal to 2, change the image to another image, etc…

However, I don’t see any array node in the nme and I don’t quite understand how I can set a condition to switch the image texture. Somebody has any idea how to do something similar?

Thanks

Hello! :smiley:

The NME doesn’t have anything like an array node indeed, because it needs to know the sizes of all the data that’s going to the shader. As for the conditional part, there’s a bunch of nodes in the “Logical” category that allow comparisons:

image

Here’s how it could be used:


Babylon.js Node Material Editor (babylonjs.com)

The Babylon.js youtube channel has a bunch of cool videos about using NME too: Create Your Own Toon Shader with Babylon.js! Part 1 - YouTube :smiley:

Once you have created your node material, you can change the texture of a Texture block programmatically by retrieving the block (by doing block=nodeMaterial.getBlockByName("XXX")) and doing block.texture = new BABYLON.Texture(...).

Thanks everyone for the answers!