2019-01-26 16:01:35 +11:00
|
|
|
#ifndef SAPPHIRE_TILEDNAVMESHGENERATOR_H
|
|
|
|
#define SAPPHIRE_TILEDNAVMESHGENERATOR_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <cassert>
|
2019-01-26 18:45:37 +11:00
|
|
|
#include <cmath>
|
2019-01-26 16:01:35 +11:00
|
|
|
|
|
|
|
#include "ext/MeshLoaderObj.h"
|
|
|
|
#include "ext/ChunkyTriMesh.h"
|
|
|
|
|
|
|
|
#include "recastnavigation/Detour/Include/DetourNavMesh.h"
|
|
|
|
#include "recastnavigation/Detour/Include/DetourNavMeshQuery.h"
|
|
|
|
#include "recastnavigation/Recast/Include/Recast.h"
|
|
|
|
|
|
|
|
class TiledNavmeshGenerator
|
|
|
|
{
|
2019-01-26 18:45:37 +11:00
|
|
|
public:
|
|
|
|
enum SamplePartitionType
|
|
|
|
{
|
|
|
|
SAMPLE_PARTITION_WATERSHED,
|
|
|
|
SAMPLE_PARTITION_MONOTONE,
|
|
|
|
SAMPLE_PARTITION_LAYERS,
|
|
|
|
};
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
enum SamplePolyAreas
|
|
|
|
{
|
|
|
|
SAMPLE_POLYAREA_GROUND,
|
|
|
|
SAMPLE_POLYAREA_WATER,
|
|
|
|
SAMPLE_POLYAREA_ROAD,
|
|
|
|
SAMPLE_POLYAREA_DOOR,
|
|
|
|
SAMPLE_POLYAREA_GRASS,
|
|
|
|
SAMPLE_POLYAREA_JUMP,
|
|
|
|
};
|
|
|
|
enum SamplePolyFlags
|
|
|
|
{
|
|
|
|
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
|
|
|
|
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
|
|
|
|
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
|
|
|
|
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
|
|
|
|
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
|
|
|
|
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int NAVMESHSET_MAGIC = 'M'<<24 | 'S'<<16 | 'E'<<8 | 'T'; //'MSET';
|
|
|
|
static const int NAVMESHSET_VERSION = 1;
|
|
|
|
|
|
|
|
struct NavMeshSetHeader
|
|
|
|
{
|
|
|
|
int magic;
|
|
|
|
int version;
|
|
|
|
int numTiles;
|
|
|
|
dtNavMeshParams params;
|
|
|
|
};
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
struct NavMeshTileHeader
|
|
|
|
{
|
|
|
|
dtTileRef tileRef;
|
|
|
|
int dataSize;
|
|
|
|
};
|
2019-01-26 16:01:35 +11:00
|
|
|
|
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
TiledNavmeshGenerator() = default;
|
|
|
|
~TiledNavmeshGenerator();
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
bool init( const std::string& path );
|
|
|
|
unsigned char* buildTileMesh( const int tx, const int ty, const float* bmin, const float* bmax, int& dataSize );
|
|
|
|
bool buildNavmesh();
|
|
|
|
void saveNavmesh( const std::string& name );
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
private:
|
|
|
|
rcConfig m_cfg;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
rcMeshLoaderObj* m_mesh;
|
|
|
|
rcChunkyTriMesh* m_chunkyMesh;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
rcContext* m_ctx;
|
|
|
|
dtNavMesh* m_navMesh;
|
|
|
|
dtNavMeshQuery* m_navQuery;
|
|
|
|
rcHeightfield* m_solid;
|
|
|
|
rcContourSet* m_cset;
|
|
|
|
rcPolyMesh* m_pmesh;
|
|
|
|
rcPolyMeshDetail* m_dmesh;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
rcCompactHeightfield* m_chf;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
unsigned char* m_triareas;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
int m_maxTiles = 0;
|
|
|
|
int m_maxPolysPerTile = 0;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
int m_tileTriCount = 0;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
int m_partitionType = SamplePartitionType::SAMPLE_PARTITION_WATERSHED;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_meshBMin[ 3 ];
|
|
|
|
float m_meshBMax[ 3 ];
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 19:41:57 +11:00
|
|
|
float m_lastBuiltTileBmin[ 3 ];
|
|
|
|
float m_lastBuiltTileBmax[ 3 ];
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:47:59 +11:00
|
|
|
// options
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_tileSize = 160.f;
|
|
|
|
float m_cellSize = 0.2f;
|
|
|
|
float m_cellHeight = 0.2f;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_agentMaxSlope = 56.f;
|
|
|
|
float m_agentHeight = 2.f;
|
|
|
|
float m_agentMaxClimb = 0.6f;
|
|
|
|
float m_agentRadius = 0.5f;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_regionMinSize = 8.f;
|
|
|
|
float m_regionMergeSize = 20.f;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 19:41:57 +11:00
|
|
|
float m_edgeMaxLen = 12.f;
|
|
|
|
float m_edgeMaxError = 1.4f;
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_vertsPerPoly = 6.f;
|
2019-01-26 16:01:35 +11:00
|
|
|
|
2019-01-26 18:45:37 +11:00
|
|
|
float m_detailSampleDist = 6.f;
|
|
|
|
float m_detailSampleMaxError = 1.f;
|
2019-01-26 19:41:57 +11:00
|
|
|
|
2019-01-26 16:01:35 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SAPPHIRE_TILEDNAVMESHGENERATOR_H
|