Geometry Nodes: improve support for Color attributes

* Add typed attribute accessors for color attributes.
* Support implicit conversions between colors and floats.
This commit is contained in:
Jacques Lucke 2020-12-03 16:25:48 +01:00
parent 2c181521ec
commit 107231eb95
3 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -26,6 +26,8 @@
namespace blender::nodes {
using bke::Color4fReadAttribute;
using bke::Color4fWriteAttribute;
using bke::Float3ReadAttribute;
using bke::Float3WriteAttribute;
using bke::FloatReadAttribute;

View File

@ -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;
}