Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
| Show All 9 Lines | |||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| namespace blender::nodes::node_geo_field_at_index_cc { | namespace blender::nodes::node_geo_field_at_index_cc { | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Int>(N_("Index")).min(0).supports_field(); | b.add_input<decl::Int>(N_("Index")).min(0).supports_field(); | ||||
| 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 83 Lines • ▼ Show 20 Lines | attribute_math::convert_to_static_type(*type_, [&](auto dummy) { | ||||
| }); | }); | ||||
| output_array = VArray<T>::ForContainer(std::move(dst_array)); | output_array = VArray<T>::ForContainer(std::move(dst_array)); | ||||
| }); | }); | ||||
| return output_array; | return output_array; | ||||
| } | } | ||||
| }; | }; | ||||
| 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); | ||||
| Field<int> index_field = params.extract_input<Field<int>>("Index"); | Field<int> index_field = params.extract_input<Field<int>>("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); | ||||
| static const std::string identifier = "Value_" + identifier_suffix(data_type); | Field<T> value_field = params.extract_input<Field<T>>(attribute_math::default_name<T>()); | ||||
| Field<T> value_field = params.extract_input<Field<T>>(identifier); | |||||
| Field<T> output_field{ | Field<T> output_field{ | ||||
| std::make_shared<FieldAtIndex>(std::move(index_field), std::move(value_field), domain)}; | std::make_shared<FieldAtIndex>(std::move(index_field), std::move(value_field), domain)}; | ||||
| params.set_output(identifier, std::move(output_field)); | params.set_output(attribute_math::default_name<T>(), std::move(output_field)); | ||||
| }); | }); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_geo_field_at_index_cc | } // namespace blender::nodes::node_geo_field_at_index_cc | ||||
| void register_node_type_geo_field_at_index() | void register_node_type_geo_field_at_index() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_field_at_index_cc; | namespace file_ns = blender::nodes::node_geo_field_at_index_cc; | ||||
| Show All 11 Lines | |||||