[Bf-blender-cvs] [91b44ebb522] geometry-nodes-curve-support: Geometry Nodes Curves: Support curves in the join geometry node

Hans Goudey noreply at git.blender.org
Thu Apr 15 20:20:21 CEST 2021


Commit: 91b44ebb52210f38113c184230279a0acff82e76
Author: Hans Goudey
Date:   Thu Apr 15 13:20:15 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rB91b44ebb52210f38113c184230279a0acff82e76

Geometry Nodes Curves: Support curves in the join geometry node

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index 52512769a47..d588830eb4d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -14,6 +14,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "BKE_derived_curve.hh"
 #include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
 #include "BKE_pointcloud.h"
@@ -262,6 +263,48 @@ static void join_components(Span<const VolumeComponent *> src_components, Geomet
   UNUSED_VARS(src_components, dst_component);
 }
 
+/**
+ * Curve components are a special case, retrieved with write access as an optimization
+ * to avoid copying unecessarily when possible.
+ */
+static void join_curve_components(MutableSpan<GeometrySet> src_geometry_sets, GeometrySet &result)
+{
+
+  Vector<CurveComponent *> src_components;
+  for (GeometrySet &geometry_set : src_geometry_sets) {
+    if (geometry_set.has_curve()) {
+      /* Getting write access for write access seems counterintuitive at first, but it can actually
+       * allow avoiding a copy in the case where the input spline has no other users, because the
+       * splines can be moved from the source curve rather than copying them from a read-only
+       * source. Retrieving the curve for write will make a copy only when necessary. */
+      CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>();
+      src_components.append(&component);
+    }
+  }
+
+  if (src_components.size() == 0) {
+    return;
+  }
+  if (src_components.size() == 1) {
+    result.add(*src_components[0]);
+    return;
+  }
+
+  CurveComponent &dst_component = result.get_component_for_write<CurveComponent>();
+  DCurve *dst_curve = new DCurve();
+  for (CurveComponent *component : src_components) {
+
+    DCurve *src_curve = component->get_for_write();
+    for (SplinePtr &spline : src_curve->splines) {
+      dst_curve->splines.append(std::move(spline));
+    }
+  }
+
+  dst_component.replace(dst_curve);
+
+  /* TODO: Make sure generic attributes in different splines have the same type. */
+}
+
 template<typename Component>
 static void join_component_type(Span<GeometrySet> src_geometry_sets, GeometrySet &result)
 {
@@ -292,6 +335,7 @@ static void geo_node_join_geometry_exec(GeoNodeExecParams params)
   join_component_type<PointCloudComponent>(geometry_sets, geometry_set_result);
   join_component_type<InstancesComponent>(geometry_sets, geometry_set_result);
   join_component_type<VolumeComponent>(geometry_sets, geometry_set_result);
+  join_curve_components(geometry_sets, geometry_set_result);
 
   params.set_output("Geometry", std::move(geometry_set_result));
 }



More information about the Bf-blender-cvs mailing list