This implements bundles and closures which are described in more detail in this blog post: https://code.blender.org/2024/11/geometry-nodes-workshop-october-2024/ tl;dr: * Bundles are containers that allow storing multiple socket values in a single value. Each value in the bundle is identified by a name. Bundles can be nested. * Closures are functions that are created with the Closure Zone and can be evaluated with the Evaluate Closure node. To use the patch, the `Bundle and Closure Nodes` experimental feature has to be enabled. This is necessary, because these features are not fully done yet and still need iterations to improve the workflow before they can be officially released. These iterations are easier to do in `main` than in a separate branch though. That's because this patch is quite large and somewhat prone to merge conflicts. Also other work we want to do, depends on this. This adds the following new nodes: * Combine Bundle: can pack multiple values into one. * Separate Bundle: extracts values from a bundle. * Closure Zone: outputs a closure zone for use in the `Evaluate Closure` node. * Evaluate Closure: evaluates the passed in closure. Things that will be added soon after this lands: * Fields in bundles and closures. The way this is done changes with #134811, so I rather implement this once both are in `main`. * UI features for keeping sockets in sync (right now there are warnings only). One bigger issue is the limited support for lazyness. For example, all inputs of a Combine Bundle node will be evaluated, even if they are not all needed. The same is true for all captured values of a closure. This is a deeper limitation that needs to be resolved at some point. This will likely be done after an initial version of this patch is done. Pull Request: https://projects.blender.org/blender/blender/pulls/128340
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
/* SPDX-FileCopyrightText: 2025 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BKE_node.hh"
|
|
|
|
#include "NOD_geometry_nodes_bundle_fwd.hh"
|
|
#include "NOD_socket_interface_key.hh"
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
namespace blender::nodes {
|
|
|
|
/**
|
|
* A bundle is a map containing keys and their corresponding values. Values are stored as the type
|
|
* they have in Geometry Nodes (#bNodeSocketType::geometry_nodes_cpp_type).
|
|
*/
|
|
class Bundle : public ImplicitSharingMixin {
|
|
public:
|
|
struct StoredItem {
|
|
SocketInterfaceKey key;
|
|
const bke::bNodeSocketType *type;
|
|
void *value;
|
|
};
|
|
|
|
private:
|
|
Vector<StoredItem> items_;
|
|
Vector<void *> buffers_;
|
|
|
|
public:
|
|
struct Item {
|
|
const bke::bNodeSocketType *type;
|
|
const void *value;
|
|
};
|
|
|
|
Bundle();
|
|
Bundle(const Bundle &other);
|
|
Bundle(Bundle &&other) noexcept;
|
|
Bundle &operator=(const Bundle &other);
|
|
Bundle &operator=(Bundle &&other) noexcept;
|
|
~Bundle();
|
|
|
|
static BundlePtr create()
|
|
{
|
|
return BundlePtr(MEM_new<Bundle>(__func__));
|
|
}
|
|
|
|
void add_new(SocketInterfaceKey key, const bke::bNodeSocketType &type, const void *value);
|
|
bool add(const SocketInterfaceKey &key, const bke::bNodeSocketType &type, const void *value);
|
|
bool add(SocketInterfaceKey &&key, const bke::bNodeSocketType &type, const void *value);
|
|
bool remove(const SocketInterfaceKey &key);
|
|
bool contains(const SocketInterfaceKey &key) const;
|
|
|
|
std::optional<Item> lookup(const SocketInterfaceKey &key) const;
|
|
|
|
Span<StoredItem> items() const
|
|
{
|
|
return items_;
|
|
}
|
|
|
|
void delete_self() override;
|
|
};
|
|
|
|
} // namespace blender::nodes
|