From 6469a99f119e6917715acab9210a5c7da8689e12 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 19 Jan 2014 15:32:09 +0200 Subject: [PATCH 1/4] Fixed item type in PolyRefArray from int to dtPolyRef --- RecastDemo/Source/NavMeshPruneTool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecastDemo/Source/NavMeshPruneTool.cpp b/RecastDemo/Source/NavMeshPruneTool.cpp index 193d79a..270c8f6 100644 --- a/RecastDemo/Source/NavMeshPruneTool.cpp +++ b/RecastDemo/Source/NavMeshPruneTool.cpp @@ -63,7 +63,7 @@ public: } m_size = n; } - inline void push(int item) { resize(m_size+1); m_data[m_size-1] = item; } + inline void push(dtPolyRef item) { resize(m_size+1); m_data[m_size-1] = item; } inline dtPolyRef pop() { if (m_size > 0) m_size--; return m_data[m_size]; } inline const dtPolyRef& operator[](int i) const { return m_data[i]; } inline dtPolyRef& operator[](int i) { return m_data[i]; } From ad7a13cbf3ecdacb741d24d2bc2c447e73314d3f Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 19 Jan 2014 16:47:26 +0200 Subject: [PATCH 2/4] Small formatting change to dividePoly() --- Recast/Source/RecastRasterization.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Recast/Source/RecastRasterization.cpp b/Recast/Source/RecastRasterization.cpp index f082438..5ad6f01 100644 --- a/Recast/Source/RecastRasterization.cpp +++ b/Recast/Source/RecastRasterization.cpp @@ -170,17 +170,17 @@ void rcAddSpan(rcContext* /*ctx*/, rcHeightfield& hf, const int x, const int y, } // divides a convex polygons into two convex polygons on both sides of a line -static void dividePoly(const float* in, int nbIn, - float* out1, int* nb1, - float* out2, int* nb2, +static void dividePoly(const float* in, int nin, + float* out1, int* nout1, + float* out2, int* nout2, float x, int axis) { float d[12]; - for (int i = 0; i < nbIn; ++i) + for (int i = 0; i < nin; ++i) d[i] = x - in[i*3+axis]; int m = 0, n = 0; - for (int i = 0, j = nbIn-1; i < nbIn; j=i, ++i) + for (int i = 0, j = nin-1; i < nin; j=i, ++i) { bool ina = d[j] >= 0; bool inb = d[i] >= 0; @@ -211,8 +211,8 @@ static void dividePoly(const float* in, int nbIn, n++; } - *nb1 = m; - *nb2 = n; + *nout1 = m; + *nout2 = n; } From 65da694f501ed69bb01319d057386355a6c6b911 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 19 Jan 2014 16:47:47 +0200 Subject: [PATCH 3/4] gitignore meshes starting with underscore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2e39568..b321a15 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ RecastDemo/Bin/RecastDemo # Build directory RecastDemo/Build +# Ignore some meshes based on name +RecastDemo/Bin/Meshes/_* + ## Logs and databases # *.log *.sql From 29db8cde1bf323e6f828db3b70a754a3025e9076 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 19 Jan 2014 17:49:40 +0200 Subject: [PATCH 4/4] Fix for detail mesh corner cases - fix case where thing long poly center may not be on the region --- Recast/Source/RecastMeshDetail.cpp | 115 +++++++++++++---------------- 1 file changed, 53 insertions(+), 62 deletions(-) diff --git a/Recast/Source/RecastMeshDetail.cpp b/Recast/Source/RecastMeshDetail.cpp index 3b94663..69ed147 100644 --- a/Recast/Source/RecastMeshDetail.cpp +++ b/Recast/Source/RecastMeshDetail.cpp @@ -751,64 +751,55 @@ static void getHeightData(const rcCompactHeightfield& chf, // since border size offset is already removed from the polymesh vertices. stack.resize(0); - - static const int offset[9*2] = - { - 0,0, -1,0, 0,1, 1,0, 0,-1, -1,-1, -1,1, 1,1, 1,-1 - }; - - // find the center of the polygon - int pcx = 0, pcz = 0; - for (int j = 0; j < npoly; ++j) - { - pcx += (int)verts[poly[j]*3+0]; - pcz += (int)verts[poly[j]*3+2]; - } - pcx /= npoly; - pcz /= npoly; - - // find a span with the right region around this point - // No need to check for connectivity because the region ensures it - for (int dir = 0; dir < 9; ++dir) - { - int ax = pcx + offset[dir*2+0]; - int az = pcz + offset[dir*2+1]; - - if (ax < hp.xmin || ax >= hp.xmin+hp.width || - az < hp.ymin || az >= hp.ymin+hp.height) - continue; - - const rcCompactCell& c = chf.cells[(ax+bs)+(az+bs)*chf.width]; - for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) - { - const rcCompactSpan& s = chf.spans[i]; - if (s.reg == region) - { - stack.push(ax); - stack.push(az); - stack.push(i); - break; - } - } - if (stack.size() > 0) - break; - } - - // Floodfill the heightfield to get 2D height data, - // starting at center location found above as seed. - memset(hp.data, 0xff, sizeof(unsigned short)*hp.width*hp.height); - // Mark start locations. - for (int i = 0; i < stack.size(); i += 3) + // Copy the height from the same region, and mark region borders + // as seed points to fill the rest. + for (int hy = 0; hy < hp.height; hy++) { - int cx = stack[i+0]; - int cy = stack[i+1]; - int ci = stack[i+2]; - int idx = cx-hp.xmin+(cy-hp.ymin)*hp.width; - const rcCompactSpan& cs = chf.spans[ci]; - hp.data[idx] = cs.y; - } + int y = hp.ymin + hy + bs; + for (int hx = 0; hx < hp.width; hx++) + { + int x = hp.xmin + hx + bs; + const rcCompactCell& c = chf.cells[x+y*chf.width]; + for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) + { + const rcCompactSpan& s = chf.spans[i]; + if (s.reg == region) + { + // Store height + hp.data[hx + hy*hp.width] = s.y; + + // If any of the neighbours is not in same region, + // add the current location as flood fill start + bool border = false; + for (int dir = 0; dir < 4; ++dir) + { + if (rcGetCon(s, dir) != RC_NOT_CONNECTED) + { + const int ax = x + rcGetDirOffsetX(dir); + const int ay = y + rcGetDirOffsetY(dir); + const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dir); + const rcCompactSpan& as = chf.spans[ai]; + if (as.reg != region) + { + border = true; + break; + } + } + } + if (border) + { + stack.push(x); + stack.push(y); + stack.push(i); + } + break; + } + } + } + } + static const int RETRACT_SIZE = 256; int head = 0; @@ -834,19 +825,19 @@ static void getHeightData(const rcCompactHeightfield& chf, const int ax = cx + rcGetDirOffsetX(dir); const int ay = cy + rcGetDirOffsetY(dir); + const int hx = ax - hp.xmin - bs; + const int hy = ay - hp.ymin - bs; - if (ax < hp.xmin || ax >= (hp.xmin+hp.width) || - ay < hp.ymin || ay >= (hp.ymin+hp.height)) + if (hx < 0 || hx >= hp.width || hy < 0 || hy >= hp.height) continue; - if (hp.data[ax-hp.xmin+(ay-hp.ymin)*hp.width] != RC_UNSET_HEIGHT) + if (hp.data[hx + hy*hp.width] != RC_UNSET_HEIGHT) continue; - const int ai = (int)chf.cells[(ax+bs)+(ay+bs)*chf.width].index + rcGetCon(cs, dir); - + const int ai = (int)chf.cells[ax + ay*chf.width].index + rcGetCon(cs, dir); const rcCompactSpan& as = chf.spans[ai]; - int idx = ax-hp.xmin+(ay-hp.ymin)*hp.width; - hp.data[idx] = as.y; + + hp.data[hx + hy*hp.width] = as.y; stack.push(ax); stack.push(ay);