I am developing a custom node tree, and my intent is to incorporate a ‘Viewer’ node that would behave similarly to the ‘Viewer’ node in the Compositor. It seems, though, that the ‘Backdrop’ image functionality is hidden for all other node trees.
I am aware of the backdrop callback (as discussed here: Drawing a background image in my custom node tree), but a higher-level API would be nice, as this would expose relevant SpaceImageEditor
properties (e.g. SpaceImageEditor.backdrop_channels
) along with the backdrop operators (e.g. node.backimage_move
).
My suspicion is that this would be a simple change, and that somwhere in the code, bl_idname == CompositorNodeTree
is the condition under which the backdrop functionality is exposed.
My proposed implementation would be to add a bl_options
property to the bpy.types.NodeTree
class. When bl_options is set to {"COMPOSITOR"}
, the backdrop functionality would be exposed. There would also need to be an API path for getting/setting the backdrop image (e.g. NodeTree.backdrop_image
)
Example code:
import bpy
from bpy.types import NodeTree
class MyCustomTree(NodeTree):
'''A custom node tree type that will show up in the node editor header'''
bl_idname = 'CustomTreeType'
bl_label = 'Custom Node Tree'
bl_icon = 'NODETREE'
bl_options = {'COMPOSITOR'}
def update(self):
active_viewer_node = get_viewer_node()
update_preview_image(self, active_viewer_node)
self.backdrop_image = bpy.data.images["Custom Viewer Node"]
def update_preview_image(node_tree, viewer_node):
### update bpy.data.images["Custom Viewer Node"] based on data fed into
### Color/Alpha inputs of viewer_node