Skip to content

Instantly share code, notes, and snippets.

@scurest
Last active March 21, 2018 19:38
Show Gist options
  • Save scurest/383b40dcf619cd19c7628bfdafa9fa6b to your computer and use it in GitHub Desktop.
Save scurest/383b40dcf619cd19c7628bfdafa9fa6b to your computer and use it in GitHub Desktop.
Make all materials in Blender (2.79) be influenced by vertex color.
import bpy
for mat in bpy.data.materials:
mat.use_nodes = True
out_node = mat.node_tree.nodes[0]
mat_node = mat.node_tree.nodes[1]
mat_node.location = -140, 425
mat_node.material = bpy.data.materials[mat.name]
geom_node = mat.node_tree.nodes.new('ShaderNodeGeometry')
geom_node.location = -140, -5
mix_node = mat.node_tree.nodes.new('ShaderNodeMixRGB')
mix_node.location = 95, 256
mix_node.blend_type = 'MULTIPLY'
mix_node.inputs[0].default_value = 1.0
mat.node_tree.links.new(mat_node.outputs['Color'], mix_node.inputs['Color1'])
mat.node_tree.links.new(geom_node.outputs['Vertex Color'], mix_node.inputs['Color2'] )
mat.node_tree.links.new(mix_node.outputs['Color'], out_node.inputs['Color'] )
mat.node_tree.links.new(mat_node.outputs['Alpha'], out_node.inputs['Alpha'] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment