From 013a53fbc9723d1caa2f388b56bbc87f2adbb301 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 10 Sep 2023 14:30:46 +0900 Subject: [PATCH] refactor: FIND_LOCAL_NEIGHBOURHOOD --- .../Tools/TestNavmeshSampleTool.cs | 14 ++----------- .../Tools/RcTestNavMeshTool.cs | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index c9680ce..a617d24 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -696,18 +696,8 @@ public class TestNavmeshSampleTool : ISampleTool } else if (_mode == RcTestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD) { - if (m_sposSet && m_startRef != 0) - { - m_neighbourhoodRadius = settings.agentRadius * 20.0f; - List resultRef = new(); - List resultParent = new(); - var status = navQuery.FindLocalNeighbourhood(m_startRef, m_spos, m_neighbourhoodRadius, m_filter, ref resultRef, ref resultParent); - if (status.Succeeded()) - { - m_polys = resultRef; - m_parent = resultParent; - } - } + m_neighbourhoodRadius = settings.agentRadius * 20.0f; + _tool.FindLocalNeighbourhood(navQuery, m_startRef, m_spos, m_neighbourhoodRadius, m_filter, ref m_polys, ref m_parent); } else if (_mode == RcTestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 0d84751..6bbb5bb 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -338,6 +338,27 @@ namespace DotRecast.Recast.Toolset.Tools return status; } + public DtStatus FindLocalNeighbourhood(DtNavMeshQuery navQuery, long startRef, RcVec3f spos, float radius, IDtQueryFilter filter, + ref List resultRef, ref List resultParent) + { + if (startRef == 0) + { + resultRef?.Clear(); + resultParent?.Clear(); + return DtStatus.DT_FAILURE; + } + + resultRef ??= new List(); + resultParent ??= new List(); + + resultRef.Clear(); + resultParent.Clear(); + + var status = navQuery.FindLocalNeighbourhood(startRef, spos, radius, filter, ref resultRef, ref resultParent); + return status; + } + + public DtStatus FindPolysAroundShape(DtNavMeshQuery navQuery, float agentHeight, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, ref List resultRefs, ref List resultParents, ref RcVec3f[] queryPoly) {