fix(navgen): qualify cover against source collision geometry

Recheck continuous hull cover at the final parking height and validate both corner approaches on the navigation mesh. Preserve terrain and driving collision for low stone fences while excluding their geometry from cover traces. Add a preview raster size option.

Verified with Rust and MSVC builds, TypeScript checks, and 300 dpi 8K bakes for Berlin, Poland, and Hurtgen.
This commit is contained in:
N0VAN0M4LY committed 2026-12-04 19:23:22 +08:00
1 parent 4191d59168
commit 6f2d9f639b
5 files changed
+288 -138

No files matched your search

+250 -114
View File
@@ -17,6 +17,7 @@
#include "DetourCommon.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
@@ -25,6 +26,7 @@
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <limits>
#include <mutex>
#include <queue>
#include <string>
@@ -83,7 +85,14 @@ static constexpr float kTileWorldSize = kTileSize * kCellSize;
static constexpr float kShallowWaterMaxM = 0.60f;
static constexpr float kShallowWaterMinM = 0.05f;
static constexpr float kRoughSlopeDeg = 18.0f;
static constexpr float kCoverProbeStartM = 0.6f;
static constexpr float kCoverScanM = 5.2f;
static constexpr float kHullLowerM = 0.65f;
static constexpr float kHullUpperM = 1.80f;
static constexpr float kTurretLowerM = 2.05f;
static constexpr float kHullColumnSpacingM = 0.9f;
static constexpr float kExtraCoverColumnM = 2.6f;
static constexpr float kGeometryToleranceM = 0.001f;
static constexpr float kPeekSightM = 14.0f;
static constexpr float kHullDownSightM = 22.0f;
static constexpr float kCoverHeightToleranceM = 1.2f;
@@ -127,7 +136,7 @@ static bool loadGeo(const std::string &path, GeoData &out) {
std::ifstream in(path, std::ios::binary);
if (!in) return false;
in.read(reinterpret_cast<char *>(&out.hdr), sizeof(WtoGeoHeader));
if (!in || std::memcmp(out.hdr.magic, WTO_GEO_MAGIC, 8) != 0 || out.hdr.version != WTO_GEO_VERSION) {
if (!in || std::memcmp(out.hdr.magic, WTO_GEO_MAGIC, 8) != 0 || (out.hdr.version != 1u && out.hdr.version != WTO_GEO_VERSION)) {
std::fprintf(stderr, "Invalid .wtogeo header: %s\n", path.c_str());
return false;
}
@@ -258,45 +267,26 @@ static inline float triNormalYRightHanded(const Vec3 &a, const Vec3 &b, const Ve
return len > 1e-6f ? (ny / len) : 0.0f;
}
/* Query whether a hard solid span exists in rcHeightfield at (wx, wz) intersecting [yLo, yHi]. */
static bool hfHasSolidInBand(const rcHeightfield &hf, float wx, float wz, float yLo, float yHi, float *outTopY = nullptr) {
int gx = (int)std::floor((wx - hf.bmin[0]) / hf.cs);
int gz = (int)std::floor((wz - hf.bmin[2]) / hf.cs);
if (gx < 0 || gz < 0 || gx >= hf.width || gz >= hf.height) return false;
int sminBand = (int)std::floor((yLo - hf.bmin[1]) / hf.ch);
int smaxBand = (int)std::ceil((yHi - hf.bmin[1]) / hf.ch);
float maxTop = -1e9f;
bool hit = false;
for (const rcSpan *s = hf.spans[gx + gz * hf.width]; s; s = s->next) {
if ((int)s->smax >= sminBand && (int)s->smin <= smaxBand) {
hit = true;
float topY = hf.bmin[1] + s->smax * hf.ch;
if (topY > maxTop) maxTop = topY;
}
static bool hasCoverVoxel(const rcHeightfield &field, float x, float z, float low, float high) {
int gx = (int)std::floor((x - field.bmin[0]) / field.cs);
int gz = (int)std::floor((z - field.bmin[2]) / field.cs);
if (gx < 0 || gz < 0 || gx >= field.width || gz >= field.height) return false;
int first = (int)std::floor((low - field.bmin[1]) / field.ch);
int last = (int)std::ceil((high - field.bmin[1]) / field.ch);
for (const rcSpan *span = field.spans[gx + gz * field.width]; span; span = span->next) {
if ((int)span->smax >= first && (int)span->smin <= last) return true;
}
if (hit && outTopY) *outTopY = maxTop;
return hit;
return false;
}
/* Raycast along XZ inside tile's hard-obstacle heightfield to check occlusion in [yLo, yHi]. */
static bool hfTraceBand(const rcHeightfield &hardHf, const GeoData &geo,
float ox, float oz, float dx, float dz,
float maxDist, float yLo, float yHi, float *outTopY = nullptr) {
float step = hardHf.cs * 0.85f;
for (float d = 0.6f; d <= maxDist; d += step) {
float px = ox + dx * d;
float pz = oz + dz * d;
float topY = -1e9f;
if (hfHasSolidInBand(hardHf, px, pz, yLo, yHi, &topY)) {
if (outTopY) *outTopY = topY;
return true;
}
/* Terrain ridge / cliff rise above yLo also acts as natural hard earth cover! */
float gy = geo.sampleHeight(px, pz);
if (gy >= yLo + 0.35f) {
if (outTopY) *outTopY = gy;
return true;
}
// The voxel bands only nominate a pose. The final test is done on source geometry after snapping Y.
static bool hasCoverCandidate(const rcHeightfield &field, const GeoData &geo,
float x, float z, float dx, float dz, float baseY) {
float low = baseY + kHullLowerM;
float high = baseY + kHullUpperM;
for (float d = kCoverProbeStartM; d <= kCoverScanM; d += field.cs * 0.85f) {
float px = x + dx * d, pz = z + dz * d;
if (hasCoverVoxel(field, px, pz, low, high) || geo.sampleHeight(px, pz) >= low + 0.35f) return true;
}
return false;
}
@@ -321,36 +311,9 @@ static bool isCoverBoundary(const rcCompactHeightfield &field, int x, int z, con
return false;
}
static bool findCornerPeek(
const rcCompactHeightfield &field, const rcHeightfield &hard, const GeoData &geo,
const CoverBake &tuning, const WtoCoverPoint &cover, float side, float (&point)[3]
) {
const float dx = cover.coverDir[0], dz = cover.coverDir[1];
for (float distance = tuning.peekMinM; distance <= tuning.peekMaxM; distance += field.cs) {
const float x = cover.pos[0] - dz * side * distance;
const float z = cover.pos[2] + dx * side * distance;
const int gx = (int)std::floor((x - field.bmin[0]) / field.cs);
const int gz = (int)std::floor((z - field.bmin[2]) / field.cs);
if (gx < 0 || gz < 0 || gx >= field.width || gz >= field.height) break;
const rcCompactCell &cell = field.cells[gx + gz * field.width];
for (unsigned int i = cell.index; i < cell.index + cell.count; ++i) {
if (!isCoverArea(field.areas[i])) continue;
float y = field.bmin[1] + field.spans[i].y * field.ch;
if (std::fabs(y - cover.pos[1]) > kCoverHeightToleranceM) continue;
if (hfTraceBand(hard, geo, x, z, dx, dz, kPeekSightM, y + 1.8f, y + 2.6f)) continue;
point[0] = x;
point[1] = y;
point[2] = z;
return true;
}
}
return false;
}
static void bakeTileCovers(
const rcCompactHeightfield &field, const rcHeightfield &hard, const GeoData &geo,
const rcConfig &cfg, const CoverBake &tuning, std::vector<WtoCoverPoint> &covers
const rcConfig &cfg, std::vector<WtoCoverPoint> &covers
) {
static const float directions[8][2] = {
{ 1.0f, 0.0f }, { 0.70710678f, 0.70710678f }, { 0.0f, 1.0f }, { -0.70710678f, 0.70710678f },
@@ -366,43 +329,19 @@ static void bakeTileCovers(
Vec3 pos{ cfg.bmin[0] + (x + 0.5f) * cfg.cs, cfg.bmin[1] + span.y * cfg.ch,
cfg.bmin[2] + (z + 0.5f) * cfg.cs };
// Every usable bearing goes through the same checks, including opposite faces of one object.
for (const auto &dir : directions) {
float dx = dir[0], dz = dir[1];
int hullHits = 0, turretHits = 0;
float totalHeight = 0.0f;
int hullHits = 0;
for (int column = -2; column <= 2; ++column) {
float offset = column * 0.9f; // Five samples across a 3.6 m hull.
float sx = pos.x - dz * offset, sz = pos.z + dx * offset;
float top = pos.y;
if (!hfTraceBand(hard, geo, sx, sz, dx, dz, kCoverScanM, pos.y + 0.65f, pos.y + 1.80f, &top)) continue;
++hullHits;
totalHeight += std::max(0.0f, top - pos.y);
turretHits += hfTraceBand(hard, geo, sx, sz, dx, dz, kCoverScanM, pos.y + 2.05f, pos.y + 2.85f);
float offset = column * kHullColumnSpacingM;
hullHits += hasCoverCandidate(hard, geo, pos.x - dz * offset, pos.z + dx * offset, dx, dz, pos.y);
}
if (hullHits < 4 || totalHeight < tuning.minCoverHeightM * hullHits) continue;
if (hullHits < 4) continue;
float width = 3.6f;
for (float off : { -2.6f, 2.6f }) {
if (hfTraceBand(hard, geo, pos.x - dz * off, pos.z + dx * off, dx, dz,
kCoverScanM, pos.y + 0.65f, pos.y + 1.80f)) width += 1.0f;
}
WtoCoverPoint cover{};
cover.pos[0] = pos.x; cover.pos[1] = pos.y; cover.pos[2] = pos.z;
cover.coverDir[0] = dx; cover.coverDir[1] = dz;
cover.halfAngleDeg = width >= 5.0f ? 42.0f : 32.0f;
cover.heightM = totalHeight / hullHits;
cover.widthM = width;
if (turretHits >= 3) {
cover.kind = WTO_COVER_FULL;
cover.hasPeekLeft = findCornerPeek(field, hard, geo, tuning, cover, -1.0f, cover.peekLeft);
cover.hasPeekRight = findCornerPeek(field, hard, geo, tuning, cover, 1.0f, cover.peekRight);
} else {
if (hfTraceBand(hard, geo, pos.x, pos.z, dx, dz, kHullDownSightM, pos.y + 2.15f, pos.y + 2.75f)) continue;
cover.kind = WTO_COVER_HULLDOWN;
}
covers.push_back(cover);
WtoCoverPoint pose{};
pose.pos[0] = pos.x; pose.pos[1] = pos.y; pose.pos[2] = pos.z;
pose.coverDir[0] = dx; pose.coverDir[1] = dz;
covers.push_back(pose);
}
}
}
@@ -546,7 +485,7 @@ static TileBakeResult buildSingleTile(
const Vec3 &v0 = geo.obsVerts[t.i0];
const Vec3 &v1 = geo.obsVerts[t.i1];
const Vec3 &v2 = geo.obsVerts[t.i2];
if (t.cls == WTO_OBS_HARD_SOLID || t.cls == WTO_OBS_TREE_THICK) {
if (t.cls == WTO_OBS_HARD_SOLID || t.cls == WTO_OBS_HARD_NO_COVER || t.cls == WTO_OBS_TREE_THICK) {
rcRasterizeTriangle(&ctx, &v0.x, &v1.x, &v2.x, RC_NULL_AREA, *solid, cfg.walkableClimb);
if (hardHf && t.cls == WTO_OBS_HARD_SOLID) {
rcRasterizeTriangle(&ctx, &v0.x, &v1.x, &v2.x, 1, *hardHf, 1);
@@ -614,7 +553,7 @@ static TileBakeResult buildSingleTile(
}
}
if (hardHf) bakeTileCovers(*chf, *hardHf, geo, cfg, coverTuning, res.covers);
if (hardHf) bakeTileCovers(*chf, *hardHf, geo, cfg, res.covers);
rcFreeHeightField(hardHf);
hardHf = nullptr;
@@ -818,6 +757,173 @@ static void markChokepoints(dtNavMesh *mesh, dtNavMeshQuery *query, float chokeD
}
}
struct CoverRay {
float x, z, dx, dz, range;
};
struct CoverSpan {
float bottom, top;
};
// Cut each triangle by the vertical plane through the probe, then clip the cut
// segment to the horizontal ray length. Its Y interval is the silhouette seen
// from the parking point at this column.
static bool coverTriangleSpan(const CoverRay &ray, const Vec3 &a, const Vec3 &b, const Vec3 &c,
CoverSpan &out) {
const Vec3 points[3] = { a, b, c };
float along[3], across[3];
for (int i = 0; i < 3; ++i) {
float x = points[i].x - ray.x, z = points[i].z - ray.z;
along[i] = x * ray.dx + z * ray.dz;
across[i] = z * ray.dx - x * ray.dz;
}
struct CutPoint { float distance, y; };
CutPoint cut[3];
int count = 0;
for (int i = 0; i < 3; ++i) {
const int j = (i + 1) % 3;
if (across[i] == 0.0f) {
cut[count++] = { along[i], points[i].y };
} else if ((across[i] < 0.0f && across[j] > 0.0f) || (across[i] > 0.0f && across[j] < 0.0f)) {
float fraction = across[i] / (across[i] - across[j]);
cut[count++] = {
along[i] + (along[j] - along[i]) * fraction,
points[i].y + (points[j].y - points[i].y) * fraction
};
}
}
if (count != 2) return false;
if (cut[0].distance > cut[1].distance) std::swap(cut[0], cut[1]);
if (cut[1].distance < kCoverProbeStartM || cut[0].distance > ray.range) return false;
float length = cut[1].distance - cut[0].distance;
if (length > kGeometryToleranceM) {
float from = std::max(kCoverProbeStartM, cut[0].distance);
float to = std::min(ray.range, cut[1].distance);
float rise = cut[1].y - cut[0].y;
float y0 = cut[0].y + (from - cut[0].distance) / length * rise;
float y1 = cut[0].y + (to - cut[0].distance) / length * rise;
out = { std::min(y0, y1), std::max(y0, y1) };
} else {
out = { std::min(cut[0].y, cut[1].y), std::max(cut[0].y, cut[1].y) };
}
return true;
}
class CoverGeometry {
public:
explicit CoverGeometry(const GeoData &geo) : geo(geo) {
cols = std::max(1, (int)std::ceil((geo.hdr.boundsMax[0] - geo.hdr.boundsMin[0]) / indexCellM));
rows = std::max(1, (int)std::ceil((geo.hdr.boundsMax[1] - geo.hdr.boundsMin[1]) / indexCellM));
cells.resize((size_t)cols * rows);
for (uint32_t i = 0; i < geo.obsTris.size(); ++i) {
const auto &tri = geo.obsTris[i];
if (tri.cls != WTO_OBS_HARD_SOLID) continue;
const auto &a = geo.obsVerts[tri.i0];
const auto &b = geo.obsVerts[tri.i1];
const auto &c = geo.obsVerts[tri.i2];
int firstX = column(std::min({ a.x, b.x, c.x }));
int lastX = column(std::max({ a.x, b.x, c.x }));
int firstZ = row(std::min({ a.z, b.z, c.z }));
int lastZ = row(std::max({ a.z, b.z, c.z }));
for (int z = firstZ; z <= lastZ; ++z) {
for (int x = firstX; x <= lastX; ++x) cells[(size_t)z * cols + x].push_back(i);
}
}
}
void collect(const CoverRay &ray, float lower, std::vector<CoverSpan> &spans) const {
spans.clear();
const float endX = ray.x + ray.dx * ray.range;
const float endZ = ray.z + ray.dz * ray.range;
float terrainTop = geo.sampleHeight(endX, endZ);
for (float d = kCoverProbeStartM; d < ray.range; d += kCellSize * 0.85f) {
terrainTop = std::max(terrainTop, geo.sampleHeight(ray.x + ray.dx * d, ray.z + ray.dz * d));
}
if (terrainTop >= lower) spans.push_back({ lower, terrainTop });
const float startX = ray.x + ray.dx * kCoverProbeStartM;
const float startZ = ray.z + ray.dz * kCoverProbeStartM;
const float xmin = std::min(startX, endX), xmax = std::max(startX, endX);
const float zmin = std::min(startZ, endZ), zmax = std::max(startZ, endZ);
const int lastX = column(xmax), lastZ = row(zmax);
for (int z = row(zmin); z <= lastZ; ++z) {
for (int x = column(xmin); x <= lastX; ++x) {
for (uint32_t i : cells[(size_t)z * cols + x]) {
const auto &tri = geo.obsTris[i];
const auto &a = geo.obsVerts[tri.i0];
const auto &b = geo.obsVerts[tri.i1];
const auto &c = geo.obsVerts[tri.i2];
if (std::max({ a.y, b.y, c.y }) < lower ||
std::max({ a.x, b.x, c.x }) < xmin || std::min({ a.x, b.x, c.x }) > xmax ||
std::max({ a.z, b.z, c.z }) < zmin || std::min({ a.z, b.z, c.z }) > zmax) continue;
CoverSpan span;
if (coverTriangleSpan(ray, a, b, c, span) && span.top >= lower) spans.push_back(span);
}
}
}
}
private:
static constexpr float indexCellM = kTileWorldSize / 16.0f;
const GeoData &geo;
int cols = 0, rows = 0;
std::vector<std::vector<uint32_t>> cells;
int column(float x) const { return std::clamp((int)std::floor((x - geo.hdr.boundsMin[0]) / indexCellM), 0, cols - 1); }
int row(float z) const { return std::clamp((int)std::floor((z - geo.hdr.boundsMin[1]) / indexCellM), 0, rows - 1); }
};
static float coverColumnHeight(const CoverGeometry &geometry, const WtoCoverPoint &cover, float offset,
std::vector<CoverSpan> &spans) {
float dx = cover.coverDir[0], dz = cover.coverDir[1];
float lower = cover.pos[1] + kHullLowerM;
geometry.collect({ cover.pos[0] - dz * offset, cover.pos[2] + dx * offset, dx, dz, kCoverScanM }, lower, spans);
std::sort(spans.begin(), spans.end(), [](const CoverSpan &a, const CoverSpan &b) { return a.bottom < b.bottom; });
if (spans.empty() || spans.front().bottom > lower + kGeometryToleranceM) return -std::numeric_limits<float>::infinity();
float top = lower;
for (const auto &span : spans) {
if (span.bottom > top + kGeometryToleranceM) break;
top = std::max(top, span.top);
}
return top - cover.pos[1];
}
static bool coveredSightBand(const CoverGeometry &geometry, const float *pos, const float *direction, float range,
float low, float high, std::vector<CoverSpan> &spans) {
geometry.collect({ pos[0], pos[2], direction[0], direction[1], range }, pos[1] + low, spans);
return std::any_of(spans.begin(), spans.end(), [&](const CoverSpan &span) { return span.bottom <= pos[1] + high; });
}
static bool qualifyCover(WtoCoverPoint &cover, const CoverGeometry &geometry,
const CoverBake &tuning, std::vector<CoverSpan> &spans) {
std::array<float, 5> heights;
for (size_t i = 0; i < heights.size(); ++i) {
heights[i] = coverColumnHeight(geometry, cover, ((int)i - 2) * kHullColumnSpacingM, spans);
}
std::sort(heights.begin(), heights.end(), [](float a, float b) { return a > b; });
// Four columns must each hide the hull through the required height.
if (heights[3] < tuning.minCoverHeightM) return false;
cover.heightM = heights[3];
const bool full = heights[2] >= kTurretLowerM;
if (!full && coveredSightBand(geometry, cover.pos, cover.coverDir, kHullDownSightM, 2.15f, 2.75f, spans)) return false;
cover.kind = full ? WTO_COVER_FULL : WTO_COVER_HULLDOWN;
cover.widthM = 4.0f * kHullColumnSpacingM;
for (float offset : { -kExtraCoverColumnM, kExtraCoverColumnM }) {
if (coverColumnHeight(geometry, cover, offset, spans) >= tuning.minCoverHeightM) cover.widthM += 1.0f;
}
cover.halfAngleDeg = cover.widthM >= 5.0f ? 42.0f : 32.0f;
return true;
}
static dtPolyRef verifyCoverPosition(dtNavMeshQuery &query, const dtQueryFilter &filter, float (&point)[3]) {
const float extent[3] = { kCellSize, kCoverHeightToleranceM, kCellSize };
dtPolyRef ref = 0;
@@ -839,16 +945,36 @@ static bool clearCoverCorridor(dtNavMeshQuery &query, const dtQueryFilter &filte
fraction >= 1.0f && (!endRef || (count > 0 && trail[count - 1] == endRef));
}
static bool verifyCover(WtoCoverPoint &cover, dtNavMeshQuery &query,
const dtQueryFilter &filter, float retreatMinM) {
static bool findCornerPeek(WtoCoverPoint &cover, dtNavMeshQuery &query, const dtQueryFilter &filter,
dtPolyRef startRef, const CoverGeometry &geometry, const CoverBake &tuning,
float side, float (&point)[3], std::vector<CoverSpan> &spans) {
dtQueryFilter dry = filter;
dry.setExcludeFlags(filter.getExcludeFlags() | WTO_FLAG_SHALLOW_WATER);
for (float distance = tuning.peekMinM; distance <= tuning.peekMaxM; distance += kCellSize) {
float candidate[3] = {
cover.pos[0] - cover.coverDir[1] * side * distance,
cover.pos[1],
cover.pos[2] + cover.coverDir[0] * side * distance
};
dtPolyRef endRef = verifyCoverPosition(query, dry, candidate);
if (!endRef || !clearCoverCorridor(query, filter, startRef, cover.pos, candidate, endRef)) continue;
if (coveredSightBand(geometry, candidate, cover.coverDir, kPeekSightM, 1.8f, 2.6f, spans)) continue;
std::copy(candidate, candidate + 3, point);
return true;
}
return false;
}
static bool verifyCover(WtoCoverPoint &cover, dtNavMeshQuery &query, const dtQueryFilter &filter,
const CoverGeometry &geometry, const CoverBake &tuning, std::vector<CoverSpan> &spans) {
dtPolyRef startRef = verifyCoverPosition(query, filter, cover.pos);
if (!startRef) return false;
if (!startRef || !qualifyCover(cover, geometry, tuning, spans)) return false;
const float heading = std::atan2(-cover.coverDir[1], -cover.coverDir[0]);
bool hasRetreat = false;
for (float offset : { 0.0f, 0.45f, -0.45f }) {
float rx = std::cos(heading + offset), rz = std::sin(heading + offset);
float end[3] = { cover.pos[0] + rx * retreatMinM, cover.pos[1], cover.pos[2] + rz * retreatMinM };
float end[3] = { cover.pos[0] + rx * tuning.retreatMinM, cover.pos[1], cover.pos[2] + rz * tuning.retreatMinM };
if (!clearCoverCorridor(query, filter, startRef, cover.pos, end)) continue;
cover.retreatDir[0] = rx;
cover.retreatDir[1] = rz;
@@ -857,12 +983,10 @@ static bool verifyCover(WtoCoverPoint &cover, dtNavMeshQuery &query,
}
if (!hasRetreat) return false;
auto validatePeek = [&](float (&point)[3]) {
dtPolyRef endRef = verifyCoverPosition(query, filter, point);
return endRef && clearCoverCorridor(query, filter, startRef, cover.pos, point, endRef);
};
cover.hasPeekLeft = cover.hasPeekLeft && validatePeek(cover.peekLeft);
cover.hasPeekRight = cover.hasPeekRight && validatePeek(cover.peekRight);
if (cover.kind == WTO_COVER_FULL) {
cover.hasPeekLeft = findCornerPeek(cover, query, filter, startRef, geometry, tuning, -1.0f, cover.peekLeft, spans);
cover.hasPeekRight = findCornerPeek(cover, query, filter, startRef, geometry, tuning, 1.0f, cover.peekRight, spans);
}
return true;
}
@@ -871,14 +995,16 @@ static unsigned int peekCount(const WtoCoverPoint &cover) {
}
static std::vector<WtoCoverPoint> filterAndDedupeCovers(
const std::vector<WtoCoverPoint> &raw, dtNavMeshQuery &query, const CoverBake &tuning
const std::vector<WtoCoverPoint> &raw, dtNavMeshQuery &query, const CoverBake &tuning, const GeoData &geo
) {
dtQueryFilter filter;
filter.setIncludeFlags(WTO_FLAG_WALK);
filter.setExcludeFlags(WTO_FLAG_DEEP_WATER | WTO_FLAG_BLOCKED);
const CoverGeometry geometry(geo);
std::vector<CoverSpan> spans;
std::vector<WtoCoverPoint> usable;
for (WtoCoverPoint cover : raw) {
if (verifyCover(cover, query, filter, tuning.retreatMinM)) usable.push_back(cover);
if (verifyCover(cover, query, filter, geometry, tuning, spans)) usable.push_back(cover);
}
std::sort(usable.begin(), usable.end(), [](const WtoCoverPoint &a, const WtoCoverPoint &b) {
@@ -925,15 +1051,25 @@ static void serializeTier(const dtNavMeshParams &params, const std::vector<Built
int main(int argc, char **argv) {
std::string geoPath, poisPath, outNavPath, outPreviewPath;
uint32_t previewSize = 1024;
for (int i = 1; i + 1 < argc; i += 2) {
std::string a = argv[i];
if (a == "--geo") geoPath = argv[i + 1];
else if (a == "--pois") poisPath = argv[i + 1];
else if (a == "--out") outNavPath = argv[i + 1];
else if (a == "--preview") outPreviewPath = argv[i + 1];
else if (a == "--preview-size") {
char *end = nullptr;
unsigned long size = std::strtoul(argv[i + 1], &end, 10);
if (*end != '\0' || size == 0 || size > 8192) {
std::fprintf(stderr, "Preview size must be between 1 and 8192 pixels.\n");
return 2;
}
previewSize = (uint32_t)size;
}
}
if (geoPath.empty() || poisPath.empty() || outNavPath.empty()) {
std::fprintf(stderr, "Usage: wto_navgen_bake --geo <in.wtogeo> --pois <in.pois.json> --out <out.wtonav> [--preview <out.preview.bin>]\n");
std::fprintf(stderr, "Usage: wto_navgen_bake --geo <in.wtogeo> --pois <in.pois.json> --out <out.wtonav> [--preview <out.preview.bin>] [--preview-size <pixels>]\n");
return 2;
}
@@ -1046,7 +1182,7 @@ int main(int argc, char **argv) {
}
/* Dedupe + retreat-verify tank covers on Tier 1 */
std::vector<WtoCoverPoint> covers = filterAndDedupeCovers(rawCovers, *queries[WTO_NAV_TIER_STANDARD], pois.cover);
std::vector<WtoCoverPoint> covers = filterAndDedupeCovers(rawCovers, *queries[WTO_NAV_TIER_STANDARD], pois.cover, geo);
int fullCnt = 0, hdCnt = 0, peekCnt = 0, bothPeeks = 0;
for (const auto &c : covers) {
if (c.kind == WTO_COVER_FULL) fullCnt++; else hdCnt++;
@@ -1226,7 +1362,7 @@ int main(int argc, char **argv) {
/* Write compact raster preview data for PNG visual inspection */
if (!outPreviewPath.empty()) {
const uint32_t pw = 1024, ph = 1024;
const uint32_t pw = previewSize, ph = previewSize;
std::vector<float> pHeight((size_t)pw * ph);
std::vector<uint16_t> pFlags((size_t)pw * ph, 0);
/* Bit 0: T0 walkable, Bit 1: T1 walkable, Bit 2: T2 walkable, Bit 3: shallow water,