1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 10:53:53 +00:00
openmw/components/detournavigator/makenavmesh.hpp
elsid cf1d8544e3
Check agent bounds on adding agent to navigator
Do not add agent bounds which are not supported by recastnavigation with given
settings and log such events.

To avoid reaching navmesh tile generation to find out it can't be generated for
such agent bounds.
2023-01-18 12:00:48 +01:00

57 lines
1.8 KiB
C++

#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_MAKENAVMESH_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_MAKENAVMESH_H
#include "recastmesh.hpp"
#include "sharednavmesh.hpp"
#include "tileposition.hpp"
#include <memory>
#include <vector>
class dtNavMesh;
struct rcConfig;
namespace DetourNavigator
{
struct Settings;
struct PreparedNavMeshData;
struct NavMeshData;
struct OffMeshConnection;
struct AgentBounds;
struct RecastSettings;
inline float getLength(const osg::Vec2i& value)
{
return std::sqrt(float(osg::square(value.x()) + osg::square(value.y())));
}
inline float getDistance(const TilePosition& lhs, const TilePosition& rhs)
{
return getLength(lhs - rhs);
}
inline bool shouldAddTile(const TilePosition& changedTile, const TilePosition& playerTile, int maxTiles)
{
const auto expectedTilesCount = std::ceil(osg::PI * osg::square(getDistance(changedTile, playerTile)));
return expectedTilesCount <= maxTiles;
}
inline bool isEmpty(const RecastMesh& recastMesh)
{
return recastMesh.getMesh().getIndices().empty() && recastMesh.getWater().empty()
&& recastMesh.getHeightfields().empty() && recastMesh.getFlatHeightfields().empty();
}
std::unique_ptr<PreparedNavMeshData> prepareNavMeshTileData(const RecastMesh& recastMesh,
const TilePosition& tilePosition, const AgentBounds& agentBounds, const RecastSettings& settings);
NavMeshData makeNavMeshTileData(const PreparedNavMeshData& data,
const std::vector<OffMeshConnection>& offMeshConnections, const AgentBounds& agentBounds,
const TilePosition& tile, const RecastSettings& settings);
NavMeshPtr makeEmptyNavMesh(const Settings& settings);
bool isSupportedAgentBounds(const RecastSettings& settings, const AgentBounds& agentBounds);
}
#endif