compatibility update for blender4

main
pullusb 2024-01-16 12:27:10 +01:00
parent 29debe4cb4
commit 74d94e2cdb
4 changed files with 65 additions and 22 deletions

View File

@ -210,10 +210,11 @@ def merge_compositor_preview(scene=None, clear=False):
# Create inputs and links to node_group # Create inputs and links to node_group
for rln in comp_list: for rln in comp_list:
if bpy.app.version < (4,0,0):
sockin = ng.node_tree.inputs.new('NodeSocketColor', rln.layer) sockin = ng.node_tree.inputs.new('NodeSocketColor', rln.layer)
else:
sockin = ng.node_tree.interface.new_socket(rln.layer, in_out='INPUT', socket_type='NodeSocketColor')
sockin = ng.inputs[-1] sockin = ng.inputs[-1]
# sockin = ng.inputs.new('NodeSocketColor', rln.layer)
# sockin = ng.inputs[-1]
links.new(rln.outputs['Image'], sockin) links.new(rln.outputs['Image'], sockin)
fn.nodegroup_merge_inputs(ng.node_tree, aa=False) # do not create AA node (needed ?) fn.nodegroup_merge_inputs(ng.node_tree, aa=False) # do not create AA node (needed ?)

View File

@ -2,7 +2,7 @@ bl_info = {
"name": "GP Render", "name": "GP Render",
"description": "Organise export of gp layers through compositor output", "description": "Organise export of gp layers through compositor output",
"author": "Samuel Bernou", "author": "Samuel Bernou",
"version": (1, 5, 0), "version": (1, 5, 1),
"blender": (3, 0, 0), "blender": (3, 0, 0),
"location": "View3D", "location": "View3D",
"warning": "", "warning": "",

26
fn.py
View File

@ -63,9 +63,12 @@ def create_aa_nodegroup(tree):
sep = create_node('CompositorNodeSepRGBA', tree=ngroup, location=(-150,0)) sep = create_node('CompositorNodeSepRGBA', tree=ngroup, location=(-150,0))
comb = create_node('CompositorNodeCombRGBA', tree=ngroup, location=(350,25)) comb = create_node('CompositorNodeCombRGBA', tree=ngroup, location=(350,25))
# if bpy.app.version >= (3,4,0): if bpy.app.version < (4,0,0):
ngroup.inputs.new('NodeSocketColor', 'Image') ngroup.inputs.new('NodeSocketColor', 'Image')
ngroup.outputs.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 # in AA
# ngroup.links.new(comb.outputs[0], ng_out.inputs[0]) # <- connect without out AA # ngroup.links.new(comb.outputs[0], ng_out.inputs[0]) # <- connect without out AA
@ -614,6 +617,7 @@ def reorder_inputs(ng):
inputs_names = [s.name for s in ng.inputs] inputs_names = [s.name for s in ng.inputs]
filtered_names = [n for n in names if n in inputs_names] filtered_names = [n for n in names if n in inputs_names]
if bpy.app.version < (4,0,0):
for dest, name in enumerate(filtered_names): for dest, name in enumerate(filtered_names):
## rebuild list at each iteration so index are good ## rebuild list at each iteration so index are good
inputs_names = [s.name for s in ng.inputs] inputs_names = [s.name for s in ng.inputs]
@ -621,12 +625,32 @@ def reorder_inputs(ng):
# reorder on node_tree not directly on node! # reorder on node_tree not directly on node!
ng.node_tree.inputs.move(src, dest) 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): 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]] 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: for s_name in ordered_out_name:
all_outnames = [o.name for o in ng.outputs] all_outnames = [o.name for o in ng.outputs]
# reorder on nodetree, not on node ! # reorder on nodetree, not on node !
if bpy.app.version < (4,0,0):
ng.node_tree.outputs.move(all_outnames.index(s_name), ordered_out_name.index(s_name)) 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): def clear_disconnected(fo):
for inp in reversed(fo.inputs): for inp in reversed(fo.inputs):

View File

@ -106,7 +106,10 @@ def connect_render_layer(rlayer, ng=None, out=None, frame=None):
if not rlayer.outputs['Image'].is_linked: if not rlayer.outputs['Image'].is_linked:
sockin = ng.inputs.get(vl_name) sockin = ng.inputs.get(vl_name)
if not sockin: if not sockin:
if bpy.app.version < (4,0,0):
sockin = ng.node_tree.inputs.new('NodeSocketColor', vl_name) sockin = ng.node_tree.inputs.new('NodeSocketColor', vl_name)
else:
sockin = ng.node_tree.interface.new_socket(vl_name, in_out='INPUT', socket_type='NodeSocketColor')
sockin = ng.inputs[-1] sockin = ng.inputs[-1]
links.new(rlayer.outputs['Image'], sockin) links.new(rlayer.outputs['Image'], sockin)
@ -119,7 +122,10 @@ def connect_render_layer(rlayer, ng=None, out=None, frame=None):
if not s.is_linked: # and not any(x.layer == s.name for x in rl_nodes) if not s.is_linked: # and not any(x.layer == s.name for x in rl_nodes)
print(f'removing grp unlinked input {s.name}') print(f'removing grp unlinked input {s.name}')
# ng.inputs.remove(s) # ng.inputs.remove(s)
if bpy.app.version < (4,0,0):
ng.node_tree.inputs.remove(s) ng.node_tree.inputs.remove(s)
else:
ng.node_tree.interface.items_tree.remove(s)
## get nodes from linked NG inputs ??? maybe more clear... ## get nodes from linked NG inputs ??? maybe more clear...
# rl_nodes = [s.links[0].from_node for s in ng.inputs if s.links and s.links[0].from_node and s.links[0].from_node.type == 'R_LAYERS'] # rl_nodes = [s.links[0].from_node for s in ng.inputs if s.links and s.links[0].from_node and s.links[0].from_node.type == 'R_LAYERS']
@ -145,7 +151,11 @@ def connect_render_layer(rlayer, ng=None, out=None, frame=None):
aa = fn.create_aa_nodegroup(ngroup)# fn.new_aa_node(ngroup) aa = fn.create_aa_nodegroup(ngroup)# fn.new_aa_node(ngroup)
groupout = ng.outputs.get(vl_name) groupout = ng.outputs.get(vl_name)
if not groupout: if not groupout:
if bpy.app.version < (4,0,0):
ng.node_tree.outputs.new('NodeSocketColor', vl_name) # assigning direcly doesn't link well ng.node_tree.outputs.new('NodeSocketColor', vl_name) # assigning direcly doesn't link well
else:
ng.node_tree.interface.new_socket(vl_name, in_out='OUTPUT', socket_type='NodeSocketColor')
groupout = ng.outputs[-1] groupout = ng.outputs[-1]
# print('ng_out.inputs.get(vl_name): ', ng_out.inputs.get(vl_name)) # print('ng_out.inputs.get(vl_name): ', ng_out.inputs.get(vl_name))
@ -158,11 +168,19 @@ def connect_render_layer(rlayer, ng=None, out=None, frame=None):
fn.reorganise_NG_nodegroup(ng) # decorative fn.reorganise_NG_nodegroup(ng) # decorative
# clean outputs # Clean outputs
if bpy.app.version < (4,0,0):
for o in reversed(ngroup.outputs): for o in reversed(ngroup.outputs):
if not o.name in [o.name for o in ngroup.inputs]: if not o.name in [o.name for o in ngroup.inputs]:
print(f'removing group output {o.name} (name not exists in group inputs)') print(f'removing group output {o.name} (name not exists in group inputs)')
ngroup.outputs.remove(o) ngroup.outputs.remove(o)
else:
n_outputs = [s for s in ngroup.interface.items_tree if s.in_out == 'OUTPUT']
n_inputs = [s for s in ngroup.interface.items_tree if s.in_out == 'INPUT']
for o in reversed(n_outputs):
if not o.name in [o.name for o in n_inputs]:
print(f'Removing group output {o.name} (name not exists in group inputs)')
ngroup.interface.remove(o)
ng.update() ng.update()
# reorder output to match inputs # reorder output to match inputs