little cleanup

This commit is contained in:
Vladislav Khorev committed 2026-05-09 20:28:25 +03:00
1 parent 13ef92160d
commit 72e05cdc28
15 files changed
+323 -197

No files matched your search

+1 -57
View File
@@ -87,14 +87,12 @@ namespace {
}
}
void PathFinder::build(const std::vector<ObstacleMesh>& obstacleMeshes,
const std::string& configPath,
void PathFinder::build(const std::string& configPath,
const std::string& zipPath)
{
ready = false;
loadedConfigPath = configPath;
loadedZipPath = zipPath;
obstacles = obstacleMeshes;
loadConfig(configPath, zipPath);
resetGridBounds();
@@ -563,16 +561,6 @@ void PathFinder::resetGridBounds()
}
}
for (const ObstacleMesh& obstacle : obstacles) {
if (!obstacle.mesh) {
continue;
}
for (const Eigen::Vector3f& point : obstacle.mesh->PositionData) {
const Eigen::Vector3f worldPoint = point + obstacle.offset;
includePoint(worldPoint.x(), worldPoint.z());
}
}
for (const ObstaclePolygon& obstacle : obstaclePolygons) {
for (const Eigen::Vector2f& point : obstacle.polygon) {
includePoint(point.x(), point.y());
@@ -593,7 +581,6 @@ void PathFinder::rebuildWalkableGrid()
{
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
markAvailableAreasWalkable();
markObstacleMeshesBlocked();
markObstaclePolygonsBlocked();
}
@@ -708,49 +695,6 @@ void PathFinder::markObstaclePolygonsBlocked()
}
}
void PathFinder::markObstacleMeshesBlocked()
{
if (!obstaclePolygons.empty()) {
// Prefer JSON-defined obstacle polygons over mesh-derived blockers.
// Mesh blockers tend to over-block (e.g. tree crowns) and are harder to author/tune.
return;
}
const float padding = agentRadius + objectPadding;
for (const ObstacleMesh& obstacle : obstacles) {
if (!obstacle.mesh || obstacle.mesh->PositionData.empty()) {
continue;
}
Eigen::Vector3f minPoint = obstacle.mesh->PositionData[0] + obstacle.offset;
Eigen::Vector3f maxPoint = minPoint;
for (const Eigen::Vector3f& localPoint : obstacle.mesh->PositionData) {
const Eigen::Vector3f point = localPoint + obstacle.offset;
minPoint = minPoint.cwiseMin(point);
maxPoint = maxPoint.cwiseMax(point);
}
Cell from;
Cell to;
worldToCell({ minPoint.x() - padding, floorY, minPoint.z() - padding }, from);
worldToCell({ maxPoint.x() + padding, floorY, maxPoint.z() + padding }, to);
from.x = (std::max)(from.x, 0);
from.z = (std::max)(from.z, 0);
to.x = (std::min)(to.x, gridWidth - 1);
to.z = (std::min)(to.z, gridDepth - 1);
for (int z = from.z; z <= to.z; ++z) {
for (int x = from.x; x <= to.x; ++x) {
const Cell cell{ x, z };
if (isInsideGrid(cell)) {
walkable[static_cast<size_t>(indexOf(cell))] = 0;
}
}
}
}
}
bool PathFinder::worldToCell(const Eigen::Vector3f& point, Cell& out) const
{
if (gridWidth <= 0 || gridDepth <= 0) {
+1 -8
View File
@@ -9,10 +9,6 @@ namespace ZL {
class PathFinder {
public:
struct ObstacleMesh {
const VertexDataStruct* mesh = nullptr;
Eigen::Vector3f offset = Eigen::Vector3f::Zero();
};
struct ObstaclePolygon {
std::string name;
@@ -35,8 +31,7 @@ public:
std::vector<Eigen::Vector2f> polygon;
};
void build(const std::vector<ObstacleMesh>& obstacleMeshes,
const std::string& configPath,
void build(const std::string& configPath,
const std::string& zipPath = "");
std::vector<Eigen::Vector3f> findPath(const Eigen::Vector3f& start,
@@ -72,7 +67,6 @@ private:
std::string loadedConfigPath;
std::string loadedZipPath;
std::vector<ObstacleMesh> obstacles;
std::vector<ObstaclePolygon> obstaclePolygons;
std::vector<unsigned char> walkable;
std::vector<NavigationArea> areas;
@@ -81,7 +75,6 @@ private:
void resetGridBounds();
void rebuildWalkableGrid();
void markAvailableAreasWalkable();
void markObstacleMeshesBlocked();
void markObstaclePolygonsBlocked();
bool worldToCell(const Eigen::Vector3f& point, Cell& out) const;