VoxelGraphFunction

Inherits: Resource

Graph for generating or processing series of 3D values.

Description:

Contains a graph that can be used to process series of values, such as voxel positions (when used as main function of a generator), or to be re-used into other graphs (like a sub-graph).

Currently this class only stores a graph, it cannot run actual processing on its own. It is usually embedded into another resource which then makes use of the graph in a specific way.

To generate voxels with it, see VoxelGeneratorGraph.

Nodes can be connected together from their outputs to the inputs of next nodes. Unconnected inputs can have default values or default implicit connections.

Nodes can also have "parameters" which are constants setup per node.

Nodes come in 3 main families: inputs (only have outputs), outputs (only have inputs), and others (which have both inputs and output to do some calculation).

Node types are identified with the enum NodeTypeID. This enum shouldn't be used in persistent contexts (such as save files) as its values may change between versions.

Graphs can only process 32-bit floating point values.

Description of node types is present in the graph editor node dialog, or at https://voxel-tools.readthedocs.io/en/latest/graph_nodes.

Properties:

Type Name Default
Array input_definitions []
Array output_definitions []

Methods:

Return Signature
void add_connection ( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index )
bool can_connect ( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index ) const
void clear ( )
int create_function_node ( VoxelGraphFunction function, Vector2 position, int id=0 )
int create_node ( NodeTypeID type_id, Vector2 position, int id=0 )
int find_node_by_name ( StringName name ) const
Array get_connections ( ) const
Variant get_node_default_input ( int node_id, int input_index ) const
bool get_node_default_inputs_autoconnect ( int node_id ) const
Vector2 get_node_gui_position ( int node_id ) const
Vector2 get_node_gui_size ( int node_id ) const
PackedInt32Array get_node_ids ( ) const
int get_node_input_index ( int node_id, String input_name ) const
StringName get_node_name ( int node_id ) const
int get_node_output_index ( int node_id, String output_name ) const
Variant get_node_param ( int node_id, int param_index ) const
int get_node_type_count ( ) const
NodeTypeID get_node_type_id ( int node_id ) const
Dictionary get_node_type_info ( int type_id ) const
void paste_graph_with_pre_generated_ids ( VoxelGraphFunction graph, PackedInt32Array node_ids, Vector2 gui_offset )
void remove_connection ( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index )
void remove_node ( int node_id )
void set_expression_node_inputs ( int node_id, PackedStringArray names )
void set_node_default_input ( int node_id, int input_index, Variant value )
void set_node_default_input_by_name ( int node_id, String input_name, Variant value )
void set_node_default_inputs_autoconnect ( int node_id, bool enabled )
void set_node_gui_position ( int node_id, Vector2 position )
void set_node_gui_size ( int node_id, Vector2 size )
void set_node_name ( int node_id, StringName name )
void set_node_param ( int node_id, int param_index, Variant value )
void set_node_param_by_name ( int node_id, String param_name, Variant value )
void set_node_param_null ( int node_id, int param_index )

Signals:

compiled( )

Emitted after the graph finished compiling, even if compiling failed.

node_name_changed( int node_id )

(This signal has no documentation)

Enumerations:

enum NodeTypeID:

  • NODE_CONSTANT = 0
  • NODE_INPUT_X = 1
  • NODE_INPUT_Y = 2
  • NODE_INPUT_Z = 3
  • NODE_OUTPUT_SDF = 4
  • NODE_CUSTOM_INPUT = 52
  • NODE_CUSTOM_OUTPUT = 53
  • NODE_ADD = 5
  • NODE_SUBTRACT = 6
  • NODE_MULTIPLY = 7
  • NODE_DIVIDE = 8
  • NODE_SIN = 9
  • NODE_FLOOR = 10
  • NODE_ABS = 11
  • NODE_SQRT = 12
  • NODE_FRACT = 13
  • NODE_STEPIFY = 14
  • NODE_WRAP = 15
  • NODE_MIN = 16
  • NODE_MAX = 17
  • NODE_DISTANCE_2D = 18
  • NODE_DISTANCE_3D = 19
  • NODE_CLAMP = 20
  • NODE_MIX = 22
  • NODE_REMAP = 23
  • NODE_SMOOTHSTEP = 24
  • NODE_CURVE = 25
  • NODE_SELECT = 26
  • NODE_NOISE_2D = 27
  • NODE_NOISE_3D = 28
  • NODE_IMAGE_2D = 29
  • NODE_SDF_PLANE = 30
  • NODE_SDF_BOX = 31
  • NODE_SDF_SPHERE = 32
  • NODE_SDF_TORUS = 33
  • NODE_SDF_PREVIEW = 34
  • NODE_SDF_SPHERE_HEIGHTMAP = 35
  • NODE_SDF_SMOOTH_UNION = 36
  • NODE_SDF_SMOOTH_SUBTRACT = 37
  • NODE_NORMALIZE_3D = 38
  • NODE_FAST_NOISE_2D = 39
  • NODE_FAST_NOISE_3D = 40
  • NODE_FAST_NOISE_GRADIENT_2D = 41
  • NODE_FAST_NOISE_GRADIENT_3D = 42
  • NODE_OUTPUT_WEIGHT = 43
  • NODE_OUTPUT_SINGLE_TEXTURE = 45
  • NODE_EXPRESSION = 46
  • NODE_POWI = 47
  • NODE_POW = 48
  • NODE_INPUT_SDF = 49
  • NODE_COMMENT = 50
  • NODE_FUNCTION = 51
  • NODE_RELAY = 54
  • NODE_SPOTS_2D = 55
  • NODE_SPOTS_3D = 56
  • NODE_TYPE_COUNT = 59
  • NODE_FAST_NOISE_2_2D = 57
  • NODE_FAST_NOISE_2_3D = 58

Property Descriptions

Array input_definitions = []

(This property has no documentation)

Array output_definitions = []

(This property has no documentation)

Method Descriptions

void add_connection( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index )

Connects the outputs of a node to the input of another node. Connecting a node to itself, or in a way that can lead it back to itself, is not supported.

bool can_connect( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index )

Tests if two ports can be connected together.

void clear( )

Removes all nodes from the graph. Input and output definitions will not be cleared.

int create_function_node( VoxelGraphFunction function, Vector2 position, int id=0 )

Creates a node based on an existing graph (creates a "sub-graph instance").

int create_node( NodeTypeID type_id, Vector2 position, int id=0 )

Creates a graph node of a given type at a specific visual position.

The position parameter does not affect how the graph will perform, however it helps organizing nodes.

An optional ID can be specified. If left to 0, the ID will be generated.

This function then returns the ID of the node, which may be useful to modify other properties of the node later.

int find_node_by_name( StringName name )

Finds a node with the specified name and returns its ID. If the node is not found, returns 0.

Array get_connections( )

Gets an array describing all connections between nodes.

The array has the following format:

[
    {
        "src_node_id": int,
        "src_port_index": int,
        "dst_node_id": int,
        "dst_port_index": int
    },
    ...
]

Variant get_node_default_input( int node_id, int input_index )

(This method has no documentation)

bool get_node_default_inputs_autoconnect( int node_id )

(This method has no documentation)

Vector2 get_node_gui_position( int node_id )

Get the position of the node in the graph editor.

Vector2 get_node_gui_size( int node_id )

Get the size of the node in the graph editor.

PackedInt32Array get_node_ids( )

Get a list of IDs of all the nodes in the graph.

Note: the order in which IDs are returned is not guaranteed to be the same after nodes are added or removed.

int get_node_input_index( int node_id, String input_name )

Gets the input index of a node from the input's name.

StringName get_node_name( int node_id )

Gets the user-defined name of the node.

int get_node_output_index( int node_id, String output_name )

Gets the output index of a node from the output's name.

Variant get_node_param( int node_id, int param_index )

Get a parameter of a node. The parameter index corresponds to the position that parameter comes in when seen in the editor.

int get_node_type_count( )

Get how many types of nodes exist in the graph system.

NodeTypeID get_node_type_id( int node_id )

Get the ID of the type of a node in the graph.

Dictionary get_node_type_info( int type_id )

Gets information about a node type from NodeTypeID.

The returned data has this structure:

{
    "name": String,
    "inputs": [
        {"name": String},
        ...
    ],
    "outputs": [
        {"name": String},
        ...
    ],
    "params": [
        {
            "name": String,
            "type": int (Variant::Type),
            "class_name": String,
            "default_value": Variant
        },
        ...
    ]
}

void paste_graph_with_pre_generated_ids( VoxelGraphFunction graph, PackedInt32Array node_ids, Vector2 gui_offset )

Copies nodes into another graph, and connections between them only.

Resources in node parameters will be duplicated if they don't have a file path.

If node_ids is provided with non-zero size, defines the IDs copied nodes will have in the destination graph, in the same order as get_node_ids from the source graph. The array must have the same size as the number of copied nodes and IDs must not already exist in the destination graph. If the array is empty, they will be generated instead.

void remove_connection( int src_node_id, int src_port_index, int dst_node_id, int dst_port_index )

Removes an existing connection between two nodes of the graph.

void remove_node( int node_id )

Removes a node from the graph.

void set_expression_node_inputs( int node_id, PackedStringArray names )

Configures inputs for an Expression node. names is the list of input names used in the expression.

If you create an Expression node from code, you should call this method afterwards.

void set_node_default_input( int node_id, int input_index, Variant value )

Sets the value an input of a node will have when it is left unconnected.

void set_node_default_input_by_name( int node_id, String input_name, Variant value )

Sets the value an input of a node will have when it is left unconnected. The input is specified by its name as seen in the editor.

void set_node_default_inputs_autoconnect( int node_id, bool enabled )

Sets wether a node input with no inbound connection will automatically create a default connection when the graph is compiled.

This is only available on specific nodes (for example, 2D or 3D noise defaults to XYZ inputs). On other nodes, it has no effect.

void set_node_gui_position( int node_id, Vector2 position )

Sets the visual position of a node of the graph, as it will appear in the editor.

void set_node_gui_size( int node_id, Vector2 size )

Sets the visual size of a node of the graph, as it will appear in the editor.

void set_node_name( int node_id, StringName name )

Sets a custom name for a node.

void set_node_param( int node_id, int param_index, Variant value )

Set a parameter of a node. The parameter index corresponds to the position that parameter comes in when seen in the editor.

void set_node_param_by_name( int node_id, String param_name, Variant value )

Set a parameter of a node, using its name as it appears in the editor.

void set_node_param_null( int node_id, int param_index )

Set a parameter of a node to null. This method only exists to workaround an issue with Godot's UndoRedo system. Prefer using set_node_param.

Generated on Jan 26, 2026