Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_attribute_math.hh" | #include "BKE_attribute_math.hh" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "NOD_socket_search_link.hh" | #include "NOD_socket_search_link.hh" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| ▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | attribute_math::convert_to_static_type(type, [&](auto dummy) { | ||||
| } | } | ||||
| else { | else { | ||||
| copy_with_indices(src_data_->typed<T>(), indices, mask, dst.typed<T>()); | copy_with_indices(src_data_->typed<T>(), indices, mask, dst.typed<T>()); | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| }; | }; | ||||
| static GField get_input_attribute_field(GeoNodeExecParams ¶ms, const eCustomDataType data_type) | |||||
| { | |||||
| switch (data_type) { | |||||
| case CD_PROP_FLOAT: | |||||
| return params.extract_input<Field<float>>("Value_Float"); | |||||
| case CD_PROP_FLOAT3: | |||||
| return params.extract_input<Field<float3>>("Value_Vector"); | |||||
| case CD_PROP_COLOR: | |||||
| return params.extract_input<Field<ColorGeometry4f>>("Value_Color"); | |||||
| case CD_PROP_BOOL: | |||||
| return params.extract_input<Field<bool>>("Value_Bool"); | |||||
| case CD_PROP_INT32: | |||||
| return params.extract_input<Field<int>>("Value_Int"); | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| } | |||||
| return {}; | |||||
| } | |||||
| static void output_attribute_field(GeoNodeExecParams ¶ms, GField field) | |||||
| { | |||||
| switch (bke::cpp_type_to_custom_data_type(field.cpp_type())) { | |||||
| case CD_PROP_FLOAT: { | |||||
| params.set_output("Value_Float", Field<float>(field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_FLOAT3: { | |||||
| params.set_output("Value_Vector", Field<float3>(field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_COLOR: { | |||||
| params.set_output("Value_Color", Field<ColorGeometry4f>(field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_BOOL: { | |||||
| params.set_output("Value_Bool", Field<bool>(field)); | |||||
| break; | |||||
| } | |||||
| case CD_PROP_INT32: { | |||||
| params.set_output("Value_Int", Field<int>(field)); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry = params.extract_input<GeometrySet>("Geometry"); | ||||
| const NodeGeometrySampleIndex &storage = node_storage(params.node()); | const NodeGeometrySampleIndex &storage = node_storage(params.node()); | ||||
| const eCustomDataType data_type = eCustomDataType(storage.data_type); | const eCustomDataType data_type = eCustomDataType(storage.data_type); | ||||
| const eAttrDomain domain = eAttrDomain(storage.domain); | const eAttrDomain domain = eAttrDomain(storage.domain); | ||||
| auto fn = std::make_shared<SampleIndexFunction>(std::move(geometry), | const std::string identifier = "Value_" + bke::type_name_identifier(data_type); | ||||
| get_input_attribute_field(params, data_type), | |||||
| domain, | GField field; | ||||
| bool(storage.clamp)); | |||||
| attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | |||||
| using T = decltype(dummy); | |||||
| field = params.get_input<Field<T>>(identifier); | |||||
| }); | |||||
| auto fn = std::make_shared<SampleIndexFunction>( | |||||
| std::move(geometry), field, domain, bool(storage.clamp)); | |||||
| auto op = FieldOperation::Create(std::move(fn), {params.extract_input<Field<int>>("Index")}); | auto op = FieldOperation::Create(std::move(fn), {params.extract_input<Field<int>>("Index")}); | ||||
| output_attribute_field(params, GField(std::move(op))); | |||||
| attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | |||||
| using T = decltype(dummy); | |||||
| params.set_output(identifier, Field<T>(std::move(op))); | |||||
| }); | |||||
| } | } | ||||
| } // namespace blender::nodes::node_geo_sample_index_cc | } // namespace blender::nodes::node_geo_sample_index_cc | ||||
| void register_node_type_geo_sample_index() | void register_node_type_geo_sample_index() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_sample_index_cc; | namespace file_ns = blender::nodes::node_geo_sample_index_cc; | ||||
| Show All 13 Lines | |||||