Cleanup: remove use of persistent data handles in geometry nodes

Those were mostly just left over from previous work on particle nodes.
They solved the problem of keeping a reference to an object over
multiple frames and in a cache. Currently, we do not have this problem
in geometry nodes, so we can also remove this layer of complexity
for now.
This commit is contained in:
2021-05-08 14:54:48 +02:00
parent 39044e68c2
commit 34439f05ab
11 changed files with 34 additions and 307 deletions

View File

@@ -22,7 +22,6 @@
#include "BKE_geometry_set.hh"
#include "BKE_geometry_set_instances.hh"
#include "BKE_node_ui_storage.hh"
#include "BKE_persistent_data_handle.hh"
#include "DNA_node_types.h"
@@ -36,8 +35,6 @@ namespace blender::nodes {
using bke::geometry_set_realize_instances;
using bke::OutputAttribute;
using bke::OutputAttribute_Typed;
using bke::PersistentDataHandleMap;
using bke::PersistentObjectHandle;
using bke::ReadAttributeLookup;
using bke::WriteAttributeLookup;
using fn::CPPType;
@@ -63,7 +60,6 @@ using fn::GVMutableArrayPtr;
class GeoNodeExecParamsProvider {
public:
DNode dnode;
const PersistentDataHandleMap *handle_map = nullptr;
const Object *self_object = nullptr;
const ModifierData *modifier = nullptr;
Depsgraph *depsgraph = nullptr;
@@ -190,11 +186,6 @@ class GeoNodeExecParams {
return *provider_->dnode->bnode();
}
const PersistentDataHandleMap &handle_map() const
{
return *provider_->handle_map;
}
const Object *self_object() const
{
return provider_->self_object;

View File

@@ -42,9 +42,7 @@ namespace blender::nodes {
static void geo_node_collection_info_exec(GeoNodeExecParams params)
{
bke::PersistentCollectionHandle collection_handle =
params.extract_input<bke::PersistentCollectionHandle>("Collection");
Collection *collection = params.handle_map().lookup(collection_handle);
Collection *collection = params.get_input<Collection *>("Collection");
GeometrySet geometry_set_out;

View File

@@ -47,9 +47,7 @@ static void geo_node_object_info_exec(GeoNodeExecParams params)
const bool transform_space_relative = (node_storage->transform_space ==
GEO_NODE_TRANSFORM_SPACE_RELATIVE);
bke::PersistentObjectHandle object_handle = params.extract_input<bke::PersistentObjectHandle>(
"Object");
Object *object = params.handle_map().lookup(object_handle);
Object *object = params.get_input<Object *>("Object");
float3 location = {0, 0, 0};
float3 rotation = {0, 0, 0};

View File

@@ -14,8 +14,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "BKE_persistent_data_handle.hh"
#include "DNA_collection_types.h"
#include "BLI_hash.h"
@@ -68,9 +66,7 @@ static void geo_node_point_instance_update(bNodeTree *UNUSED(tree), bNode *node)
static void get_instance_references__object(const GeoNodeExecParams &params,
MutableSpan<InstanceReference> r_references)
{
bke::PersistentObjectHandle object_handle = params.get_input<bke::PersistentObjectHandle>(
"Object");
Object *object = params.handle_map().lookup(object_handle);
Object *object = params.get_input<Object *>("Object");
if (object == params.self_object()) {
object = nullptr;
}
@@ -86,9 +82,7 @@ static void get_instance_references__collection(const GeoNodeExecParams &params,
const bNode &node = params.node();
NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node.storage;
bke::PersistentCollectionHandle collection_handle =
params.get_input<bke::PersistentCollectionHandle>("Collection");
Collection *collection = params.handle_map().lookup(collection_handle);
Collection *collection = params.get_input<Collection *>("Collection");
if (collection == nullptr) {
return;
}

View File

@@ -133,11 +133,11 @@ static void geo_node_switch_exec(GeoNodeExecParams params)
break;
}
case SOCK_OBJECT: {
output_input<bke::PersistentObjectHandle>(params, input, "_007", "Output_007");
output_input<Object *>(params, input, "_007", "Output_007");
break;
}
case SOCK_COLLECTION: {
output_input<bke::PersistentCollectionHandle>(params, input, "_008", "Output_008");
output_input<Collection *>(params, input, "_008", "Output_008");
break;
}
default:

View File

@@ -35,7 +35,6 @@
#include "BKE_geometry_set.hh"
#include "BKE_lib_id.h"
#include "BKE_node.h"
#include "BKE_persistent_data_handle.hh"
#include "DNA_collection_types.h"
@@ -632,63 +631,15 @@ static bNodeSocketType *make_socket_type_string()
return socktype;
}
class ObjectSocketMultiFunction : public blender::fn::MultiFunction {
private:
Object *object_;
public:
ObjectSocketMultiFunction(Object *object) : object_(object)
{
static blender::fn::MFSignature signature = create_signature();
this->set_signature(&signature);
}
static blender::fn::MFSignature create_signature()
{
blender::fn::MFSignatureBuilder signature{"Object Socket"};
signature.depends_on_context();
signature.single_output<blender::bke::PersistentObjectHandle>("Object");
return signature.build();
}
void call(blender::IndexMask mask,
blender::fn::MFParams params,
blender::fn::MFContext context) const override
{
blender::MutableSpan output =
params.uninitialized_single_output<blender::bke::PersistentObjectHandle>(0, "Object");
/* Try to get a handle map, so that the object can be converted to a handle. */
const blender::bke::PersistentDataHandleMap *handle_map =
context.get_global_context<blender::bke::PersistentDataHandleMap>(
"PersistentDataHandleMap");
if (handle_map == nullptr) {
/* Return empty handles when there is no handle map. */
output.fill_indices(mask, blender::bke::PersistentObjectHandle());
return;
}
blender::bke::PersistentObjectHandle handle = handle_map->lookup(object_);
for (int64_t i : mask) {
output[i] = handle;
}
}
};
MAKE_CPP_TYPE(PersistentObjectHandle, blender::bke::PersistentObjectHandle);
MAKE_CPP_TYPE(PersistentCollectionHandle, blender::bke::PersistentCollectionHandle);
MAKE_CPP_TYPE(Object, Object *)
MAKE_CPP_TYPE(Collection, Collection *)
static bNodeSocketType *make_socket_type_object()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_OBJECT, PROP_NONE);
socktype->get_cpp_type = []() {
/* Objects are not passed along as raw pointers, but as handles. */
return &blender::fn::CPPType::get<blender::bke::PersistentObjectHandle>();
};
socktype->expand_in_mf_network = [](blender::nodes::SocketMFNetworkBuilder &builder) {
Object *object = builder.socket_default_value<bNodeSocketValueObject>()->value;
builder.construct_generator_fn<ObjectSocketMultiFunction>(object);
socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Object *>(); };
socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Object **)r_value = ((bNodeSocketValueObject *)socket.default_value)->value;
};
return socktype;
}
@@ -706,9 +657,9 @@ static bNodeSocketType *make_socket_type_geometry()
static bNodeSocketType *make_socket_type_collection()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_COLLECTION, PROP_NONE);
socktype->get_cpp_type = []() {
/* Objects are not passed along as raw pointers, but as handles. */
return &blender::fn::CPPType::get<blender::bke::PersistentCollectionHandle>();
socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Collection *>(); };
socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Collection **)r_value = ((bNodeSocketValueCollection *)socket.default_value)->value;
};
return socktype;
}