Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created January 22, 2023 01:37
Show Gist options
  • Select an option

  • Save SuddenDevelopment/e3144969f7a499683349f7bdb91acbb8 to your computer and use it in GitHub Desktop.

Select an option

Save SuddenDevelopment/e3144969f7a499683349f7bdb91acbb8 to your computer and use it in GitHub Desktop.
backport blender 3.4 mix shader node to 3.3 mix rgb node
import bpy
def changeNodes(objNodeTree):
for objNode in objNodeTree.nodes:
if objNode.type == 'GROUP' and objNode.node_tree:
changeNodes(objNode.node_tree)
# look for the generic mix node from 3.4 to try and make it mixrgb in 3.3
# [0]Factor, [2]A, [4]B == [0]fac, [1]color1, [2]color2
elif objNode.type=='' and objNode.inputs[0].name == 'Factor':
# objNode.inputs[0].name == 'Factor' and objNode.inputs[2].name == 'A' and objNode.inputs[4].name == 'B':
# look for the target node type
objNewNode = objNodeTree.nodes.new(type='ShaderNodeMixRGB')
objNewNode.inputs[0].default_value = objNode.inputs[0].default_value
#objNewNode.inputs[1].default_value = objNode.inputs[2].default_value
#objNewNode.inputs[2].default_value = objNode.inputs[4].default_value
# look for the links
for objLink in objNodeTree.links:
# combined so we dont need to loop 2x, conditions are cheaper than loops
if objLink.from_node.name == objNode.name:
# connect to the new one
objNodeTree.links.new(objNewNode.outputs[0], objLink.to_socket)
elif objLink.to_node.location == objNode.location and objLink.to_node == objNode:
print(objLink.to_node.name,objNode.name)
if objLink.to_socket.name == 'Factor':
objNodeTree.links.new(objLink.from_socket, objNewNode.inputs[0])
elif objLink.to_socket.name == 'A':
objNodeTree.links.new(objLink.from_socket, objNewNode.inputs[1])
elif objLink.to_socket.name == 'B':
objNodeTree.links.new(objLink.from_socket, objNewNode.inputs[2])
# disconnect from the old one
objNodeTree.links.remove(objLink)
# GTFO!
objNodeTree.nodes.remove(objNode)
return
for objMaterial in bpy.data.materials:
if objMaterial.node_tree:
changeNodes(objMaterial.node_tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment