From 299ac2befa8e5bae24d0116e4009f014d924d96c Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Fri, 8 Nov 2024 14:43:22 +0100 Subject: [PATCH] navigation - improved path debug draw --- src/navigation/editor/navigation_plugins.cpp | 10 +++++++--- src/navigation/navigation_module.cpp | 17 ++++++++++------- src/navigation/navigation_module.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/navigation/editor/navigation_plugins.cpp b/src/navigation/editor/navigation_plugins.cpp index 90203c423b..24a180a766 100644 --- a/src/navigation/editor/navigation_plugins.cpp +++ b/src/navigation/editor/navigation_plugins.cpp @@ -38,7 +38,6 @@ struct PropertyGridPlugin final : PropertyGrid::IPlugin { void onAgentGUI(EntityRef entity, WorldEditor& editor) { World& world = *editor.getWorld(); auto* module = static_cast(world.getModule("navigation")); - static bool debug_draw_path = false; const dtCrowdAgent* agent = module->getDetourAgent(entity); if (agent) { ImGui::LabelText("Desired speed", "%f", agent->desiredSpeed); @@ -56,8 +55,11 @@ struct PropertyGridPlugin final : PropertyGrid::IPlugin { if (agent->targetState < lengthOf(TARGET_STATES)) ImGui::LabelText("Target state", "%s", TARGET_STATES[agent->targetState]); } - ImGui::Checkbox("Draw path", &debug_draw_path); - if (debug_draw_path) module->debugDrawPath(entity); + ImGui::Checkbox("Draw path", &m_debug_draw_path); + if (m_debug_draw_path) { + ImGui::Checkbox("Draw path polygons", &m_debug_draw_path_polys); + } + if (m_debug_draw_path) module->debugDrawPath(entity, m_debug_draw_path_polys); } void update() override { @@ -164,6 +166,8 @@ struct PropertyGridPlugin final : PropertyGrid::IPlugin { StudioApp& m_app; NavmeshBuildJob* m_job = nullptr; + bool m_debug_draw_path = false; + bool m_debug_draw_path_polys = false; }; diff --git a/src/navigation/navigation_module.cpp b/src/navigation/navigation_module.cpp index a88641424e..704959d94d 100644 --- a/src/navigation/navigation_module.cpp +++ b/src/navigation/navigation_module.cpp @@ -541,7 +541,7 @@ struct NavigationModuleImpl final : NavigationModule } - void debugDrawPath(EntityRef entity) override + void debugDrawPath(EntityRef entity, bool include_polygons) override { auto render_module = static_cast(m_world.getModule("renderer")); if (!render_module) return; @@ -560,13 +560,16 @@ struct NavigationModuleImpl final : NavigationModule const dtPolyRef* path = dt_agent->corridor.getPath(); const int npath = dt_agent->corridor.getPathCount(); - for (int j = 0; j < npath; ++j) { - dtPolyRef ref = path[j]; - const dtMeshTile* tile = nullptr; - const dtPoly* poly = nullptr; - if (dtStatusFailed(zone.navmesh->getTileAndPolyByRef(ref, &tile, &poly))) continue; - drawPoly(render_module, zone_tr, *tile, *poly); + if (include_polygons) { + for (int j = 0; j < npath; ++j) { + dtPolyRef ref = path[j]; + const dtMeshTile* tile = nullptr; + const dtPoly* poly = nullptr; + if (dtStatusFailed(zone.navmesh->getTileAndPolyByRef(ref, &tile, &poly))) continue; + + drawPoly(render_module, zone_tr, *tile, *poly); + } } Vec3 prev = *(Vec3*)dt_agent->npos; diff --git a/src/navigation/navigation_module.h b/src/navigation/navigation_module.h index 8526696955..be5bc2d2d6 100644 --- a/src/navigation/navigation_module.h +++ b/src/navigation/navigation_module.h @@ -70,7 +70,7 @@ struct NavigationModule : IModule virtual void debugDrawCompactHeightfield(EntityRef zone) = 0; virtual void debugDrawHeightfield(EntityRef zone) = 0; virtual void debugDrawContours(EntityRef zone) = 0; - virtual void debugDrawPath(EntityRef agent_entity) = 0; + virtual void debugDrawPath(EntityRef agent_entity, bool include_polygons) = 0; virtual const dtCrowdAgent* getDetourAgent(EntityRef entity) = 0; virtual bool isNavmeshReady(EntityRef zone) const = 0; virtual bool hasDebugDrawData(EntityRef zoneko) const = 0;