# Use Mesh Metadata as Input for Node Material

**URL:** <https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108>\
**Category:** Questions\
**Tags:** material, nodematerial\
**Created:** [December 1, 2023, 7:59pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108 "2023-12-01T19:59:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsaffo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dsaffo/32/31907_2.png) [@dsaffo](https://forum.babylonjs.com/u/dsaffo)\
**Post date:** [December 1, 2023, 7:59pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/1 "2023-12-01T19:59:42Z")

</div>

Hello,

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](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.

Thank you.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 1, 2023, 8:51pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/2 "2023-12-01T20:51:41Z")

</div>

For GLTF there are some ways which are described here - [How to Access extras Property of Loaded GLTF - #4 by sebavan](https://forum.babylonjs.com/t/how-to-access-extras-property-of-loaded-gltf/22139/4)  
Or (for meshes created with Babylon) just use `mesh.metadata` - [Mesh | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/BABYLON.Mesh#metadata)

---

<div class="post-metadata">

**Author:** ![dsaffo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dsaffo/32/31907_2.png) [@dsaffo](https://forum.babylonjs.com/u/dsaffo)\
**Post date:** [December 1, 2023, 9:08pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/3 "2023-12-01T21:08:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 2, 2023, 1:34am UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/4 "2023-12-02T01:34:56Z")

</div>

You can use mesh.onBeforeRenderObservable to set the blocks value corresponding to your metadata.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 2, 2023, 3:26am UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/5 "2023-12-02T03:26:16Z")

</div>

This is just illustrative example - [https://playground.babylonjs.com/#44N2I0#10](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 `mesh.metadata`.  
In this case it is even simpler like here - [https://playground.babylonjs.com/#44N2I0#14](https://playground.babylonjs.com/#44N2I0#14)

---

<div class="post-metadata">

**Author:** ![dsaffo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dsaffo/32/31907_2.png) [@dsaffo](https://forum.babylonjs.com/u/dsaffo)\
**Post date:** [December 4, 2023, 9:14pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/6 "2023-12-04T21:14:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peterimg](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@peterimg](https://forum.babylonjs.com/u/peterimg)\
**Post date:** [December 30, 2024, 12:04pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/7 "2024-12-30T12:04:56Z")

</div>

@labris, @sebavan

I just found this tread and I have the same question.

In the solution you proposed, you need to have material clones anyway. So your increasing Draw Calls.

I would like to have a mesh.metadata parameter read inside the material and applying the same material to different meshes or instances.

Its a walk around not the solution to a question.

With the new version 7 is there something that could actually do it?

Regards  
Peter

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 30, 2024, 11:34pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/8 "2024-12-30T23:34:44Z")

</div>

Relying on instances only works if your geometry are similar and in this case you should rely on a custom attribute.

---

<div class="post-metadata">

**Author:** ![peterimg](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@peterimg](https://forum.babylonjs.com/u/peterimg)\
**Post date:** [December 31, 2024, 11:03am UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/9 "2024-12-31T11:03:35Z")

</div>

@sebavan

Hi so how should you read them? Why not the metadata? that I can set up during mesh cloning?

Regards  
Peter

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 31, 2024, 9:27pm UTC](https://forum.babylonjs.com/t/use-mesh-metadata-as-input-for-node-material/46108/10 "2024-12-31T21:27:10Z")

</div>

Oh yes, you can, only mentioning due to this part of the thread:

> you need to have material clones anyway. So your increasing Draw Calls.

This will be similar here in term of draw calls.
