compatibility update for blender4

This commit is contained in:
pullusb
2024-01-16 12:27:10 +01:00
parent 29debe4cb4
commit 74d94e2cdb
4 changed files with 65 additions and 22 deletions
+34 -10
View File
@@ -63,9 +63,12 @@ def create_aa_nodegroup(tree):
sep = create_node('CompositorNodeSepRGBA', tree=ngroup, location=(-150,0))
comb = create_node('CompositorNodeCombRGBA', tree=ngroup, location=(350,25))
# if bpy.app.version >= (3,4,0):
ngroup.inputs.new('NodeSocketColor', 'Image')
ngroup.outputs.new('NodeSocketColor', 'Image')
if bpy.app.version < (4,0,0):
ngroup.inputs.new('NodeSocketColor', 'Image')
ngroup.outputs.new('NodeSocketColor', 'Image')
else:
ngroup.interface.new_socket('Image', in_out='INPUT', socket_type='NodeSocketColor')
ngroup.interface.new_socket('Image', in_out='OUTPUT', socket_type='NodeSocketColor')
# in AA
# ngroup.links.new(comb.outputs[0], ng_out.inputs[0]) # <- connect without out AA
@@ -614,19 +617,40 @@ def reorder_inputs(ng):
inputs_names = [s.name for s in ng.inputs]
filtered_names = [n for n in names if n in inputs_names]
for dest, name in enumerate(filtered_names):
## rebuild list at each iteration so index are good
inputs_names = [s.name for s in ng.inputs]
src = inputs_names.index(name)
# reorder on node_tree not directly on node!
ng.node_tree.inputs.move(src, dest)
if bpy.app.version < (4,0,0):
for dest, name in enumerate(filtered_names):
## rebuild list at each iteration so index are good
inputs_names = [s.name for s in ng.inputs]
src = inputs_names.index(name)
# reorder on node_tree not directly on node!
ng.node_tree.inputs.move(src, dest)
else:
n_inputs = [s for s in ng.node_tree.interface.items_tree if s.in_out == 'INPUT']
for dest, name in enumerate(filtered_names):
item = next((s for s in ng.node_tree.interface.items_tree if s.in_out == 'INPUT' and s.name == name), None)
if not item: # Dbg
print(f'!PROBLEM with input "{name}"')
continue
# Need to offset index (inputs are listed after output in item_tree list)
dest = dest + n_inputs[0].position
ng.node_tree.interface.move(item, dest)
ng.node_tree.interface_update(bpy.context)
def reorder_outputs(ng):
ordered_out_name = [nis.name for nis in ng.inputs if nis.name in [o.name for o in ng.outputs]]
for s_name in ordered_out_name:
all_outnames = [o.name for o in ng.outputs]
# reorder on nodetree, not on node !
ng.node_tree.outputs.move(all_outnames.index(s_name), ordered_out_name.index(s_name))
if bpy.app.version < (4,0,0):
ng.node_tree.outputs.move(all_outnames.index(s_name), ordered_out_name.index(s_name))
else:
item = next((s for s in ng.node_tree.interface.items_tree if s.in_out == 'OUTPUT' and s.name == s_name), None)
if not item: # Dbg
print(f'!PROBLEM with output "{s_name}"')
continue
ng.node_tree.interface.move(item, ordered_out_name.index(s_name))
ng.node_tree.interface_update(bpy.context)
def clear_disconnected(fo):
for inp in reversed(fo.inputs):