[Bf-blender-cvs] [32cb953b9b7] temp-geometry-nodes-fields-prototype: anonymous attribute fields
Jacques Lucke
noreply at git.blender.org
Thu Jul 29 21:41:13 CEST 2021
Commit: 32cb953b9b7aeafd7702afa9104bb58439e53ede
Author: Jacques Lucke
Date: Thu Jul 29 19:28:58 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB32cb953b9b7aeafd7702afa9104bb58439e53ede
anonymous attribute fields
===================================================================
M source/blender/blenkernel/BKE_field.hh
M source/blender/modifiers/intern/MOD_nodes_evaluator.cc
M source/blender/nodes/geometry/node_geometry_util.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_field.hh b/source/blender/blenkernel/BKE_field.hh
index 48da2c7bfb2..e1b8bdf97ab 100644
--- a/source/blender/blenkernel/BKE_field.hh
+++ b/source/blender/blenkernel/BKE_field.hh
@@ -33,6 +33,8 @@
#include "FN_cpp_type_make.hh"
#include "FN_multi_function.hh"
+#include "BKE_customdata.h"
+
namespace blender::bke {
using fn::CPPType;
@@ -85,13 +87,55 @@ class IndexFieldInputKey : public FieldInputKey {
}
};
-class AttributeFieldInputKey : public FieldInputKey {
+class AnonymousAttributeFieldInputKey : public FieldInputKey {
+ private:
+ AnonymousCustomDataLayerID *layer_id_;
+ const CPPType &type_;
+
+ public:
+ AnonymousAttributeFieldInputKey(AnonymousCustomDataLayerID &layer_id, const CPPType &type)
+ : layer_id_(&layer_id), type_(type)
+ {
+ CustomData_anonymous_id_strong_increment(layer_id_);
+ }
+
+ ~AnonymousAttributeFieldInputKey()
+ {
+ CustomData_anonymous_id_strong_decrement(layer_id_);
+ }
+
+ const CPPType &type() const override
+ {
+ return type_;
+ }
+
+ uint64_t hash() const override
+ {
+ return get_default_hash(layer_id_);
+ }
+
+ const AnonymousCustomDataLayerID &layer_id() const
+ {
+ return *layer_id_;
+ }
+
+ private:
+ bool is_same_as(const FieldInputKey &other) const override
+ {
+ if (const AnonymousAttributeFieldInputKey *other_typed =
+ dynamic_cast<const AnonymousAttributeFieldInputKey *>(&other)) {
+ return layer_id_ == other_typed->layer_id_ && type_ == other_typed->type_;
+ }
+ }
+};
+
+class PersistentAttributeFieldInputKey : public FieldInputKey {
private:
std::string name_;
const CPPType *type_;
public:
- AttributeFieldInputKey(std::string name, const CPPType &type)
+ PersistentAttributeFieldInputKey(std::string name, const CPPType &type)
: name_(std::move(name)), type_(&type)
{
}
@@ -114,8 +158,8 @@ class AttributeFieldInputKey : public FieldInputKey {
private:
bool is_same_as(const FieldInputKey &other) const override
{
- if (const AttributeFieldInputKey *other_typed = dynamic_cast<const AttributeFieldInputKey *>(
- &other)) {
+ if (const PersistentAttributeFieldInputKey *other_typed =
+ dynamic_cast<const PersistentAttributeFieldInputKey *>(&other)) {
return other_typed->type_ == type_ && other_typed->name_ == name_;
}
return false;
@@ -361,10 +405,18 @@ class MultiFunctionField : public Field {
}
};
-class AttributeField : public GVArrayInputField<AttributeFieldInputKey> {
+class PersistentAttributeField : public GVArrayInputField<PersistentAttributeFieldInputKey> {
+ public:
+ PersistentAttributeField(std::string name, const CPPType &type)
+ : GVArrayInputField<PersistentAttributeFieldInputKey>(std::move(name), type)
+ {
+ }
+};
+
+class AnonymousAttributeField : public GVArrayInputField<AnonymousAttributeFieldInputKey> {
public:
- AttributeField(std::string name, const CPPType &type)
- : GVArrayInputField<AttributeFieldInputKey>(std::move(name), type)
+ AnonymousAttributeField(AnonymousCustomDataLayerID &layer_id, const CPPType &type)
+ : GVArrayInputField<AnonymousAttributeFieldInputKey>(layer_id, type)
{
}
};
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 1c47fe63c54..8fe45963209 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -364,7 +364,7 @@ static void get_socket_value(const SocketRef &socket, void *r_value)
case SOCK_VECTOR: {
if (socket.is_input() && (socket.bsocket()->flag & SOCK_HIDE_VALUE)) {
new (r_value) bke::FieldRef<float3>(
- FieldPtr{new bke::AttributeField("position", CPPType::get<float3>())});
+ FieldPtr{new bke::PersistentAttributeField("position", CPPType::get<float3>())});
}
else {
float3 value;
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc
index 77d573b1daf..6339b03f6c1 100644
--- a/source/blender/nodes/geometry/node_geometry_util.cc
+++ b/source/blender/nodes/geometry/node_geometry_util.cc
@@ -62,8 +62,8 @@ void prepare_field_inputs(bke::FieldInputs &field_inputs,
{
const int domain_size = component.attribute_domain_size(domain);
for (const bke::FieldInputKey &key : field_inputs) {
- if (const bke::AttributeFieldInputKey *attribute_key =
- dynamic_cast<const bke::AttributeFieldInputKey *>(&key)) {
+ if (const bke::PersistentAttributeFieldInputKey *attribute_key =
+ dynamic_cast<const bke::PersistentAttributeFieldInputKey *>(&key)) {
const StringRef name = attribute_key->name();
const CPPType &cpp_type = attribute_key->type();
const CustomDataType type = bke::cpp_type_to_custom_data_type(cpp_type);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute.cc
index 57d8ccb5942..a0f6dc5add1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute.cc
@@ -83,7 +83,7 @@ static void geo_node_attribute_exec(GeoNodeExecParams params)
const CPPType *cpp_type = get_cpp_type((eNodeSocketDatatype)node_storage->output_type);
BLI_assert(cpp_type != nullptr);
- bke::FieldPtr field = new bke::AttributeField(std::move(name), *cpp_type);
+ bke::FieldPtr field = new bke::PersistentAttributeField(std::move(name), *cpp_type);
if (cpp_type->is<float>()) {
params.set_output("Attribute", bke::FieldRef<float>(std::move(field)));
}
More information about the Bf-blender-cvs
mailing list