[Bf-blender-cvs] [c8b0fcb1775] geometry-nodes-deduplicate-float-math: support creating constant dummy attributes
Jacques Lucke
noreply at git.blender.org
Wed Nov 25 13:47:59 CET 2020
Commit: c8b0fcb1775eb83f998feed4fafc49aa928588b7
Author: Jacques Lucke
Date: Wed Nov 25 13:07:55 2020 +0100
Branches: geometry-nodes-deduplicate-float-math
https://developer.blender.org/rBc8b0fcb1775eb83f998feed4fafc49aa928588b7
support creating constant dummy attributes
===================================================================
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..f7b3a83dc0c 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -152,6 +152,19 @@ class GeometryComponent {
return this->attribute_get_for_read(attribute_name, domain, type, &default_value);
}
+ blender::bke::ReadAttributePtr attribute_get_constant_for_read(const AttributeDomain domain,
+ const CustomDataType data_type,
+ const void *value) const;
+
+ 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