Previously, when a socket was detected to be unused, it was just grayed out. This patch adds support for automatically hiding unused sockets based on this convention: Menu inputs control visibility while other inputs only control whether something is grayed out. More specifically, an input is visible if any of these conditions is met: * It affects the output currently. * It never affects the output. In this case its usage does not depend on any menu input. * It is used if all non-menu inputs are considered to be unknown. In the future, we could support customizing which inputs are allowed to control visibility. For now it's good to use the convention that Blender generally follows itself. As before, panels are grayed out if they only contain grayed out sockets and panels are hidden when they don't contain any visible sockets. Hiding inputs works in group nodes, the Geometry Nodes modifier and node operators. In theory it will work for all node tree types, but since only Geometry Nodes supports the Menu Switch node currently, this patch currently only makes a difference there. The implementation reuses the existing `SocketUsageInferencer` with a different sets of inputs. So no new core-inferencing logic was needed. Design task: #132706. Pull Request: https://projects.blender.org/blender/blender/pulls/138186
56 lines
2.2 KiB
C++
56 lines
2.2 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"
|
|
|
|
#include "NOD_geometry_nodes_execute.hh"
|
|
#include "NOD_socket_usage_inference_fwd.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<SocketUsage> 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<SocketUsage> 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<SocketUsage> 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 PropertiesVectorSet &properties,
|
|
MutableSpan<SocketUsage> r_input_usages);
|
|
|
|
} // namespace blender::nodes::socket_usage_inference
|