1
1

Geometry Nodes: fix z-up spline normal calculation

Previously it didn't work when the tangents were collinear to the z axis.
This commit is contained in:
2021-06-16 12:20:10 +02:00
parent 00fc110d3f
commit 94084b2d3c

View File

@@ -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();
}
}
}