diff options
author | Jacques Lucke <jacques@blender.org> | 2020-12-03 18:25:48 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-12-03 18:25:48 +0300 |
commit | 107231eb956a953c89a2ab134371988ebe338c59 (patch) | |
tree | b8e46bf488b089766e5f2e41dd9affd096efd38c | |
parent | 2c181521ec0c4e0fca579fb512801410570800fb (diff) |
Geometry Nodes: improve support for Color attributes
* Add typed attribute accessors for color attributes.
* Support implicit conversions between colors and floats.
-rw-r--r-- | source/blender/blenkernel/BKE_attribute_access.hh | 6 | ||||
-rw-r--r-- | source/blender/nodes/NOD_geometry_exec.hh | 2 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_tree_multi_function.cc | 4 |
3 files changed, 9 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index f5ee2cf2bf5..c4a704ef385 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -23,6 +23,7 @@ #include "BKE_attribute.h" +#include "BLI_color.hh" #include "BLI_float3.hh" struct Mesh; @@ -267,10 +268,9 @@ template<typename T> class TypedWriteAttribute { using FloatReadAttribute = TypedReadAttribute<float>; using Float3ReadAttribute = TypedReadAttribute<float3>; +using Color4fReadAttribute = TypedReadAttribute<Color4f>; using FloatWriteAttribute = TypedWriteAttribute<float>; using Float3WriteAttribute = TypedWriteAttribute<float3>; - -const CPPType *custom_data_type_to_cpp_type(const CustomDataType type); -CustomDataType cpp_type_to_custom_data_type(const CPPType &type); +using Color4fWriteAttribute = TypedWriteAttribute<Color4f>; } // namespace blender::bke diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index 2b95f76d06b..fde576d7429 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -26,6 +26,8 @@ namespace blender::nodes { +using bke::Color4fReadAttribute; +using bke::Color4fWriteAttribute; using bke::Float3ReadAttribute; using bke::Float3WriteAttribute; using bke::FloatReadAttribute; diff --git a/source/blender/nodes/intern/node_tree_multi_function.cc b/source/blender/nodes/intern/node_tree_multi_function.cc index 8440e996651..ec5527a2970 100644 --- a/source/blender/nodes/intern/node_tree_multi_function.cc +++ b/source/blender/nodes/intern/node_tree_multi_function.cc @@ -204,6 +204,10 @@ static DataTypeConversions create_implicit_conversions() conversions, "float3 to Color4f", [](float3 a) { return Color4f(a.x, a.y, a.z, 1.0f); }); add_implicit_conversion<Color4f, float3>( conversions, "Color4f to float3", [](Color4f a) { return float3(a.r, a.g, a.b); }); + add_implicit_conversion<float, Color4f>( + conversions, "float to Color4f", [](float a) { return Color4f(a, a, a, 1.0f); }); + add_implicit_conversion<Color4f, float>( + conversions, "Color4f to float", [](Color4f a) { return rgb_to_grayscale(a); }); return conversions; } |