Heres how I implemented debug drawing. I added two methods to the 'dtStatNavMesh' class in the file '"DetourStatNavMesh.cs", i got the core of the drawing routines from the Recast tool.
Sorry for the formatting, i pasted this code from my game engine and deleted the triangle drawing.
You call the routines like this, from your main 'Draw()'
DebugDrawNavMesh(); // draw polygons
DebugDrawNavMesh(true); // draw inner polygon edges
DebugDrawNavMesh(false); // draw outer polygon edges
#if DEBUG
static int triCountDraw = (180 * 3);
Vector3[] m_TmpBuff = new Vector[triCountDraw];
public void DebugDrawNavMesh()
{
Color triClr = new Color(0, 196, 255, 64);
int curVert = 0;
Vector3 pos = Vector3.Zero;
for (int i = 0; i < getPolyDetailCount(); ++i)
{
dtStatPoly p = getPoly(i);
dtStatPolyDetail pd = getPolyDetail(i);
for (int j = 0; j < pd.ntris; ++j)
{
byte[] t = getDetailTri(pd.tbase + j);
for (int k = 0; k < 3; ++k)
{
if (t[k] < p.nv)
{
pos.X = getVertex((int)p.v[t[k]]).X;
pos.Y = getVertex((int)p.v[t[k]]).Y;
pos.Z = getVertex((int)p.v[t[k]]).Z;
}
else
{
pos.X = getDetailVertex(pd.vbase + (t[k] - p.nv)).X;
pos.Y = getDetailVertex(pd.vbase + (t[k] - p.nv)).Y;
pos.Z = getDetailVertex(pd.vbase + (t[k] - p.nv)).Z;
}
m_TmpBuff[curVert] = pos;
curVert++;
}
//
// render if buffer full
//
if (curVert >= (triCountDraw - 3))
{
//
// TODO: Add your code to draw 'm_TmpBuff' as a triangle list with (curVert / 3) number of primitives
//
curVert = 0;
}
}
}
//
// render if buffer full
//
if (curVert > 3)
{
//
// TODO: Add your code to draw 'm_TmpBuff' as a triangle list with (curVert / 3) number of primitives
//
curVert = 0;
}
}
//
// Draw navigation mesh for debug purposes
//
unsafe public struct TempTV
{
public float* p;
}
public void DebugDrawNavMesh(bool inner)
{
Color triClr = Color.White;
Vector3 vrt0 = Vector3.Zero;
Vector3 vrt1 = Vector3.Zero;
Vector3 vrt2 = Vector3.Zero;
Vector3 vrt3 = Vector3.Zero;
Vector3 vrtn = Vector3.Zero;
Vector3 posStart = Vector3.Zero;
Vector3 posEnd = Vector3.Zero;
if (inner)
{
triClr = new Color(0, 48, 64, 64);
}
else
{
triClr = new Color(0, 28, 44, 180);
}
int curVert = 0;
for (int i = 0; i < getPolyCount(); ++i)
{
dtStatPoly p = getPoly(i);
dtStatPolyDetail pd = getPolyDetail(i);
for (int j = 0, nj = (int)p.nv; j < nj; ++j)
{
if (inner)
{
// Skip non-connected edges.
if ((int)p.n[j] == 0) continue;
}
else
{
// Skip connected edges.
if ((int)p.n[j] != 0) continue;
}
Vector3 v0 = Vector3.Zero;
Vector3 v1 = Vector3.Zero;
v0 = getVertex((int)p.v[ j ]);
v0 = getVertex((int)p.v[ (j + 1) % nj ]);
// Draw detail mesh edges which align with the actual poly edge.
// This is really slow.
for (int k = 0; k < pd.ntris; ++k)
{
byte[] t = getDetailTri(pd.tbase + k);
Vector3[] tmpTv = new Vector3[3];
for (int m = 0; m < 3; ++m)
{
tmpTv[m] = Vector3.Zero;
if (t[m] < p.nv)
{
tmpTv[m] = getVertex((int)p.v[t[m]]);
}
else
{
tmpTv[m] = getDetailVertex(pd.vbase + (t[m] - p.nv));
}
}
for (int m = 0, n = 2; m < 3; n=m++)
{
if (((t[3] >> (n*2)) & 0x3) == 0) continue; // Skip inner edges.
if (distancePtLine2d(ref tmpTv[n], ref v0, ref v1) < thr && distancePtLine2d(ref tmpTv[m], ref v0, ref v1) < thr)
{
posStart.X = tmpTv[n].X;
posStart.Y = tmpTv[n].Y;
posStart.Z = tmpTv[n].Z;
posEnd.X = tmpTv[m].X;
posEnd.Y = tmpTv[m].Y;
posEnd.Z = tmpTv[m].Z;
vrtn = (posEnd - posStart);
if (vrtn.LengthSquared() > (2 * 2))
{
vrtn.Normalize();
vrtn = Vector3.Cross(vrtn, Vector3.UnitY);
vrt0 = posStart + (vrtn * -10.0f);
vrt1 = posStart + (vrtn * 10.0f);
vrt2 = posEnd + (vrtn * -10.0f);
vrt3 = posEnd + (vrtn * 10.0f);
m_TmpBuff[curVert++] = vrt0;
m_TmpBuff[curVert++] = vrt1;
m_TmpBuff[curVert++] = vrt2;
m_TmpBuff[curVert++] = vrt1;
m_TmpBuff[curVert++] = vrt3;
m_TmpBuff[curVert++] = vrt2;
if (curVert >= (triCountDraw - 6))
{
//
// TODO: Add your code to draw 'm_TmpBuff' as a triangle list with (curVert / 3) number of primitives AND 'triClr' color
//
curVert = 0;
}
}
}
}
}
}
}
if (curVert > 3)
{
//
// TODO: Add your code to draw 'm_TmpBuff' as a triangle list with (curVert / 3) number of primitives AND 'triClr' color
//
curVert = 0;
}
}
#endif // DEBUG
Let me know if this helps, if it does i might add it to the download.
Kevin