Skip to content

Commit

Permalink
Now for real...
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Mar 6, 2024
1 parent 40dd476 commit d9ffbbb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion vnavmesh/Debug/DebugDetourNavmesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,14 +84,21 @@ 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)
{
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);
}
}
}
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion vnavmesh/Navmesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d9ffbbb

Please sign in to comment.