fix(woc): fromTerrain skips degenerate triangles before normalize

The walkability classifier did glm::normalize(cross(...)) without
guarding for zero-length cross. A flat-on-itself triangle (e.g. all
three vertices at the same height in a hole-edge case) produces NaN
normal, NaN walkability flag, and crashes the downstream nz check.
Now the cross-length is computed once and the triangle is skipped if
it's effectively zero.
This commit is contained in:
Kelsi 2026-05-06 05:26:46 -07:00
parent 70bbed4222
commit 2b5f69187e

View file

@ -74,10 +74,16 @@ WoweeCollision WoweeCollisionBuilder::fromTerrain(const ADTTerrain& terrain,
glm::vec3 v01 = vtx(i01), v11 = vtx(i11);
auto classifyTri = [&](const glm::vec3& a, const glm::vec3& b, const glm::vec3& c) {
// Skip degenerate triangles — would produce NaN normals
// and crash collision intersection tests downstream.
glm::vec3 cross = glm::cross(b - a, c - a);
float crossLen = glm::length(cross);
if (crossLen < 1e-8f) return;
WoweeCollision::Triangle tri;
tri.v0 = a; tri.v1 = b; tri.v2 = c;
glm::vec3 normal = glm::normalize(glm::cross(b - a, c - a));
glm::vec3 normal = cross / crossLen;
float nz = std::abs(normal.z);
tri.flags = 0;