NOTE: Changed the generation procedure, see samples! Erode walkable area before area is generated. Allow to mark areas on chf. Generate regions following areas (+ many fixes here and there to make it alwasy work). Part 2

This commit is contained in:
Mikko Mononen
2010-02-01 14:58:30 +00:00
parent 9035462e86
commit f839fb080a
13 changed files with 5699 additions and 477 deletions

View File

@@ -72,6 +72,11 @@ inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
unsigned int duIntToCol(int i, int a);
void duIntToCol(int i, float* col);
inline unsigned int duDarkenColor(unsigned int col)
{
return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
}
void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide);
void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
@@ -105,6 +110,9 @@ void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float
void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
float maxx, float maxy, float maxz, unsigned int col);
void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
float maxx, float maxy, float maxz, unsigned int col);
void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
const float x1, const float y1, const float z1, const float h,
const float as0, const float as1, unsigned int col);

View File

@@ -27,9 +27,9 @@ inline int bit(int a, int b)
unsigned int duIntToCol(int i, int a)
{
int r = bit(i, 0) + bit(i, 3) * 2 + 1;
int g = bit(i, 1) + bit(i, 4) * 2 + 1;
int b = bit(i, 2) + bit(i, 5) * 2 + 1;
int r = bit(i, 1) + bit(i, 3) * 2 + 1;
int g = bit(i, 2) + bit(i, 4) * 2 + 1;
int b = bit(i, 0) + bit(i, 5) * 2 + 1;
return duRGBA(r*63,g*63,b*63,a);
}
@@ -200,6 +200,29 @@ void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
dd->vertex(minx, maxy, maxz, col);
}
void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
float maxx, float maxy, float maxz, unsigned int col)
{
// Top
dd->vertex(minx, miny, minz, col);
dd->vertex(maxx, miny, minz, col);
dd->vertex(maxx, miny, minz, col);
dd->vertex(maxx, miny, maxz, col);
dd->vertex(maxx, miny, maxz, col);
dd->vertex(minx, miny, maxz, col);
dd->vertex(minx, miny, maxz, col);
dd->vertex(minx, miny, minz, col);
// bottom
dd->vertex(minx, maxy, minz, col);
dd->vertex(maxx, maxy, minz, col);
dd->vertex(maxx, maxy, minz, col);
dd->vertex(maxx, maxy, maxz, col);
dd->vertex(maxx, maxy, maxz, col);
dd->vertex(minx, maxy, maxz, col);
dd->vertex(minx, maxy, maxz, col);
dd->vertex(minx, maxy, minz, col);
}
void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
float maxx, float maxy, float maxz, const unsigned int* fcol)

View File

@@ -22,11 +22,6 @@
#include "RecastDebugDraw.h"
#include "Recast.h"
inline unsigned int dark(unsigned int col)
{
return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
}
void duDebugDrawTriMesh(duDebugDraw* dd, const float* verts, int nverts,
const int* tris, const float* normals, int ntris,
const unsigned char* flags)
@@ -161,8 +156,6 @@ void duDebugDrawCompactHeightfieldSolid(duDebugDraw* dd, const rcCompactHeightfi
const float cs = chf.cs;
const float ch = chf.ch;
unsigned int color = duRGBA(0,192,255,64);
dd->begin(DU_DRAW_QUADS);
for (int y = 0; y < chf.height; ++y)
@@ -176,6 +169,15 @@ void duDebugDrawCompactHeightfieldSolid(duDebugDraw* dd, const rcCompactHeightfi
for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
{
const rcCompactSpan& s = chf.spans[i];
unsigned int color;
if (chf.areas[i] == RC_WALKABLE_AREA)
color = duRGBA(0,192,255,64);
else if (chf.areas[i] == RC_NULL_AREA)
color = duRGBA(0,0,0,64);
else
color = duIntToCol(chf.areas[i], 255);
const float fy = chf.bmin[1] + (s.y+1)*ch;
dd->vertex(fx, fy, fz, color);
dd->vertex(fx, fy, fz+cs, color);
@@ -189,6 +191,9 @@ void duDebugDrawCompactHeightfieldSolid(duDebugDraw* dd, const rcCompactHeightfi
void duDebugDrawCompactHeightfieldRegions(duDebugDraw* dd, const rcCompactHeightfield& chf)
{
if (!chf.regs)
return;
const float cs = chf.cs;
const float ch = chf.ch;
@@ -207,8 +212,8 @@ void duDebugDrawCompactHeightfieldRegions(duDebugDraw* dd, const rcCompactHeight
const rcCompactSpan& s = chf.spans[i];
const float fy = chf.bmin[1] + (s.y)*ch;
unsigned int color;
if (chf.reg[i])
color = duIntToCol(chf.reg[i], 192);
if (chf.regs[i])
color = duIntToCol(chf.regs[i], 192);
else
color = duRGBA(0,0,0,64);
@@ -226,6 +231,9 @@ void duDebugDrawCompactHeightfieldRegions(duDebugDraw* dd, const rcCompactHeight
void duDebugDrawCompactHeightfieldDistance(duDebugDraw* dd, const rcCompactHeightfield& chf)
{
if (!chf.dist)
return;
const float cs = chf.cs;
const float ch = chf.ch;
@@ -378,7 +386,7 @@ void duDebugDrawRegionConnections(duDebugDraw* dd, const rcContourSet& cset, con
for (int i = 0; i < cset.nconts; ++i)
{
const rcContour* cont = &cset.conts[i];
unsigned int color = dark(duIntToCol(cont->reg,a));
unsigned int color = duDarkenColor(duIntToCol(cont->reg,a));
getContourCenter(cont, orig, cs, ch, pos);
dd->vertex(pos, color);
}
@@ -424,7 +432,7 @@ void duDebugDrawRawContours(duDebugDraw* dd, const rcContourSet& cset, const flo
for (int i = 0; i < cset.nconts; ++i)
{
const rcContour& c = cset.conts[i];
unsigned int color = dark(duIntToCol(c.reg, a));
unsigned int color = duDarkenColor(duIntToCol(c.reg, a));
for (int j = 0; j < c.nrverts; ++j)
{
@@ -487,7 +495,7 @@ void duDebugDrawContours(duDebugDraw* dd, const rcContourSet& cset, const float
for (int i = 0; i < cset.nconts; ++i)
{
const rcContour& c = cset.conts[i];
unsigned int color = dark(duIntToCol(c.reg, a));
unsigned int color = duDarkenColor(duIntToCol(c.reg, a));
for (int j = 0; j < c.nverts; ++j)
{
const int* v = &c.verts[j*4];
@@ -520,7 +528,15 @@ void duDebugDrawPolyMesh(duDebugDraw* dd, const struct rcPolyMesh& mesh)
for (int i = 0; i < mesh.npolys; ++i)
{
const unsigned short* p = &mesh.polys[i*nvp*2];
unsigned int color = duIntToCol(i, 192);
unsigned int color;
if (mesh.areas[i] == RC_WALKABLE_AREA)
color = duRGBA(0,192,255,64);
else if (mesh.areas[i] == RC_NULL_AREA)
color = duRGBA(0,0,0,64);
else
color = duIntToCol(mesh.areas[i], 255);
unsigned short vi[3];
for (int j = 2; j < nvp; ++j)
{

View File

@@ -1060,16 +1060,15 @@ int dtNavMesh::queryPolygons(const float* center, const float* extents, dtQueryF
vadd(bmax, center, extents);
// Find tiles the query touches.
const int minx = (int)floorf((bmin[0]-m_orig[0]) / m_tileWidth);
const int maxx = (int)ceilf((bmax[0]-m_orig[0]) / m_tileWidth);
const int miny = (int)floorf((bmin[2]-m_orig[2]) / m_tileHeight);
const int maxy = (int)ceilf((bmax[2]-m_orig[2]) / m_tileHeight);
const int minx = (int)((bmin[0]-m_orig[0]) / m_tileWidth);
const int maxx = (int)((bmax[0]-m_orig[0]) / m_tileWidth);
const int miny = (int)((bmin[2]-m_orig[2]) / m_tileHeight);
const int maxy = (int)((bmax[2]-m_orig[2]) / m_tileHeight);
int n = 0;
for (int y = miny; y < maxy; ++y)
for (int y = miny; y <= maxy; ++y)
{
for (int x = minx; x < maxx; ++x)
for (int x = minx; x <= maxx; ++x)
{
dtMeshTile* tile = getTileAt(x,y);
if (!tile) continue;

File diff suppressed because it is too large Load Diff

View File

@@ -281,13 +281,14 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>61</integer>
<integer>39</integer>
<integer>35</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 752}, {358, 643}}</string>
<string>{{0, 196}, {358, 643}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@@ -322,7 +323,7 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A30F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>InputGeom.cpp</string>
<string>Sample_SoloMeshSimple.cpp</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@@ -330,11 +331,11 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A40F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>InputGeom.cpp</string>
<string>Sample_SoloMeshSimple.cpp</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6BF7C4061113209A002B3F46</string>
<string>6BF7C6B4111722A5002B3F46</string>
<key>history</key>
<array>
<string>6B8DE70D10B01BBF00DF20FB</string>
@@ -345,52 +346,57 @@
<string>6BB7FDC110F37703006DA0A6</string>
<string>6BB7FF6D10F4E8E2006DA0A6</string>
<string>6B69739F10FFCA4500984788</string>
<string>6BCF325F1104CFE7009445BF</string>
<string>6BCF33651105BBA2009445BF</string>
<string>6BCF341A1105EC43009445BF</string>
<string>6BF7BE1F110F0792002B3F46</string>
<string>6BF7BE5C110F170A002B3F46</string>
<string>6BF7C0E511116E74002B3F46</string>
<string>6BF7C0E911116E74002B3F46</string>
<string>6BF7C0EC11116E74002B3F46</string>
<string>6BF7C0ED11116E74002B3F46</string>
<string>6BF7C0EE11116E74002B3F46</string>
<string>6BF7C0EF11116E74002B3F46</string>
<string>6BF7C0F011116E74002B3F46</string>
<string>6BF7C0F311116E74002B3F46</string>
<string>6BF7C16211119C69002B3F46</string>
<string>6BF7C1D01111BCF2002B3F46</string>
<string>6BF7C1E21111BD81002B3F46</string>
<string>6BF7C1ED1111C0A6002B3F46</string>
<string>6BF7C2441111DAC1002B3F46</string>
<string>6BF7C2761112BE4F002B3F46</string>
<string>6BF7C2851112C348002B3F46</string>
<string>6BF7C2A51112D13E002B3F46</string>
<string>6BF7C2BD1112D453002B3F46</string>
<string>6BF7C2DB1112D4DA002B3F46</string>
<string>6BF7C2EF1112D646002B3F46</string>
<string>6BF7C2F51112D716002B3F46</string>
<string>6BF7C2F61112D716002B3F46</string>
<string>6BF7C3211112DB82002B3F46</string>
<string>6BF7C3281112DDCE002B3F46</string>
<string>6BF7C3431112E74B002B3F46</string>
<string>6BF7C36E1112EB25002B3F46</string>
<string>6BF7C37C1113026E002B3F46</string>
<string>6BF7C37D1113026E002B3F46</string>
<string>6BF7C392111316AD002B3F46</string>
<string>6BF7C393111316AD002B3F46</string>
<string>6BF7C394111316AD002B3F46</string>
<string>6BF7C395111316AD002B3F46</string>
<string>6BF7C3BC111318BA002B3F46</string>
<string>6BF7C3CC11131F26002B3F46</string>
<string>6BF7C3CD11131F26002B3F46</string>
<string>6BF7C3CE11131F26002B3F46</string>
<string>6BF7C3CF11131F26002B3F46</string>
<string>6BF7C3D011131F26002B3F46</string>
<string>6BF7C3F611131F84002B3F46</string>
<string>6BF7C3FA11132015002B3F46</string>
<string>6BF7C4021113209A002B3F46</string>
<string>6BF7C4031113209A002B3F46</string>
<string>6BF7C4641115C514002B3F46</string>
<string>6BF7C4821115C7C4002B3F46</string>
<string>6BF7C4831115C7C4002B3F46</string>
<string>6BF7C50D1115DB96002B3F46</string>
<string>6BF7C50E1115DB96002B3F46</string>
<string>6BF7C5241115FA3B002B3F46</string>
<string>6BF7C5831115FEFF002B3F46</string>
<string>6BF7C5BD1116E1C6002B3F46</string>
<string>6BF7C5BE1116E1C6002B3F46</string>
<string>6BF7C5C81116E247002B3F46</string>
<string>6BF7C5D41116E3A1002B3F46</string>
<string>6BF7C5E61116E464002B3F46</string>
<string>6BF7C5ED1116F280002B3F46</string>
<string>6BF7C5F81116F346002B3F46</string>
<string>6BF7C5F91116F346002B3F46</string>
<string>6BF7C6481117108B002B3F46</string>
<string>6BF7C6581117142A002B3F46</string>
<string>6BF7C6591117142A002B3F46</string>
<string>6BF7C67A1117163B002B3F46</string>
<string>6BF7C67C1117163B002B3F46</string>
<string>6BF7C67D1117163B002B3F46</string>
<string>6BF7C68B111720C6002B3F46</string>
<string>6BF7C68C111720C6002B3F46</string>
<string>6BF7C69A11172159002B3F46</string>
<string>6BF7C69B11172159002B3F46</string>
<string>6BF7C6A211172253002B3F46</string>
<string>6BF7C6AA11172278002B3F46</string>
<string>6BF7C6B1111722A5002B3F46</string>
<string>6BF7C6B2111722A5002B3F46</string>
</array>
<key>prevStack</key>
<array>
@@ -424,23 +430,13 @@
<string>6BF7C0F811116E74002B3F46</string>
<string>6BF7C0F911116E74002B3F46</string>
<string>6BF7C0FA11116E74002B3F46</string>
<string>6BF7C0FC11116E74002B3F46</string>
<string>6BF7C0FD11116E74002B3F46</string>
<string>6BF7C0FE11116E74002B3F46</string>
<string>6BF7C0FF11116E74002B3F46</string>
<string>6BF7C10011116E74002B3F46</string>
<string>6BF7C10111116E74002B3F46</string>
<string>6BF7C10211116E74002B3F46</string>
<string>6BF7C10311116E74002B3F46</string>
<string>6BF7C10411116E74002B3F46</string>
<string>6BF7C10511116E74002B3F46</string>
<string>6BF7C10611116E74002B3F46</string>
<string>6BF7C10711116E74002B3F46</string>
<string>6BF7C10811116E74002B3F46</string>
<string>6BF7C10911116E74002B3F46</string>
<string>6BF7C10A11116E74002B3F46</string>
<string>6BF7C10B11116E74002B3F46</string>
<string>6BF7C10C11116E74002B3F46</string>
<string>6BF7C10E11116E74002B3F46</string>
<string>6BF7C10F11116E74002B3F46</string>
<string>6BF7C11011116E74002B3F46</string>
@@ -451,13 +447,11 @@
<string>6BF7C11911116E74002B3F46</string>
<string>6BF7C12C11116FFB002B3F46</string>
<string>6BF7C12E11116FFB002B3F46</string>
<string>6BF7C13911118CEB002B3F46</string>
<string>6BF7C13A11118CEB002B3F46</string>
<string>6BF7C14A11119BB4002B3F46</string>
<string>6BF7C14E11119BB4002B3F46</string>
<string>6BF7C14F11119BB4002B3F46</string>
<string>6BF7C15411119BB4002B3F46</string>
<string>6BF7C16611119C69002B3F46</string>
<string>6BF7C16E11119D8F002B3F46</string>
<string>6BF7C17511119EDD002B3F46</string>
<string>6BF7C17711119EDD002B3F46</string>
@@ -501,59 +495,35 @@
<string>6BF7C2701112B56F002B3F46</string>
<string>6BF7C2791112BE4F002B3F46</string>
<string>6BF7C27A1112BE4F002B3F46</string>
<string>6BF7C2801112C0EA002B3F46</string>
<string>6BF7C28A1112C349002B3F46</string>
<string>6BF7C28B1112C349002B3F46</string>
<string>6BF7C28C1112C349002B3F46</string>
<string>6BF7C2971112C4A2002B3F46</string>
<string>6BF7C2A81112D13E002B3F46</string>
<string>6BF7C2A91112D13E002B3F46</string>
<string>6BF7C2AA1112D13E002B3F46</string>
<string>6BF7C2AB1112D13E002B3F46</string>
<string>6BF7C2AC1112D13E002B3F46</string>
<string>6BF7C2B31112D395002B3F46</string>
<string>6BF7C2B51112D395002B3F46</string>
<string>6BF7C2B61112D395002B3F46</string>
<string>6BF7C2B71112D395002B3F46</string>
<string>6BF7C2B81112D395002B3F46</string>
<string>6BF7C2C61112D453002B3F46</string>
<string>6BF7C2C71112D453002B3F46</string>
<string>6BF7C2C81112D453002B3F46</string>
<string>6BF7C2C91112D453002B3F46</string>
<string>6BF7C2CB1112D453002B3F46</string>
<string>6BF7C2CD1112D453002B3F46</string>
<string>6BF7C2CF1112D453002B3F46</string>
<string>6BF7C2D11112D453002B3F46</string>
<string>6BF7C2E21112D520002B3F46</string>
<string>6BF7C2E91112D611002B3F46</string>
<string>6BF7C2F21112D646002B3F46</string>
<string>6BF7C2F91112D716002B3F46</string>
<string>6BF7C2FA1112D716002B3F46</string>
<string>6BF7C30C1112D8C1002B3F46</string>
<string>6BF7C3141112DAFB002B3F46</string>
<string>6BF7C3171112DAFB002B3F46</string>
<string>6BF7C3241112DB82002B3F46</string>
<string>6BF7C3251112DB82002B3F46</string>
<string>6BF7C32A1112DDCE002B3F46</string>
<string>6BF7C33C1112E5D1002B3F46</string>
<string>6BF7C3461112E74B002B3F46</string>
<string>6BF7C3481112E74B002B3F46</string>
<string>6BF7C3601112EA84002B3F46</string>
<string>6BF7C3611112EA84002B3F46</string>
<string>6BF7C3621112EA84002B3F46</string>
<string>6BF7C3641112EA84002B3F46</string>
<string>6BF7C3651112EA84002B3F46</string>
<string>6BF7C3661112EA84002B3F46</string>
<string>6BF7C3671112EA84002B3F46</string>
<string>6BF7C3681112EA84002B3F46</string>
<string>6BF7C3701112EB25002B3F46</string>
<string>6BF7C3711112EB25002B3F46</string>
<string>6BF7C3781112FE75002B3F46</string>
<string>6BF7C37F1113026E002B3F46</string>
<string>6BF7C3801113026E002B3F46</string>
<string>6BF7C3811113026E002B3F46</string>
<string>6BF7C38A11130EA2002B3F46</string>
<string>6BF7C390111313CC002B3F46</string>
<string>6BF7C398111316AD002B3F46</string>
<string>6BF7C399111316AD002B3F46</string>
<string>6BF7C39A111316AD002B3F46</string>
@@ -587,7 +557,6 @@
<string>6BF7C3E211131F26002B3F46</string>
<string>6BF7C3E311131F26002B3F46</string>
<string>6BF7C3E411131F26002B3F46</string>
<string>6BF7C3E511131F26002B3F46</string>
<string>6BF7C3E611131F26002B3F46</string>
<string>6BF7C3E711131F26002B3F46</string>
<string>6BF7C3E811131F26002B3F46</string>
@@ -602,10 +571,99 @@
<string>6BF7C3F111131F26002B3F46</string>
<string>6BF7C3F211131F26002B3F46</string>
<string>6BF7C3F311131F26002B3F46</string>
<string>6BF7C3F811131F84002B3F46</string>
<string>6BF7C3FC11132015002B3F46</string>
<string>6BF7C4041113209A002B3F46</string>
<string>6BF7C4051113209A002B3F46</string>
<string>6BF7C4381115BCC0002B3F46</string>
<string>6BF7C43A1115BCC0002B3F46</string>
<string>6BF7C4431115BDD6002B3F46</string>
<string>6BF7C4661115C514002B3F46</string>
<string>6BF7C4671115C514002B3F46</string>
<string>6BF7C46A1115C514002B3F46</string>
<string>6BF7C47B1115C6B4002B3F46</string>
<string>6BF7C47C1115C6B4002B3F46</string>
<string>6BF7C4871115C7C4002B3F46</string>
<string>6BF7C4881115C7C4002B3F46</string>
<string>6BF7C4891115C7C4002B3F46</string>
<string>6BF7C4B61115CE76002B3F46</string>
<string>6BF7C4EA1115D2E3002B3F46</string>
<string>6BF7C4EB1115D2E3002B3F46</string>
<string>6BF7C4F11115D4F7002B3F46</string>
<string>6BF7C4FD1115D5E8002B3F46</string>
<string>6BF7C5121115DB96002B3F46</string>
<string>6BF7C5131115DB96002B3F46</string>
<string>6BF7C5141115DB96002B3F46</string>
<string>6BF7C5151115DB96002B3F46</string>
<string>6BF7C5161115DB96002B3F46</string>
<string>6BF7C5171115DB96002B3F46</string>
<string>6BF7C52C1115FA3B002B3F46</string>
<string>6BF7C52F1115FA3B002B3F46</string>
<string>6BF7C5371115FA3B002B3F46</string>
<string>6BF7C5391115FA3B002B3F46</string>
<string>6BF7C5501115FB84002B3F46</string>
<string>6BF7C5621115FC70002B3F46</string>
<string>6BF7C5881115FEFF002B3F46</string>
<string>6BF7C58A1115FEFF002B3F46</string>
<string>6BF7C58D1115FEFF002B3F46</string>
<string>6BF7C5941115FF90002B3F46</string>
<string>6BF7C5A7111601A1002B3F46</string>
<string>6BF7C5A9111601A1002B3F46</string>
<string>6BF7C5C01116E1C6002B3F46</string>
<string>6BF7C5C11116E1C6002B3F46</string>
<string>6BF7C5C21116E1C6002B3F46</string>
<string>6BF7C5CA1116E247002B3F46</string>
<string>6BF7C5D71116E3A1002B3F46</string>
<string>6BF7C5D81116E3A1002B3F46</string>
<string>6BF7C5F11116F280002B3F46</string>
<string>6BF7C5F21116F280002B3F46</string>
<string>6BF7C5F31116F280002B3F46</string>
<string>6BF7C5F41116F280002B3F46</string>
<string>6BF7C5FC1116F346002B3F46</string>
<string>6BF7C6081116F61A002B3F46</string>
<string>6BF7C6091116F61A002B3F46</string>
<string>6BF7C60B1116F61A002B3F46</string>
<string>6BF7C60C1116F61A002B3F46</string>
<string>6BF7C60E1116F61A002B3F46</string>
<string>6BF7C6101116F61A002B3F46</string>
<string>6BF7C6121116F61A002B3F46</string>
<string>6BF7C6191116F648002B3F46</string>
<string>6BF7C6231116F7B1002B3F46</string>
<string>6BF7C6241116F7B1002B3F46</string>
<string>6BF7C62C111707F3002B3F46</string>
<string>6BF7C62D111707F3002B3F46</string>
<string>6BF7C11111116E74002B3F46</string>
<string>6BF7C64A1117108B002B3F46</string>
<string>6BF7C650111711A3002B3F46</string>
<string>6BF7C65D1117142A002B3F46</string>
<string>6BF7C65E1117142A002B3F46</string>
<string>6BF7C65F1117142A002B3F46</string>
<string>6BF7C6601117142A002B3F46</string>
<string>6BF7C6611117142A002B3F46</string>
<string>6BF7C6621117142A002B3F46</string>
<string>6BF7C6631117142A002B3F46</string>
<string>6BF7C6641117142A002B3F46</string>
<string>6BF7C6651117142A002B3F46</string>
<string>6BF7C6661117142A002B3F46</string>
<string>6BF7C6671117142A002B3F46</string>
<string>6BF7C6681117142A002B3F46</string>
<string>6BF7C6691117142A002B3F46</string>
<string>6BF7C66A1117142A002B3F46</string>
<string>6BF7C66B1117142A002B3F46</string>
<string>6BF7C676111715D1002B3F46</string>
<string>6BF7C677111715D1002B3F46</string>
<string>6BF7C678111715D1002B3F46</string>
<string>6BF7C67F1117163B002B3F46</string>
<string>6BF7C6801117163B002B3F46</string>
<string>6BF7C690111720C6002B3F46</string>
<string>6BF7C691111720C6002B3F46</string>
<string>6BF7C692111720C6002B3F46</string>
<string>6BF7C693111720C6002B3F46</string>
<string>6BF7C694111720C6002B3F46</string>
<string>6BF7C695111720C6002B3F46</string>
<string>6BF7C6A411172253002B3F46</string>
<string>6BF7C6AC11172278002B3F46</string>
<string>6BF7C6AD11172278002B3F46</string>
<string>6BF7C6B3111722A5002B3F46</string>
</array>
</dict>
<key>SplitCount</key>
@@ -619,18 +677,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {876, 563}}</string>
<string>{{0, 0}, {876, 491}}</string>
<key>RubberWindowFrame</key>
<string>11 76 1256 702 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>563pt</string>
<string>491pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>93pt</string>
<string>165pt</string>
<key>Tabs</key>
<array>
<dict>
@@ -660,7 +718,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {876, 176}}</string>
<string>{{10, 27}, {876, 138}}</string>
</dict>
<key>Module</key>
<string>PBXProjectFindModule</string>
@@ -698,7 +756,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {876, 66}}</string>
<string>{{10, 27}, {876, 138}}</string>
<key>RubberWindowFrame</key>
<string>11 76 1256 702 0 0 1280 778 </string>
</dict>
@@ -783,12 +841,12 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {1256, 367}}</string>
<string>{{0, 0}, {1256, 260}}</string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
<key>Proportion</key>
<string>367pt</string>
<string>260pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
@@ -807,8 +865,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {623, 80}}</string>
<string>{{623, 0}, {633, 80}}</string>
<string>{{0, 0}, {623, 109}}</string>
<string>{{623, 0}, {633, 109}}</string>
</array>
</dict>
<key>VerticalSplitView</key>
@@ -823,8 +881,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {1256, 80}}</string>
<string>{{0, 79}, {1256, 210}}</string>
<string>{{0, 0}, {1256, 109}}</string>
<string>{{0, 109}, {1256, 287}}</string>
</array>
</dict>
</dict>
@@ -844,7 +902,7 @@
<key>DebugSTDIOWindowFrame</key>
<string>{{200, 200}, {500, 300}}</string>
<key>Frame</key>
<string>{{0, 372}, {1256, 289}}</string>
<string>{{0, 265}, {1256, 396}}</string>
<key>PBXDebugSessionStackFrameViewKey</key>
<dict>
<key>DebugVariablesTableConfiguration</key>
@@ -857,13 +915,13 @@
<real>403</real>
</array>
<key>Frame</key>
<string>{{623, 0}, {633, 80}}</string>
<string>{{623, 0}, {633, 109}}</string>
</dict>
</dict>
<key>Module</key>
<string>PBXDebugSessionModule</string>
<key>Proportion</key>
<string>289pt</string>
<string>396pt</string>
</dict>
</array>
<key>Name</key>

View File

@@ -43,6 +43,7 @@
6BCF32361104CD05009445BF /* OffMeshConnectionTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BCF32351104CD05009445BF /* OffMeshConnectionTool.cpp */; };
6BF7C1401111953A002B3F46 /* TestCase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF7C13F1111953A002B3F46 /* TestCase.cpp */; };
6BF7C3C511131B1F002B3F46 /* BoxVolumeTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF7C3C411131B1F002B3F46 /* BoxVolumeTool.cpp */; };
6BF7C4541115C277002B3F46 /* RecastArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF7C4531115C277002B3F46 /* RecastArea.cpp */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
/* End PBXBuildFile section */
@@ -116,6 +117,7 @@
6BF7C13F1111953A002B3F46 /* TestCase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TestCase.cpp; path = ../../Source/TestCase.cpp; sourceTree = SOURCE_ROOT; };
6BF7C3C311131B0F002B3F46 /* BoxVolumeTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BoxVolumeTool.h; path = ../../Include/BoxVolumeTool.h; sourceTree = SOURCE_ROOT; };
6BF7C3C411131B1F002B3F46 /* BoxVolumeTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BoxVolumeTool.cpp; path = ../../Source/BoxVolumeTool.cpp; sourceTree = SOURCE_ROOT; };
6BF7C4531115C277002B3F46 /* RecastArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastArea.cpp; path = ../../../Recast/Source/RecastArea.cpp; sourceTree = SOURCE_ROOT; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Recast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Recast.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -245,6 +247,7 @@
6B137C800F7FCBFE00459200 /* RecastLog.h */,
6B137C810F7FCBFE00459200 /* RecastTimer.h */,
6B624169103434880002E346 /* RecastMeshDetail.cpp */,
6BF7C4531115C277002B3F46 /* RecastArea.cpp */,
);
name = Recast;
sourceTree = "<group>";
@@ -395,6 +398,7 @@
6BCF32361104CD05009445BF /* OffMeshConnectionTool.cpp in Sources */,
6BF7C1401111953A002B3F46 /* TestCase.cpp in Sources */,
6BF7C3C511131B1F002B3F46 /* BoxVolumeTool.cpp in Sources */,
6BF7C4541115C277002B3F46 /* RecastArea.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -35,6 +35,7 @@ enum SampleToolType
{
TOOL_NONE = 0,
TOOL_TILE_EDIT,
TOOL_TILE_HIGHLIGHT,
TOOL_NAVMESH_TESTER,
TOOL_OFFMESH_CONNECTION,
TOOL_BOX_VOLUME,

View File

@@ -32,6 +32,7 @@ protected:
{
inline Tile() : chf(0), solid(0), cset(0), pmesh(0), dmesh(0), buildTime(0) {}
inline ~Tile() { delete chf; delete cset; delete solid; delete pmesh; delete dmesh; }
int x, y;
rcCompactHeightfield* chf;
rcHeightfield* solid;
rcContourSet* cset;
@@ -66,6 +67,7 @@ protected:
int m_statTimePerTile[MAX_STAT_BUCKETS];
int m_statTimePerTileSamples;
int m_highLightedTileX, m_highLightedTileY;
enum DrawMode
{
@@ -91,6 +93,7 @@ protected:
DrawMode m_drawMode;
void cleanup();
bool canDrawTile(int x, int y);
public:
Sample_SoloMeshTiled();
@@ -104,6 +107,8 @@ public:
virtual void handleRenderOverlay(double* proj, double* model, int* view);
virtual void handleMeshChanged(class InputGeom* geom);
virtual bool handleBuild();
void setHighlightedTile(const float* pos);
};

View File

@@ -389,13 +389,22 @@ void InputGeom::drawBoxVolumes(struct duDebugDraw* dd, bool hilight)
{
dd->depthMask(false);
dd->begin(DU_DRAW_LINES, 1.0f);
dd->begin(DU_DRAW_LINES, 2.0f);
for (int i = 0; i < m_boxVolCount; ++i)
{
unsigned int col = duIntToCol(m_boxVolTypes[i], 220);
unsigned int col = duIntToCol(m_boxVolTypes[i]+1, 220);
const float* bounds = &m_boxVolVerts[i*3*2];
duAppendBoxWire(dd, bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5], col);
}
}
dd->end();
dd->begin(DU_DRAW_POINTS, 4.0f);
for (int i = 0; i < m_boxVolCount; ++i)
{
unsigned int col = duDarkenColor(duIntToCol(m_boxVolTypes[i]+1, 255));
const float* bounds = &m_boxVolVerts[i*3*2];
duAppendBoxPoints(dd, bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5], col);
}
dd->end();
dd->depthMask(true);

View File

@@ -43,7 +43,7 @@
Sample_SoloMeshSimple::Sample_SoloMeshSimple() :
m_keepInterResults(false),
m_keepInterResults(true),
m_triflags(0),
m_solid(0),
m_chf(0),
@@ -203,7 +203,6 @@ void Sample_SoloMeshSimple::handleRender()
m_geom->getMesh()->getTris(), m_geom->getMesh()->getNormals(), m_geom->getMesh()->getTriCount(),
m_agentMaxSlope);
m_geom->drawOffMeshConnections(&dd);
m_geom->drawBoxVolumes(&dd);
}
else if (m_drawMode != DRAWMODE_NAVMESH_TRANS)
{
@@ -211,7 +210,6 @@ void Sample_SoloMeshSimple::handleRender()
duDebugDrawTriMesh(&dd, m_geom->getMesh()->getVerts(), m_geom->getMesh()->getVertCount(),
m_geom->getMesh()->getTris(), m_geom->getMesh()->getNormals(), m_geom->getMesh()->getTriCount(), 0);
m_geom->drawOffMeshConnections(&dd);
m_geom->drawBoxVolumes(&dd);
}
glDisable(GL_FOG);
@@ -295,12 +293,7 @@ void Sample_SoloMeshSimple::handleRender()
glDepthMask(GL_TRUE);
}
/* static const float startCol[4] = { 0.5f, 0.1f, 0.0f, 0.75f };
static const float endCol[4] = { 0.2f, 0.4f, 0.0f, 0.75f };
if (m_sposSet)
drawAgent(m_spos, m_agentRadius, m_agentHeight, m_agentMaxClimb, startCol);
if (m_eposSet)
drawAgent(m_epos, m_agentRadius, m_agentHeight, m_agentMaxClimb, endCol);*/
m_geom->drawBoxVolumes(&dd);
if (m_tool)
m_tool->handleRender();
@@ -441,6 +434,7 @@ bool Sample_SoloMeshSimple::handleBuild()
rcFilterLedgeSpans(m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid);
rcFilterWalkableLowHeightSpans(m_cfg.walkableHeight, *m_solid);
//
// Step 4. Partition walkable surface to simple regions.
//
@@ -467,6 +461,23 @@ bool Sample_SoloMeshSimple::handleBuild()
delete m_solid;
m_solid = 0;
}
// Erode the walkable area by agent radius.
if (!rcErodeArea(RC_WALKABLE_AREA, m_cfg.walkableRadius, *m_chf))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
return false;
}
// (Optional) Mark areas.
const float* boxVerts = m_geom->getBoxVolumeVerts();
const unsigned char* boxTypes = m_geom->getBoxVolumeTypes();
for (int i = 0; i < m_geom->getBoxVolumeCount(); ++i)
{
const float* v = &boxVerts[i*3*2];
rcMarkBoxArea(&v[0], &v[3], boxTypes[i], *m_chf);
}
// Prepare for region partitioning, by calculating distance field along the walkable surface.
if (!rcBuildDistanceField(*m_chf))
@@ -477,12 +488,12 @@ bool Sample_SoloMeshSimple::handleBuild()
}
// Partition the walkable surface into simple regions without holes.
if (!rcBuildRegions(*m_chf, m_cfg.walkableRadius, m_cfg.borderSize, m_cfg.minRegionSize, m_cfg.mergeRegionSize))
if (!rcBuildRegions(*m_chf, m_cfg.borderSize, m_cfg.minRegionSize, m_cfg.mergeRegionSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not build regions.");
}
//
// Step 5. Trace and simplify region contours.
//
@@ -624,6 +635,8 @@ bool Sample_SoloMeshSimple::handleBuild()
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Border: %.1fms (%.1f%%)", m_buildTimes.filterBorder/1000.0f, m_buildTimes.filterBorder*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Walkable: %.1fms (%.1f%%)", m_buildTimes.filterWalkable/1000.0f, m_buildTimes.filterWalkable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Reachable: %.1fms (%.1f%%)", m_buildTimes.filterMarkReachable/1000.0f, m_buildTimes.filterMarkReachable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Erode walkable area: %.1fms (%.1f%%)", m_buildTimes.erodeArea/1000.0f, m_buildTimes.erodeArea*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Build Distancefield: %.1fms (%.1f%%)", m_buildTimes.buildDistanceField/1000.0f, m_buildTimes.buildDistanceField*pc);
rcGetLog()->log(RC_LOG_PROGRESS, " - distance: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldDist/1000.0f, m_buildTimes.buildDistanceFieldDist*pc);

View File

@@ -34,11 +34,82 @@
#include "DetourDebugDraw.h"
#include "NavMeshTesterTool.h"
#include "OffMeshConnectionTool.h"
#include "BoxVolumeTool.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
class TileHighlightTool : public SampleTool
{
Sample_SoloMeshTiled* m_sample;
float m_hitPos[3];
bool m_hitPosSet;
float m_agentRadius;
public:
TileHighlightTool() :
m_sample(0),
m_hitPosSet(false),
m_agentRadius(0)
{
}
virtual ~TileHighlightTool()
{
if (m_sample)
m_sample->setHighlightedTile(0);
}
virtual int type() { return TOOL_TILE_HIGHLIGHT; }
virtual void init(Sample* sample)
{
m_sample = (Sample_SoloMeshTiled*)sample;
}
virtual void reset() {}
virtual void handleMenu()
{
imguiValue("Click LMB to highlight a tile.");
}
virtual void handleClick(const float* p, bool shift)
{
m_hitPosSet = true;
vcopy(m_hitPos,p);
if (m_sample)
m_sample->setHighlightedTile(m_hitPos);
}
virtual void handleRender()
{
if (m_hitPosSet)
{
const float s = m_sample->getAgentRadius();
glColor4ub(0,0,0,128);
glLineWidth(2.0f);
glBegin(GL_LINES);
glVertex3f(m_hitPos[0]-s,m_hitPos[1]+0.1f,m_hitPos[2]);
glVertex3f(m_hitPos[0]+s,m_hitPos[1]+0.1f,m_hitPos[2]);
glVertex3f(m_hitPos[0],m_hitPos[1]-s+0.1f,m_hitPos[2]);
glVertex3f(m_hitPos[0],m_hitPos[1]+s+0.1f,m_hitPos[2]);
glVertex3f(m_hitPos[0],m_hitPos[1]+0.1f,m_hitPos[2]-s);
glVertex3f(m_hitPos[0],m_hitPos[1]+0.1f,m_hitPos[2]+s);
glEnd();
glLineWidth(1.0f);
}
}
virtual void handleRenderOverlay(double* proj, double* model, int* view)
{
}
};
Sample_SoloMeshTiled::Sample_SoloMeshTiled() :
m_measurePerTileTimings(false),
m_keepInterResults(false),
@@ -48,6 +119,8 @@ Sample_SoloMeshTiled::Sample_SoloMeshTiled() :
m_tileSet(0),
m_statPolysPerTileSamples(0),
m_statTimePerTileSamples(0),
m_highLightedTileX(-1),
m_highLightedTileY(-1),
m_drawMode(DRAWMODE_NAVMESH)
{
setTool(new NavMeshTesterTool);
@@ -114,6 +187,14 @@ void Sample_SoloMeshTiled::handleTools()
{
setTool(new OffMeshConnectionTool);
}
if (imguiCheck("Create Box Volumes", type == TOOL_BOX_VOLUME))
{
setTool(new BoxVolumeTool);
}
if (imguiCheck("Highlight Tile", type == TOOL_TILE_HIGHLIGHT))
{
setTool(new TileHighlightTool);
}
imguiSeparator();
@@ -277,7 +358,7 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
if (m_tileSet->tiles[i].chf && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawCompactHeightfieldSolid(&dd, *m_tileSet->tiles[i].chf);
}
}
@@ -286,7 +367,7 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
if (m_tileSet->tiles[i].chf && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawCompactHeightfieldDistance(&dd, *m_tileSet->tiles[i].chf);
}
}
@@ -294,7 +375,7 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
if (m_tileSet->tiles[i].chf && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawCompactHeightfieldRegions(&dd, *m_tileSet->tiles[i].chf);
}
}
@@ -304,7 +385,7 @@ void Sample_SoloMeshTiled::handleRender()
glEnable(GL_FOG);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].solid)
if (m_tileSet->tiles[i].solid && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawHeightfieldSolid(&dd, *m_tileSet->tiles[i].solid);
}
glDisable(GL_FOG);
@@ -314,7 +395,7 @@ void Sample_SoloMeshTiled::handleRender()
glEnable(GL_FOG);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].solid)
if (m_tileSet->tiles[i].solid && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawHeightfieldWalkable(&dd, *m_tileSet->tiles[i].solid);
}
glDisable(GL_FOG);
@@ -324,7 +405,7 @@ void Sample_SoloMeshTiled::handleRender()
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
if (m_tileSet->tiles[i].cset && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawRawContours(&dd, *m_tileSet->tiles[i].cset);
}
glDepthMask(GL_TRUE);
@@ -334,7 +415,7 @@ void Sample_SoloMeshTiled::handleRender()
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
if (m_tileSet->tiles[i].cset && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
{
duDebugDrawRawContours(&dd, *m_tileSet->tiles[i].cset, 0.5f);
duDebugDrawContours(&dd, *m_tileSet->tiles[i].cset);
@@ -347,7 +428,7 @@ void Sample_SoloMeshTiled::handleRender()
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
if (m_tileSet->tiles[i].cset && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawContours(&dd, *m_tileSet->tiles[i].cset);
}
glDepthMask(GL_TRUE);
@@ -356,14 +437,14 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
if (m_tileSet->tiles[i].chf && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawCompactHeightfieldRegions(&dd, *m_tileSet->tiles[i].chf);
}
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
if (m_tileSet->tiles[i].cset && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawRegionConnections(&dd, *m_tileSet->tiles[i].cset);
}
glDepthMask(GL_TRUE);
@@ -379,7 +460,7 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].pmesh)
if (m_tileSet->tiles[i].pmesh && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawPolyMesh(&dd, *m_tileSet->tiles[i].pmesh);
}
}
@@ -397,7 +478,7 @@ void Sample_SoloMeshTiled::handleRender()
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].dmesh)
if (m_tileSet->tiles[i].dmesh && canDrawTile(m_tileSet->tiles[i].x,m_tileSet->tiles[i].y))
duDebugDrawPolyMeshDetail(&dd, *m_tileSet->tiles[i].dmesh);
}
}
@@ -405,16 +486,12 @@ void Sample_SoloMeshTiled::handleRender()
}
}
/* static const float startCol[4] = { 0.5f, 0.1f, 0.0f, 0.75f };
static const float endCol[4] = { 0.2f, 0.4f, 0.0f, 0.75f };
if (m_sposSet)
drawAgent(m_spos, m_agentRadius, m_agentHeight, m_agentMaxClimb, startCol);
if (m_eposSet)
drawAgent(m_epos, m_agentRadius, m_agentHeight, m_agentMaxClimb, endCol);
*/
m_geom->drawBoxVolumes(&dd);
if (m_tool)
m_tool->handleRender();
glDepthMask(GL_TRUE);
}
static float nicenum(float x, int round)
@@ -608,7 +685,7 @@ bool Sample_SoloMeshTiled::handleBuild()
m_cfg.mergeRegionSize = (int)rcSqr(m_regionMergeSize);
m_cfg.maxVertsPerPoly = (int)m_vertsPerPoly;
m_cfg.tileSize = (int)m_tileSize;
m_cfg.borderSize = m_cfg.walkableRadius + 3; // Reserve enough padding.
m_cfg.borderSize = m_cfg.walkableRadius + 4; // Reserve enough padding.
m_cfg.detailSampleDist = m_detailSampleDist < 0.9f ? 0 : m_cellSize * m_detailSampleDist;
m_cfg.detailSampleMaxError = m_cellHeight * m_detailSampleMaxError;
@@ -684,7 +761,9 @@ bool Sample_SoloMeshTiled::handleBuild()
{
rcTimeVal startTime = rcGetPerformanceTimer();
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
tile.x = x;
tile.y = y;
// Calculate the per tile bounding box.
tileCfg.bmin[0] = m_cfg.bmin[0] + (x*m_cfg.tileSize - m_cfg.borderSize)*m_cfg.cs;
@@ -753,6 +832,22 @@ bool Sample_SoloMeshTiled::handleBuild()
continue;
}
// Erode the walkable area by agent radius.
if (!rcErodeArea(RC_WALKABLE_AREA, m_cfg.walkableRadius, *chf))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Could not erode.");
continue;
}
const float* boxVerts = m_geom->getBoxVolumeVerts();
const unsigned char* boxTypes = m_geom->getBoxVolumeTypes();
for (int i = 0; i < m_geom->getBoxVolumeCount(); ++i)
{
const float* v = &boxVerts[i*3*2];
rcMarkBoxArea(&v[0], &v[3], boxTypes[i], *chf);
}
if (!rcBuildDistanceField(*chf))
{
if (rcGetLog())
@@ -760,8 +855,7 @@ bool Sample_SoloMeshTiled::handleBuild()
continue;
}
if (!rcBuildRegions(*chf, tileCfg.walkableRadius, tileCfg.borderSize,
tileCfg.minRegionSize, tileCfg.mergeRegionSize))
if (!rcBuildRegions(*chf, tileCfg.borderSize, tileCfg.minRegionSize, tileCfg.mergeRegionSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not build regions.", x, y);
@@ -991,6 +1085,8 @@ bool Sample_SoloMeshTiled::handleBuild()
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Walkable: %.1fms (%.1f%%)", m_buildTimes.filterWalkable/1000.0f, m_buildTimes.filterWalkable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Reachable: %.1fms (%.1f%%)", m_buildTimes.filterMarkReachable/1000.0f, m_buildTimes.filterMarkReachable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Erode walkable area: %.1fms (%.1f%%)", m_buildTimes.erodeArea/1000.0f, m_buildTimes.erodeArea*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Build Distancefield: %.1fms (%.1f%%)", m_buildTimes.buildDistanceField/1000.0f, m_buildTimes.buildDistanceField*pc);
rcGetLog()->log(RC_LOG_PROGRESS, " - distance: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldDist/1000.0f, m_buildTimes.buildDistanceFieldDist*pc);
rcGetLog()->log(RC_LOG_PROGRESS, " - blur: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldBlur/1000.0f, m_buildTimes.buildDistanceFieldBlur*pc);
@@ -1021,3 +1117,23 @@ bool Sample_SoloMeshTiled::handleBuild()
return true;
}
bool Sample_SoloMeshTiled::canDrawTile(int x, int y)
{
if (m_highLightedTileX == -1) return true;
return m_highLightedTileX == x && m_highLightedTileY == y;
}
void Sample_SoloMeshTiled::setHighlightedTile(const float* pos)
{
if (!pos)
{
m_highLightedTileX = -1;
m_highLightedTileY = -1;
return;
}
const float* bmin = m_geom->getMeshBoundsMin();
const float ts = m_tileSize*m_cellSize;
m_highLightedTileX = (int)((pos[0] - bmin[0]) / ts);
m_highLightedTileY = (int)((pos[2] - bmin[2]) / ts);
}

View File

@@ -34,6 +34,7 @@
#include "DetourDebugDraw.h"
#include "NavMeshTesterTool.h"
#include "OffMeshConnectionTool.h"
#include "BoxVolumeTool.h"
#ifdef WIN32
# define snprintf _snprintf
@@ -257,6 +258,10 @@ void Sample_TileMesh::handleTools()
{
setTool(new OffMeshConnectionTool);
}
if (imguiCheck("Create Box Volumes", type == TOOL_BOX_VOLUME))
{
setTool(new BoxVolumeTool);
}
imguiSeparator();
@@ -337,6 +342,8 @@ void Sample_TileMesh::handleRender()
if (m_tool)
m_tool->handleRender();
m_geom->drawBoxVolumes(&dd);
glDepthMask(GL_TRUE);
}
@@ -419,10 +426,8 @@ void Sample_TileMesh::buildTile(const float* pos)
const float* bmax = m_geom->getMeshBoundsMax();
const float ts = m_tileSize*m_cellSize;
const int tx = (int)floorf((pos[0] - bmin[0]) / ts);
const int ty = (int)floorf((pos[2] - bmin[2]) / ts);
if (tx < 0 || ty < 0)
return;
const int tx = (int)((pos[0] - bmin[0]) / ts);
const int ty = (int)((pos[2] - bmin[2]) / ts);
m_tileBmin[0] = bmin[0] + tx*ts;
m_tileBmin[1] = bmin[1];
@@ -457,10 +462,8 @@ void Sample_TileMesh::removeTile(const float* pos)
const float* bmax = m_geom->getMeshBoundsMax();
const float ts = m_tileSize*m_cellSize;
const int tx = (int)floorf((pos[0] - bmin[0]) / ts);
const int ty = (int)floorf((pos[2] - bmin[2]) / ts);
if (tx < 0 || ty < 0)
return;
const int tx = (int)((pos[0] - bmin[0]) / ts);
const int ty = (int)((pos[2] - bmin[2]) / ts);
m_tileBmin[0] = bmin[0] + tx*ts;
m_tileBmin[1] = bmin[1];
@@ -676,6 +679,23 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
delete m_solid;
m_solid = 0;
}
// Erode the walkable area by agent radius.
if (!rcErodeArea(RC_WALKABLE_AREA, m_cfg.walkableRadius, *m_chf))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
return false;
}
const float* boxVerts = m_geom->getBoxVolumeVerts();
const unsigned char* boxTypes = m_geom->getBoxVolumeTypes();
for (int i = 0; i < m_geom->getBoxVolumeCount(); ++i)
{
const float* v = &boxVerts[i*3*2];
rcMarkBoxArea(&v[0], &v[3], boxTypes[i], *m_chf);
}
// Prepare for region partitioning, by calculating distance field along the walkable surface.
if (!rcBuildDistanceField(*m_chf))
@@ -686,7 +706,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
}
// Partition the walkable surface into simple regions without holes.
if (!rcBuildRegions(*m_chf, m_cfg.walkableRadius, m_cfg.borderSize, m_cfg.minRegionSize, m_cfg.mergeRegionSize))
if (!rcBuildRegions(*m_chf, m_cfg.borderSize, m_cfg.minRegionSize, m_cfg.mergeRegionSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not build regions.");
@@ -823,6 +843,8 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Walkable: %.1fms (%.1f%%)", m_buildTimes.filterWalkable/1000.0f, m_buildTimes.filterWalkable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Reachable: %.1fms (%.1f%%)", m_buildTimes.filterMarkReachable/1000.0f, m_buildTimes.filterMarkReachable*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Erode walkable area: %.1fms (%.1f%%)", m_buildTimes.erodeArea/1000.0f, m_buildTimes.erodeArea*pc);
rcGetLog()->log(RC_LOG_PROGRESS, "Build Distancefield: %.1fms (%.1f%%)", m_buildTimes.buildDistanceField/1000.0f, m_buildTimes.buildDistanceField*pc);
rcGetLog()->log(RC_LOG_PROGRESS, " - distance: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldDist/1000.0f, m_buildTimes.buildDistanceFieldDist*pc);
rcGetLog()->log(RC_LOG_PROGRESS, " - blur: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldBlur/1000.0f, m_buildTimes.buildDistanceFieldBlur*pc);