Fix: Node Wrangler: new reroutes offset when output hidden
[blender-addons.git] / amaranth / node_editor / templates / vectorblur.py
blob03ca93fc24d600b2ea39bdd168c0cd6acfd3a625
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from mathutils import Vector
7 class AMTH_NODE_OT_AddTemplateVectorBlur(bpy.types.Operator):
8 bl_idname = "node.template_add_vectorblur"
9 bl_label = "Add Vector Blur"
10 bl_description = "Add a vector blur filter"
11 bl_options = {"REGISTER", "UNDO"}
13 @classmethod
14 def poll(cls, context):
15 space = context.space_data
16 tree = context.scene.node_tree
17 return space.type == "NODE_EDITOR" \
18 and space.node_tree is not None \
19 and space.tree_type == "CompositorNodeTree" \
20 and tree \
21 and tree.nodes.active \
22 and tree.nodes.active.type == "R_LAYERS"
24 def _setupNodes(self, context):
25 scene = context.scene
26 space = context.space_data
27 tree = scene.node_tree
29 bpy.ops.node.select_all(action="DESELECT")
31 act_node = tree.nodes.active
32 #rlayer = act_node.scene.render.layers[act_node.layer]
34 #if not rlayer.use_pass_vector:
35 #rlayer.use_pass_vector = True
37 vblur = tree.nodes.new(type="CompositorNodeVecBlur")
38 vblur.use_curved = True
39 vblur.factor = 0.5
41 tree.links.new(act_node.outputs["Image"], vblur.inputs["Image"])
42 tree.links.new(act_node.outputs["Depth"], vblur.inputs["Z"])
43 tree.links.new(act_node.outputs["Vector"], vblur.inputs["Speed"])
45 if tree.nodes.active:
46 vblur.location = tree.nodes.active.location
47 vblur.location += Vector((250.0, 0.0))
48 else:
49 vblur.location += Vector(
50 (space.cursor_location[0], space.cursor_location[1]))
52 vblur.select = True
54 def execute(self, context):
55 self._setupNodes(context)
57 return {"FINISHED"}