Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-06-16 13:20:10 +0300
committerJacques Lucke <jacques@blender.org>2021-06-16 13:20:28 +0300
commit94084b2d3c5d151dc6ab19c9868813ac5eacf336 (patch)
treedd7f0f2b20eda8a6fe6b4060ddf17688daab1c01
parent00fc110d3f9d33471af8e3f9f8a71c732e1a4bdd (diff)
Geometry Nodes: fix z-up spline normal calculation
Previously it didn't work when the tangents were collinear to the z axis.
-rw-r--r--source/blender/blenkernel/intern/spline_base.cc16
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();
+ }
}
}