Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/attribute_access.cc')
-rw-r--r--source/blender/blenkernel/intern/attribute_access.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index d36e9ed3e86..f2ad873b10e 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -46,6 +46,8 @@ using blender::StringRef;
using blender::StringRefNull;
using blender::fn::GMutableSpan;
using blender::fn::GSpan;
+using blender::fn::GVArray_For_GSpan;
+using blender::fn::GVArray_For_SingleValue;
namespace blender::bke {
@@ -628,8 +630,35 @@ std::optional<GSpan> CustomDataAttributes::get_for_read(const StringRef name) co
return {};
}
+/**
+ * Return a virtual array for a stored attribute, or a single value virtual array with the default
+ * value if the attribute doesn't exist. If no default value is provided, the default value for the
+ * type will be used.
+ */
+GVArrayPtr CustomDataAttributes::get_for_read(const StringRef name,
+ const CustomDataType data_type,
+ const void *default_value) const
+{
+ const CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type);
+
+ std::optional<GSpan> attribute = this->get_for_read(name);
+ if (!attribute) {
+ const int domain_size = this->size_;
+ return std::make_unique<GVArray_For_SingleValue>(
+ *type, domain_size, (default_value == nullptr) ? type->default_value() : default_value);
+ }
+
+ if (attribute->type() == *type) {
+ return std::make_unique<GVArray_For_GSpan>(*attribute);
+ }
+ const blender::nodes::DataTypeConversions &conversions =
+ blender::nodes::get_implicit_type_conversions();
+ return conversions.try_convert(std::make_unique<GVArray_For_GSpan>(*attribute), *type);
+}
+
std::optional<GMutableSpan> CustomDataAttributes::get_for_write(const StringRef name)
{
+ /* If this assert hits, it most likely means that #reallocate was not called at some point. */
BLI_assert(size_ != 0);
for (CustomDataLayer &layer : MutableSpan(data.layers, data.totlayer)) {
if (layer.name == name) {