// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Core/Math/Vector3.h"
class Scene;
class NavMesh;
#define NAV_MESH_PATH_MAX_SIZE 200
///
/// The result information for navigation mesh queries.
///
API_STRUCT() struct NavMeshHit
{
DECLARE_SCRIPTING_TYPE_MINIMAL(NavMeshHit);
///
/// The hit point position.
///
API_FIELD() Vector3 Position;
///
/// The distance to hit point (from the query origin).
///
API_FIELD() float Distance;
///
/// The hit point normal vector.
///
API_FIELD() Vector3 Normal;
};
///
/// 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:
///
/// Gets the navigation mesh (read-only). Use the other API to request data to use safe access to the navigation system.
///
/// The navigation mesh.
static NavMesh* GetNavMesh();
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);
///
/// 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);
///
/// 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 USE_EDITOR
///
/// Draws the navigation for all the scenes (uses DebugDraw interface).
///
static void DrawNavMesh();
#endif
};