Geometry Nodes: add utility to convert CPPType to static type

This commit is contained in:
Jacques Lucke 2021-04-21 16:57:43 +02:00
parent 9fa9854e2a
commit b9cbf7fc80
1 changed files with 29 additions and 0 deletions

View File

@ -21,8 +21,12 @@
#include "DNA_customdata_types.h"
#include "FN_cpp_type.hh"
namespace blender::attribute_math {
using fn::CPPType;
/**
* Utility function that simplifies calling a templated function based on a custom data type.
*/
@ -54,6 +58,31 @@ void convert_to_static_type(const CustomDataType data_type, const Func &func)
}
}
template<typename Func> void convert_to_static_type(const fn::CPPType &cpp_type, const Func &func)
{
if (cpp_type.is<float>()) {
func(float());
}
else if (cpp_type.is<float2>()) {
func(float2());
}
else if (cpp_type.is<float3>()) {
func(float3());
}
else if (cpp_type.is<int>()) {
func(int());
}
else if (cpp_type.is<bool>()) {
func(bool());
}
else if (cpp_type.is<Color4f>()) {
func(Color4f());
}
else {
BLI_assert_unreachable();
}
}
/* -------------------------------------------------------------------- */
/** \name Mix three values of the same type.
*