19 #ifndef DETOURTILECACHEBUILDER_H
20 #define DETOURTILECACHEBUILDER_H
22 #include <AtomsUtils/Globals.h>
23 #include <AtomsUtils/NavigationMesh/Detour/DetourAlloc.h>
24 #include <AtomsUtils/NavigationMesh/Detour/DetourStatus.h>
28 static const int DT_TILECACHE_MAGIC =
'D'<<24 |
'T'<<16 |
'L'<<8 |
'R';
29 static const int DT_TILECACHE_VERSION = 1;
31 static const unsigned char DT_TILECACHE_NULL_AREA = 0;
32 static const unsigned char DT_TILECACHE_WALKABLE_AREA = 63;
33 static const unsigned short DT_TILECACHE_NULL_IDX = 0xffff;
40 float bmin[3], bmax[3];
43 unsigned short minx, maxx, miny,
maxy;
50 unsigned short* heights;
59 unsigned short* verts;
114 void dtLog(
const char* format, ...);
122 virtual void doDtLog(
const char* ,
const int ) {}
135 virtual void* alloc(
const int size)
140 virtual void free(
void* ptr)
148 virtual int maxCompressedSize(
const int bufferSize) = 0;
149 virtual dtStatus compress(
const unsigned char* buffer,
const int bufferSize,
150 unsigned char* compressed,
const int maxCompressedSize,
int* compressedSize) = 0;
151 virtual dtStatus decompress(
const unsigned char* compressed,
const int compressedSize,
152 unsigned char* buffer,
const int maxBufferSize,
int* bufferSize) = 0;
161 inline T* operator=(T* p);
166 inline ~
dtFixedArray() {
if (m_alloc) m_alloc->free(m_ptr); }
167 inline operator T*() {
return m_ptr; }
168 inline int size()
const {
return m_size; }
169 inline void set(
unsigned char v) { memset(m_ptr, v,
sizeof(T)*m_size); }
172 inline int getDirOffsetX(
int dir)
174 const int offset[4] = { -1, 0, 1, 0, };
175 return offset[dir&0x03];
178 inline int getDirOffsetY(
int dir)
180 const int offset[4] = { 0, 1, 0, -1 };
181 return offset[dir&0x03];
185 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
186 dtTileCacheLayerHeader* header,
187 const unsigned short* heights,
188 const unsigned char* areas,
189 const unsigned char* cons,
190 unsigned char** outData,
int* outDataSize);
192 ATOMSUTILS_EXPORT
void dtFreeTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheLayer* layer);
194 ATOMSUTILS_EXPORT dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompressor* comp,
195 unsigned char* compressed,
const int compressedSize,
196 dtTileCacheLayer** layerOut);
198 ATOMSUTILS_EXPORT dtTileCacheContourSet* dtAllocTileCacheContourSet(dtTileCacheAlloc* alloc);
199 ATOMSUTILS_EXPORT
void dtFreeTileCacheContourSet(dtTileCacheAlloc* alloc, dtTileCacheContourSet* cset);
201 ATOMSUTILS_EXPORT dtTileCacheClusterSet* dtAllocTileCacheClusterSet(dtTileCacheAlloc* alloc);
202 ATOMSUTILS_EXPORT
void dtFreeTileCacheClusterSet(dtTileCacheAlloc* alloc, dtTileCacheClusterSet* clusters);
204 ATOMSUTILS_EXPORT dtTileCachePolyMesh* dtAllocTileCachePolyMesh(dtTileCacheAlloc* alloc);
205 ATOMSUTILS_EXPORT
void dtFreeTileCachePolyMesh(dtTileCacheAlloc* alloc, dtTileCachePolyMesh* lmesh);
208 ATOMSUTILS_EXPORT dtTileCachePolyMeshDetail* dtAllocTileCachePolyMeshDetail(dtTileCacheAlloc* alloc);
209 ATOMSUTILS_EXPORT
void dtFreeTileCachePolyMeshDetail(dtTileCacheAlloc* alloc, dtTileCachePolyMeshDetail* dmesh);
211 ATOMSUTILS_EXPORT dtTileCacheDistanceField* dtAllocTileCacheDistanceField(dtTileCacheAlloc* alloc);
212 ATOMSUTILS_EXPORT
void dtFreeTileCacheDistanceField(dtTileCacheAlloc* alloc, dtTileCacheDistanceField* dfield);
215 ATOMSUTILS_EXPORT dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
216 const float* pos,
const float radius,
const float height,
const unsigned char areaId);
219 ATOMSUTILS_EXPORT dtStatus dtMarkBoxArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
220 const float* pos,
const float* extent,
const unsigned char areaId);
222 ATOMSUTILS_EXPORT dtStatus dtMarkConvexArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
223 const float* verts,
const int nverts,
const float hmin,
const float hmax,
const unsigned char areaId);
225 ATOMSUTILS_EXPORT dtStatus dtReplaceCylinderArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
226 const float* pos,
const float radius,
const float height,
const unsigned char areaId,
227 const unsigned char filterAreaId);
229 ATOMSUTILS_EXPORT dtStatus dtReplaceBoxArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
230 const float* pos,
const float* extent,
const unsigned char areaId,
const unsigned char filterAreaId);
232 ATOMSUTILS_EXPORT dtStatus dtReplaceConvexArea(dtTileCacheLayer& layer,
const float* orig,
const float cs,
const float ch,
233 const float* verts,
const int nverts,
const float hmin,
const float hmax,
const unsigned char areaId,
234 const unsigned char filterAreaId);
236 ATOMSUTILS_EXPORT dtStatus dtReplaceArea(dtTileCacheLayer& layer,
const unsigned char areaId,
const unsigned char filterAreaId);
240 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheDistanceField(dtTileCacheAlloc* alloc, dtTileCacheLayer& layer, dtTileCacheDistanceField& dfield);
242 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc* alloc,
243 const int minRegionArea,
const int mergeRegionArea,
244 dtTileCacheLayer& layer, dtTileCacheDistanceField dfield);
246 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheRegionsMonotone(dtTileCacheAlloc* alloc,
247 const int minRegionArea,
const int mergeRegionArea,
248 dtTileCacheLayer& layer);
250 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheRegionsChunky(dtTileCacheAlloc* alloc,
251 const int minRegionArea,
const int mergeRegionArea,
252 dtTileCacheLayer& layer,
int regionChunkSize);
255 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheContours(dtTileCacheAlloc* alloc,
256 dtTileCacheLayer& layer,
257 const int walkableClimb,
const float maxError,
258 const float cs,
const float ch,
259 dtTileCacheContourSet& lcset,
260 dtTileCacheClusterSet& lclusters);
262 ATOMSUTILS_EXPORT dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc,
263 dtTileCacheLogContext* ctx,
264 dtTileCacheContourSet& lcset,
265 dtTileCachePolyMesh& mesh);
268 ATOMSUTILS_EXPORT dtStatus dtBuildTileCachePolyMeshDetail(dtTileCacheAlloc* alloc,
269 const float cs,
const float ch,
270 const float sampleDist,
const float sampleMaxError,
271 dtTileCacheLayer& layer,
272 dtTileCachePolyMesh& lmesh,
273 dtTileCachePolyMeshDetail& dmesh);
275 ATOMSUTILS_EXPORT dtStatus dtBuildTileCacheClusters(dtTileCacheAlloc* alloc,
276 dtTileCacheClusterSet& lclusters,
277 dtTileCachePolyMesh& lmesh);
Definition: DetourTileCacheBuilder.h:157
Definition: DetourTileCacheBuilder.h:109
void dtLog(const char *format,...)
virtual void doDtLog(const char *, const int)
Definition: DetourTileCacheBuilder.h:122
AtomsCore namespace.
Definition: Base64.h:13
ATOMSUTILS_EXPORT void * dtAlloc(int size, dtAllocHint hint)
@ DT_ALLOC_TEMP
Memory used temporarily within a function.
Definition: DetourAlloc.h:31
ATOMSUTILS_EXPORT bool dtTileCacheHeaderSwapEndian(unsigned char *data, const int dataSize)
ATOMSUTILS_EXPORT void dtFree(void *ptr)
Definition: DetourTileCacheBuilder.h:128
Definition: DetourTileCacheBuilder.h:71
int npolys
The number of polys.
Definition: DetourTileCacheBuilder.h:74
int nclusters
The number of clusters.
Definition: DetourTileCacheBuilder.h:72
int nregs
The number of regions.
Definition: DetourTileCacheBuilder.h:73
unsigned short * regMap
Cluster Id for each region [size: nregs].
Definition: DetourTileCacheBuilder.h:75
unsigned short * polyMap
Cluster Id for each poly [size: npolys].
Definition: DetourTileCacheBuilder.h:76
Definition: DetourTileCacheBuilder.h:147
Definition: DetourTileCacheBuilder.h:57
Definition: DetourTileCacheBuilder.h:65
Definition: DetourTileCacheBuilder.h:103
unsigned short maxDist
Max distance.
Definition: DetourTileCacheBuilder.h:104
unsigned short * data
distance for every cell in layer
Definition: DetourTileCacheBuilder.h:105
Definition: DetourTileCacheBuilder.h:47
unsigned short regCount
Region count.
Definition: DetourTileCacheBuilder.h:49
Definition: DetourTileCacheBuilder.h:93
int nverts
The number of vertices in verts.
Definition: DetourTileCacheBuilder.h:95
float * verts
The mesh vertices. [Size: 3*nverts].
Definition: DetourTileCacheBuilder.h:98
unsigned int * meshes
The sub-mesh data. [Size: 4*nmeshes].
Definition: DetourTileCacheBuilder.h:97
int ntris
The number of triangles in tris.
Definition: DetourTileCacheBuilder.h:96
unsigned char * tris
The mesh triangles. [Size: 4*ntris].
Definition: DetourTileCacheBuilder.h:99
int nmeshes
The number of sub-meshes defined by meshes.
Definition: DetourTileCacheBuilder.h:94
Definition: DetourTileCacheBuilder.h:80
unsigned short * flags
Per polygon flags.
Definition: DetourTileCacheBuilder.h:86
unsigned short * verts
Vertices of the mesh, 3 elements per vertex.
Definition: DetourTileCacheBuilder.h:84
int npolys
Number of polygons.
Definition: DetourTileCacheBuilder.h:83
unsigned short * polys
Polygons of the mesh, nvp*2 elements per polygon.
Definition: DetourTileCacheBuilder.h:85
unsigned char * areas
Area ID of polygons.
Definition: DetourTileCacheBuilder.h:87
unsigned short * regs
Region ID of polygon.
Definition: DetourTileCacheBuilder.h:88
int nverts
Number of vertices.
Definition: DetourTileCacheBuilder.h:82