Fall back to a cast if clipping point to poly gives us something sucky

This commit is contained in:
Jarrod Doyle 2025-01-15 22:16:52 +00:00
parent 477eb692c5
commit 6a7ee922b5
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 19 additions and 0 deletions

View File

@ -831,6 +831,25 @@ public class LightMapper
var p2d = planeMapper.MapTo2d(pos);
p2d = MathUtils.ClipPointToPoly2d(p2d, v2ds);
pos = planeMapper.MapTo3d(p2d);
// If the clipping fails, just say screw it and cast :(
// TODO: This fails if there's an immovable object blocking the poly center. Need give object polys a different type and do a filtered cast/loop cast ignoring immobile hits
occluded = TraceOcclusion(polyCenter + planeMapper.Normal * 0.25f, pos);
if (occluded)
{
var origin = polyCenter + planeMapper.Normal * 0.25f;
var direction = pos - origin;
var hitResult = _scene.Trace(new Ray
{
Origin = polyCenter + planeMapper.Normal * 0.25f,
Direction = Vector3.Normalize(direction),
});
if (hitResult)
{
pos = hitResult.Position;
}
}
}
tracePoints[i] = pos;