[Bf-blender-cvs] [94084b2d3c5] master: Geometry Nodes: fix z-up spline normal calculation

Jacques Lucke noreply at git.blender.org
Wed Jun 16 12:20:41 CEST 2021


Commit: 94084b2d3c5d151dc6ab19c9868813ac5eacf336
Author: Jacques Lucke
Date:   Wed Jun 16 12:20:10 2021 +0200
Branches: master
https://developer.blender.org/rB94084b2d3c5d151dc6ab19c9868813ac5eacf336

Geometry Nodes: fix z-up spline normal calculation

Previously it didn't work when the tangents were collinear to the z axis.

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

M	source/blender/blenkernel/intern/spline_base.cc

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

diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index 2781ff1e49a..c9d4f62845f 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -209,10 +209,20 @@ static float3 rotate_direction_around_axis(const float3 &direction,
   return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle);
 }
 
-static void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> normals)
+static void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> r_normals)
 {
-  for (const int i : normals.index_range()) {
-    normals[i] = float3::cross(tangents[i], float3(0.0f, 0.0f, 1.0f)).normalized();
+  BLI_assert(r_normals.size() == tangents.size());
+
+  /* Same as in `vec_to_quat`. */
+  const float epsilon = 1e-4f;
+  for (const int i : r_normals.index_range()) {
+    const float3 &tangent = tangents[i];
+    if (fabsf(tangent.x) + fabsf(tangent.y) < epsilon) {
+      r_normals[i] = {1.0f, 0.0f, 0.0f};
+    }
+    else {
+      r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized();
+    }
   }
 }



More information about the Bf-blender-cvs mailing list