Sculpt: Avoid setting vertex normal to the zero vector

It is possible for the simple vertex normal calculated during Paint
BVH normal updates to have a length of 0 if the connected faces cancel
each other out. This is a generally unlikely scenario, but will almost
always lead to further corruption of the mesh with the new normal.

If we detect this case, set the vertex normal to (0, 0, 1)

Pull Request: https://projects.blender.org/blender/blender/pulls/146004
This commit is contained in:
Sean Kim
2025-09-11 01:20:10 +02:00
committed by Sean Kim
parent 391377c804
commit e9295fad65

View File

@@ -1120,7 +1120,11 @@ static void normals_calc_verts_simple(const GroupedSpan<int> vert_to_face_map,
for (const int face : vert_to_face_map[vert]) {
normal += face_normals[face];
}
vert_normals[vert] = math::normalize(normal);
float length;
vert_normals[vert] = math::normalize_and_get_length(normal, length);
if (length == 0.0f) {
vert_normals[vert] = float3(0, 0, 1);
}
}
}