How to find materials and texture without any mesh

Hi everybody,

i’d like to make a function which dispose all the materials and texture without any mesh associated to minimize the size of the babylon file when i save the project.

Is there any function to do such a thing ?

Thanks in advance,


you can use scene.materials and scene.textures to get the full list for both of them.

Yes but how can i find that a material has no more mesh associated with it ?

ohhhh I see, unfortunately we do not have that.

You would need to first create a list of all materials used in the scene by going through scene.meshes

Then disposed all the unused ones and collect all their textures.

Finally you would be able to dispose the textures who are not part of any other materials.

Would be a pretty cool helper function though :slight_smile:


I whipped up a playground that demonstrates a way to do this. It would be nice to create a helper function. The logic wasn’t too hard.

Note: Babylon creates some textures that aren’t attached to meshes or materials but are used as part of the PBR/environment stuff. I think a helper function should know how to exclude those from the search.

1 Like