I am trying to create a node material that can function like a color scale that will set a meshes color from a predefined gradient based on a input. Ideally this input value is read in from the meshes metadata, similarly to how you can use the meshes position as an input value. Is this possible?
Here is a NME example i’ve been using to try stuff out: https://nme.babylonjs.com/#TR9E67#7
Right now the input to step the gradient color is just a static float, but the goal would be to replace it with a value from the meshes metadata.
For GLTF there are some ways which are described here - How to Access extras Property of Loaded GLTF - #4 by sebavan
Or (for meshes created with Babylon) just use
mesh.metadata - Mesh | Babylon.js Documentation
I understand how to access the metadata information from a mesh generally, what I am struggling with is applying it in the context of a node material that can dynamically read the metadata from the meshes it is applied too.
For example if i have 3 spheres that I apply the same node material to, the node material will get the input value from each spheres metadata property and set the gradient step accordingly.
You can use mesh.onBeforeRenderObservable to set the blocks value corresponding to your metadata.
This is just illustrative example - https://playground.babylonjs.com/#44N2I0#10
3 meshes use the same NME materials but with different values. In this example they depend on time, but there is no problem to make these input values to depend on
In this case it is even simpler like here - https://playground.babylonjs.com/#44N2I0#14
Yep! more or less what I was going for thank you! I was hoping to avoid cloning the material and using more than one material per mesh but it looks like that is not practical.