This patch automatically grays out input values which can't affect the output currently. It works with inputs of group nodes, geometry nodes modifiers and node tools. To achieve this, it analyses the node tree and partially evaluates it to figure out which group inputs are currently not linked to an output or are disabled by e.g. some switch node. Original proposal: https://devtalk.blender.org/t/dynamic-socket-visibility/31874 Related info in blog post: https://code.blender.org/2023/11/geometry-nodes-workshop-november-2023/#dynamic-socket-visibility Follow up task for designing a UI that allows hiding sockets: #132706 Limitations: * The inferencing does not update correctly when a socket starts being animated/driven. I haven't found a good way to invalidate the cache in a good way reliably yet. It's only a very short term problem though. It fixes itself after the next modification of the node tree and is only noticeable when animating some specific sockets such as the switch node condition. * Whether a socket is grayed out is not exposed in the Python API yet. That will be done separately. * Only a partial evaluation is done to determine if an input affects an output. There should be no cases where a socket is found to be unused when it can actually affect the output. However, there can be cases where a socket is inferenced to be used even if it is not due to some complex condition. Depending on the exact circumstances, this can either be improved or the condition in the node tree should be simplified. Pull Request: https://projects.blender.org/blender/blender/pulls/132219
53 lines
2.1 KiB
C++
53 lines
2.1 KiB
C++
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_array.hh"
|
|
#include "BLI_generic_pointer.hh"
|
|
|
|
struct bNodeTree;
|
|
struct bNodeSocket;
|
|
struct IDProperty;
|
|
|
|
namespace blender::nodes::socket_usage_inference {
|
|
|
|
/**
|
|
* Get a boolean value for each input socket in the given tree that indicates whether that input is
|
|
* used. It is assumed that all output sockets in the tree are used.
|
|
*/
|
|
Array<bool> infer_all_input_sockets_usage(const bNodeTree &tree);
|
|
|
|
/**
|
|
* Get a boolean value for each node group input that indicates whether that input is used by the
|
|
* outputs. The result can be used to e.g. gray out or hide individual inputs that are unused.
|
|
*
|
|
* \param group: The node group that is called.
|
|
* \param group_input_values: An optional input value for each node group input. The type is
|
|
* expected to be `bNodeSocketType::base_cpp_type`. If the input value for a socket is not known
|
|
* or can't be represented as base type, null has to be passed instead.
|
|
* \param r_input_usages: The destination array where the inferred usages are written.
|
|
*/
|
|
void infer_group_interface_inputs_usage(const bNodeTree &group,
|
|
Span<GPointer> group_input_values,
|
|
MutableSpan<bool> r_input_usages);
|
|
|
|
/**
|
|
* Same as above, but automatically retrieves the input values from the given sockets..
|
|
* This is used for group nodes.
|
|
*/
|
|
void infer_group_interface_inputs_usage(const bNodeTree &group,
|
|
Span<const bNodeSocket *> input_sockets,
|
|
MutableSpan<bool> r_input_usages);
|
|
|
|
/**
|
|
* Same as above, but automatically retrieves the input values from the given properties.
|
|
* This is used with the geometry nodes modifier and node tools.
|
|
*/
|
|
void infer_group_interface_inputs_usage(const bNodeTree &group,
|
|
const IDProperty *properties,
|
|
MutableSpan<bool> r_input_usages);
|
|
|
|
} // namespace blender::nodes::socket_usage_inference
|