Skip to content

Commit

Permalink
navigation - improved path debug draw
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Nov 8, 2024
1 parent 64ae585 commit 299ac2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/navigation/editor/navigation_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct PropertyGridPlugin final : PropertyGrid::IPlugin {
void onAgentGUI(EntityRef entity, WorldEditor& editor) {
World& world = *editor.getWorld();
auto* module = static_cast<NavigationModule*>(world.getModule("navigation"));
static bool debug_draw_path = false;
const dtCrowdAgent* agent = module->getDetourAgent(entity);
if (agent) {
ImGui::LabelText("Desired speed", "%f", agent->desiredSpeed);
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
};


Expand Down
17 changes: 10 additions & 7 deletions src/navigation/navigation_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RenderModule*>(m_world.getModule("renderer"));
if (!render_module) return;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/navigation_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 299ac2b

Please sign in to comment.