Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_field_on_domain.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #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" | ||||
| #include "BKE_attribute_math.hh" | #include "BKE_attribute_math.hh" | ||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| namespace blender::nodes::node_geo_field_on_domain_cc { | namespace blender::nodes::node_geo_field_on_domain_cc { | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Float>(N_("Value"), "Value_Float").supports_field(); | b.add_input<decl::Float>(N_("Value"), "Float").supports_field(); | ||||
| b.add_input<decl::Int>(N_("Value"), "Value_Int").supports_field(); | b.add_input<decl::Int>(N_("Value"), "Int").supports_field(); | ||||
| b.add_input<decl::Vector>(N_("Value"), "Value_Vector").supports_field(); | b.add_input<decl::Vector>(N_("Value"), "Vector").supports_field(); | ||||
| b.add_input<decl::Color>(N_("Value"), "Value_Color").supports_field(); | b.add_input<decl::Color>(N_("Value"), "Color").supports_field(); | ||||
| b.add_input<decl::Bool>(N_("Value"), "Value_Bool").supports_field(); | b.add_input<decl::Bool>(N_("Value"), "Bool").supports_field(); | ||||
| b.add_output<decl::Float>(N_("Value"), "Value_Float").field_source(); | b.add_output<decl::Float>(N_("Value"), "Float").field_source(); | ||||
| b.add_output<decl::Int>(N_("Value"), "Value_Int").field_source(); | b.add_output<decl::Int>(N_("Value"), "Int").field_source(); | ||||
| b.add_output<decl::Vector>(N_("Value"), "Value_Vector").field_source(); | b.add_output<decl::Vector>(N_("Value"), "Vector").field_source(); | ||||
| b.add_output<decl::Color>(N_("Value"), "Value_Color").field_source(); | b.add_output<decl::Color>(N_("Value"), "Color").field_source(); | ||||
| b.add_output<decl::Bool>(N_("Value"), "Value_Bool").field_source(); | b.add_output<decl::Bool>(N_("Value"), "Bool").field_source(); | ||||
| } | } | ||||
| static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | ||||
| { | { | ||||
| uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); | uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); | ||||
| uiItemR(layout, ptr, "domain", 0, "", ICON_NONE); | uiItemR(layout, ptr, "domain", 0, "", ICON_NONE); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | GVArray get_varray_for_context(const GeometryComponent &component, | ||||
| value_evaluator.add(src_field_); | value_evaluator.add(src_field_); | ||||
| value_evaluator.evaluate(); | value_evaluator.evaluate(); | ||||
| const GVArray &values = value_evaluator.get_evaluated(0); | const GVArray &values = value_evaluator.get_evaluated(0); | ||||
| return component.attribute_try_adapt_domain(values, src_domain_, domain); | return component.attribute_try_adapt_domain(values, src_domain_, domain); | ||||
| } | } | ||||
| }; | }; | ||||
| static StringRefNull identifier_suffix(eCustomDataType data_type) | |||||
| { | |||||
| switch (data_type) { | |||||
| case CD_PROP_BOOL: | |||||
| return "Bool"; | |||||
| case CD_PROP_FLOAT: | |||||
| return "Float"; | |||||
| case CD_PROP_INT32: | |||||
| return "Int"; | |||||
| case CD_PROP_COLOR: | |||||
| return "Color"; | |||||
| case CD_PROP_FLOAT3: | |||||
| return "Vector"; | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| return ""; | |||||
| } | |||||
| } | |||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| const bNode &node = params.node(); | const bNode &node = params.node(); | ||||
| const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1); | const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1); | ||||
| const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom2); | const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom2); | ||||
| 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); | ||||
| static const std::string identifier = "Value_" + identifier_suffix(data_type); | Field<T> src_field = params.extract_input<Field<T>>(attribute_math::default_name<T>()); | ||||
| Field<T> src_field = params.extract_input<Field<T>>(identifier); | |||||
| Field<T> dst_field{std::make_shared<FieldOnDomain>(std::move(src_field), domain)}; | Field<T> dst_field{std::make_shared<FieldOnDomain>(std::move(src_field), domain)}; | ||||
| params.set_output(identifier, std::move(dst_field)); | params.set_output(attribute_math::default_name<T>(), std::move(dst_field)); | ||||
| }); | }); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_geo_field_on_domain_cc | } // namespace blender::nodes::node_geo_field_on_domain_cc | ||||
| void register_node_type_geo_field_on_domain() | void register_node_type_geo_field_on_domain() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_field_on_domain_cc; | namespace file_ns = blender::nodes::node_geo_field_on_domain_cc; | ||||
| Show All 11 Lines | |||||