4
$\begingroup$

Is it possible to create a custom compositor node using python? I'd like to be create the following node:

  1. Input sockets for Image and Z render results
  2. Load the image into numpy arrays
  3. Manipulate the numpy arrays in various ways
  4. Output socket for resulting image.

I've been able to create a new node type and register it the with the CompositorNodeTree, but it doesn't actually do anything. Is there a method I can implement (e.g. process or something) that can trigger the node process the image?

$\endgroup$
6
$\begingroup$

While it is possible to define a pynode that can be added to existing node trees, they are considered unsupported and have limited functionality - mostly they don't get an event to automatically update. I don't think anything has changed since this previous answer.

The two main pynode projects are animation nodes and sverchok - both of these projects have implemented bpy.app.handlers that trigger an update of their node trees for various events. You will need to experiment to see if you are able to get some results using one of the render related handlers to update your node, but I don't think that any of the handlers fall between rendering and compositing.

Depending on your needs, you may be able to use a script that renders a frame, updates your node to get the result and then save the render result or viewer node output.

You may also want to try manipulating the render after it is completed instead of during compositing.

bpy.ops.render.render()
img = bpy.data.images['Viewer Node']
w = img.size[0]
h = img.size[1]
arr = np.array(img.pixels[:])
arr = arr.reshape((w,h,4))
$\endgroup$
  • $\begingroup$ Is it possible to add existing nodes to a custom pynode tree? For example, use a cloud texture output? $\endgroup$ – VSB Nov 27 '18 at 21:44
  • 1
    $\begingroup$ @VSB no. But you can access the same algorithm and use it in your nodes. You will find it in mathutils.noise $\endgroup$ – sambler Nov 28 '18 at 6:08
3
$\begingroup$

Not through python, no. Since Blender is open source you could always code a custom node like the built-in ones and recompile Blender itself. But there's no functionality for adding new compositing nodes at runtime through plugins or scripting or anything like that.

The node you created (and any nodes created via Python) are merely UI elements. They don't actually process data, they are visual representations of some other thing that will do the processing. The python nodes API is meant primarily to allow addons to add their own node editor pages for whatever functionality they need to represent to the user with nodes. Due to the way the API works it's also possible to use it to make custom nodes show up in the compositor or BI/Cycles shader trees. There is no way to supply the actual "business end" of such a node though.

$\endgroup$
2
$\begingroup$

Someone has compiled a version that would allow you to write your own Python scripts to process images in the compositor without recompiling:

https://github.com/bitsawer/blender-custom-nodes

I find it really useful. However, the number of input/output nodes appear to be fixed. I would really like to see this feature in the official release.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.