Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_attribute_math.hh" | #include "BKE_attribute_math.hh" | ||||
| #include "NOD_socket_search_link.hh" | #include "NOD_socket_search_link.hh" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| ▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | public: | ||||
| std::optional<eAttrDomain> preferred_domain( | std::optional<eAttrDomain> preferred_domain( | ||||
| const GeometryComponent & /*component*/) const override | const GeometryComponent & /*component*/) const override | ||||
| { | { | ||||
| return source_domain_; | return source_domain_; | ||||
| } | } | ||||
| }; | }; | ||||
| template<typename T> std::string identifier_suffix() | |||||
| { | |||||
| if constexpr (std::is_same_v<T, int>) { | |||||
| return "Int"; | |||||
| } | |||||
| if constexpr (std::is_same_v<T, float>) { | |||||
| return "Float"; | |||||
| } | |||||
| if constexpr (std::is_same_v<T, float3>) { | |||||
| return "Vector"; | |||||
| } | |||||
| } | |||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| const NodeAccumulateField &storage = node_storage(params.node()); | const NodeAccumulateField &storage = node_storage(params.node()); | ||||
| const eCustomDataType data_type = eCustomDataType(storage.data_type); | const eCustomDataType data_type = eCustomDataType(storage.data_type); | ||||
| const eAttrDomain source_domain = eAttrDomain(storage.domain); | const eAttrDomain source_domain = eAttrDomain(storage.domain); | ||||
| Field<int> group_index_field = params.extract_input<Field<int>>("Group Index"); | Field<int> group_index_field = params.extract_input<Field<int>>("Group Index"); | ||||
| attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | ||||
| using T = decltype(dummy); | using T = decltype(dummy); | ||||
| if constexpr (std::is_same_v<T, int> || std::is_same_v<T, float> || | if constexpr (std::is_same_v<T, int> || std::is_same_v<T, float> || | ||||
| std::is_same_v<T, float3>) { | std::is_same_v<T, float3>) { | ||||
| const std::string suffix = " " + identifier_suffix<T>(); | const std::string suffix = " " + bke::type_name_identifier<T>(); | ||||
| Field<T> input_field = params.extract_input<Field<T>>("Value" + suffix); | Field<T> input_field = params.extract_input<Field<T>>("Value" + suffix); | ||||
| if (params.output_is_required("Leading" + suffix)) { | if (params.output_is_required("Leading" + suffix)) { | ||||
| params.set_output( | params.set_output( | ||||
| "Leading" + suffix, | "Leading" + suffix, | ||||
| Field<T>{std::make_shared<AccumulateFieldInput<T>>( | Field<T>{std::make_shared<AccumulateFieldInput<T>>( | ||||
| source_domain, input_field, group_index_field, AccumulationMode::Leading)}); | source_domain, input_field, group_index_field, AccumulationMode::Leading)}); | ||||
| } | } | ||||
| if (params.output_is_required("Trailing" + suffix)) { | if (params.output_is_required("Trailing" + suffix)) { | ||||
| Show All 32 Lines | |||||