Merge pull request #82285 from lyuma/nan_lods

Avoid crash when generating LODs on meshes with non-finite vertices.
This commit is contained in:
Rémi Verschelde 2023-09-25 17:18:43 +02:00
commit a9af6af4b6
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -514,6 +514,10 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const Vector3 &v2 = vertices_ptr[new_indices_ptr[j + 2]];
Vector3 face_normal = vec3_cross(v0 - v2, v0 - v1);
float face_area = face_normal.length(); // Actually twice the face area, since it's the same error_factor on all faces, we don't care
if (!Math::is_finite(face_area) || face_area == 0) {
WARN_PRINT_ONCE("Ignoring face with non-finite normal in LOD generation.");
continue;
}
Vector3 dir = face_normal / face_area;
int ray_count = CLAMP(5.0 * face_area * error_factor, 16, 64);