8
$\begingroup$

is it possible to create custom nodes for the geometry node editor (NOT node groups, combining blender built-in nodes), define inputs and outputs and execute some python code in between? I couldn't find any information about completely userdefined nodes nor tutorials anywhere.

Further information about the usecase:

I want to create a node, which executes a more elaborate python code involving some linear algebra and finding eigenvalues of matrices. Therefore I created a python code using scipy, installed the scipy package in blender and I am already able to execute it within blender in the scripting environment and it outputs the correct values in the system console. Now I want to take the input values from a geometry node (position in x and y), calculate the output value of my python function and assign it as a z coordinate to all my verticies.

$\endgroup$
6
  • 1
    $\begingroup$ No, it's not possible. The developers have never exported an interface to python that would allow doing so and have routinely said that for performance reasons they would not. $\endgroup$ Feb 28, 2022 at 21:12
  • $\begingroup$ ahhh, thats too bad. My problem is, that the operation is too complicated and can't be expressed as a combination of math nodes as far as I know. Due to the fact, that one input value of the matrix process has to be animated, I can't precompute the values in a different script and apply them as a displacement texture. $\endgroup$
    – Max Hacki
    Feb 28, 2022 at 21:25
  • 1
    $\begingroup$ instead of giving up or fixating on GN i would think about animation nodes or sverchok. There you can execute python code and use that result. And yes, you can combine animation nodes and geometry nodes. $\endgroup$
    – Chris
    Mar 1, 2022 at 6:58
  • $\begingroup$ Thanks Chris! I managed to use animation nodes(AN) and created my geometry inside AN, moved my verticies with some python code, thats it. perfect! thanks, I was not aware of AN. $\endgroup$
    – Max Hacki
    Mar 6, 2022 at 20:19
  • 3
    $\begingroup$ While there is no python API (and no plans to add one), the internal C++ API is fairly concise. I recommend this article on how to add your own geometry node: blog.exppad.com/article/writing-blender-geometry-node $\endgroup$
    – Fullk33
    Jun 15, 2022 at 8:14

1 Answer 1

0
$\begingroup$

I've found this method:

import bpy
from bpy.types import Node, NodeSocket

class MyCustomNode(Node):
    '''This is a custom node that multiplies two inputs and outputs the result.'''

    bl_idname = 'CustomNodeType' # Unique identifier for your node type
    bl_label = 'My Custom Node' # Display name for your node

    # Define the input and output sockets for your node
    my_input_1 : NodeSocket
    my_input_2 : NodeSocket
    my_output : NodeSocket

    def init(self, context):
        # This method is called when the node is created
        self.inputs.new('NodeSocketFloat', 'Input 1')
        self.inputs.new('NodeSocketFloat', 'Input 2')
        self.outputs.new('NodeSocketFloat', 'Output')
    
    def update(self):
        # This method is called when the node updates
        self.outputs[0].default_value = self.inputs[0].default_value * self.inputs[1].default_value

# Register your node type with Blender
bpy.utils.register_class(MyCustomNode)

Simply execute the script, then add it to your nodes:

enter image description here

I was searching too, I'm just testing to go further...
Blender v3.4.1 - It's now possible -

$\endgroup$
8
  • $\begingroup$ Hello ! Have you tested this ? It doesn't work. $\endgroup$
    – Gorgious
    May 9, 2023 at 15:36
  • 1
    $\begingroup$ Interesting approach, but unfortunately I have to confirm what @Gorgious noted: The node is visible, but the values are empty (tested with 3.4.x and 3.5.x). $\endgroup$
    – quellenform
    May 9, 2023 at 16:00
  • 1
    $\begingroup$ there are complications : projects.blender.org/blender/blender/issues/67649 PS: old posts, real situation to define... $\endgroup$
    – s4mdf0o1
    May 10, 2023 at 11:29
  • 1
    $\begingroup$ may be a way to do that gist.github.com/strike-digital/0b5a2c0111f1aec3923b5fd17d1881e2 lines 40, 218, then 248 $\endgroup$
    – s4mdf0o1
    May 11, 2023 at 6:38
  • 1
    $\begingroup$ Your approach can work as a kind of a wrapper for a driver, or a more elaborate driver. It can modify 'default values' of standard nodes, it can provide some cool interface to the user, but it can't ever process data evaluated in geonodes, not without going to extreme lengths by detecting a change in the node tree, inserting some kind of output node (e.g. spawning a point based on a value of interest), evaluating the modifier (if there's more, disabling all modifiers below current), reading a value in the evaluated object... $\endgroup$ Oct 10, 2023 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .