Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | static std::optional<Mesh *> mesh_merge_by_distance(const MeshComponent &mesh_component, | ||||
| const int src_size = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT); | const int src_size = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT); | ||||
| GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_POINT}; | GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_POINT}; | ||||
| FieldEvaluator evaluator{context, src_size}; | FieldEvaluator evaluator{context, src_size}; | ||||
| evaluator.add(selection_field); | evaluator.add(selection_field); | ||||
| evaluator.evaluate(); | evaluator.evaluate(); | ||||
| const IndexMask selection = evaluator.get_evaluated_as_mask(0); | const IndexMask selection = evaluator.get_evaluated_as_mask(0); | ||||
| if (selection.is_empty()) { | if (selection.is_empty()) { | ||||
| return nullptr; | return std::nullopt; | ||||
| } | } | ||||
| const Mesh &mesh = *mesh_component.get_for_read(); | const Mesh &mesh = *mesh_component.get_for_read(); | ||||
| return geometry::mesh_merge_by_distance_all(mesh, selection, merge_distance); | return geometry::mesh_merge_by_distance_all(mesh, selection, merge_distance); | ||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| const Field<bool> selection = params.extract_input<Field<bool>>("Selection"); | const Field<bool> selection = params.extract_input<Field<bool>>("Selection"); | ||||
| const float merge_distance = params.extract_input<float>("Distance"); | const float merge_distance = params.extract_input<float>("Distance"); | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| if (geometry_set.has_pointcloud()) { | if (geometry_set.has_pointcloud()) { | ||||
| PointCloud *result = pointcloud_merge_by_distance( | PointCloud *result = pointcloud_merge_by_distance( | ||||
| *geometry_set.get_component_for_read<PointCloudComponent>(), merge_distance, selection); | *geometry_set.get_component_for_read<PointCloudComponent>(), merge_distance, selection); | ||||
| if (result) { | |||||
| geometry_set.replace_pointcloud(result); | geometry_set.replace_pointcloud(result); | ||||
| } | } | ||||
| } | |||||
| if (geometry_set.has_mesh()) { | if (geometry_set.has_mesh()) { | ||||
| std::optional<Mesh *> result = mesh_merge_by_distance( | std::optional<Mesh *> result = mesh_merge_by_distance( | ||||
| *geometry_set.get_component_for_read<MeshComponent>(), merge_distance, selection); | *geometry_set.get_component_for_read<MeshComponent>(), merge_distance, selection); | ||||
| if (result) { | if (result) { | ||||
| geometry_set.replace_mesh(*result); | geometry_set.replace_mesh(*result); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| Show All 18 Lines | |||||