Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/BKE_attribute_math.hh
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | case CD_PROP_FLOAT3: | ||||
| break; | break; | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| func(int()); | func(int()); | ||||
| break; | break; | ||||
| case CD_PROP_BOOL: | case CD_PROP_BOOL: | ||||
| func(bool()); | func(bool()); | ||||
| break; | break; | ||||
| case CD_PROP_COLOR: | case CD_PROP_COLOR: | ||||
| func(Color4f()); | func(ColorGeometry4f()); | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert_unreachable(); | BLI_assert_unreachable(); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| template<typename Func> | template<typename Func> | ||||
| Show All 9 Lines | else if (cpp_type.is<float3>()) { | ||||
| func(float3()); | func(float3()); | ||||
| } | } | ||||
| else if (cpp_type.is<int>()) { | else if (cpp_type.is<int>()) { | ||||
| func(int()); | func(int()); | ||||
| } | } | ||||
| else if (cpp_type.is<bool>()) { | else if (cpp_type.is<bool>()) { | ||||
| func(bool()); | func(bool()); | ||||
| } | } | ||||
| else if (cpp_type.is<Color4f>()) { | else if (cpp_type.is<ColorGeometry4f>()) { | ||||
| func(Color4f()); | func(ColorGeometry4f()); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert_unreachable(); | BLI_assert_unreachable(); | ||||
| } | } | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mix three values of the same type. | /** \name Mix three values of the same type. | ||||
| Show All 27 Lines | |||||
| template<> | template<> | ||||
| inline float3 mix3(const float3 &weights, const float3 &v0, const float3 &v1, const float3 &v2) | inline float3 mix3(const float3 &weights, const float3 &v0, const float3 &v1, const float3 &v2) | ||||
| { | { | ||||
| return weights.x * v0 + weights.y * v1 + weights.z * v2; | return weights.x * v0 + weights.y * v1 + weights.z * v2; | ||||
| } | } | ||||
| template<> | template<> | ||||
| inline Color4f mix3(const float3 &weights, const Color4f &v0, const Color4f &v1, const Color4f &v2) | inline ColorGeometry4f mix3(const float3 &weights, | ||||
| const ColorGeometry4f &v0, | |||||
| const ColorGeometry4f &v1, | |||||
| const ColorGeometry4f &v2) | |||||
| { | { | ||||
| Color4f result; | ColorGeometry4f result; | ||||
| interp_v4_v4v4v4(result, v0, v1, v2, weights); | interp_v4_v4v4v4(result, v0, v1, v2, weights); | ||||
| return result; | return result; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mix two values of the same type. | /** \name Mix two values of the same type. | ||||
| Show All 23 Lines | template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) | ||||
| return float2::interpolate(a, b, factor); | return float2::interpolate(a, b, factor); | ||||
| } | } | ||||
| template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) | template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) | ||||
| { | { | ||||
| return float3::interpolate(a, b, factor); | return float3::interpolate(a, b, factor); | ||||
| } | } | ||||
| template<> inline Color4f mix2(const float factor, const Color4f &a, const Color4f &b) | template<> | ||||
| inline ColorGeometry4f mix2(const float factor, const ColorGeometry4f &a, const ColorGeometry4f &b) | |||||
| { | { | ||||
| Color4f result; | ColorGeometry4f result; | ||||
| interp_v4_v4v4(result, a, b, factor); | interp_v4_v4v4(result, a, b, factor); | ||||
| return result; | return result; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mix a dynamic amount of values with weights for many elements. | /** \name Mix a dynamic amount of values with weights for many elements. | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | for (const int64_t i : buffer_.index_range()) { | ||||
| } | } | ||||
| else { | else { | ||||
| buffer_[i] = default_value_; | buffer_[i] = default_value_; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| class Color4fMixer { | class ColorGeometryMixer { | ||||
| private: | private: | ||||
| MutableSpan<Color4f> buffer_; | MutableSpan<ColorGeometry4f> buffer_; | ||||
| Color4f default_color_; | ColorGeometry4f default_color_; | ||||
| Array<float> total_weights_; | Array<float> total_weights_; | ||||
| public: | public: | ||||
| Color4fMixer(MutableSpan<Color4f> buffer, Color4f default_color = {0, 0, 0, 1}); | ColorGeometryMixer(MutableSpan<ColorGeometry4f> buffer, | ||||
| void mix_in(const int64_t index, const Color4f &color, const float weight = 1.0f); | ColorGeometry4f default_color = ColorGeometry4f(0.0f, 0.0f, 0.0f, 1.0f)); | ||||
| void mix_in(const int64_t index, const ColorGeometry4f &color, const float weight = 1.0f); | |||||
| void finalize(); | void finalize(); | ||||
| }; | }; | ||||
| template<typename T> struct DefaultMixerStruct { | template<typename T> struct DefaultMixerStruct { | ||||
| /* Use void by default. This can be check for in `if constexpr` statements. */ | /* Use void by default. This can be check for in `if constexpr` statements. */ | ||||
| using type = void; | using type = void; | ||||
| }; | }; | ||||
| template<> struct DefaultMixerStruct<float> { | template<> struct DefaultMixerStruct<float> { | ||||
| using type = SimpleMixer<float>; | using type = SimpleMixer<float>; | ||||
| }; | }; | ||||
| template<> struct DefaultMixerStruct<float2> { | template<> struct DefaultMixerStruct<float2> { | ||||
| using type = SimpleMixer<float2>; | using type = SimpleMixer<float2>; | ||||
| }; | }; | ||||
| template<> struct DefaultMixerStruct<float3> { | template<> struct DefaultMixerStruct<float3> { | ||||
| using type = SimpleMixer<float3>; | using type = SimpleMixer<float3>; | ||||
| }; | }; | ||||
| template<> struct DefaultMixerStruct<Color4f> { | template<> struct DefaultMixerStruct<ColorGeometry4f> { | ||||
| /* Use a special mixer for colors. Color4f can't be added/multiplied, because this is not | /* Use a special mixer for colors. ColorGeometry4f can't be added/multiplied, because this is not | ||||
| * something one should usually do with colors. */ | * something one should usually do with colors. */ | ||||
| using type = Color4fMixer; | using type = ColorGeometryMixer; | ||||
| }; | }; | ||||
| template<> struct DefaultMixerStruct<int> { | template<> struct DefaultMixerStruct<int> { | ||||
| static int double_to_int(const double &value) | static int double_to_int(const double &value) | ||||
| { | { | ||||
| return static_cast<int>(value); | return static_cast<int>(value); | ||||
| } | } | ||||
| /* Store interpolated ints in a double temporarily, so that weights are handled correctly. It | /* Store interpolated ints in a double temporarily, so that weights are handled correctly. It | ||||
| * uses double instead of float so that it is accurate for all 32 bit integers. */ | * uses double instead of float so that it is accurate for all 32 bit integers. */ | ||||
| Show All 19 Lines | |||||