From 5500e99ed8af01e6ef927db5c5f78c3ea1722379 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 31 Aug 2023 09:37:27 +0200 Subject: [PATCH] Add `NavMeshPathFlags` to navmesh for partial paths info --- Source/Engine/Navigation/NavMeshRuntime.cpp | 4 ++- Source/Engine/Navigation/NavMeshRuntime.h | 29 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Navigation/NavMeshRuntime.cpp b/Source/Engine/Navigation/NavMeshRuntime.cpp index b09f8346a..913c46e3e 100644 --- a/Source/Engine/Navigation/NavMeshRuntime.cpp +++ b/Source/Engine/Navigation/NavMeshRuntime.cpp @@ -78,9 +78,10 @@ bool NavMeshRuntime::FindDistanceToWall(const Vector3& startPosition, NavMeshHit return true; } -bool NavMeshRuntime::FindPath(const Vector3& startPosition, const Vector3& endPosition, Array& resultPath) const +bool NavMeshRuntime::FindPath(const Vector3& startPosition, const Vector3& endPosition, Array& resultPath, NavMeshPathFlags& resultFlags) const { resultPath.Clear(); + resultFlags = NavMeshPathFlags::None; ScopeLock lock(Locker); const auto query = GetNavMeshQuery(); if (!query || !_navMesh) @@ -120,6 +121,7 @@ bool NavMeshRuntime::FindPath(const Vector3& startPosition, const Vector3& endPo if (pathSize == 1 && dtStatusDetail(findPathStatus, DT_PARTIAL_RESULT)) { + resultFlags |= NavMeshPathFlags::PartialPath; // TODO: skip adding 2nd end point if it's not reachable (use navmesh raycast check? or physics check? or local Z distance check?) resultPath.Resize(2); resultPath[0] = startPosition; diff --git a/Source/Engine/Navigation/NavMeshRuntime.h b/Source/Engine/Navigation/NavMeshRuntime.h index 2183ca6f2..6070ec0e1 100644 --- a/Source/Engine/Navigation/NavMeshRuntime.h +++ b/Source/Engine/Navigation/NavMeshRuntime.h @@ -24,6 +24,19 @@ public: BytesContainer Data; }; +/// +/// The navigation mesh path flags. +/// +enum class NavMeshPathFlags +{ + // Nothing. + None = 0, + // Path is only partially generated, goal is unreachable so path represents the best guess. + PartialPath = 1, +}; + +DECLARE_ENUM_OPERATORS(NavMeshPathFlags); + /// /// The navigation mesh runtime object that builds the navmesh from all loaded scenes. /// @@ -106,7 +119,21 @@ public: /// The end position. /// The result path. /// True if found valid path between given two points (it may be partial), otherwise false if failed. - bool FindPath(const Vector3& startPosition, const Vector3& endPosition, Array& resultPath) const; + bool FindPath(const Vector3& startPosition, const Vector3& endPosition, Array& resultPath) const + { + NavMeshPathFlags flags; + return FindPath(startPosition, endPosition, resultPath, flags); + } + + /// + /// Finds the path between the two positions presented as a list of waypoints stored in the corners array. + /// + /// The start position. + /// The end position. + /// The result path. + /// The result path flags. + /// True if found valid path between given two points (it may be partial), otherwise false if failed. + bool FindPath(const Vector3& startPosition, const Vector3& endPosition, Array& resultPath, NavMeshPathFlags& resultFlags) const; /// /// Tests the path between the two positions (non-partial).