diff --git a/OP_merge_layers.py b/OP_merge_layers.py index 3ee29a3..56cd90e 100644 --- a/OP_merge_layers.py +++ b/OP_merge_layers.py @@ -210,10 +210,11 @@ def merge_compositor_preview(scene=None, clear=False): # Create inputs and links to node_group for rln in comp_list: - sockin = ng.node_tree.inputs.new('NodeSocketColor', rln.layer) + if bpy.app.version < (4,0,0): + 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.new('NodeSocketColor', rln.layer) - # sockin = ng.inputs[-1] links.new(rln.outputs['Image'], sockin) fn.nodegroup_merge_inputs(ng.node_tree, aa=False) # do not create AA node (needed ?) diff --git a/__init__.py b/__init__.py index 61d2fb0..e7226b7 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "GP Render", "description": "Organise export of gp layers through compositor output", "author": "Samuel Bernou", - "version": (1, 5, 0), + "version": (1, 5, 1), "blender": (3, 0, 0), "location": "View3D", "warning": "", diff --git a/fn.py b/fn.py index 74165a3..6d2edd2 100644 --- a/fn.py +++ b/fn.py @@ -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): diff --git a/gen_vlayer.py b/gen_vlayer.py index 92a5b3e..e2aea53 100644 --- a/gen_vlayer.py +++ b/gen_vlayer.py @@ -106,7 +106,10 @@ def connect_render_layer(rlayer, ng=None, out=None, frame=None): if not rlayer.outputs['Image'].is_linked: sockin = ng.inputs.get(vl_name) if not sockin: - sockin = ng.node_tree.inputs.new('NodeSocketColor', vl_name) + if bpy.app.version < (4,0,0): + 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] 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) print(f'removing grp unlinked input {s.name}') # ng.inputs.remove(s) - ng.node_tree.inputs.remove(s) + if bpy.app.version < (4,0,0): + ng.node_tree.inputs.remove(s) + else: + ng.node_tree.interface.items_tree.remove(s) ## 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'] @@ -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) groupout = ng.outputs.get(vl_name) if not groupout: - ng.node_tree.outputs.new('NodeSocketColor', vl_name) # assigning direcly doesn't link well + if bpy.app.version < (4,0,0): + 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] # 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 - # clean outputs - for o in reversed(ngroup.outputs): - 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)') - ngroup.outputs.remove(o) + # Clean outputs + if bpy.app.version < (4,0,0): + for o in reversed(ngroup.outputs): + 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)') + 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() # reorder output to match inputs