1 # SPDX-License-Identifier: GPL-2.0-or-later
3 Display Active Image Node on Image Editor
5 When selecting an Image node, it will show it on the Image editor (if
6 there is any available). If you don't like this behavior, you can
7 disable it from the Amaranth Toolset panel on the Scene properties.
8 Coded by the awesome Sergey Sharybin. This feature only works on Blender
9 2.68 and newer. Select an Image Node in the Compositor or Cycles nodes
10 editor, there must be at least one image editor available.
18 image_nodes
= ("CompositorNodeRLayers",
19 "CompositorNodeImage",
20 "CompositorNodeViewer",
21 "CompositorNodeComposite",
23 "ShaderNodeTexEnvironment",
24 "GeometryNodeImageTexture")
27 class AMTH_NODE_OT_show_active_node_image(bpy
.types
.Operator
):
28 """Show active image node image in the image editor"""
29 bl_idname
= "node.show_active_node_image"
30 bl_label
= "Preview Image from Node"
34 def poll(cls
, context
):
35 return context
.active_node
is not None
37 def execute(self
, context
):
40 def invoke(self
, context
, event
):
41 mlocx
= event
.mouse_region_x
42 mlocy
= event
.mouse_region_y
43 select_node
= bpy
.ops
.node
.select(location
=(mlocx
, mlocy
), extend
=False)
45 if 'FINISHED' in select_node
: # Only run if we're clicking on a node
46 get_addon
= "amaranth" in context
.preferences
.addons
.keys()
50 preferences
= context
.preferences
.addons
["amaranth"].preferences
51 if preferences
.use_image_node_display
:
52 if context
.active_node
:
53 active_node
= context
.active_node
55 if active_node
.bl_idname
in image_nodes
:
56 # Use largest image editor
59 for a
in context
.screen
.areas
:
60 if a
.type == "IMAGE_EDITOR":
61 size
= a
.width
* a
.height
66 for space
in area
.spaces
:
67 if space
.type == "IMAGE_EDITOR":
68 if active_node
.bl_idname
== "CompositorNodeViewer":
69 space
.image
= bpy
.data
.images
[
71 elif active_node
.bl_idname
in ["CompositorNodeComposite", "CompositorNodeRLayers"]:
72 space
.image
= bpy
.data
.images
[
74 elif active_node
.bl_idname
== "GeometryNodeImageTexture":
75 if active_node
.inputs
['Image'].is_linked
:
76 self
.report({'INFO'}, "Previewing linked sockets is not supported yet")
78 if active_node
.inputs
['Image'].default_value
:
79 space
.image
= active_node
.inputs
['Image'].default_value
80 elif active_node
.image
:
81 space
.image
= active_node
.image
83 self
.report({'INFO'}, "No image detected")
91 return {"PASS_THROUGH"}
95 bpy
.utils
.register_class(AMTH_NODE_OT_show_active_node_image
)
96 kc
= bpy
.context
.window_manager
.keyconfigs
.addon
97 km
= kc
.keymaps
.new(name
="Node Editor", space_type
="NODE_EDITOR")
98 kmi
= km
.keymap_items
.new("node.show_active_node_image",
99 "LEFTMOUSE", "DOUBLE_CLICK")
100 KEYMAPS
.append((km
, kmi
))
104 bpy
.utils
.unregister_class(AMTH_NODE_OT_show_active_node_image
)
105 for km
, kmi
in KEYMAPS
:
106 km
.keymap_items
.remove(kmi
)