[Bf-blender-cvs] [63a8b3b9720] master: Geometry Nodes: Curve Endpoints Node

Angus Stanton noreply at git.blender.org
Wed Jul 7 05:24:18 CEST 2021


Commit: 63a8b3b9720cf2660cb7a6cd431fdd3014534c4a
Author: Angus Stanton
Date:   Tue Jul 6 22:24:04 2021 -0500
Branches: master
https://developer.blender.org/rB63a8b3b9720cf2660cb7a6cd431fdd3014534c4a

Geometry Nodes: Curve Endpoints Node

This node is quite similar to the curve to points node, but creates
points for only the start and end of each spline. This is a separate
node because the sampling from the curve to points node don't apply,
and just for ease of use.

All attributes from the curves are copied, including the data for
instancing: tangents, normals, and the derived rotations. One simple
use case is to make round caps on curves by instancinghalves of a
sphere on each end of the splines.

Differential Revision: https://developer.blender.org/D11719

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/geometry/node_geometry_util.hh
A	source/blender/nodes/geometry/nodes/node_geo_curve_endpoints.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b25d2be7de0..e8be38bccb6 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -506,6 +506,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeCurveResample"),
         NodeItem("GeometryNodeMeshToCurve"),
         NodeItem("GeometryNodeCurveToPoints"),
+        NodeItem("GeometryNodeCurveEndpoints"),
         NodeItem("GeometryNodeCurveLength"),
         NodeItem("GeometryNodeCurveReverse"),
     ]),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 301fe875d79..fcf1f3a0b52 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1457,6 +1457,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_CURVE_PRIMITIVE_CIRCLE 1066
 #define GEO_NODE_VIEWER 1067
 #define GEO_NODE_CURVE_PRIMITIVE_LINE 1068
+#define GEO_NODE_CURVE_ENDPOINTS 1069
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 6a6cc3ffaad..49fe2e66e05 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5115,6 +5115,7 @@ static void registerGeometryNodes()
   register_node_type_geo_bounding_box();
   register_node_type_geo_collection_info();
   register_node_type_geo_convex_hull();
+  register_node_type_geo_curve_endpoints();
   register_node_type_geo_curve_length();
   register_node_type_geo_curve_primitive_bezier_segment();
   register_node_type_geo_curve_primitive_circle();
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 74ba85426c6..603d4e32ee1 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -164,6 +164,7 @@ set(SRC
   geometry/nodes/node_geo_collection_info.cc
   geometry/nodes/node_geo_common.cc
   geometry/nodes/node_geo_convex_hull.cc
+  geometry/nodes/node_geo_curve_endpoints.cc
   geometry/nodes/node_geo_curve_length.cc  
   geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
   geometry/nodes/node_geo_curve_primitive_circle.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 99f95e7f07e..8144e2a2696 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -51,6 +51,7 @@ void register_node_type_geo_boolean(void);
 void register_node_type_geo_bounding_box(void);
 void register_node_type_geo_collection_info(void);
 void register_node_type_geo_convex_hull(void);
+void register_node_type_geo_curve_endpoints(void);
 void register_node_type_geo_curve_length(void);
 void register_node_type_geo_curve_primitive_bezier_segment(void);
 void register_node_type_geo_curve_primitive_circle(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 2d15fcca24b..ccf009fe6e9 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -303,6 +303,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_REVERSE, 0, "CURVE_REVERSE", CurveReverse, "Curve Reverse", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_POINTS, def_geo_curve_to_points, "CURVE_TO_POINTS", CurveToPoints, "Curve to Points", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINTS, 0, "CURVE_ENDPOINTS", CurveEndpoints, "Curve Endpoints", "")
 DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, 0, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "")
 DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 79a98c5ebf0..956b7b8a005 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -70,4 +70,26 @@ void copy_point_attributes_based_on_mask(const GeometryComponent &in_component,
                                          Span<bool> masks,
                                          const bool invert);
 
+struct CurveToPointsResults {
+  int result_size;
+  MutableSpan<float3> positions;
+  MutableSpan<float> radii;
+  MutableSpan<float> tilts;
+
+  Map<std::string, GMutableSpan> point_attributes;
+
+  MutableSpan<float3> tangents;
+  MutableSpan<float3> normals;
+  MutableSpan<float3> rotations;
+};
+/**
+ * Create references for all result point cloud attributes to simplify accessing them later on.
+ */
+CurveToPointsResults curve_to_points_create_result_attributes(PointCloudComponent &points,
+                                                              const CurveEval &curve);
+
+void curve_create_default_rotation_attribute(Span<float3> tangents,
+                                             Span<float3> normals,
+                                             MutableSpan<float3> rotations);
+
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_endpoints.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoints.cc
new file mode 100644
index 00000000000..4f86a7ef88a
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoints.cc
@@ -0,0 +1,221 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "BLI_task.hh"
+#include "BLI_timeit.hh"
+
+#include "BKE_pointcloud.h"
+#include "BKE_spline.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_curve_endpoints_in[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_curve_endpoints_out[] = {
+    {SOCK_GEOMETRY, N_("Start Points")},
+    {SOCK_GEOMETRY, N_("End Points")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+/**
+ * Evaluate splines in parallel to speed up the rest of the node's execution.
+ */
+static void evaluate_splines(Span<SplinePtr> splines)
+{
+  threading::parallel_for_each(splines, [](const SplinePtr &spline) {
+    /* These functions fill the corresponding caches on each spline. */
+    spline->evaluated_positions();
+    spline->evaluated_tangents();
+    spline->evaluated_normals();
+    spline->evaluated_lengths();
+  });
+}
+
+/**
+ * \note Use attributes from the curve component rather than the attribute data directly on the
+ * attribute storage to allow reading the virtual spline attributes like "cyclic" and "resolution".
+ */
+static void copy_spline_domain_attributes(const CurveComponent &curve_component,
+                                          Span<int> offsets,
+                                          PointCloudComponent &points)
+{
+  curve_component.attribute_foreach([&](StringRefNull name, const AttributeMetaData &meta_data) {
+    if (meta_data.domain != ATTR_DOMAIN_CURVE) {
+      return true;
+    }
+    GVArrayPtr spline_attribute = curve_component.attribute_get_for_read(
+        name, ATTR_DOMAIN_CURVE, meta_data.data_type);
+
+    OutputAttribute result_attribute = points.attribute_try_get_for_output_only(
+        name, ATTR_DOMAIN_POINT, meta_data.data_type);
+    GMutableSpan result = result_attribute.as_span();
+
+    /* Only copy the attributes of splines in the offsets. */
+    for (const int i : offsets.index_range()) {
+      spline_attribute->get(offsets[i], result[i]);
+    }
+
+    result_attribute.save();
+    return true;
+  });
+}
+
+/* Get the offsets for the splines whose endpoints we want to output. Filter those which are cylic,
+ * or that evaluate to empty. Could be easily adapted to include a selection argument to support
+ * attribute selection. */
+static blender::Vector<int> get_endpoint_spline_offsets(Span<SplinePtr> splines)
+{
+  blender::Vector<int> spline_offsets;
+  spline_offsets.reserve(splines.size());
+
+  for (const int i : splines.index_range()) {
+    if (!(splines[i]->is_cyclic() || splines[i]->evaluated_points_size() == 0)) {
+      spline_offsets.append(i);
+    }
+  }
+
+  return spline_offsets;
+}
+
+/**
+ * Copy the endpoint attributes from the correct positions at the splines at the offsets to
+ * the start and end attributes.
+ */
+static void copy_endpoint_attributes(Span<SplinePtr> splines,
+                                     Span<int> offsets,
+                                     CurveToPointsResults &start_data,
+                                     CurveToPointsResults &end_data)
+{
+  threading::parallel_for(offsets.index_range(), 64, [&](IndexRange range) {
+    for (const int i : range) {
+      const Spline &spline = *splines[offsets[i]];
+
+      /* Copy the start and end point data over. */
+      start_data.positions[i] = spline.evaluated_positions().first();
+      start_data.tangents[i] = spline.evaluated_tangents().first();
+      start_data.normals[i] = spline.evaluated_normals().first();
+      start_data.radii[i] = spline.radii().first();
+      start_data.tilts[i] = spline.tilts().first();
+
+      end_data.positions[i] = spline.evaluated_positions().last();
+      end_data.tangents[i] = spline.evaluated_tangents().last();
+      end_data.normals[i] = spline.evaluated_normals().last();
+      end_data.radii[i] = spline.radi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list