Fix: Node Wrangler: new reroutes offset when output hidden
[blender-addons.git] / amaranth / node_editor / simplify_nodes.py
blob5cdc6a78e940f25267aa3695f6285701b06b5fea
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 """
3 Nodes Simplify Panel [WIP Feature]
5 Disable/Enable certain nodes at a time. Useful to quickly "simplify"
6 compositing.
7 This feature is a work in progress, the main issue now is when switching
8 many different kinds one after the other.
10 On the Nodes Editor Properties N panel.
11 """
13 import bpy
16 def init():
17 nodes_compo_types = (
18 ("ALL", "All Types", "", 0),
19 ("BLUR", "Blur", "", 1),
20 ("BOKEHBLUR", "Bokeh Blur", "", 2),
21 ("VECBLUR", "Vector Blur", "", 3),
22 ("DEFOCUS", "Defocus", "", 4),
23 ("R_LAYERS", "Render Layer", "", 5),
25 node = bpy.types.Node
26 nodes_compo = bpy.types.CompositorNodeTree
27 nodes_compo.types = bpy.props.EnumProperty(
28 items=nodes_compo_types, name="Types")
29 nodes_compo.toggle_mute = bpy.props.BoolProperty(default=False)
30 node.status = bpy.props.BoolProperty(default=False)
33 def clear():
34 wm = bpy.context.window_manager
35 for p in ("types", "toggle_mute", "status"):
36 if wm.get(p):
37 del wm[p]
40 class AMTH_NODE_PT_simplify(bpy.types.Panel):
42 bl_space_type = "NODE_EDITOR"
43 bl_region_type = "UI"
44 bl_label = "Simplify"
45 bl_options = {"DEFAULT_CLOSED"}
47 @classmethod
48 def poll(cls, context):
49 space = context.space_data
50 return space.type == "NODE_EDITOR" \
51 and space.node_tree is not None \
52 and space.tree_type == "CompositorNodeTree"
54 def draw(self, context):
55 layout = self.layout
56 node_tree = context.scene.node_tree
58 if node_tree is not None:
59 layout.prop(node_tree, "types")
60 layout.operator(AMTH_NODE_OT_toggle_mute.bl_idname,
61 text="Turn On" if node_tree.toggle_mute else "Turn Off",
62 icon="RESTRICT_VIEW_OFF" if node_tree.toggle_mute else "RESTRICT_VIEW_ON")
64 if node_tree.types == "VECBLUR":
65 layout.label(text="This will also toggle the Vector pass {}".format(
66 "on" if node_tree.toggle_mute else "off"), icon="INFO")
69 class AMTH_NODE_OT_toggle_mute(bpy.types.Operator):
71 bl_idname = "node.toggle_mute"
72 bl_label = "Toggle Mute"
74 def execute(self, context):
75 scene = context.scene
76 node_tree = scene.node_tree
77 node_type = node_tree.types
78 rlayers = scene.render
80 if "amaranth_pass_vector" not in scene.keys():
81 scene["amaranth_pass_vector"] = []
83 # can"t extend() the list, so make a dummy one
84 pass_vector = scene["amaranth_pass_vector"]
86 if not pass_vector:
87 pass_vector = []
89 if node_tree.toggle_mute:
90 for node in node_tree.nodes:
91 if node_type == "ALL":
92 node.mute = node.status
93 if node.type == node_type:
94 node.mute = node.status
95 if node_type == "VECBLUR":
96 for layer in rlayers.layers:
97 if layer.name in pass_vector:
98 layer.use_pass_vector = True
99 pass_vector.remove(layer.name)
101 node_tree.toggle_mute = False
103 else:
104 for node in node_tree.nodes:
105 if node_type == "ALL":
106 node.mute = True
107 if node.type == node_type:
108 node.status = node.mute
109 node.mute = True
110 if node_type == "VECBLUR":
111 for layer in rlayers.layers:
112 if layer.use_pass_vector:
113 pass_vector.append(layer.name)
114 layer.use_pass_vector = False
115 pass
117 node_tree.toggle_mute = True
119 # Write back to the custom prop
120 pass_vector = sorted(set(pass_vector))
121 scene["amaranth_pass_vector"] = pass_vector
123 return {"FINISHED"}
126 def register():
127 init()
128 bpy.utils.register_class(AMTH_NODE_PT_simplify)
129 bpy.utils.register_class(AMTH_NODE_OT_toggle_mute)
132 def unregister():
133 clear()
134 bpy.utils.unregister_class(AMTH_NODE_PT_simplify)
135 bpy.utils.unregister_class(AMTH_NODE_OT_toggle_mute)