diff options
-rw-r--r-- | source/blender/blenkernel/intern/spline_base.cc | 16 |
1 files changed, 13 insertions, 3 deletions
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(); + } } } |