diff options
author | Hans Goudey <h.goudey@me.com> | 2021-06-02 15:24:42 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-06-02 15:24:42 +0300 |
commit | 34f99bc6be3c343dd371e1f877e972cc80dd396d (patch) | |
tree | 0d967f7625939ce3fc111725355f564443c3836c /source/blender/blenkernel/BKE_attribute_access.hh | |
parent | 6cd64f8caacc1a7c679d962a053f73263fc18c2c (diff) |
Geometry Nodes: Allow reading converted attribute directly from spline
Often it would be beneficial to avoid the virtual array implementation
in `geometry_component_curve.cc` that flattens an attribute for every
spline and instead read an attribute separately for every input spline.
This commit implements functions to do that.
The downside is some code duplication-- we now have two places handling
this conversion. However, we can head in this general direction for the
attribute API anyway and support accessing attributes in smaller
contiguous chunks where necessary.
No functional changes in this commit.
Differential Revision: https://developer.blender.org/D11456
Diffstat (limited to 'source/blender/blenkernel/BKE_attribute_access.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_attribute_access.hh | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index c3bc4d3ca4a..381a03d29d7 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -333,6 +333,21 @@ class CustomDataAttributes { void reallocate(const int size); std::optional<blender::fn::GSpan> get_for_read(const blender::StringRef name) const; + + blender::fn::GVArrayPtr get_for_read(const StringRef name, + const CustomDataType data_type, + const void *default_value) const; + + template<typename T> + blender::fn::GVArray_Typed<T> get_for_read(const blender::StringRef name, + const T &default_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); + GVArrayPtr varray = this->get_for_read(name, type, &default_value); + return blender::fn::GVArray_Typed<T>(std::move(varray)); + } + std::optional<blender::fn::GMutableSpan> get_for_write(const blender::StringRef name); bool create(const blender::StringRef name, const CustomDataType data_type); bool create_by_move(const blender::StringRef name, const CustomDataType data_type, void *buffer); |