From f845b2241a5314ffdf351c554bb7cafa631b696a Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 19 May 2026 22:02:06 +0200 Subject: [PATCH] feat(physics): add [indoor-walkable] probe line Extends the existing [indoor-bsp] probe surface in FindEnvCollisions with a per-call [indoor-walkable] line gated on PhysicsDiagnostics.ProbeIndoorBspEnabled (no new flag). Logs the synthesized contact plane, the polyId hit, and the signed Z gap (dz) between foot and plane. Lets the visual-verification step distinguish "FindWalkableSphere picked the right polygon" from "FindWalkableSphere returned a miss and we fell through to outdoor-terrain backstop", which is critical for triaging any remaining indoor collision oddities after the BSP port lands. Runtime-toggleable via the existing DebugPanel "Indoor BSP probe" checkbox; zero cost when disabled. Spec: docs/superpowers/specs/2026-05-19-indoor-walkable-plane-bsp-port-design.md Co-Authored-By: Claude Sonnet 4.6 --- src/AcDream.Core/Physics/TransitionTypes.cs | 29 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/AcDream.Core/Physics/TransitionTypes.cs b/src/AcDream.Core/Physics/TransitionTypes.cs index 50dc718..ae2b3de 100644 --- a/src/AcDream.Core/Physics/TransitionTypes.cs +++ b/src/AcDream.Core/Physics/TransitionTypes.cs @@ -1383,10 +1383,31 @@ public sealed class Transition // Retail: CEnvCell::find_env_collisions returns from the cell // branch with the cell's walkable plane set — no fall-through // to terrain. - if (TryFindIndoorWalkablePlane(cellPhysics, localCenter, sphereRadius, - out var indoorPlane, - out var indoorVertices, - out uint _)) + bool walkableHit = TryFindIndoorWalkablePlane( + cellPhysics, localCenter, sphereRadius, + out var indoorPlane, + out var indoorVertices, + out uint hitPolyId); + + if (PhysicsDiagnostics.ProbeIndoorBspEnabled) + { + if (walkableHit) + { + // dz = signed gap between foot and synthesized plane. + // Plane: N·p + D = 0 ⇒ pZ_on_plane = -D/N.z (for upward-facing planes) + // gap = foot.Z - pZ_on_plane = foot.Z - (-D/N.z) = foot.Z + D/N.z + float dz = footCenter.Z + indoorPlane.D / indoorPlane.Normal.Z; + Console.WriteLine(System.FormattableString.Invariant( + $"[indoor-walkable] cell=0x{sp.CheckCellId:X8} wpos=({footCenter.X:F3},{footCenter.Y:F3},{footCenter.Z:F3}) probe={INDOOR_WALKABLE_PROBE_DISTANCE:F2} result=HIT poly=0x{hitPolyId:X4} wn=({indoorPlane.Normal.X:F3},{indoorPlane.Normal.Y:F3},{indoorPlane.Normal.Z:F3}) wD={indoorPlane.D:F3} dz={dz:+0.00;-0.00;+0.00}")); + } + else + { + Console.WriteLine(System.FormattableString.Invariant( + $"[indoor-walkable] cell=0x{sp.CheckCellId:X8} wpos=({footCenter.X:F3},{footCenter.Y:F3},{footCenter.Z:F3}) probe={INDOOR_WALKABLE_PROBE_DISTANCE:F2} result=MISS")); + } + } + + if (walkableHit) { return ValidateWalkable( footCenter,