fix(core): UCG Stage 1 — ResolvePortalPolygon all-or-nothing (match BuildLoadedCell)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5bc72d5cd1
commit
03f08f00c1
2 changed files with 41 additions and 5 deletions
|
|
@ -76,11 +76,15 @@ public sealed class EnvCell : ObjCell
|
||||||
|
|
||||||
private static IReadOnlyList<Vector3> ResolvePortalPolygon(CellStruct cellStruct, ushort polygonId)
|
private static IReadOnlyList<Vector3> ResolvePortalPolygon(CellStruct cellStruct, ushort polygonId)
|
||||||
{
|
{
|
||||||
if (!cellStruct.Polygons.TryGetValue(polygonId, out var poly)) return Array.Empty<Vector3>();
|
if (!cellStruct.Polygons.TryGetValue(polygonId, out var poly) || poly.VertexIds.Count < 3)
|
||||||
var verts = new List<Vector3>(poly.VertexIds.Count);
|
return Array.Empty<Vector3>();
|
||||||
foreach (var vid in poly.VertexIds)
|
var verts = new Vector3[poly.VertexIds.Count];
|
||||||
if (cellStruct.VertexArray.Vertices.TryGetValue((ushort)vid, out var v))
|
for (int i = 0; i < poly.VertexIds.Count; i++)
|
||||||
verts.Add(new Vector3(v.Origin.X, v.Origin.Y, v.Origin.Z));
|
{
|
||||||
|
if (!cellStruct.VertexArray.Vertices.TryGetValue((ushort)poly.VertexIds[i], out var v))
|
||||||
|
return Array.Empty<Vector3>(); // any miss -> empty (matches BuildLoadedCell:5686-5691)
|
||||||
|
verts[i] = new Vector3(v.Origin.X, v.Origin.Y, v.Origin.Z);
|
||||||
|
}
|
||||||
return verts;
|
return verts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,36 @@ public class EnvCellFromDatTests
|
||||||
Assert.Equal(Vector3.Zero, env.LocalBoundsMax);
|
Assert.Equal(Vector3.Zero, env.LocalBoundsMax);
|
||||||
Assert.Null(env.ContainmentBsp);
|
Assert.Null(env.ContainmentBsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FromDat_PortalPolygonMissingAVertex_YieldsEmptyPolygonLocal()
|
||||||
|
{
|
||||||
|
var cellStruct = new CellStruct
|
||||||
|
{
|
||||||
|
VertexArray = new VertexArray { Vertices = new Dictionary<ushort, SWVertex>
|
||||||
|
{
|
||||||
|
[0] = new SWVertex { Origin = new Vector3(0, 0, 0) },
|
||||||
|
[1] = new SWVertex { Origin = new Vector3(1, 0, 0) },
|
||||||
|
// vertex 2 intentionally MISSING
|
||||||
|
}},
|
||||||
|
Polygons = new Dictionary<ushort, Polygon>
|
||||||
|
{
|
||||||
|
[0] = new Polygon { VertexIds = new List<short> { 0, 1, 2 } },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var dat = new DatEnvCell
|
||||||
|
{
|
||||||
|
Flags = (EnvCellFlags)0,
|
||||||
|
CellPortals = new List<DatCellPortal>
|
||||||
|
{
|
||||||
|
new() { OtherCellId = 0x0105, PolygonId = 0, OtherPortalId = 0, Flags = (PortalFlags)0 },
|
||||||
|
},
|
||||||
|
VisibleCells = new List<ushort>(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var env = EnvCell.FromDat(0xA9B40104u, dat, cellStruct, Matrix4x4.Identity);
|
||||||
|
|
||||||
|
Assert.Single(env.Portals);
|
||||||
|
Assert.Empty(env.Portals[0].PolygonLocal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue