autobuild beta
1.1.1 - changed: autobuild beta
This commit is contained in:
@@ -349,6 +349,103 @@ def get_frames_bbox(node_tree):
|
||||
|
||||
## -- nodes helper functions
|
||||
|
||||
def merge_gplayer_viewlayers(ob, act=None, layers=None):
|
||||
if act is None:
|
||||
act = ob.data.layers.active
|
||||
if layers is None:
|
||||
layers = [l for l in ob.data.layers if l.select and l != act]
|
||||
|
||||
rd_scn = bpy.data.scenes.get('Render')
|
||||
if not rd_scn:
|
||||
return ({'ERROR'}, 'Viewlayers needs to be generated first!')
|
||||
|
||||
if not act.viewlayer_render:
|
||||
return ({'ERROR'}, f'Active layer {act.info} has no viewlayer assigned')
|
||||
|
||||
# list layers and viewlayers
|
||||
vls = [rd_scn.view_layers.get(l.viewlayer_render) for l in layers
|
||||
if l.viewlayer_render and l.viewlayer_render != act.viewlayer_render and rd_scn.view_layers.get(l.viewlayer_render)]
|
||||
|
||||
vl_names = [v.name for v in vls]
|
||||
|
||||
for n in reversed(rd_scn.node_tree.nodes):
|
||||
if n.type == 'R_LAYERS' and n.layer in vl_names:
|
||||
for lnk in n.outputs[0].links:
|
||||
grp = lnk.to_node
|
||||
if grp.type != 'GROUP':
|
||||
continue
|
||||
if not grp.name.startswith('NG'):
|
||||
continue
|
||||
sockin = lnk.to_socket
|
||||
sockout = grp.outputs.get(sockin.name)
|
||||
if not sockout:
|
||||
continue
|
||||
|
||||
for grplink in sockout.links:
|
||||
if grplink.to_node.type != 'OUTPUT_FILE':
|
||||
continue
|
||||
fo_socket = grplink.to_socket
|
||||
fo = grplink.to_node
|
||||
fo.file_slots.remove(fo_socket)
|
||||
|
||||
# remove input and output from group
|
||||
# grp.inputs.remove(sockin) # do not clear inside !!
|
||||
# grp.outputs.remove(sockout) # do not clear inside !!
|
||||
ngroup = grp.node_tree
|
||||
for i in range(len(grp.inputs))[::-1]:
|
||||
if grp.inputs[i].name == sockin.name:
|
||||
ngroup.inputs.remove(ngroup.inputs[i])
|
||||
break
|
||||
for i in range(len(grp.outputs))[::-1]:
|
||||
if grp.outputs[i].name == sockout.name:
|
||||
ngroup.outputs.remove(ngroup.outputs[i])
|
||||
break
|
||||
|
||||
# remove render_layer node
|
||||
rd_scn.node_tree.nodes.remove(n)
|
||||
|
||||
# assign view layer from active to selected
|
||||
for l in layers:
|
||||
l.viewlayer_render = act.viewlayer_render
|
||||
|
||||
## delete unused_vl
|
||||
|
||||
# used_vl_name = [n.layer for n in rd_scn.node_tree.nodes if n.type == 'R_LAYERS' and n.layer]
|
||||
for vl in vls:
|
||||
rd_scn.view_layers.remove(vl)
|
||||
# if not vl.name in used_vl_name:
|
||||
# rd_scn.view_layers.remove(vl)
|
||||
|
||||
def group_adjacent_layer_prefix_rlayer(ob, excluded_prefix=[], first_name=True):
|
||||
'''Set viewlayer and renderlayers by Gp layer adjacent prefix
|
||||
Call merge_gplayer_viewlayers with grouped prefix
|
||||
:excluded_prefix: List of prefixes to exclude from merge or str with comma separated values
|
||||
:first_name: Keep the viewlayer of the bottom layer in group, else last
|
||||
'''
|
||||
|
||||
from itertools import groupby
|
||||
re_prefix = re.compile(r'^([A-Z]{2})_')
|
||||
|
||||
if isinstance(excluded_prefix, str):
|
||||
excluded_prefix = [p.strip() for p in excluded_prefix.split(',')]
|
||||
|
||||
## Create adjacent grp list: [('CO', [layer1, layer2]), ('LN', [layer3, layer4])]
|
||||
adjacent_prefix_groups = [
|
||||
(g[0], list(g[1])) for g in
|
||||
groupby([l for l in ob.data.layers],
|
||||
key=lambda l: re_prefix.search(l.info).group(1) if re_prefix.search(l.info) else '')
|
||||
]
|
||||
|
||||
for prefix, layer_grp in adjacent_prefix_groups:
|
||||
if len(layer_grp) < 2:
|
||||
continue
|
||||
if not prefix or prefix in excluded_prefix:
|
||||
continue
|
||||
|
||||
ref = layer_grp[0] if first_name else layer_grp[-1]
|
||||
merge_gplayer_viewlayers(ob, act=ref, layers=layer_grp)
|
||||
|
||||
|
||||
def clear_nodegroup(name, full_clear=False):
|
||||
'''remove duplication of a nodegroup (.???)
|
||||
also remove the base one if full_clear True
|
||||
|
||||
Reference in New Issue
Block a user