diff --git a/Recast/Source/RecastRegion.cpp b/Recast/Source/RecastRegion.cpp
index acda7b4..dbcec6a 100644
--- a/Recast/Source/RecastRegion.cpp
+++ b/Recast/Source/RecastRegion.cpp
@@ -437,12 +437,19 @@ static unsigned short* expandRegions(int maxIter, unsigned short level,
struct rcRegion
{
- inline rcRegion(unsigned short i) : count(0), id(i), area(0), remap(false) {}
+ inline rcRegion(unsigned short i) :
+ count(0),
+ id(i),
+ area(0),
+ remap(false),
+ visited(false)
+ {}
int count;
unsigned short id;
unsigned char area;
bool remap;
+ bool visited;
rcIntArray connections;
rcIntArray floors;
};
@@ -759,8 +766,10 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionSize, int mergeRegio
}
}
}
-
- // Remove too small unconnected regions.
+
+ // Remove too small regions.
+ rcIntArray stack(32);
+ rcIntArray trace(32);
for (int i = 0; i < nreg; ++i)
{
rcRegion& reg = regions[i];
@@ -768,19 +777,62 @@ static bool filterSmallRegions(rcContext* ctx, int minRegionSize, int mergeRegio
continue;
if (reg.count == 0)
continue;
+ if (reg.visited)
+ continue;
- if (reg.connections.size() == 1 && reg.connections[0] == 0)
+ // Count the total size of all the connected regions.
+ // Also keep track of the regions connects to a tile border.
+ bool connectsToBorder = false;
+ int count = 0;
+ stack.resize(0);
+ trace.resize(0);
+
+ reg.visited = true;
+ stack.push(i);
+
+ while (stack.size())
{
- if (reg.count < minRegionSize)
+ // Pop
+ int ri = stack.pop();
+
+ rcRegion& creg = regions[ri];
+
+ count += creg.count;
+ trace.push(ri);
+
+ for (int j = 0; j < creg.connections.size(); ++j)
{
- // Non-connected small region, remove.
- reg.count = 0;
- reg.id = 0;
+ if (creg.connections[j] & RC_BORDER_REG)
+ {
+ connectsToBorder = true;
+ continue;
+ }
+ rcRegion& nreg = regions[creg.connections[j]];
+ if (nreg.visited)
+ continue;
+ if (nreg.id == 0 || (nreg.id & RC_BORDER_REG))
+ continue;
+ // Visit
+ stack.push(nreg.id);
+ nreg.visited = true;
+ }
+ }
+
+ // If the accumulated regions size is too small, remove it.
+ // Do not remove areas which connect to tile borders
+ // as their size cannot be estimated correctly and removing them
+ // can potentially remove necessary areas.
+ if (count < minRegionSize && !connectsToBorder)
+ {
+ // Kill all visited regions.
+ for (int j = 0; j < trace.size(); ++j)
+ {
+ regions[trace[j]].count = 0;
+ regions[trace[j]].id = 0;
}
}
}
-
-
+
// Merge too small regions to neighbour regions.
int mergeCount = 0 ;
do
diff --git a/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast b/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast
index de9d6a6..5d104d8 100755
Binary files a/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast and b/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast differ
diff --git a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser
index 0afeaca..7c95ba1 100644
--- a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser
+++ b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser
@@ -210,6 +210,16 @@
6BB2EE281261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE281261C92300E350F8 /* PBXTextBookmark */;
6BB2EE291261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE291261C92300E350F8 /* PBXTextBookmark */;
6BB2EE2A1261C92300E350F8 /* PBXTextBookmark */ = 6BB2EE2A1261C92300E350F8 /* PBXTextBookmark */;
+ 6BB2EE351261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE351261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE361261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE361261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE371261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE371261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE381261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE381261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE391261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE391261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */ = 6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */;
+ 6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */;
+ 6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */;
+ 6BB2EE401261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE401261D02000E350F8 /* PBXTextBookmark */;
+ 6BB2EE411261D02000E350F8 /* PBXTextBookmark */ = 6BB2EE411261D02000E350F8 /* PBXTextBookmark */;
6BBB0361124E242E00533229 = 6BBB0361124E242E00533229 /* PBXTextBookmark */;
6BBB0363124E242E00533229 = 6BBB0363124E242E00533229 /* PBXTextBookmark */;
6BBB0365124E242E00533229 = 6BBB0365124E242E00533229 /* PBXTextBookmark */;
@@ -365,9 +375,9 @@
};
6B137C830F7FCC1100459200 /* RecastContour.cpp */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {933, 12480}}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 9945}}";
sepNavSelRange = "{20095, 0}";
- sepNavVisRange = "{19784, 431}";
+ sepNavVisRange = "{19389, 1374}";
sepNavWindowFrame = "{{38, 30}, {1214, 722}}";
};
};
@@ -396,9 +406,9 @@
};
6B137C890F7FCC1100459200 /* RecastRegion.cpp */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {933, 18896}}";
- sepNavSelRange = "{22176, 0}";
- sepNavVisRange = "{21660, 751}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 17082}}";
+ sepNavSelRange = "{19532, 0}";
+ sepNavVisRange = "{17831, 971}";
};
};
6B1C8E08121EB4FF0048697F /* PBXTextBookmark */ = {
@@ -420,9 +430,9 @@
};
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1219, 2470}}";
- sepNavSelRange = "{1307, 0}";
- sepNavVisRange = "{1241, 281}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 2769}}";
+ sepNavSelRange = "{2884, 0}";
+ sepNavVisRange = "{2623, 1223}";
};
};
6B25B6180FFA62BE004F1BC4 /* main.cpp */ = {
@@ -500,9 +510,9 @@
};
6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {931, 6045}}";
- sepNavSelRange = "{1110, 0}";
- sepNavVisRange = "{789, 626}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 5954}}";
+ sepNavSelRange = "{1003, 0}";
+ sepNavVisRange = "{842, 1275}";
};
};
6B555DF6100B273500247EA3 /* stb_truetype.h */ = {
@@ -810,7 +820,7 @@
fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
name = "RecastRegion.cpp: 931";
rLen = 0;
- rLoc = 22176;
+ rLoc = 23307;
rType = 0;
vrLen = 751;
vrLoc = 21660;
@@ -856,9 +866,9 @@
};
6B98470511E733B600FA177B /* RecastAlloc.h */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {933, 1120}}";
- sepNavSelRange = "{2032, 0}";
- sepNavVisRange = "{1347, 951}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 910}}";
+ sepNavSelRange = "{1797, 71}";
+ sepNavVisRange = "{969, 1378}";
};
};
6B98473011E737D800FA177B /* PBXTextBookmark */ = {
@@ -894,9 +904,9 @@
};
6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1219, 8281}}";
- sepNavSelRange = "{8071, 18}";
- sepNavVisRange = "{7496, 602}";
+ sepNavIntBoundsRect = "{{0, 0}, {931, 8307}}";
+ sepNavSelRange = "{11545, 0}";
+ sepNavVisRange = "{10675, 1806}";
};
};
6BA1E88E10C7BFD3008007F6 /* Sample_SoloMeshSimple.h */ = {
@@ -1656,6 +1666,106 @@
vrLen = 626;
vrLoc = 789;
};
+ 6BB2EE351261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */;
+ name = "imguiRenderGL.cpp: 22";
+ rLen = 0;
+ rLoc = 1003;
+ rType = 0;
+ vrLen = 1275;
+ vrLoc = 842;
+ };
+ 6BB2EE361261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B98470511E733B600FA177B /* RecastAlloc.h */;
+ name = "RecastAlloc.h: 51";
+ rLen = 71;
+ rLoc = 1797;
+ rType = 0;
+ vrLen = 1378;
+ vrLoc = 969;
+ };
+ 6BB2EE371261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
+ name = "RecastRegion.cpp: 849";
+ rLen = 0;
+ rLoc = 19562;
+ rType = 0;
+ vrLen = 1078;
+ vrLoc = 19104;
+ };
+ 6BB2EE381261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */;
+ name = "Sample_SoloMeshSimple.cpp: 380";
+ rLen = 0;
+ rLoc = 11545;
+ rType = 0;
+ vrLen = 1806;
+ vrLoc = 10675;
+ };
+ 6BB2EE391261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
+ name = "Sample.cpp: 121";
+ rLen = 15;
+ rLoc = 2865;
+ rType = 0;
+ vrLen = 1409;
+ vrLoc = 3254;
+ };
+ 6BB2EE3A1261CEB800E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
+ name = "Sample.cpp: 121";
+ rLen = 0;
+ rLoc = 2884;
+ rType = 0;
+ vrLen = 1152;
+ vrLoc = 2586;
+ };
+ 6BB2EE3E1261D02000E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */;
+ name = "Sample.cpp: 121";
+ rLen = 0;
+ rLoc = 2884;
+ rType = 0;
+ vrLen = 1223;
+ vrLoc = 2623;
+ };
+ 6BB2EE3F1261D02000E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B137C830F7FCC1100459200 /* RecastContour.cpp */;
+ name = "RecastContour.cpp: 752";
+ rLen = 0;
+ rLoc = 20095;
+ rType = 0;
+ vrLen = 1374;
+ vrLoc = 19389;
+ };
+ 6BB2EE401261D02000E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
+ name = "RecastRegion.cpp: 849";
+ rLen = 0;
+ rLoc = 19562;
+ rType = 0;
+ vrLen = 1093;
+ vrLoc = 19103;
+ };
+ 6BB2EE411261D02000E350F8 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */;
+ name = "RecastRegion.cpp: 830";
+ rLen = 0;
+ rLoc = 19532;
+ rType = 0;
+ vrLen = 971;
+ vrLoc = 17831;
+ };
6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {933, 3712}}";
diff --git a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.perspectivev3 b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.perspectivev3
index 230b93f..603a898 100644
--- a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.perspectivev3
+++ b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.perspectivev3
@@ -284,7 +284,7 @@
PBXSmartGroupTreeModuleOutlineStateSelectionKey
- 29
+ 34
27
1
0
@@ -326,7 +326,7 @@
PBXProjectModuleGUID
6B8632A30F78115100E2684A
PBXProjectModuleLabel
- imguiRenderGL.cpp
+ RecastRegion.cpp
PBXSplitModuleInNavigatorKey
Split0
@@ -334,11 +334,11 @@
PBXProjectModuleGUID
6B8632A40F78115100E2684A
PBXProjectModuleLabel
- imguiRenderGL.cpp
+ RecastRegion.cpp
_historyCapacity
0
bookmark
- 6BB2EE2A1261C92300E350F8
+ 6BB2EE411261D02000E350F8
history
6BBB4AA5115B4F3400CF791D
@@ -357,7 +357,6 @@
6BAF46D3121D8FF1008CFCDF
6B1C8E08121EB4FF0048697F
6BA6876E1222F02E00730711
- 6BA687831222F42100730711
6BA687881222F4DB00730711
6BA687CA1222FA9300730711
6BD402111224336600995864
@@ -370,9 +369,7 @@
6BD402B4122441CB00995864
6B920A521225C0AC00D5B5AD
6B920A6D1225C5DD00D5B5AD
- 6B920AA81225DBCB00D5B5AD
6BA7F8AC1226EF0400C8C47A
- 6BA7F8D01226EF9D00C8C47A
6BA7F8EC1227002300C8C47A
6BA7F8ED1227002300C8C47A
6BA7F8EE1227002300C8C47A
@@ -412,8 +409,6 @@
6BA8CF501255D44700272A3B
6BA8CF511255D44700272A3B
6BA8CF5B1255D49B00272A3B
- 6BA8CF6F1255D50700272A3B
- 6BA8CF7B1255D5FE00272A3B
6BA8CF7C1255D5FE00272A3B
6BA8CF941255D97400272A3B
6BA8CF951255D97400272A3B
@@ -430,7 +425,12 @@
6BB2EE261261C92300E350F8
6BB2EE271261C92300E350F8
6BB2EE281261C92300E350F8
- 6BB2EE291261C92300E350F8
+ 6BB2EE351261CEB800E350F8
+ 6BB2EE361261CEB800E350F8
+ 6BB2EE381261CEB800E350F8
+ 6BB2EE3E1261D02000E350F8
+ 6BB2EE3F1261D02000E350F8
+ 6BB2EE401261D02000E350F8
SplitCount
@@ -444,18 +444,18 @@
GeometryConfiguration
Frame
- {{0, 0}, {992, 379}}
+ {{0, 0}, {992, 673}}
RubberWindowFrame
0 59 1278 719 0 0 1280 778
Module
PBXNavigatorGroup
Proportion
- 379pt
+ 673pt
Proportion
- 294pt
+ 0pt
Tabs
@@ -485,7 +485,7 @@
GeometryConfiguration
Frame
- {{10, 27}, {992, 267}}
+ {{10, 27}, {992, -27}}
RubberWindowFrame
0 59 1278 719 0 0 1280 778
diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp
index 4e89dc5..7a5ebc6 100644
--- a/RecastDemo/Source/Sample.cpp
+++ b/RecastDemo/Source/Sample.cpp
@@ -118,7 +118,7 @@ void Sample::resetCommonSettings()
m_agentRadius = 0.6f;
m_agentMaxClimb = 0.9f;
m_agentMaxSlope = 45.0f;
- m_regionMinSize = 50;
+ m_regionMinSize = 8;
m_regionMergeSize = 20;
m_edgeMaxLen = 12.0f;
m_edgeMaxError = 1.3f;