How to GTLF material extras to a dictionary?

Hi,
This set props to whatever was stored in material custom props.

var props = orgPBEMaterial.metadata?.gltf?.extras;

The output in Babylonjs looks like this:

{
    "TextureAmbientOcclusion": "textures/metal/25fdb3ed.png",
    "TextureHeight": "textures/default/default_height.png",
    "newColor": [
        1,
        1,
        1
    ]
}

How would I convert this to Dictionary<string, string>?
Where key is name as TextureHeight, and value is as textures/default/default_height.png

Thank you.

You can not as the color is not a string here but the object itself is already “dictionary” like in a sense. You can indeed access a string by doing

orgPBEMaterial.metadata?.gltf?.extras.TextureAmbientOcclusion

or

orgPBEMaterial.metadata?.gltf?.extras["TextureAmbientOcclusion"]

Accessing newColor in the same way would return an array

3 Likes