[Bf-blender-cvs] [2f9dbe9e7c6] temp-geometry-nodes-curve-deform-node: Curve Deform Node: Working deform for positive axes, stretch to fit option

Hans Goudey noreply at git.blender.org
Fri Jun 11 20:33:10 CEST 2021


Commit: 2f9dbe9e7c6b0f2950a77fd901cd533a3f30cd6b
Author: Hans Goudey
Date:   Fri Jun 11 13:33:03 2021 -0500
Branches: temp-geometry-nodes-curve-deform-node
https://developer.blender.org/rB2f9dbe9e7c6b0f2950a77fd901cd533a3f30cd6b

Curve Deform Node: Working deform for positive axes, stretch to fit option

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

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/geometry/nodes/node_geo_curve_deform.cc

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

diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 68db7a857ac..a3cb0215406 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1365,8 +1365,8 @@ typedef struct NodeGeometryCurveResample {
 typedef struct NodeGeometryCurveDeform {
   /* GeometryNodeCurveDeformMode. */
   uint8_t input_mode;
-  /* GeometryNodeCurveDeformPositionAxis. */
-  uint8_t position_axis;
+  /* GeometryNodeCurveDeformAxis. */
+  uint8_t axis;
   /* GeometryNodeAttributeInputMode (float or attribute). */
   uint8_t attribute_input_type;
 
@@ -1896,14 +1896,14 @@ typedef enum GeometryNodeCurveDeformMode {
   GEO_NODE_CURVE_DEFORM_ATTRIBUTE = 1,
 } GeometryNodeCurveDeformMode;
 
-typedef enum GeometryNodeCurveDeformPositionAxis {
-  GEO_NODE_CURVE_DEFORM_POSX = 1,
-  GEO_NODE_CURVE_DEFORM_POSY = 2,
-  GEO_NODE_CURVE_DEFORM_POSZ = 3,
-  GEO_NODE_CURVE_DEFORM_NEGX = 4,
-  GEO_NODE_CURVE_DEFORM_NEGY = 5,
-  GEO_NODE_CURVE_DEFORM_NEGZ = 6,
-} GeometryNodeCurveDeformPositionAxis;
+typedef enum GeometryNodeCurveDeformAxis {
+  GEO_NODE_CURVE_DEFORM_POSX = 0,
+  GEO_NODE_CURVE_DEFORM_POSY = 1,
+  GEO_NODE_CURVE_DEFORM_POSZ = 2,
+  GEO_NODE_CURVE_DEFORM_NEGX = 3,
+  GEO_NODE_CURVE_DEFORM_NEGY = 4,
+  GEO_NODE_CURVE_DEFORM_NEGZ = 5,
+} GeometryNodeCurveDeformAxis;
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 17d60de9c1b..5dea9a69ff7 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9852,7 +9852,7 @@ static void def_geo_curve_deform(StructRNA *srna)
       {0, NULL, 0, NULL, NULL},
   };
 
-  static const EnumPropertyItem position_axis_items[] = {
+  static const EnumPropertyItem axis_items[] = {
       {GEO_NODE_CURVE_DEFORM_POSX, "POS_X", 0, "X", ""},
       {GEO_NODE_CURVE_DEFORM_POSY, "POS_Y", 0, "Y", ""},
       {GEO_NODE_CURVE_DEFORM_POSZ, "POS_Z", 0, "Z", ""},
@@ -9869,8 +9869,8 @@ static void def_geo_curve_deform(StructRNA *srna)
   RNA_def_property_ui_text(prop, "Input Mode", "How to specify the curve parameter at each point");
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 
-  prop = RNA_def_property(srna, "position_axis", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_items(prop, position_axis_items);
+  prop = RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, axis_items);
   RNA_def_property_ui_text(prop, "Position Axis", "");
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 
@@ -10871,8 +10871,10 @@ static void rna_def_node_socket_standard_types(BlenderRNA *brna)
       brna, "NodeSocketFloatAngle", "NodeSocketInterfaceFloatAngle", PROP_ANGLE);
   rna_def_node_socket_float(
       brna, "NodeSocketFloatTime", "NodeSocketInterfaceFloatTime", PROP_TIME);
-  rna_def_node_socket_float(
-      brna, "NodeSocketFloatTimeAbsolute", "NodeSocketInterfaceFloatTimeAbsolute", PROP_TIME_ABSOLUTE);
+  rna_def_node_socket_float(brna,
+                            "NodeSocketFloatTimeAbsolute",
+                            "NodeSocketInterfaceFloatTimeAbsolute",
+                            PROP_TIME_ABSOLUTE);
   rna_def_node_socket_float(
       brna, "NodeSocketFloatDistance", "NodeSocketInterfaceFloatDistance", PROP_DISTANCE);
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_deform.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_deform.cc
index 30cbf0c5ea8..7c60eb6debf 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_deform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_deform.cc
@@ -35,8 +35,8 @@ static bNodeSocketTemplate geo_node_curve_deform_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
     {SOCK_GEOMETRY, N_("Curve")},
     {SOCK_STRING, N_("Factor")},
-    {SOCK_FLOAT, N_("Factor"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX},
-    // {SOCK_BOOLEAN, N_("Use Radius")},
+    {SOCK_FLOAT, N_("Factor"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+    {SOCK_BOOLEAN, N_("Stretch to Fit")},
     {-1, ""},
 };
 
@@ -51,7 +51,7 @@ static void geo_node_curve_deform_layout(uiLayout *layout, bContext *UNUSED(C),
   NodeGeometryCurveDeform &node_storage = *(NodeGeometryCurveDeform *)node->storage;
   const GeometryNodeCurveDeformMode mode = (GeometryNodeCurveDeformMode)node_storage.input_mode;
 
-  uiItemR(layout, ptr, "position_axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
+  uiItemR(layout, ptr, "axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
 
   uiItemR(layout, ptr, "input_mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
 
@@ -68,7 +68,7 @@ static void geo_node_curve_deform_init(bNodeTree *UNUSED(tree), bNode *node)
       sizeof(NodeGeometryCurveDeform), __func__);
 
   data->input_mode = GEO_NODE_CURVE_DEFORM_POSITION;
-  data->position_axis = GEO_NODE_CURVE_DEFORM_POSX;
+  data->axis = GEO_NODE_CURVE_DEFORM_POSX;
   data->attribute_input_type = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
   node->storage = data;
 }
@@ -90,61 +90,25 @@ static void geo_node_curve_deform_update(bNodeTree *UNUSED(ntree), bNode *node)
       mode == GEO_NODE_CURVE_DEFORM_ATTRIBUTE);
 }
 
-static void spline_deform(const Spline &spline,
-                          Span<float> index_factors,
-                          Span<int> sorted_indices,
-                          const int axis_index,
-                          MutableSpan<float3> positions)
-{
-  Span<float3> spline_positions = spline.evaluated_positions();
-  Span<float3> spline_tangents = spline.evaluated_tangents();
-  Span<float3> spline_normals = spline.evaluated_normals();
-  GVArray_Typed<float> radii = spline.interpolate_to_evaluated_points(spline.radii());
-
-  parallel_for(positions.index_range(), 1024, [&](IndexRange range) {
-    for (const int i : range) {
-      const int i_position = sorted_indices[i];
-      const Spline::LookupResult interp = spline.lookup_data_from_index_factor(index_factors[i]);
-      const int index = interp.evaluated_index;
-      const int next_index = interp.next_evaluated_index;
-      const float factor = interp.factor;
-
-      float4x4 matrix = float4x4::from_normalized_axis_data(
-          {0, 0, 0},
-          float3::interpolate(spline_normals[index], spline_normals[next_index], factor)
-              .normalized(),
-          float3::interpolate(spline_tangents[index], spline_tangents[next_index], factor)
-              .normalized());
-      matrix.apply_scale(interpf(radii[next_index], radii[index], factor));
-
-      float3 position = positions[i_position];
-      position[axis_index] = 0.0f;
-
-      positions[i_position] = matrix * position;
-      positions[i_position] += float3::interpolate(
-          spline_positions[index], spline_positions[next_index], factor);
-    }
-  });
-}
-
-static int axis_to_index(const GeometryNodeCurveDeformPositionAxis axis)
+enum class Axis { X, Y, Z };
+static Axis axis_from_deform_axis(const GeometryNodeCurveDeformAxis axis)
 {
   switch (axis) {
     case GEO_NODE_CURVE_DEFORM_POSX:
     case GEO_NODE_CURVE_DEFORM_NEGX:
-      return 0;
+      return Axis::X;
     case GEO_NODE_CURVE_DEFORM_POSY:
     case GEO_NODE_CURVE_DEFORM_NEGY:
-      return 1;
+      return Axis::Y;
     case GEO_NODE_CURVE_DEFORM_POSZ:
     case GEO_NODE_CURVE_DEFORM_NEGZ:
-      return 2;
+      return Axis::Z;
   }
   BLI_assert_unreachable();
-  return -1;
+  return Axis::X;
 }
 
-static bool axis_is_negative(const GeometryNodeCurveDeformPositionAxis axis)
+static bool axis_is_negative(const GeometryNodeCurveDeformAxis axis)
 {
   switch (axis) {
     case GEO_NODE_CURVE_DEFORM_POSX:
@@ -160,42 +124,201 @@ static bool axis_is_negative(const GeometryNodeCurveDeformPositionAxis axis)
   return false;
 }
 
-static float find_upper_bound(Span<float3> positions, const int index)
+struct SplineDataInput {
+  const Spline &spline;
+  Span<float3> positions;
+  Span<float3> tangents;
+  Span<float3> normals;
+  GVArray_Typed<float> radii;
+};
+
+static float3 deform_position(const SplineDataInput &in,
+                              const float index_factor,
+                              const float cotangent_factor,
+                              const float normal_factor)
+{
+  const Spline::LookupResult interp = in.spline.lookup_data_from_index_factor(index_factor);
+  const int index = interp.evaluated_index;
+  const int next = interp.next_evaluated_index;
+  const float factor = interp.factor;
+
+  const float3 position = float3::interpolate(in.positions[index], in.positions[next], factor);
+  const float3 tangent = float3::interpolate(in.tangents[index], in.tangents[next], factor);
+  const float3 normal = float3::interpolate(in.normals[index], in.normals[next], factor);
+  const float3 cotangent = float3::cross(tangent, normal).normalized();
+  const float radius = interpf(in.radii[next], in.radii[index], factor);
+
+  return position + (cotangent * cotangent_factor + normal * normal_factor) * radius;
+}
+
+struct Bounds {
+  float3 min;
+  float3 max;
+  float3 inv_size;
+};
+
+static Bounds position_bounds(const Span<float3> positions)
 {
-  float max = FLT_MIN;
+  float3 min = float3(FLT_MAX);
+  float3 max = float3(-FLT_MAX);
   for (const float3 &position : positions) {
-    if (position[index] > max) {
-      max = position[index];
-    }
+    minmax_v3v3_v3(min, max, position);
   }
-  return max;
+  return {min, max, float3::safe_divide(float3(1), max - min)};
 }
 
-static float find_lower_bound(Span<float3> positions, const int index)
+static void spline_deform(const SplineDataInput &spline_data,
+                          const Span<float> index_factors,
+                          const Span<int> indices,
+                          const Axis axis,
+                          const Bounds &bounds,
+                          MutableSpan<float3> positions)
 {
-  float min = FLT_MAX;
-  for (const float3 &position : positions) {
-    if (position[index] < min) {
-      min = position[index];
+  switch (axis) {
+    case Axis::X:
+      parallel_for(positions.index_range(), 1024, [&](IndexRange range) {
+        for (const int i : range) {
+          const float3 co =

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list