fix(navgen): bake crushable riExtra objects and true chokepoints
Read both damage tables in config/rendinst_dmg.blk. riExtra blocks are named after each destructible object and often carry hp without a destructionImpulse, so dry-stone and wooden fences, metal railings, sandbags and car wrecks were baked as solid walls. Stock damage data now decides before model-name guesses, with the impulse and hp limits in the navBake tuning section. Flag chokepoints on the eroded voxel field instead of per polygon. A span is a chokepoint only when no passable span within reach has room for a passage chokepointMaxWidthVehicles wide, so long polygons touching a wall no longer mark open yards. Chokepoints become WTO_FLAG_CHOKEPOINT on all three tiers and keep their surface area. Let roads cover rough slopes, map Poland's concrete streets as road, and add an extractor --report with ground material shares and per-object classification. Previews draw short cover ticks and record 300 DPI. Verified with Rust release and MSVC builds without warnings, TypeScript checks, and rebakes of Berlin, Poland and Hurtgen on 2.61.0.58 with 15/15, 416/416 and 840/840 spawn-to-capture connectivity on every tier.
This commit is contained in:
1 parent
ed5296e0b8
commit
21ab1084a6
8 files changed
+430
-112
No files matched your search
+115
-37
@@ -59,6 +59,7 @@ struct CoverBake {
|
||||
|
||||
struct PoisData {
|
||||
CoverBake cover{};
|
||||
float chokepointMaxWidthVehicles = 0.0f;
|
||||
std::vector<PoiPt> t1Spawns;
|
||||
std::vector<PoiPt> t2Spawns;
|
||||
std::vector<PoiPt> caps;
|
||||
@@ -95,6 +96,9 @@ static constexpr float kExtraCoverColumnM = 2.6f;
|
||||
static constexpr float kGeometryToleranceM = 0.001f;
|
||||
// Intermediate Recast area. Its serialized area is ground.
|
||||
static constexpr unsigned char kPlatformArea = RC_WALKABLE_AREA - 1;
|
||||
// Intermediate Recast area bit that splits chokepoint polygons from their surroundings. It is
|
||||
// stripped from the serialized area and becomes WTO_FLAG_CHOKEPOINT.
|
||||
static constexpr unsigned char kChokeAreaBit = 0x20;
|
||||
|
||||
static bool hasCoverGeometry(uint8_t cls) {
|
||||
return cls == WTO_OBS_HARD_SOLID || cls == WTO_OBS_PLATFORM;
|
||||
@@ -270,6 +274,11 @@ static bool loadPois(const std::string &path, PoisData &out) {
|
||||
std::fprintf(stderr, "Invalid cover baking settings in %s. Regenerate it with mission-bounds.mts.\n", path.c_str());
|
||||
return false;
|
||||
}
|
||||
out.chokepointMaxWidthVehicles = readJsonNumber(content, "chokepointMaxWidthVehicles", -1.0f);
|
||||
if (!(out.chokepointMaxWidthVehicles >= 1.0f && out.chokepointMaxWidthVehicles <= 4.0f)) {
|
||||
std::fprintf(stderr, "Invalid navigation baking settings in %s. Regenerate it with mission-bounds.mts.\n", path.c_str());
|
||||
return false;
|
||||
}
|
||||
parsePoiArray(content, "team1Spawns", out.t1Spawns);
|
||||
parsePoiArray(content, "team2Spawns", out.t2Spawns);
|
||||
parsePoiArray(content, "captureZones", out.caps);
|
||||
@@ -376,12 +385,95 @@ static void markRoadAreas(rcCompactHeightfield &field, const GeoData &geo) {
|
||||
if (!geo.isRoad(wx, wz)) continue;
|
||||
const rcCompactCell &cell = field.cells[x + z * field.width];
|
||||
for (unsigned int i = cell.index; i < cell.index + cell.count; ++i) {
|
||||
if (field.areas[i] == WTO_AREA_GROUND) field.areas[i] = WTO_AREA_ROAD;
|
||||
if (field.areas[i] == WTO_AREA_GROUND || field.areas[i] == WTO_AREA_ROUGH) field.areas[i] = WTO_AREA_ROAD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Visits the up to eight spans around span `i` at cell (x, z) that it connects to. */
|
||||
template <typename Fn>
|
||||
static void forEachNeighborSpan(const rcCompactHeightfield &field, int x, int z, int i, Fn &&fn) {
|
||||
const rcCompactSpan &span = field.spans[i];
|
||||
for (int dir = 0; dir < 4; ++dir) {
|
||||
int con = rcGetCon(span, dir);
|
||||
if (con == RC_NOT_CONNECTED) continue;
|
||||
int ax = x + rcGetDirOffsetX(dir);
|
||||
int az = z + rcGetDirOffsetY(dir);
|
||||
int ai = (int)field.cells[ax + az * field.width].index + con;
|
||||
fn(ai, false);
|
||||
int dir2 = (dir + 1) & 3;
|
||||
int con2 = rcGetCon(field.spans[ai], dir2);
|
||||
if (con2 == RC_NOT_CONNECTED) continue;
|
||||
int bx = ax + rcGetDirOffsetX(dir2);
|
||||
int bz = az + rcGetDirOffsetY(dir2);
|
||||
fn((int)field.cells[bx + bz * field.width].index + con2, true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flags narrow passages on the eroded compact heightfield. Erosion already removed the vehicle's
|
||||
* own half width, so a span's chamfer distance to the nearest impassable span is the room left
|
||||
* beside the vehicle. A span lies in a chokepoint when no passable span within reach has at least
|
||||
* `clearanceM` of room; spans that touch a wall beside open ground keep their plain surface.
|
||||
*/
|
||||
static int markChokepointSpans(rcCompactHeightfield &field, float clearanceM) {
|
||||
auto passable = [](unsigned char area) {
|
||||
return area != RC_NULL_AREA && area != WTO_AREA_DEEP_WATER && area != WTO_AREA_NO_GO;
|
||||
};
|
||||
const int threshold = (int)std::lround(2.0f * clearanceM / field.cs); /* 2 = one cell */
|
||||
const int reachCells = (int)std::ceil(clearanceM / field.cs) + 1;
|
||||
const int n = field.spanCount;
|
||||
std::vector<uint16_t> dist((size_t)n, 0);
|
||||
for (int i = 0; i < n; ++i) dist[(size_t)i] = passable(field.areas[i]) ? 0xffff : 0;
|
||||
|
||||
/* Distances beyond the threshold need not be exact, so relax only as far as it reaches. */
|
||||
for (int pass = 0; pass <= threshold / 2 + 1; ++pass) {
|
||||
for (int z = 0; z < field.height; ++z) {
|
||||
for (int x = 0; x < field.width; ++x) {
|
||||
const rcCompactCell &cell = field.cells[x + z * field.width];
|
||||
for (int i = (int)cell.index, end = (int)(cell.index + cell.count); i < end; ++i) {
|
||||
if (!dist[(size_t)i]) continue;
|
||||
uint16_t best = dist[(size_t)i];
|
||||
forEachNeighborSpan(field, x, z, i, [&](int ni, bool diagonal) {
|
||||
int d = (int)dist[(size_t)ni] + (diagonal ? 3 : 2);
|
||||
if (d < best) best = (uint16_t)d;
|
||||
});
|
||||
dist[(size_t)i] = best;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint16_t> room = dist, next((size_t)n);
|
||||
for (int step = 0; step < reachCells; ++step) {
|
||||
for (int z = 0; z < field.height; ++z) {
|
||||
for (int x = 0; x < field.width; ++x) {
|
||||
const rcCompactCell &cell = field.cells[x + z * field.width];
|
||||
for (int i = (int)cell.index, end = (int)(cell.index + cell.count); i < end; ++i) {
|
||||
uint16_t best = room[(size_t)i];
|
||||
if (dist[(size_t)i]) {
|
||||
forEachNeighborSpan(field, x, z, i, [&](int ni, bool) {
|
||||
if (dist[(size_t)ni] && room[(size_t)ni] > best) best = room[(size_t)ni];
|
||||
});
|
||||
}
|
||||
next[(size_t)i] = best;
|
||||
}
|
||||
}
|
||||
}
|
||||
room.swap(next);
|
||||
}
|
||||
|
||||
int marked = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
unsigned char area = field.areas[i];
|
||||
if (!dist[(size_t)i] || room[(size_t)i] >= threshold || area >= kChokeAreaBit) continue;
|
||||
field.areas[i] = (unsigned char)(area | kChokeAreaBit);
|
||||
marked++;
|
||||
}
|
||||
return marked;
|
||||
}
|
||||
|
||||
struct BuiltTile {
|
||||
int tx = 0;
|
||||
int tz = 0;
|
||||
@@ -400,7 +492,8 @@ static TileBakeResult buildSingleTile(
|
||||
uint32_t tierIndex,
|
||||
int tx, int tz,
|
||||
float mapMinX, float mapMinZ,
|
||||
const CoverBake &coverTuning, bool bakeCovers
|
||||
const CoverBake &coverTuning, bool bakeCovers,
|
||||
float chokeClearanceM
|
||||
) {
|
||||
TileBakeResult res;
|
||||
res.tile.tx = tx;
|
||||
@@ -424,6 +517,10 @@ static TileBakeResult buildSingleTile(
|
||||
cfg.borderSize = cfg.walkableRadius + 3;
|
||||
// Cover and corner rays must see hard collision on the other side of tile boundaries.
|
||||
if (bakeCovers) cfg.borderSize = std::max(cfg.borderSize, coverBorderCells(coverTuning));
|
||||
// Erosion walls off the heightfield edge; chokepoint reach must stay clear of that band.
|
||||
if (chokeClearanceM > 0.0f) {
|
||||
cfg.borderSize = std::max(cfg.borderSize, cfg.walkableRadius + 2 * (int)std::ceil(chokeClearanceM / cfg.cs) + 4);
|
||||
}
|
||||
cfg.width = cfg.tileSize + cfg.borderSize * 2;
|
||||
cfg.height = cfg.tileSize + cfg.borderSize * 2;
|
||||
cfg.detailSampleDist = 12.0f * cfg.cs;
|
||||
@@ -586,6 +683,7 @@ static TileBakeResult buildSingleTile(
|
||||
rcMedianFilterWalkableArea(&ctx, *chf);
|
||||
rcMedianFilterWalkableArea(&ctx, *chf);
|
||||
markRoadAreas(*chf, geo);
|
||||
if (chokeClearanceM > 0.0f) markChokepointSpans(*chf, chokeClearanceM);
|
||||
|
||||
if (!rcBuildDistanceField(&ctx, *chf) ||
|
||||
!rcBuildRegions(&ctx, *chf, cfg.borderSize, cfg.minRegionArea, cfg.mergeRegionArea)) {
|
||||
@@ -629,6 +727,8 @@ static TileBakeResult buildSingleTile(
|
||||
/* Assign initial polygon flags from Area ID */
|
||||
for (int i = 0; i < pmesh->npolys; ++i) {
|
||||
unsigned char a = pmesh->areas[i];
|
||||
const bool choke = a != RC_NULL_AREA && a < kPlatformArea && (a & kChokeAreaBit);
|
||||
if (choke) a = pmesh->areas[i] = (unsigned char)(a & ~kChokeAreaBit);
|
||||
if (a == WTO_AREA_DEEP_WATER) pmesh->flags[i] = WTO_FLAG_DEEP_WATER;
|
||||
else if (a == WTO_AREA_SHALLOW_WATER) pmesh->flags[i] = WTO_FLAG_WALK | WTO_FLAG_SHALLOW_WATER;
|
||||
else if (a == WTO_AREA_NO_GO) pmesh->flags[i] = WTO_FLAG_BLOCKED;
|
||||
@@ -638,6 +738,7 @@ static TileBakeResult buildSingleTile(
|
||||
pmesh->flags[i] = WTO_FLAG_WALK | WTO_FLAG_PLATFORM;
|
||||
} else if (a != RC_NULL_AREA) pmesh->flags[i] = WTO_FLAG_WALK;
|
||||
else pmesh->flags[i] = 0;
|
||||
if (choke && (pmesh->flags[i] & WTO_FLAG_WALK)) pmesh->flags[i] |= WTO_FLAG_CHOKEPOINT;
|
||||
}
|
||||
|
||||
dtNavMeshCreateParams params{};
|
||||
@@ -833,38 +934,16 @@ static bool verifyDownhillLinks(const dtNavMesh &mesh, const GeoData &geo, uint3
|
||||
return true;
|
||||
}
|
||||
|
||||
static void markChokepoints(dtNavMesh *mesh, dtNavMeshQuery *query, float chokeDistM) {
|
||||
dtQueryFilter filter;
|
||||
filter.setIncludeFlags(WTO_FLAG_WALK);
|
||||
filter.setExcludeFlags(WTO_FLAG_DEEP_WATER | WTO_FLAG_BLOCKED);
|
||||
const dtNavMesh *cmesh = mesh;
|
||||
for (int i = 0; i < cmesh->getMaxTiles(); ++i) {
|
||||
const dtMeshTile *tile = cmesh->getTile(i);
|
||||
static int countChokepointPolys(const dtNavMesh &mesh) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < mesh.getMaxTiles(); ++i) {
|
||||
const dtMeshTile *tile = mesh.getTile(i);
|
||||
if (!tile || !tile->header) continue;
|
||||
dtPolyRef base = cmesh->getPolyRefBase(tile);
|
||||
for (int p = 0; p < tile->header->polyCount; ++p) {
|
||||
const dtPoly &poly = tile->polys[p];
|
||||
if (poly.getType() == DT_POLYTYPE_OFFMESH_CONNECTION) continue;
|
||||
uint8_t area = poly.getArea();
|
||||
if (area == WTO_AREA_DEEP_WATER || area == WTO_AREA_SHALLOW_WATER) continue;
|
||||
float cx = 0, cy = 0, cz = 0;
|
||||
for (int v = 0; v < poly.vertCount; ++v) {
|
||||
const float *vp = &tile->verts[poly.verts[v] * 3];
|
||||
cx += vp[0]; cy += vp[1]; cz += vp[2];
|
||||
}
|
||||
float inv = 1.0f / (float)poly.vertCount;
|
||||
float pos[3] = { cx * inv, cy * inv, cz * inv };
|
||||
dtPolyRef ref = base | (dtPolyRef)p;
|
||||
float hitDist = 999.0f;
|
||||
float hitPos[3], hitNorm[3];
|
||||
if (dtStatusSucceed(query->findDistanceToWall(ref, pos, chokeDistM + 1.0f, &filter, &hitDist, hitPos, hitNorm))) {
|
||||
if (hitDist < chokeDistM) {
|
||||
mesh->setPolyArea(ref, WTO_AREA_CHOKEPOINT);
|
||||
mesh->setPolyFlags(ref, poly.flags | WTO_FLAG_CHOKEPOINT);
|
||||
}
|
||||
}
|
||||
if (tile->polys[p].flags & WTO_FLAG_CHOKEPOINT) count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
struct CoverRay {
|
||||
@@ -1245,6 +1324,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
for (uint32_t tierIdx = 0; tierIdx < WTO_NAV_TIER_COUNT; ++tierIdx) {
|
||||
const bool doCovers = (tierIdx == WTO_NAV_TIER_STANDARD);
|
||||
/* Room beside the vehicle left in a passage exactly chokepointMaxWidthVehicles wide. */
|
||||
const float chokeClearanceM = (pois.chokepointMaxWidthVehicles - 1.0f) * kTiers[tierIdx].agentRadius;
|
||||
tierTiles[tierIdx].resize((size_t)totalTiles);
|
||||
std::atomic<int> nextTile{ 0 };
|
||||
std::mutex covMtx;
|
||||
@@ -1258,7 +1339,7 @@ int main(int argc, char **argv) {
|
||||
if (idx >= totalTiles) break;
|
||||
int tx = idx % tilesX;
|
||||
int tz = idx / tilesX;
|
||||
auto br = buildSingleTile(geo, buckets[(size_t)idx], tierIdx, tx, tz, mapMinX, mapMinZ, pois.cover, doCovers);
|
||||
auto br = buildSingleTile(geo, buckets[(size_t)idx], tierIdx, tx, tz, mapMinX, mapMinZ, pois.cover, doCovers, chokeClearanceM);
|
||||
tierTiles[tierIdx][(size_t)idx] = br.tile;
|
||||
if (doCovers && !br.covers.empty()) {
|
||||
localCov.insert(localCov.end(), br.covers.begin(), br.covers.end());
|
||||
@@ -1285,11 +1366,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
int pruned = pruneUnreachableIslands(meshes[tierIdx], queries[tierIdx], geo, pois);
|
||||
if (!verifyDownhillLinks(*meshes[tierIdx], geo, tierIdx)) return 1;
|
||||
if (tierIdx == WTO_NAV_TIER_STANDARD) {
|
||||
markChokepoints(meshes[tierIdx], queries[tierIdx], 3.8f);
|
||||
}
|
||||
std::printf(" %s (r=%.2fm): tiles=%d/%d polys=%d prunedIslands=%d\n",
|
||||
kTiers[tierIdx].name, kTiers[tierIdx].agentRadius, builtCnt, totalTiles, polyCnt, pruned);
|
||||
std::printf(" %s (r=%.2fm): tiles=%d/%d polys=%d chokepointPolys=%d prunedIslands=%d\n",
|
||||
kTiers[tierIdx].name, kTiers[tierIdx].agentRadius, builtCnt, totalTiles, polyCnt,
|
||||
countChokepointPolys(*meshes[tierIdx]), pruned);
|
||||
}
|
||||
|
||||
/* Dedupe + retreat-verify tank covers on Tier 1 */
|
||||
@@ -1362,7 +1441,6 @@ int main(int argc, char **argv) {
|
||||
pf.setAreaCost(WTO_AREA_FOREST, 2.10f);
|
||||
pf.setAreaCost(WTO_AREA_CRUSHABLE, 2.40f);
|
||||
pf.setAreaCost(WTO_AREA_SHALLOW_WATER, 2.60f);
|
||||
pf.setAreaCost(WTO_AREA_CHOKEPOINT, 1.80f);
|
||||
const float snapExt[3] = { 12.0f, 12.0f, 12.0f };
|
||||
|
||||
std::vector<PoiPt> allSpawns = pois.t1Spawns;
|
||||
|
||||
Reference in new issue
Block a user