From 12e8950bac74c031448416716e356e84ba7f891a Mon Sep 17 00:00:00 2001 From: Jonathan Adamczewski Date: Tue, 10 Jan 2017 14:13:20 -0800 Subject: [PATCH] Add toggles for heightfield filtering --- RecastDemo/Include/Sample.h | 4 ++++ RecastDemo/Source/Sample.cpp | 14 +++++++++++++- RecastDemo/Source/Sample_SoloMesh.cpp | 9 ++++++--- RecastDemo/Source/Sample_TileMesh.cpp | 9 ++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 687fd4c..814fa3e 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -114,6 +114,10 @@ protected: float m_detailSampleDist; float m_detailSampleMaxError; int m_partitionType; + + bool m_filterLowHangingObstacles; + bool m_filterLedgeSpans; + bool m_filterWalkableLowHeightSpans; SampleTool* m_tool; SampleToolState* m_toolStates[MAX_TOOLS]; diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index 3046e8e..45075a7 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -42,7 +42,10 @@ Sample::Sample() : m_crowd(0), m_navMeshDrawFlags(DU_DRAWNAVMESH_OFFMESHCONS|DU_DRAWNAVMESH_CLOSEDLIST), m_tool(0), - m_ctx(0) + m_ctx(0), + m_filterLowHangingObstacles(true), + m_filterLedgeSpans(true), + m_filterWalkableLowHeightSpans(true) { resetCommonSettings(); m_navQuery = dtAllocNavMeshQuery(); @@ -201,6 +204,15 @@ void Sample::handleCommonSettings() if (imguiCheck("Layers", m_partitionType == SAMPLE_PARTITION_LAYERS)) m_partitionType = SAMPLE_PARTITION_LAYERS; + imguiSeparator(); + imguiLabel("Filtering"); + if (imguiCheck("Low Hanging Obstacles", m_filterLowHangingObstacles)) + m_filterLowHangingObstacles = !m_filterLowHangingObstacles; + if (imguiCheck("Ledge Spans", m_filterLedgeSpans)) + m_filterLedgeSpans= !m_filterLedgeSpans; + if (imguiCheck("Walkable Low Height Spans", m_filterWalkableLowHeightSpans)) + m_filterWalkableLowHeightSpans = !m_filterWalkableLowHeightSpans; + imguiSeparator(); imguiLabel("Polygonization"); imguiSlider("Max Edge Length", &m_edgeMaxLen, 0.0f, 50.0f, 1.0f); diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index 1e5b75d..f08210f 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -457,9 +457,12 @@ bool Sample_SoloMesh::handleBuild() // Once all geoemtry is rasterized, we do initial pass of filtering to // remove unwanted overhangs caused by the conservative rasterization // as well as filter spans where the character cannot possibly stand. - rcFilterLowHangingWalkableObstacles(m_ctx, m_cfg.walkableClimb, *m_solid); - rcFilterLedgeSpans(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid); - rcFilterWalkableLowHeightSpans(m_ctx, m_cfg.walkableHeight, *m_solid); + if (m_filterLowHangingObstacles) + rcFilterLowHangingWalkableObstacles(m_ctx, m_cfg.walkableClimb, *m_solid); + if (m_filterLedgeSpans) + rcFilterLedgeSpans(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid); + if (m_filterWalkableLowHeightSpans) + rcFilterWalkableLowHeightSpans(m_ctx, m_cfg.walkableHeight, *m_solid); // diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index c305743..d7b1b16 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -1056,9 +1056,12 @@ unsigned char* Sample_TileMesh::buildTileMesh(const int tx, const int ty, const // Once all geometry is rasterized, we do initial pass of filtering to // remove unwanted overhangs caused by the conservative rasterization // as well as filter spans where the character cannot possibly stand. - rcFilterLowHangingWalkableObstacles(m_ctx, m_cfg.walkableClimb, *m_solid); - rcFilterLedgeSpans(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid); - rcFilterWalkableLowHeightSpans(m_ctx, m_cfg.walkableHeight, *m_solid); + if (m_filterLowHangingObstacles) + rcFilterLowHangingWalkableObstacles(m_ctx, m_cfg.walkableClimb, *m_solid); + if (m_filterLedgeSpans) + rcFilterLedgeSpans(m_ctx, m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid); + if (m_filterWalkableLowHeightSpans) + rcFilterWalkableLowHeightSpans(m_ctx, m_cfg.walkableHeight, *m_solid); // Compact the heightfield so that it is faster to handle from now on. // This will result more cache coherent data as well as the neighbours