fix(m2): degenerate-normal guard during walkable-floor raycast

The matrix-transformed normal could be near-zero if the M2 instance
has a degenerate scale; glm::normalize then returns NaN that
contaminates the slope check (NaN < 0.35 is false → no early-out)
and bestNormalZ goes NaN, breaking the walkable-floor heuristic.

Length-check the transformed normal and fall back to the (0,0,1)
flat default — same pattern as the WMO renderer.
This commit is contained in:
Kelsi 2026-05-06 08:49:26 -07:00
parent ae20fbf621
commit 61fb486b9e

View file

@ -765,8 +765,12 @@ std::optional<float> M2Renderer::getFloorHeight(float glX, float glY, float glZ,
if (nLen > 0.001f) {
localN /= nLen;
if (localN.z < 0.0f) localN = -localN;
worldN = glm::normalize(
glm::vec3(instance.modelMatrix * glm::vec4(localN, 0.0f)));
glm::vec3 transformedN = glm::vec3(
instance.modelMatrix * glm::vec4(localN, 0.0f));
float wnLen = glm::length(transformedN);
if (wnLen > 0.001f) {
worldN = transformedN / wnLen;
} // else: keep worldN = (0,0,1) flat default
if (std::abs(worldN.z) < 0.35f) continue; // too steep (~70° max slope)
}