Files
test/source/blender/blenkernel/intern/node_enum_definition.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
922 B
C++
Raw Normal View History

Geometry Nodes: Menu Switch Node This patch adds support for _Menu Switch_ nodes and enum definitions in node trees more generally. The design is based on the outcome of the [2022 Nodes Workshop](https://code.blender.org/2022/11/geometry-nodes-workshop-2022/#menu-switch). The _Menu Switch_ node is an advanced version of the _Switch_ node which has a customizable **menu input socket** instead of a simple boolean. The _items_ of this menu are owned by the node itself. Each item has a name and description and unique identifier that is used internally. A menu _socket_ represents a concrete value out of the list of items. To enable selection of an enum value for unconnected sockets the menu is presented as a dropdown list like built-in enums. When the socket is connected a shared pointer to the enum definition is propagated along links and stored in socket default values. This allows node groups to expose a menu from an internal menu switch as a parameter. The enum definition is a runtime copy of the enum items in DNA that allows sharing. A menu socket can have multiple connections, which can lead to ambiguity. If two or more different menu source nodes are connected to a socket it gets marked as _undefined_. Any connection to an undefined menu socket is invalid as a hint to users that there is a problem. A warning/error is also shown on nodes with undefined menu sockets. At runtime the value of a menu socket is the simple integer identifier. This can also be a field in geometry nodes. The identifier is unique within each enum definition, and it is persistent even when items are added, removed, or changed. Changing the name of an item does not affect the internal identifier, so users can rename enum items without breaking existing input values. This also persists if, for example, a linked node group is temporarily unavailable. Pull Request: https://projects.blender.org/blender/blender/pulls/113445
2024-01-26 12:40:01 +01:00
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "DNA_array_utils.hh"
#include "DNA_node_types.h"
#include "BKE_node_enum.hh"
using blender::bke::NodeSocketValueMenuRuntimeFlag;
bool bNodeSocketValueMenu::has_conflict() const
{
return this->runtime_flag & NodeSocketValueMenuRuntimeFlag::NODE_MENU_ITEMS_CONFLICT;
}
blender::Span<NodeEnumItem> NodeEnumDefinition::items() const
{
return {this->items_array, this->items_num};
}
Geometry Nodes: unify menu switch with other nodes with dynamic sockets This changes the menu switch socket to use the socket-items system (`NOD_socket_items.hh`) that is already used by the simulation zone, repeat zone, bake node and index switch node. By using this system, the per-node boilerplate can be removed significantly. This is especially important as we plan to have dynamic socket amounts in more nodes in the future. There are some user visible changes which make the node more consistent with others: * Move the menu items list into the properties panel as in 0c585a1b8af. * Add an extend socket. * Duplicating a menu item keeps the name of the old one. There is also a (backward compatible) change in the Python API: It's now possible to directly access `node.enum_items` and `node.active_index` instead of having to use `node.enum_definition.enum_items`. This is consistent with the other nodes. For backward compatibility, `node.enum_definition` still exists, but simply returns the node itself. Many API functions from `NodeEnumDefinition` like `NodeEnumDefinition::remove_item` have been removed. Those are not used anymore and are unnecessary boilerplate. If ever necessary, they can be implemented back in terms of the socket-items system. The socket-items system had to be extended a little bit to support the case for the menu switch node where each socket item has a name but no type. Previously, there was the case without name and type in the index switch node, and the case with both in the bake node and zones. The system was trivial to extend to this case. Pull Request: https://projects.blender.org/blender/blender/pulls/121234
2024-04-30 10:19:32 +02:00
blender::MutableSpan<NodeEnumItem> NodeEnumDefinition::items()
Geometry Nodes: Menu Switch Node This patch adds support for _Menu Switch_ nodes and enum definitions in node trees more generally. The design is based on the outcome of the [2022 Nodes Workshop](https://code.blender.org/2022/11/geometry-nodes-workshop-2022/#menu-switch). The _Menu Switch_ node is an advanced version of the _Switch_ node which has a customizable **menu input socket** instead of a simple boolean. The _items_ of this menu are owned by the node itself. Each item has a name and description and unique identifier that is used internally. A menu _socket_ represents a concrete value out of the list of items. To enable selection of an enum value for unconnected sockets the menu is presented as a dropdown list like built-in enums. When the socket is connected a shared pointer to the enum definition is propagated along links and stored in socket default values. This allows node groups to expose a menu from an internal menu switch as a parameter. The enum definition is a runtime copy of the enum items in DNA that allows sharing. A menu socket can have multiple connections, which can lead to ambiguity. If two or more different menu source nodes are connected to a socket it gets marked as _undefined_. Any connection to an undefined menu socket is invalid as a hint to users that there is a problem. A warning/error is also shown on nodes with undefined menu sockets. At runtime the value of a menu socket is the simple integer identifier. This can also be a field in geometry nodes. The identifier is unique within each enum definition, and it is persistent even when items are added, removed, or changed. Changing the name of an item does not affect the internal identifier, so users can rename enum items without breaking existing input values. This also persists if, for example, a linked node group is temporarily unavailable. Pull Request: https://projects.blender.org/blender/blender/pulls/113445
2024-01-26 12:40:01 +01:00
{
return {this->items_array, this->items_num};
}
namespace blender::bke {
const RuntimeNodeEnumItem *RuntimeNodeEnumItems::find_item_by_identifier(
const int identifier) const
{
for (const RuntimeNodeEnumItem &item : this->items) {
if (item.identifier == identifier) {
return &item;
}
}
return nullptr;
}
} // namespace blender::bke