From d9ffbbb8fb86c240d2df0c53967e3c923361430f Mon Sep 17 00:00:00 2001 From: Andrew Gilewsky Date: Wed, 6 Mar 2024 22:49:33 +0000 Subject: [PATCH] Now for real... --- vnavmesh/Debug/DebugDetourNavmesh.cs | 38 +++++++++++++++++++++++++++- vnavmesh/Navmesh.cs | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/vnavmesh/Debug/DebugDetourNavmesh.cs b/vnavmesh/Debug/DebugDetourNavmesh.cs index d66922d..5cc7233 100644 --- a/vnavmesh/Debug/DebugDetourNavmesh.cs +++ b/vnavmesh/Debug/DebugDetourNavmesh.cs @@ -43,6 +43,12 @@ public override void Dispose() } public void Draw() + { + DrawMesh(); + DrawQuery(); + } + + private void DrawMesh() { using var nr = _tree.Node("Detour navmesh"); if (!nr.Opened) @@ -78,7 +84,7 @@ public void Draw() for (int j = 0; j < tile.data.header.polyCount; ++j) { var p = tile.data.polys[j]; - using var ntri = _tree.Node($"{p.index}: {p.vertCount} vertices, flags={p.flags:X}, area={p.GetArea()}, polytype={p.GetPolyType()}"); + using var ntri = _tree.Node($"{p.index} (0x{p.index:X}): {p.vertCount} vertices, flags={p.flags:X}, area={p.GetArea()}, polytype={p.GetPolyType()}"); if (ntri.SelectedOrHovered) VisualizeRoughPolygon(tile, p, true); if (ntri.Opened) @@ -86,6 +92,13 @@ public void Draw() for (int k = 0; k < p.vertCount; ++k) if (_tree.LeafNode($"{p.verts[k]} ({GetVertex(tile, p.verts[k])}), neighbours={p.neis[k]:X}").SelectedOrHovered) VisualizeVertex(GetVertex(tile, p.verts[k])); + + for (int k = tile.polyLinks[p.index]; k != DtNavMesh.DT_NULL_LINK; k = tile.links[k].next) + { + var link = tile.links[k]; + if (_tree.LeafNode($"Link {k}: refs={link.refs:X}, edge={link.edge}, side={link.side}, bmin={link.bmin}, bmax={link.bmax}").SelectedOrHovered) + VisualizeRoughPolygon(link.refs, true); + } } } } @@ -160,6 +173,23 @@ public void Draw() } } + private void DrawQuery() + { + using var nr = _tree.Node("Detour query", _query == null || _query.GetNodePool().GetNodeCount() == 0); + if (!nr.Opened) + return; + + int i = 1; + foreach (var n in _query!.GetNodePool().AsEnumerable()) + { + if (_tree.LeafNode($"{i++}: {n.id:X}, parent={n.pidx}, enter={n.pos}, cost={n.cost}, total={n.total}, state={n.state}, flags={n.flags}").SelectedOrHovered) + { + VisualizeRoughPolygon(n.id, true); + VisualizeVertex(n.pos.RecastToSystem()); + } + } + } + private EffectMesh.Data GetOrInitVisualizerRough(int tileIndex) { ref var perTile = ref _perTile[tileIndex]; @@ -282,6 +312,12 @@ private void VisualizeRoughPolygon(DtMeshTile tile, DtPoly poly, bool colorByAre VisualizeRoughPolygon(tile, visu, poly, colorByArea, true); } + private void VisualizeRoughPolygon(long refs, bool colorByArea) + { + if (_navmesh.GetTileAndPolyByRef(refs, out var tile, out var poly).Succeeded()) + VisualizeRoughPolygon(tile, poly, colorByArea); + } + // effect + data are expected to be already bound private void VisualizeRoughPolygon(DtMeshTile tile, EffectMesh.Data visu, DtPoly poly, bool colorByArea, bool highlight) { diff --git a/vnavmesh/Navmesh.cs b/vnavmesh/Navmesh.cs index de04ec9..e906fdd 100644 --- a/vnavmesh/Navmesh.cs +++ b/vnavmesh/Navmesh.cs @@ -12,7 +12,7 @@ namespace Navmesh; public record class Navmesh(DtNavMesh Mesh, VoxelMap Volume) { public static readonly uint Magic = 0x444D564E; // 'NVMD' - public static readonly uint Version = 6; + public static readonly uint Version = 7; // throws an exception on failure public static Navmesh Deserialize(BinaryReader reader, NavmeshSettings settings)