Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/BKE_attribute_math.hh
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #pragma once | #pragma once | ||||
| #include "BLI_array.hh" | #include "BLI_array.hh" | ||||
| #include "BLI_color.hh" | #include "BLI_color.hh" | ||||
| #include "BLI_cpp_type.hh" | #include "BLI_cpp_type.hh" | ||||
| #include "BLI_math_vector.h" | #include "BLI_math_vector.h" | ||||
| #include "BLI_math_vector.hh" | #include "BLI_math_vector.hh" | ||||
| #include "DNA_customdata_types.h" | #include "BKE_customdata.h" | ||||
| namespace blender::attribute_math { | namespace blender::attribute_math { | ||||
| /** | /** | ||||
| * Utility function that simplifies calling a templated function based on a custom data type. | * Utility function that simplifies calling a templated function based on a run-time data type. | ||||
| */ | */ | ||||
| template<typename Func> | template<typename Func> | ||||
| inline void convert_to_static_type(const CustomDataType data_type, const Func &func) | inline void convert_to_static_type(const CPPType &cpp_type, const Func &func) | ||||
| { | { | ||||
| switch (data_type) { | cpp_type.to_static_type_tag<float, float2, float3, int, bool, int8_t, ColorGeometry4f>( | ||||
| case CD_PROP_FLOAT: | [&](auto type_tag) { | ||||
| func(float()); | using T = typename decltype(type_tag)::type; | ||||
| break; | if constexpr (std::is_same_v<T, void>) { | ||||
| case CD_PROP_FLOAT2: | /* It's expected that the given cpp type is one of the supported once. */ | ||||
| func(float2()); | |||||
| break; | |||||
| case CD_PROP_FLOAT3: | |||||
| func(float3()); | |||||
| break; | |||||
| case CD_PROP_INT32: | |||||
| func(int()); | |||||
| break; | |||||
| case CD_PROP_BOOL: | |||||
| func(bool()); | |||||
| break; | |||||
| case CD_PROP_INT8: | |||||
| func(int8_t()); | |||||
| break; | |||||
| case CD_PROP_COLOR: | |||||
| func(ColorGeometry4f()); | |||||
| break; | |||||
| default: | |||||
| BLI_assert_unreachable(); | BLI_assert_unreachable(); | ||||
| break; | |||||
| } | } | ||||
| else { | |||||
| func(T()); | |||||
| } | |||||
| }); | |||||
| } | } | ||||
| template<typename Func> | template<typename Func> | ||||
| inline void convert_to_static_type(const CPPType &cpp_type, const Func &func) | inline void convert_to_static_type(const CustomDataType data_type, const Func &func) | ||||
| { | { | ||||
| if (cpp_type.is<float>()) { | const CPPType &cpp_type = *bke::custom_data_type_to_cpp_type(data_type); | ||||
| func(float()); | convert_to_static_type(cpp_type, func); | ||||
| } | |||||
| 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<int8_t>()) { | |||||
| func(int8_t()); | |||||
| } | |||||
| else if (cpp_type.is<ColorGeometry4f>()) { | |||||
| func(ColorGeometry4f()); | |||||
| } | |||||
| else { | |||||
| BLI_assert_unreachable(); | |||||
| } | |||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mix three values of the same type. | /** \name Mix three values of the same type. | ||||
| * | * | ||||
| * This is typically used to interpolate values within a triangle. | * This is typically used to interpolate values within a triangle. | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 317 Lines • Show Last 20 Lines | |||||