This commit is contained in:
Vladislav Khorev 2026-04-18 17:30:41 +03:00
commit 57789eed24
5 changed files with 85 additions and 2 deletions

View File

@ -113,6 +113,17 @@
[1, -5.5],
[-0.2, -5.5]
]
},
{
"name": "main_corridor",
"available": true,
"forbidden": true,
"polygon": [
[-15, 15],
[15, 15],
[15, 2.2],
[-15, 2.2]
]
}
]
}

View File

@ -322,6 +322,7 @@ void Location::setup()
}
//#ifdef SHOW_PATH
buildDebugNavMeshes();
buildDebugForbiddenMeshes();
//#endif
auto planner = [this](const Eigen::Vector3f& start, const Eigen::Vector3f& end) {
@ -366,6 +367,35 @@ void Location::setup()
renderer.shaderManager.PopShader();
renderer.SetMatrix();
}
void Location::buildDebugForbiddenMeshes()
{
debugForbiddenMeshes.clear();
const auto& areas = navigation.getAreas();
float y = navigation.getFloorY() + 0.2f;
Eigen::Vector3f blue(0.0f, 0.0f, 1.0f);
for (const auto& area : areas) {
if (area.forbidden && area.polygon.size() >= 3) {
VertexRenderStruct mesh;
mesh.data = CreatePolygonFloor(area.polygon, y, blue);
mesh.RefreshVBO();
debugForbiddenMeshes.push_back(std::move(mesh));
}
}
}
void Location::drawDebugForbidden()
{
if (debugForbiddenMeshes.empty()) return;
renderer.shaderManager.PushShader("defaultColor");
renderer.SetMatrix();
for (const auto& mesh : debugForbiddenMeshes) {
renderer.DrawVertexRenderStruct(mesh);
}
renderer.shaderManager.PopShader();
renderer.SetMatrix();
}
//#endif
@ -551,7 +581,8 @@ void Location::setup()
for (auto& npc : npcs) npc->draw(renderer);
//#ifdef SHOW_PATH
//drawDebugNavigation();
drawDebugNavigation();
drawDebugForbidden();
//#endif
renderer.PopMatrix();
@ -734,6 +765,7 @@ void Location::setup()
CheckGlError(__FILE__, __LINE__);
drawDebugNavigation();
drawDebugForbidden();
renderer.PopMatrix();
renderer.PopProjectionMatrix();

View File

@ -77,6 +77,10 @@ namespace ZL
std::vector<VertexRenderStruct> debugNavMeshes;
void buildDebugNavMeshes();
void drawDebugNavigation();
std::vector<VertexRenderStruct> debugForbiddenMeshes;
void buildDebugForbiddenMeshes();
void drawDebugForbidden();
//#endif
bool rightMouseDown = false;
int lastMouseX = 0;

View File

@ -246,6 +246,7 @@ void PathFinder::loadConfig(const std::string& configPath, const std::string& zi
NavigationArea area;
area.name = item.value("name", "");
area.available = item.value("available", true);
area.forbidden = item.value("forbidden", false);
area.polygon = readPolygon(item);
if (area.name.empty()) {
@ -314,10 +315,44 @@ void PathFinder::resetGridBounds()
gridDepth = static_cast<int>(std::ceil((maxZ - minZ) / cellSize));
}
void PathFinder::rebuildWalkableGrid()
/*void PathFinder::rebuildWalkableGrid()
{
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
markAvailableAreasWalkable();
markObstacleMeshesBlocked();
}*/
void PathFinder::rebuildWalkableGrid()
{
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
for (const NavigationArea& area : areas) {
if (area.available && !area.forbidden) {
for (int z = 0; z < gridDepth; ++z) {
for (int x = 0; x < gridWidth; ++x) {
const Cell cell{ x, z };
const Eigen::Vector3f center = cellCenter(cell);
if (pointInPolygon(center.x(), center.z(), area.polygon)) {
walkable[static_cast<size_t>(indexOf(cell))] = 1;
}
}
}
}
}
for (const NavigationArea& area : areas) {
if (area.forbidden) {
for (int z = 0; z < gridDepth; ++z) {
for (int x = 0; x < gridWidth; ++x) {
const Cell cell{ x, z };
const Eigen::Vector3f center = cellCenter(cell);
if (pointInPolygon(center.x(), center.z(), area.polygon)) {
walkable[static_cast<size_t>(indexOf(cell))] = 0;
}
}
}
}
}
markObstacleMeshesBlocked();
}

View File

@ -22,6 +22,7 @@ public:
struct NavigationArea {
std::string name;
bool available = true;
bool forbidden = false;
std::vector<Eigen::Vector2f> polygon;
};