// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "NavigationTypes.h" class Scene; /// /// The navigation service used for path finding and agents navigation system. /// API_CLASS(Static) class FLAXENGINE_API Navigation { DECLARE_SCRIPTING_TYPE_NO_SPAWN(Navigation); public: /// /// Finds the distance from the specified start position to the nearest polygon wall. /// /// The start position. /// The result hit information. Valid only when query succeed. /// The maximum distance to search for wall (search radius). /// True if ray hits an matching object, otherwise false. API_FUNCTION() static bool FindDistanceToWall(const Vector3& startPosition, API_PARAM(Out) NavMeshHit& hitInfo, float maxDistance = MAX_float); /// /// 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. /// True if found valid path between given two points (it may be partial), otherwise false if failed. API_FUNCTION() static bool FindPath(const Vector3& startPosition, const Vector3& endPosition, API_PARAM(Out) Array& resultPath); /// /// Tests the path between the two positions (non-partial). /// /// The start position. /// The end position. /// True if found valid path between given two points, otherwise false if failed. API_FUNCTION() static bool TestPath(const Vector3& startPosition, const Vector3& endPosition); /// /// Projects the point to nav mesh surface (finds the nearest polygon). /// /// The source point. /// The result position on the navmesh (valid only if method returns true). /// True if found valid location on the navmesh, otherwise false. API_FUNCTION() static bool ProjectPoint(const Vector3& point, API_PARAM(Out) Vector3& result); /// /// Finds random location on nav mesh. /// /// The result position on the navmesh (valid only if method returns true). /// True if found valid location on the navmesh, otherwise false. API_FUNCTION() static bool FindRandomPoint(API_PARAM(Out) Vector3& result); /// /// Finds random location on nav mesh within the reach of specified location. /// /// The source point to find random location around it. /// The search distance for a random point. Maximum distance for a result point from the center of the circle. /// The result position on the navmesh (valid only if method returns true). /// True if found valid location on the navmesh, otherwise false. API_FUNCTION() static bool FindRandomPointAroundCircle(const Vector3& center, float radius, API_PARAM(Out) Vector3& result); /// /// Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position. /// /// The start position. /// The end position. /// The result hit information. Valid only when query succeed. /// True if ray hits an matching object, otherwise false. API_FUNCTION() static bool RayCast(const Vector3& startPosition, const Vector3& endPosition, API_PARAM(Out) NavMeshHit& hitInfo); public: #if COMPILE_WITH_NAV_MESH_BUILDER /// /// Returns true if navigation system is during navmesh building (any request is valid or async task active). /// API_PROPERTY() static bool IsBuildingNavMesh(); /// /// Gets the navmesh building progress (normalized to range 0-1). /// API_PROPERTY() static float GetNavMeshBuildingProgress(); /// /// Builds the Nav Mesh for the given scene (discards all its tiles). /// /// /// Requests are enqueued till the next game scripts update. Actual navmesh building in done via Thread Pool tasks in a background to prevent game thread stalls. /// /// The scene. /// The timeout to wait before building Nav Mesh (in milliseconds). API_FUNCTION() static void BuildNavMesh(Scene* scene, float timeoutMs = 50); /// /// Builds the Nav Mesh for the given scene (builds only the tiles overlapping the given bounding box). /// /// /// Requests are enqueued till the next game scripts update. Actual navmesh building in done via Thread Pool tasks in a background to prevent game thread stalls. /// /// The scene. /// The bounds in world-space to build overlapping tiles. /// The timeout to wait before building Nav Mesh (in milliseconds). API_FUNCTION() static void BuildNavMesh(Scene* scene, const BoundingBox& dirtyBounds, float timeoutMs = 50); #endif #if COMPILE_WITH_DEBUG_DRAW /// /// Draws the navigation for all the scenes (uses DebugDraw interface). /// static void DrawNavMesh(); #endif };