diff --git a/Source/Engine/Navigation/NavMeshRuntime.cpp b/Source/Engine/Navigation/NavMeshRuntime.cpp index eae20561b..b35ade92d 100644 --- a/Source/Engine/Navigation/NavMeshRuntime.cpp +++ b/Source/Engine/Navigation/NavMeshRuntime.cpp @@ -16,9 +16,6 @@ #define USE_NAV_MESH_ALLOC 1 // TODO: try not using USE_NAV_MESH_ALLOC -#define DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL 50.0f -#define DEFAULT_NAV_QUERY_EXTENT_VERTICAL 250.0f - namespace { FORCE_INLINE void InitFilter(dtQueryFilter& filter) @@ -58,7 +55,7 @@ bool NavMeshRuntime::FindDistanceToWall(const Vector3& startPosition, NavMeshHit dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 startPositionNavMesh; Vector3::Transform(startPosition, Properties.Rotation, startPositionNavMesh); @@ -96,7 +93,7 @@ bool NavMeshRuntime::FindPath(const Vector3& startPosition, const Vector3& endPo dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 startPositionNavMesh, endPositionNavMesh; Vector3::Transform(startPosition, Properties.Rotation, startPositionNavMesh); @@ -164,7 +161,7 @@ bool NavMeshRuntime::TestPath(const Vector3& startPosition, const Vector3& endPo dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 startPositionNavMesh, endPositionNavMesh; Vector3::Transform(startPosition, Properties.Rotation, startPositionNavMesh); @@ -211,7 +208,7 @@ bool NavMeshRuntime::ProjectPoint(const Vector3& point, Vector3& result) const dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 pointNavMesh; Vector3::Transform(point, Properties.Rotation, pointNavMesh); @@ -269,7 +266,7 @@ bool NavMeshRuntime::FindRandomPointAroundCircle(const Vector3& center, float ra dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 centerNavMesh; Vector3::Transform(center, Properties.Rotation, centerNavMesh); @@ -307,7 +304,7 @@ bool NavMeshRuntime::RayCast(const Vector3& startPosition, const Vector3& endPos dtQueryFilter filter; InitFilter(filter); - Vector3 extent(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL); + Vector3 extent = Properties.DefaultQueryExtent; Vector3 startPositionNavMesh, endPositionNavMesh; Vector3::Transform(startPosition, Properties.Rotation, startPositionNavMesh); diff --git a/Source/Engine/Navigation/Navigation.cpp b/Source/Engine/Navigation/Navigation.cpp index db9c95089..d7fdcfc33 100644 --- a/Source/Engine/Navigation/Navigation.cpp +++ b/Source/Engine/Navigation/Navigation.cpp @@ -146,7 +146,7 @@ bool NavAreaProperties::operator==(const NavAreaProperties& other) const bool NavMeshProperties::operator==(const NavMeshProperties& other) const { - return Name == other.Name && Quaternion::NearEqual(Rotation, other.Rotation, 0.001f) && Agent == other.Agent; + return Name == other.Name && Quaternion::NearEqual(Rotation, other.Rotation, 0.001f) && Agent == other.Agent && Vector3::NearEqual(DefaultQueryExtent, other.DefaultQueryExtent); } class NavigationService : public EngineService diff --git a/Source/Engine/Navigation/NavigationSettings.cs b/Source/Engine/Navigation/NavigationSettings.cs index 8a97e4adc..bfd2b5381 100644 --- a/Source/Engine/Navigation/NavigationSettings.cs +++ b/Source/Engine/Navigation/NavigationSettings.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. using System; +using System.Runtime.Serialization; using FlaxEngine; namespace FlaxEditor.Content.Settings @@ -22,6 +23,7 @@ namespace FlaxEditor.Content.Settings navMesh.Agent.Height = 144.0f; navMesh.Agent.StepHeight = 35.0f; navMesh.Agent.MaxSlopeAngle = 60.0f; + navMesh.DefaultQueryExtent = new Vector3(50.0f, 250.0f, 50.0f); // Init nav areas NavAreas = new NavAreaProperties[2]; @@ -51,6 +53,7 @@ namespace FlaxEditor.Content.Settings navMesh.Agent.Height = 144.0f; navMesh.Agent.StepHeight = 35.0f; navMesh.Agent.MaxSlopeAngle = 60.0f; + navMesh.DefaultQueryExtent = new Vector3(50.0f, 250.0f, 50.0f); } // [Deprecated on 12.01.2021, expires on 12.01.2022] @@ -105,6 +108,23 @@ namespace FlaxEditor.Content.Settings namespace FlaxEngine { + partial struct NavMeshProperties + { + [OnDeserialized] + internal void OnDeserialized(StreamingContext context) + { + // [Deprecated on 07.04.2021, expires on 07.04.2022] + if (DefaultQueryExtent.IsZero) + DefaultQueryExtent = new Vector3(50.0f, 250.0f, 50.0f); + } + + /// + public override string ToString() + { + return Name; + } + } + partial struct NavAgentProperties { /// diff --git a/Source/Engine/Navigation/NavigationTypes.h b/Source/Engine/Navigation/NavigationTypes.h index 11ebaeb1a..732ce4a0f 100644 --- a/Source/Engine/Navigation/NavigationTypes.h +++ b/Source/Engine/Navigation/NavigationTypes.h @@ -83,6 +83,12 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(NavMeshProperties); API_FIELD(Attributes="EditorOrder(30)") NavAgentProperties Agent; + /// + /// The default extents for the nav queries that defines the search distance along each axis (x, y, z). Smaller values prevent queries from snapping to too far locations. + /// + API_FIELD(Attributes="EditorOrder(40)") + Vector3 DefaultQueryExtent = Vector3(50.0f, 250.0f, 50.0f); + bool operator==(const NavMeshProperties& other) const; bool operator!=(const NavMeshProperties& other) const