Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-01-25 20:07:12 +0300
committerHans Goudey <h.goudey@me.com>2022-01-25 20:07:31 +0300
commit0ec94d5359d732c5ed819379d601ab2124798079 (patch)
treeed6120add58bc0a730ae899e4460693944e5965b /source/blender/nodes
parent932d8dba52abae669bfcfabf5dcdf9683e064473 (diff)
Geometry Nodes: Port weld modifier to the merge by distance node
This commit moves the weld modifier code to the geometry module so that it can be used in the "Merge by Distance" geometry node from ec1b0c2014a8b91c2. The "All" mode is exposed in the node for now, though we could expose the "Connected" mode in the future. The modifier itself is responsible for creating the selections from the vertex group. The "All" mode takes an `IndexMask` for the selection, and the "Connected" mode takes a boolean array, since it actually iterates over all edges. Some disabled code for a BVH mode has not been copied over, it's still accessible through the patches and git history anyway, and it made the port slightly simpler. Differential Revision: https://developer.blender.org/D13907
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
index 54006062374..deb149fd0f0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
@@ -14,6 +14,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "GEO_mesh_merge_by_distance.hh"
#include "GEO_point_merge_by_distance.hh"
#include "node_geometry_util.hh"
@@ -22,7 +23,8 @@ namespace blender::nodes::node_geo_merge_by_distance_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Geometry>(N_("Geometry")).supported_type({GEO_COMPONENT_TYPE_POINT_CLOUD});
+ b.add_input<decl::Geometry>(N_("Geometry"))
+ .supported_type({GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_MESH});
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
b.add_input<decl::Float>(N_("Distance")).default_value(0.1f).min(0.0f).subtype(PROP_DISTANCE);
b.add_output<decl::Geometry>(N_("Geometry"));
@@ -46,6 +48,25 @@ static PointCloud *pointcloud_merge_by_distance(const PointCloudComponent &src_p
return geometry::point_merge_by_distance(src_points, merge_distance, selection);
}
+static std::optional<Mesh *> mesh_merge_by_distance(const MeshComponent &mesh_component,
+ const float merge_distance,
+ const Field<bool> &selection_field)
+{
+ const int src_size = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_POINT};
+ FieldEvaluator evaluator{context, src_size};
+ evaluator.add(selection_field);
+ evaluator.evaluate();
+
+ const IndexMask selection = evaluator.get_evaluated_as_mask(0);
+ if (selection.is_empty()) {
+ return nullptr;
+ }
+
+ const Mesh &mesh = *mesh_component.get_for_read();
+ return geometry::mesh_merge_by_distance_all(mesh, selection, merge_distance);
+}
+
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
@@ -59,6 +80,13 @@ static void node_geo_exec(GeoNodeExecParams params)
*geometry_set.get_component_for_read<PointCloudComponent>(), merge_distance, selection);
geometry_set.replace_pointcloud(result);
}
+ if (geometry_set.has_mesh()) {
+ std::optional<Mesh *> result = mesh_merge_by_distance(
+ *geometry_set.get_component_for_read<MeshComponent>(), merge_distance, selection);
+ if (result) {
+ geometry_set.replace_mesh(*result);
+ }
+ }
});
params.set_output("Geometry", std::move(geometry_set));