diff options
author | Jacques Lucke <jacques@blender.org> | 2022-03-19 12:57:40 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-03-19 12:57:40 +0300 |
commit | 8711483632823524019a6cc95575c5a4ba5aa831 (patch) | |
tree | 76c2f8355d0fce66f4f9e35b5ec1282960e51209 /source/blender/blenkernel/intern/customdata.cc | |
parent | 3e16f3b3ef4b8f385b30fe4a1e00860620f610ee (diff) |
BLI: generalize converting CPPType to static type
Previously, the conversion was done manually for a fixed set of types.
Now, there is a more general utility that can be used in other contexts
(outside of geometry nodes attribute processing) as well.
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.cc')
-rw-r--r-- | source/blender/blenkernel/intern/customdata.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index b348e18a6a8..251d73dc315 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -18,9 +18,11 @@ #include "DNA_meshdata_types.h" #include "BLI_bitmap.h" +#include "BLI_color.hh" #include "BLI_endian_switch.h" #include "BLI_math.h" #include "BLI_math_color_blend.h" +#include "BLI_math_vector.hh" #include "BLI_mempool.h" #include "BLI_path_util.h" #include "BLI_string.h" @@ -5234,3 +5236,56 @@ void CustomData_debug_info_from_layers(const CustomData *data, const char *inden } #endif /* NDEBUG */ + +namespace blender::bke { + +const blender::CPPType *custom_data_type_to_cpp_type(const CustomDataType type) +{ + switch (type) { + case CD_PROP_FLOAT: + return &CPPType::get<float>(); + case CD_PROP_FLOAT2: + return &CPPType::get<float2>(); + case CD_PROP_FLOAT3: + return &CPPType::get<float3>(); + case CD_PROP_INT32: + return &CPPType::get<int>(); + case CD_PROP_COLOR: + return &CPPType::get<ColorGeometry4f>(); + case CD_PROP_BOOL: + return &CPPType::get<bool>(); + case CD_PROP_INT8: + return &CPPType::get<int8_t>(); + default: + return nullptr; + } + return nullptr; +} + +CustomDataType cpp_type_to_custom_data_type(const blender::CPPType &type) +{ + if (type.is<float>()) { + return CD_PROP_FLOAT; + } + if (type.is<float2>()) { + return CD_PROP_FLOAT2; + } + if (type.is<float3>()) { + return CD_PROP_FLOAT3; + } + if (type.is<int>()) { + return CD_PROP_INT32; + } + if (type.is<ColorGeometry4f>()) { + return CD_PROP_COLOR; + } + if (type.is<bool>()) { + return CD_PROP_BOOL; + } + if (type.is<int8_t>()) { + return CD_PROP_INT8; + } + return static_cast<CustomDataType>(-1); +} + +} // namespace blender::bke |