Download

Batch altering of material graphs

hi!

I often find myself needing to do the same alterations to all the materials coming out of other applications. As a simple and current example, I need to import FBX files from the tiltbrush VR painting app, which can often consist of dozens of materials all of which have to be rewired in the same way - set to double sided, multiply vertex color node with the existing texture sample input, swap the output of the texture sample from RGB to alpha. A great candidate for automation. Now, I thought I could do this with python but so far I’ve only figured how to change the material properties to set the material to two sided, but no idea of how to add nodes and change connections to the graph. Is it at all possible?Is there a different way of achieving that?

Is it possible for you to create some master materials ahead of time with all the things you’ll need to change created as parameters? When you import the FBX files, don’t create/import new materials. In python, create instances of your master materials and change the values you need. Then assign them to the FBX (which I only know how to do manually) .

You can also create new materials programmatically if you know what needs to be there. Then assign them to the FBX. But if all the materials have the same nodes, but with different values, then you’re probably better off creating the master material.

Thanks brisket, I was trying to think of a solution in that direction but my brain froze halfway through. Assigning a material to a mesh programmatically is straightforward as is changing properties to an instanced material, and the naming of textures, materials and meshes in the fbx exports from tiltbrush should make it not too hard either. I’ll leave that as an exercise for the next person who needs it more than me - I myself found for my case that even if there’s hundreds of meshes in the fbx, there’s only a handful of materials that need to be changed which i can do manually for the time being.