[Bf-blender-cvs] [044def82b9c] geometry-nodes: Geometry Nodes: add utility method to create a dummy attribute reader
Jacques Lucke
noreply at git.blender.org
Wed Nov 25 15:40:46 CET 2020
Commit: 044def82b9cd7fb6dc4ce5a923a68a985e257dc6
Author: Jacques Lucke
Date: Wed Nov 25 15:31:56 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rB044def82b9cd7fb6dc4ce5a923a68a985e257dc6
Geometry Nodes: add utility method to create a dummy attribute reader
This can be used when instead of an actual attribute, a constant value
should be used.
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/attribute_access.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 1e5a4d3c543..284c9ae4c9f 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -152,6 +152,21 @@ class GeometryComponent {
return this->attribute_get_for_read(attribute_name, domain, type, &default_value);
}
+ /* Get a read-only dummy attribute that always returns the same value. */
+ blender::bke::ReadAttributePtr attribute_get_constant_for_read(const AttributeDomain domain,
+ const CustomDataType data_type,
+ const void *value) const;
+
+ /* Get a read-only dummy attribute that always returns the same value. */
+ template<typename T>
+ blender::bke::TypedReadAttribute<T> attribute_get_constant_for_read(const AttributeDomain domain,
+ const T &value) const
+ {
+ const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
+ const CustomDataType type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
+ return this->attribute_get_constant_for_read(domain, type, &value);
+ }
+
/**
* Returns the attribute with the given parameters if it exists.
* If an exact match does not exist, other attributes with the same name are deleted and a new
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index ad5f7e1a781..c3df7374fb0 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -533,15 +533,21 @@ ReadAttributePtr GeometryComponent::attribute_get_for_read(const StringRef attri
if (attribute) {
return attribute;
}
+ return this->attribute_get_constant_for_read(domain, data_type, default_value);
+}
+blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_read(
+ const AttributeDomain domain, const CustomDataType data_type, const void *value) const
+{
+ BLI_assert(this->attribute_domain_supported(domain));
const blender::fn::CPPType *cpp_type = blender::bke::custom_data_type_to_cpp_type(data_type);
BLI_assert(cpp_type != nullptr);
- if (default_value == nullptr) {
- default_value = cpp_type->default_value();
+ if (value == nullptr) {
+ value = cpp_type->default_value();
}
const int domain_size = this->attribute_domain_size(domain);
return std::make_unique<blender::bke::ConstantReadAttribute>(
- domain, domain_size, *cpp_type, default_value);
+ domain, domain_size, *cpp_type, value);
}
WriteAttributePtr GeometryComponent::attribute_try_ensure_for_write(const StringRef attribute_name,
More information about the Bf-blender-cvs
mailing list