File output - Selectable socket to connect in popup

1.7.2

- added: selectable output popup in `connect to file output` operator
This commit is contained in:
pullusb
2024-04-18 15:11:59 +02:00
parent c6dfcb6655
commit ad083e45b6
4 changed files with 213 additions and 18 deletions
+66 -16
View File
@@ -1871,7 +1871,32 @@ def recursive_node_connect_check(l, target_node):
return True
return False
def connect_to_file_output(node_list, file_out=None):
def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None, file_format=None):
"""Connect selected nodes output to file output(s)
if a file output is selected, add intputs on it
Args:
node_list (list[bpy.types.Nodes,]): Nodes to connect
file_out (bpy.types.CompositorNode, optional): File output node to connect to instead of new
Defaults to None
base_path (str, optional): Directory of images to render.
if not passed, will use source node layer name
Defaults to ''.
file_format (dict, optionnal): converts each dictionary key into a file output format
attribute and assigns the corresponding value.
Defaults to None.
excludes (dict, optionnal): List of output names to exclude {node_name: [outputs,]}.
Defaults toNone.
frame (bpy.types.CompositorNode, optional): If given, create nodes into a frame.
Defaults to None.
Returns:
list[bpy.types.CompositorNode]: All nodes created.
"""
scene = bpy.context.scene
nodes = scene.node_tree.nodes
links = scene.node_tree.links
@@ -1881,10 +1906,13 @@ def connect_to_file_output(node_list, file_out=None):
if not node_list:
return
excludes = excludes or {}
for node in node_list:
exclusions = excludes.get(node.name) or []
## create one output facing node and connect all
outs = [o for o in node.outputs if not o.is_unavailable and not 'crypto' in o.name.lower()]
cryptout = [o for o in node.outputs if not o.is_unavailable and 'crypto' in o.name.lower()]
outs = [o for o in node.outputs if not o.is_unavailable and not 'crypto' in o.name.lower() and o.name not in exclusions]
cryptout = [o for o in node.outputs if not o.is_unavailable and 'crypto' in o.name.lower() and o.name not in exclusions]
if node.type == 'R_LAYERS':
out_base = node.layer
@@ -1902,15 +1930,23 @@ def connect_to_file_output(node_list, file_out=None):
if not fo:
# color = (0.2,0.3,0.5)
fo = create_node('CompositorNodeOutputFile', tree=scene.node_tree, location=(real_loc(node)[0]+500, real_loc(node)[1]+50), width=600)
set_file_output_format(fo)
if file_format:
for k, v in file_format.items():
setattr(fo.format, k, v)
else:
set_file_output_format(fo)
fo.name = out_name
if node.parent:
fo.parent = node.parent
if fo.format.file_format == 'OPEN_EXR_MULTILAYER':
fo.base_path = f'//render/{out_base}/{out_base}_'
if base_path:
fo.base_path = base_path
else:
fo.base_path = f'//render/{out_base}'
if fo.format.file_format == 'OPEN_EXR_MULTILAYER':
fo.base_path = f'//render/{out_base}/{out_base}_'
else:
fo.base_path = f'//render/{out_base}'
for o in outs:
if next((l for l in o.links if recursive_node_connect_check(l, fo)), None):
@@ -1923,6 +1959,7 @@ def connect_to_file_output(node_list, file_out=None):
fo.file_slots.new(slot_name)
out_input = fo.inputs[-1]
links.new(o, out_input)
clear_disconnected(fo)
fo.update()
@@ -1935,18 +1972,25 @@ def connect_to_file_output(node_list, file_out=None):
if not fo:
# color = (0.2,0.3,0.5)
fo = create_node('CompositorNodeOutputFile', tree=scene.node_tree, location=(real_loc(node)[0]+400, real_loc(node)[1]-200), width=220)
set_file_output_format(fo) # OPEN_EXR_MULTILAYER, RGBA, ZIP
fo.format.color_depth = '32'
if file_format:
for k, v in file_format.items():
setattr(fo.format, k, v)
else:
set_file_output_format(fo) # OPEN_EXR_MULTILAYER, RGBA, ZIP
fo.format.color_depth = '32' # For crypto force 32bit
fo.name = out_name
if node.parent:
fo.parent = node.parent
if fo.format.file_format == 'OPEN_EXR_MULTILAYER':
## FIXME: find a better organization for separated crypto pass
fo.base_path = f'//render/{out_base}/cryptos/cryptos_'
if base_path:
fo.base_path = base_path
else:
fo.base_path = f'//render/{out_base}'
# fo.base_path = f'//render/{out_base}/cryptos'
if fo.format.file_format == 'OPEN_EXR_MULTILAYER':
## FIXME: find a better organization for separated crypto pass
fo.base_path = f'//render/{out_base}/cryptos/cryptos_'
else:
fo.base_path = f'//render/{out_base}'
for o in cryptout:
## Skip already connected
@@ -1961,8 +2005,14 @@ def connect_to_file_output(node_list, file_out=None):
slot_name = slot_name
else:
slot_name = f'{slot_name}/{slot_name}_'
fo.file_slots.new(slot_name)
## Setting both file_slots and layer_slots...
# fs = fo.file_slots.new(slot_name)
# fs.path = f'{slot_name}/{slot_name}_' # Error 'NodeSocketColor' object has no attribute 'path'
# ls = fo.layer_slots.new(slot_name)
# ls.name = slot_name
out_input = fo.inputs[-1]
links.new(o, out_input)
clear_disconnected(fo)