[Bf-blender-cvs] [d475f994606] master: Geometry Nodes: Support "Evaluated" mode in Resample Curve node

Hans Goudey noreply at git.blender.org
Sat Sep 11 05:59:04 CEST 2021


Commit: d475f994606e38a69cab4e2b64c9237d0ee62726
Author: Hans Goudey
Date:   Fri Sep 10 22:58:30 2021 -0500
Branches: master
https://developer.blender.org/rBd475f994606e38a69cab4e2b64c9237d0ee62726

Geometry Nodes: Support "Evaluated" mode in Resample Curve node

Just like the curve to points node, this mode outputs point locations
based on the input curve's evaluated points (the points you see in the
viewport). This is expected to be faster, since it doesn't have to
sample equal positions on the result, and it's also consistent with
the existing choices in the curve to points node.

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

M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc

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

diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index b294e93310c..86e134799aa 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10091,6 +10091,12 @@ static void def_geo_curve_resample(StructRNA *srna)
   PropertyRNA *prop;
 
   static EnumPropertyItem mode_items[] = {
+      {GEO_NODE_CURVE_SAMPLE_EVALUATED,
+       "EVALUATED",
+       0,
+       "Evaluated",
+       "Output the input spline's evaluated points, based on the resolution attribute for NURBS "
+       "and Bezier splines. Poly splines are unchanged"},
       {GEO_NODE_CURVE_SAMPLE_COUNT,
        "COUNT",
        0,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
index 6f40687540c..447f2989308 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
@@ -42,7 +42,7 @@ static void geo_node_curve_resample_declare(NodeDeclarationBuilder &b)
 
 static void geo_node_curve_resample_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
-  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
+  uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
 }
 
 static void geo_node_curve_resample_init(bNodeTree *UNUSED(tree), bNode *node)
@@ -148,6 +148,36 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count)
   return output_spline;
 }
 
+static SplinePtr resample_spline_evaluated(const Spline &src)
+{
+  std::unique_ptr<PolySpline> dst = std::make_unique<PolySpline>();
+  Spline::copy_base_settings(src, *dst);
+  dst->resize(src.evaluated_points_size());
+
+  dst->positions().copy_from(src.evaluated_positions());
+  dst->positions().copy_from(src.evaluated_positions());
+  src.interpolate_to_evaluated(src.radii())->materialize(dst->radii());
+  src.interpolate_to_evaluated(src.tilts())->materialize(dst->tilts());
+
+  src.attributes.foreach_attribute(
+      [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
+        std::optional<GSpan> src_attribute = src.attributes.get_for_read(attribute_id);
+        if (dst->attributes.create(attribute_id, meta_data.data_type)) {
+          std::optional<GMutableSpan> dst_attribute = dst->attributes.get_for_write(attribute_id);
+          if (dst_attribute) {
+            src.interpolate_to_evaluated(*src_attribute)->materialize(dst_attribute->data());
+            return true;
+          }
+        }
+
+        BLI_assert_unreachable();
+        return true;
+      },
+      ATTR_DOMAIN_POINT);
+
+  return dst;
+}
+
 static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve,
                                                  const SampleModeParam &mode_param)
 {
@@ -174,6 +204,13 @@ static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve,
       }
     });
   }
+  else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_EVALUATED) {
+    threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) {
+      for (const int i : range) {
+        output_splines[i] = resample_spline_evaluated(*input_splines[i]);
+      }
+    });
+  }
 
   output_curve->attributes = input_curve.attributes;



More information about the Bf-blender-cvs mailing list