diff --git a/src/AcDream.Core/Physics/CellTransit.cs b/src/AcDream.Core/Physics/CellTransit.cs index 12bfa0d..564a46f 100644 --- a/src/AcDream.Core/Physics/CellTransit.cs +++ b/src/AcDream.Core/Physics/CellTransit.cs @@ -186,11 +186,28 @@ public static class CellTransit foreach (var portal in building.Portals) { var otherCell = cache.GetCellStruct(portal.OtherCellId); - if (otherCell?.CellBSP?.Root is null) continue; + if (otherCell?.CellBSP?.Root is null) + { + if (PhysicsDiagnostics.ProbeIndoorBspEnabled) + { + string reason = otherCell is null ? "cell not cached" : "CellBSP null"; + Console.WriteLine(System.FormattableString.Invariant( + $"[check-bldg] portal->0x{portal.OtherCellId:X8} skipped: {reason}")); + } + continue; + } // Sphere center in the OTHER cell's local space. var localCenter = Vector3.Transform(worldSphereCenter, otherCell.InverseWorldTransform); - if (BSPQuery.PointInsideCellBsp(otherCell.CellBSP.Root, localCenter)) + bool inside = BSPQuery.PointInsideCellBsp(otherCell.CellBSP.Root, localCenter); + + if (PhysicsDiagnostics.ProbeIndoorBspEnabled) + { + Console.WriteLine(System.FormattableString.Invariant( + $"[check-bldg] portal->0x{portal.OtherCellId:X8} wpos=({worldSphereCenter.X:F3},{worldSphereCenter.Y:F3},{worldSphereCenter.Z:F3}) lpos=({localCenter.X:F3},{localCenter.Y:F3},{localCenter.Z:F3}) inside={inside}")); + } + + if (inside) { candidates.Add(portal.OtherCellId); } diff --git a/src/AcDream.Core/Physics/PhysicsEngine.cs b/src/AcDream.Core/Physics/PhysicsEngine.cs index d9e3633..5061f34 100644 --- a/src/AcDream.Core/Physics/PhysicsEngine.cs +++ b/src/AcDream.Core/Physics/PhysicsEngine.cs @@ -769,7 +769,7 @@ public sealed class PhysicsEngine return new ResolveResult( sp.CheckPos, - ResolveCellId(sp.CheckPos, sphereRadius, sp.CheckCellId), + ResolveCellId(sp.GlobalSphere[0].Origin, sphereRadius, sp.CheckCellId), onGround, collisionNormalValid, collisionNormal); @@ -787,7 +787,7 @@ public sealed class PhysicsEngine uint partialCellId = sp.CheckCellId != 0 ? sp.CheckCellId : cellId; return new ResolveResult( sp.CheckPos, - ResolveCellId(sp.CheckPos, sphereRadius, partialCellId), + ResolveCellId(sp.GlobalSphere[0].Origin, sphereRadius, partialCellId), partialOnGround, collisionNormalValid, collisionNormal); diff --git a/src/AcDream.Core/Physics/TransitionTypes.cs b/src/AcDream.Core/Physics/TransitionTypes.cs index 4a6d696..1deed49 100644 --- a/src/AcDream.Core/Physics/TransitionTypes.cs +++ b/src/AcDream.Core/Physics/TransitionTypes.cs @@ -1181,7 +1181,7 @@ public sealed class Transition Vector3 footCenter = sp.GlobalSphere[0].Origin; float sphereRadius = sp.GlobalSphere[0].Radius; - uint resolvedOutdoorCellId = engine.ResolveCellId(sp.CheckPos, sphereRadius, sp.CheckCellId); + uint resolvedOutdoorCellId = engine.ResolveCellId(sp.GlobalSphere[0].Origin, sphereRadius, sp.CheckCellId); if (resolvedOutdoorCellId != sp.CheckCellId) sp.SetCheckPos(sp.CheckPos, resolvedOutdoorCellId);