Atoms Crowd  7.0.0
DetourNavMesh.h
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18 
19 #ifndef DETOURNAVMESH_H
20 #define DETOURNAVMESH_H
21 
22 #include <AtomsUtils/Globals.h>
23 #include <AtomsUtils/NavigationMesh/Detour/DetourAlloc.h>
24 #include <AtomsUtils/NavigationMesh/Detour/DetourStatus.h>
25 
26 namespace AtomsUtils {
27 
28 // Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef.
29 // It is also recommended that you change dtHashRef() to a proper 64-bit hash.
30 
31 #ifndef USE_64BIT_ADDRESS
32 #define USE_64BIT_ADDRESS 1
33 #endif
34 
35 #if USE_64BIT_ADDRESS
36 
37 #if defined(__LP64__)
38 // LP64 (Linux/OS X): unreal will define its uint64 type as "unsigned long long" so we need to match this
39 typedef unsigned long long Type_uint64;
40 #else
41 #include <stdint.h>
42 typedef uint64_t Type_uint64;
43 #endif
44 
47 typedef Type_uint64 dtPolyRef;
48 
51 typedef Type_uint64 dtTileRef;
52 
54 typedef Type_uint64 dtClusterRef;
55 
56 #else
57 
60 typedef unsigned int dtPolyRef;
61 
64 typedef unsigned int dtTileRef;
65 
67 typedef unsigned int dtClusterRef;
68 
69 #endif // USE_64BIT_ADDRESS
70 
73 static const int DT_VERTS_PER_POLYGON = 6;
74 
80 
82 static const int DT_NAVMESH_MAGIC = 'D'<<24 | 'N'<<16 | 'A'<<8 | 'V';
83 
85 static const int DT_NAVMESH_VERSION = 7;
86 
88 static const int DT_NAVMESH_STATE_MAGIC = 'D'<<24 | 'N'<<16 | 'M'<<8 | 'S';
89 
91 static const int DT_NAVMESH_STATE_VERSION = 1;
92 
94 
97 static const unsigned short DT_EXT_LINK = 0x8000;
98 
100 static const unsigned int DT_NULL_LINK = 0xffffffff;
101 
103 static const unsigned char DT_OFFMESH_CON_BIDIR = 0x01;
104 static const unsigned char DT_OFFMESH_CON_POINT = 0x02;
105 static const unsigned char DT_OFFMESH_CON_SEGMENT = 0x04;
106 static const unsigned char DT_OFFMESH_CON_CHEAPAREA = 0x08;
107 
110 static const int DT_MAX_AREAS = 64;
111 
113 static const int DT_MIN_SALT_BITS = 5;
114 static const int DT_SALT_BASE = 1;
115 
117 static const int DT_MAX_OFFMESH_SEGMENT_PARTS = 4;
118 static const int DT_INVALID_SEGMENT_PART = 0xffff;
119 
121 static const unsigned char DT_CONNECTION_INTERNAL = (1 << 7);
122 static const unsigned char DT_LINK_FLAG_OFFMESH_CON = (1 << 6);
123 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_BIDIR = (1 << 5);
124 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_BACKTRACKER = (1 << 4);
125 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_ENABLED = (1 << 3);
126 static const unsigned char DT_LINK_FLAG_SIDE_MASK = 7;
127 
129 static const unsigned char DT_CLINK_VALID_FWD = 0x01;
130 static const unsigned char DT_CLINK_VALID_BCK = 0x02;
131 
133 static const unsigned int DT_CLINK_FIRST = 0x80000000;
134 
135 
139 {
141 };
142 
145 {
149 };
150 
153 {
156 };
157 
160 {
167 };
168 
170 {
172 };
173 
174 
177 struct dtPoly
178 {
180  unsigned int firstLink;
181 
184  unsigned short verts[DT_VERTS_PER_POLYGON];
185 
187  unsigned short neis[DT_VERTS_PER_POLYGON];
188 
190  unsigned short flags;
191 
193  unsigned char vertCount;
194 
197  unsigned char areaAndtype;
198 
200  inline void setArea(unsigned char a) { areaAndtype = (areaAndtype & 0xc0) | (a & 0x3f); }
201 
203  inline void setType(unsigned char t) { areaAndtype = (areaAndtype & 0x3f) | (t << 6); }
204 
206  inline unsigned char getArea() const { return areaAndtype & 0x3f; }
207 
209  inline unsigned char getType() const { return areaAndtype >> 6; }
210 };
211 
214 {
215  unsigned int vertBase;
216  unsigned int triBase;
217  unsigned char vertCount;
218  unsigned char triCount;
219 };
220 
224 struct dtLink
225 {
227  unsigned int next;
228  unsigned char edge;
229  unsigned char side;
230  unsigned char bmin;
231  unsigned char bmax;
232 };
233 
237 struct dtBVNode
238 {
239  unsigned short bmin[3];
240  unsigned short bmax[3];
241  int i;
242 };
243 
245 {
246  float startA[3];
247  float endA[3];
248  float startB[3];
249  float endB[3];
250 
252  float rad;
253 
255  float height;
256 
258  unsigned int userId;
259 
261  unsigned short firstPoly;
262 
264  unsigned char npolys;
265 
267  unsigned char flags;
268 
270  inline void setFlags(unsigned char conFlags)
271  {
272  flags = ((conFlags & DT_OFFMESH_CON_BIDIR) ? 0x80 : 0);
273  }
274 
276  inline bool getBiDirectional() const { return (flags & 0x80) != 0; }
277 };
278 
282 {
284  float pos[6];
285 
287  float rad;
288 
290  float height;
291 
293  unsigned int userId;
294 
296  unsigned short poly;
297 
299  unsigned char side;
300 
302  unsigned char flags;
303 
305  inline void setFlags(unsigned char conFlags)
306  {
307  flags = ((conFlags & DT_OFFMESH_CON_BIDIR) ? 0x80 : 0) |
308  ((conFlags & DT_OFFMESH_CON_CHEAPAREA) ? 0x40 : 0);
309  }
310 
312  inline bool getBiDirectional() const { return (flags & 0x80) != 0; }
313 
315  inline bool getSnapToCheapestArea() const { return (flags & 0x40) != 0; }
316 };
317 
319 struct dtCluster
320 {
321  float center[3];
322  unsigned int firstLink;
323  unsigned int numLinks;
324 };
325 
328 {
330  unsigned int next;
331  unsigned char flags;
332 };
333 
337 {
338  int magic;
339  int version;
340  int x;
341  int y;
342  int layer;
343  unsigned int userId;
344  int polyCount;
345  int vertCount;
348 
351 
362  float bmin[3];
363  float bmax[3];
364 
367 
369 };
370 
374 {
375  unsigned int salt;
376 
377  unsigned int linksFreeList;
380  float* verts;
383 
385  float* detailVerts;
386 
388  unsigned char* detailTris;
389 
393 
396 
397  unsigned char* data;
398  int dataSize;
399  int flags;
401 
403  unsigned short* polyClusters;
404 
406  unsigned int dynamicFreeListO;
408  unsigned int dynamicFreeListC;
409 };
410 
416 {
417  float orig[3];
418  float tileWidth;
419  float tileHeight;
420  int maxTiles;
421  int maxPolys;
422 };
423 
426 class ATOMSUTILS_EXPORT dtNavMesh
427 {
428 public:
429  dtNavMesh();
430  ~dtNavMesh();
431 
434 
438  dtStatus init(const dtNavMeshParams* params);
439 
446  dtStatus init(unsigned char* data, const int dataSize, const int flags);
447 
449  const dtNavMeshParams* getParams() const;
450 
458  dtStatus addTile(unsigned char* data, int dataSize, int flags, dtTileRef lastRef, dtTileRef* result);
459 
465  dtStatus removeTile(dtTileRef ref, unsigned char** data, int* dataSize);
466 
468 
471 
476  void calcTileLoc(const float* pos, int* tx, int* ty) const;
477 
483  const dtMeshTile* getTileAt(const int x, const int y, const int layer) const;
484 
485 
490  int getTileCountAt(const int x, const int y) const;
491 
492 
499  int getTilesAt(const int x, const int y,
500  dtMeshTile const** tiles, const int maxTiles) const;
501 
507  dtTileRef getTileRefAt(int x, int y, int layer) const;
508 
512  dtTileRef getTileRef(const dtMeshTile* tile) const;
513 
518  const dtMeshTile* getTileByRef(dtTileRef ref) const;
519 
522  int getMaxTiles() const;
523 
527  const dtMeshTile* getTile(int i) const;
528 
534  dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const;
535 
540  void getTileAndPolyByRefUnsafe(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const;
541 
545  bool isValidPolyRef(dtPolyRef ref) const;
546 
550  dtPolyRef getPolyRefBase(const dtMeshTile* tile) const;
551 
556 
564  dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, const float* currentPos, float* startPos, float* endPos) const;
565 
570 
575 
579  void updateOffMeshConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags);
580 
584  void updateOffMeshSegmentConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags);
585 
587 
591 
596  dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags);
597 
602  dtStatus getPolyFlags(dtPolyRef ref, unsigned short* resultFlags) const;
603 
608  dtStatus setPolyArea(dtPolyRef ref, unsigned char area);
609 
614  dtStatus getPolyArea(dtPolyRef ref, unsigned char* resultArea) const;
615 
619  int getTileStateSize(const dtMeshTile* tile) const;
620 
626  dtStatus storeTileState(const dtMeshTile* tile, unsigned char* data, const int maxDataSize) const;
627 
633  dtStatus restoreTileState(dtMeshTile* tile, const unsigned char* data, const int maxDataSize);
634 
636 
640 
646  inline dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
647  {
648  return ((dtPolyRef)salt << (m_polyBits+m_tileBits)) | ((dtPolyRef)it << m_polyBits) | (dtPolyRef)ip;
649  }
650 
658  inline void decodePolyId(dtPolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip) const
659  {
660  const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
661  const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1;
662  const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1;
663  salt = (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
664  it = (unsigned int)((ref >> m_polyBits) & tileMask);
665  ip = (unsigned int)(ref & polyMask);
666  }
667 
672  inline unsigned int decodePolyIdSalt(dtPolyRef ref) const
673  {
674  const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
675  return (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
676  }
677 
682  inline unsigned int decodePolyIdTile(dtPolyRef ref) const
683  {
684  const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1;
685  return (unsigned int)((ref >> m_polyBits) & tileMask);
686  }
687 
692  inline unsigned int decodePolyIdPoly(dtPolyRef ref) const
693  {
694  const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1;
695  return (unsigned int)(ref & polyMask);
696  }
697 
701  inline unsigned int decodeClusterIdTile(dtClusterRef ref) const
702  {
703  return decodePolyIdTile(ref);
704  }
705 
709  inline unsigned int decodeClusterIdCluster(dtClusterRef ref) const
710  {
711  return decodePolyIdPoly(ref);
712  }
713 
715 
717  void applyWorldOffset(const float* offset);
718 
720  inline dtLink& getLink(dtMeshTile* tile, unsigned int linkIdx)
721  {
722  return (linkIdx < (unsigned int)tile->header->maxLinkCount) ? tile->links[linkIdx] : tile->dynamicLinksO[linkIdx - tile->header->maxLinkCount];
723  }
724 
725  inline const dtLink& getLink(const dtMeshTile* tile, unsigned int linkIdx) const
726  {
727  return (linkIdx < (unsigned int)tile->header->maxLinkCount) ? tile->links[linkIdx] : tile->dynamicLinksO[linkIdx - tile->header->maxLinkCount];
728  }
729 
731  inline dtClusterLink& getClusterLink(dtMeshTile* tile, unsigned int linkIdx)
732  {
733  return tile->dynamicLinksC[linkIdx - DT_CLINK_FIRST];
734  }
735 
736  inline const dtClusterLink& getClusterLink(const dtMeshTile* tile, unsigned int linkIdx) const
737  {
738  return tile->dynamicLinksC[linkIdx - DT_CLINK_FIRST];
739  }
740 
742  void linkOffMeshHelper(dtMeshTile* tile0, unsigned int polyIdx0, dtMeshTile* tile1, unsigned int polyIdx1, unsigned char side, unsigned char edge);
743 
744  inline bool isEmpty() const
745  {
746  // has no tile grid set up
747  return (m_tileWidth > 0 && m_tileHeight > 0) == false;
748  }
749 
750  inline unsigned int getSaltBits() const
751  {
752  return m_saltBits;
753  }
754 
755  void applyAreaCostOrder(unsigned char* costOrder);
756 
758  int getNeighbourTilesCountAt(const int x, const int y, const int side) const;
759 
760  bool getNeighbourCoords(const int x, const int y, const int side, int& outX, int& outY) const
761  {
762  outX = x;
763  outY = y;
764  switch (side)
765  {
766  case 0: ++outX; break;
767  case 1: ++outX; ++outY; break;
768  case 2: ++outY; break;
769  case 3: --outX; ++outY; break;
770  case 4: --outX; break;
771  case 5: --outX; --outY; break;
772  case 6: --outY; break;
773  case 7: ++outX; --outY; break;
774  };
775  // @todo we might want to do some validation
776  return true;
777  }
778 
779  unsigned int getTileIndex(const dtMeshTile* tile) const
780  {
781  return (unsigned int)(tile - m_tiles);
782  }
783 
784 public:
785 
786  // result struct for findConnectingPolys
788  {
789  float min;
790  float max;
791  dtPolyRef ref;
792  };
793 
796 
798  int getTilesAt(const int x, const int y,
799  dtMeshTile** tiles, const int maxTiles) const;
800 
802  int getNeighbourTilesAt(const int x, const int y, const int side,
803  dtMeshTile** tiles, const int maxTiles) const;
804 
806  int findConnectingPolys(const float* va, const float* vb,
807  const dtMeshTile* fromTile, int fromPolyIdx,
808  const dtMeshTile* tile, int side,
810 
815 
817  void connectExtLinks(dtMeshTile* tile, dtMeshTile* target, int side, bool updateCLinks);
819  void connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int side, bool updateCLinks);
820 
823 
825  void connectClusterLink(dtMeshTile* tile0, unsigned int cluster0,
826  dtMeshTile* tile1, unsigned int cluster1,
827  unsigned char flags, bool bCheckExisting = true);
828 
831 
832  // TODO: These methods are duplicates from dtNavMeshQuery, but are needed for off-mesh connection finding.
833 
835  int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax,
836  dtPolyRef* polys, const int maxPolys, bool bExcludeUnwalkable = false) const;
838  dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center,
839  const float* extents, float* nearestPt, bool bExcludeUnwalkable = false) const;
840  dtPolyRef findCheapestNearPolyInTile(const dtMeshTile* tile, const float* center,
841  const float* extents, float* nearestPt) const;
843  void closestPointOnPolyInTile(const dtMeshTile* tile, unsigned int ip,
844  const float* pos, float* closest) const;
845 
847  float m_orig[3];
848  float m_tileWidth, m_tileHeight;
852 
853  unsigned char m_areaCostOrder[DT_MAX_AREAS];
854 
858 
859  unsigned int m_saltBits;
860  unsigned int m_tileBits;
861  unsigned int m_polyBits;
862 };
863 
867 ATOMSUTILS_EXPORT dtNavMesh* dtAllocNavMesh();
868 
872 ATOMSUTILS_EXPORT void dtFreeNavMesh(dtNavMesh* navmesh);
873 
874 // helper for reading tiles
876 {
877  static const int MaxTiles = 32;
878  dtMeshTile* Tiles[MaxTiles];
879 
880  int NumAllocated;
881  dtMeshTile** AllocatedTiles;
882 
883  ReadTilesHelper() : NumAllocated(0), AllocatedTiles(0) {}
884  ~ReadTilesHelper()
885  {
886  dtFree(AllocatedTiles);
887  }
888 
889  dtMeshTile** PrepareArray(int RequestedSize)
890  {
891  if (RequestedSize < MaxTiles)
892  {
893  return Tiles;
894  }
895 
896  if (NumAllocated < RequestedSize)
897  {
898  dtFree(AllocatedTiles);
899  AllocatedTiles = (dtMeshTile**)dtAlloc(RequestedSize * sizeof(dtMeshTile*), DT_ALLOC_TEMP);
900  NumAllocated = RequestedSize;
901  }
902 
903  return AllocatedTiles;
904  }
905 };
906 
907 }
908 
909 #endif // DETOURNAVMESH_H
910 
912 
913 // This section contains detailed documentation for members that don't have
914 // a source file. It reduces clutter in the main section of the header.
915 
A simple dynamic array of integers.
Definition: DetourAlloc.h:147
Definition: DetourNavMesh.h:427
dtPolyRef findNearestPolyInTile(const dtMeshTile *tile, const float *center, const float *extents, float *nearestPt, bool bExcludeUnwalkable=false) const
Find nearest polygon within a tile.
int m_maxTiles
Max number of tiles.
Definition: DetourNavMesh.h:849
unsigned int m_saltBits
Number of salt bits in the tile ID.
Definition: DetourNavMesh.h:859
const dtOffMeshSegmentConnection * getOffMeshSegmentConnectionByRef(dtPolyRef ref) const
dtMeshTile * m_tiles
List of tiles.
Definition: DetourNavMesh.h:857
dtStatus getPolyArea(dtPolyRef ref, unsigned char *resultArea) const
int m_tileLutSize
Tile hash lookup size (must be pot).
Definition: DetourNavMesh.h:850
unsigned int decodeClusterIdTile(dtClusterRef ref) const
Definition: DetourNavMesh.h:701
void unconnectClusterLinks(dtMeshTile *tile, dtMeshTile *target)
Removes cluster links at specified side.
unsigned int decodePolyIdSalt(dtPolyRef ref) const
Definition: DetourNavMesh.h:672
const dtMeshTile * getTileByRef(dtTileRef ref) const
int m_tileLutMask
Tile hash lookup mask.
Definition: DetourNavMesh.h:851
dtNavMeshParams m_params
Current initialization params. TODO: do not store this info twice.
Definition: DetourNavMesh.h:846
unsigned int decodePolyIdPoly(dtPolyRef ref) const
Definition: DetourNavMesh.h:692
dtStatus addTile(unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result)
const dtMeshTile * getTile(int i) const
void getTileAndPolyByRefUnsafe(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
void updateOffMeshConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags)
bool isValidPolyRef(dtPolyRef ref) const
int getNeighbourTilesCountAt(const int x, const int y, const int side) const
Returns neighbour tile count based on side of given tile.
void connectClusterLink(dtMeshTile *tile0, unsigned int cluster0, dtMeshTile *tile1, unsigned int cluster1, unsigned char flags, bool bCheckExisting=true)
Try to connect clusters.
void connectExtLinks(dtMeshTile *tile, dtMeshTile *target, int side, bool updateCLinks)
Builds external polygon links for a tile.
dtMeshTile * m_nextFree
Freelist of tiles.
Definition: DetourNavMesh.h:856
void updateOffMeshSegmentConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags)
dtStatus restoreTileState(dtMeshTile *tile, const unsigned char *data, const int maxDataSize)
int getTilesAt(const int x, const int y, dtMeshTile const **tiles, const int maxTiles) const
dtMeshTile * getTile(int i)
Returns pointer to tile in the tile array.
int queryPolygonsInTile(const dtMeshTile *tile, const float *qmin, const float *qmax, dtPolyRef *polys, const int maxPolys, bool bExcludeUnwalkable=false) const
Queries polygons within a tile.
dtTileRef getTileRefAt(int x, int y, int layer) const
int findConnectingPolys(const float *va, const float *vb, const dtMeshTile *fromTile, int fromPolyIdx, const dtMeshTile *tile, int side, dtChunkArray< FConnectingPolyData > &cons) const
Returns all polygons in neighbour tile based on portal defined by the segment.
int getTileCountAt(const int x, const int y) const
int getNeighbourTilesAt(const int x, const int y, const int side, dtMeshTile **tiles, const int maxTiles) const
Returns neighbour tile based on side.
unsigned int decodeClusterIdCluster(dtClusterRef ref) const
Definition: DetourNavMesh.h:709
dtClusterLink & getClusterLink(dtMeshTile *tile, unsigned int linkIdx)
Helper for accessing cluster links.
Definition: DetourNavMesh.h:731
const dtMeshTile * getTileAt(const int x, const int y, const int layer) const
const dtOffMeshConnection * getOffMeshConnectionByRef(dtPolyRef ref) const
dtStatus setPolyArea(dtPolyRef ref, unsigned char area)
dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
Definition: DetourNavMesh.h:646
dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
unsigned int m_tileBits
Number of tile bits in the tile ID.
Definition: DetourNavMesh.h:860
const dtNavMeshParams * getParams() const
The navigation mesh initialization params.
dtStatus removeTile(dtTileRef ref, unsigned char **data, int *dataSize)
dtTileRef getTileRef(const dtMeshTile *tile) const
void closestPointOnPolyInTile(const dtMeshTile *tile, unsigned int ip, const float *pos, float *closest) const
Returns closest point on polygon.
void connectIntLinks(dtMeshTile *tile)
Builds internal polygons links for a tile.
unsigned int decodePolyIdTile(dtPolyRef ref) const
Definition: DetourNavMesh.h:682
dtPolyRef getPolyRefBase(const dtMeshTile *tile) const
void decodePolyId(dtPolyRef ref, unsigned int &salt, unsigned int &it, unsigned int &ip) const
Definition: DetourNavMesh.h:658
dtStatus storeTileState(const dtMeshTile *tile, unsigned char *data, const int maxDataSize) const
void applyWorldOffset(const float *offset)
Shift navigation mesh by provided offset.
int getMaxTiles() const
dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, const float *currentPos, float *startPos, float *endPos) const
dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags)
void baseOffMeshLinks(dtMeshTile *tile)
Builds internal polygons links for a tile.
void calcTileLoc(const float *pos, int *tx, int *ty) const
int getTileStateSize(const dtMeshTile *tile) const
void unconnectExtLinks(dtMeshTile *tile, dtMeshTile *target)
Removes external links at specified side.
dtStatus init(unsigned char *data, const int dataSize, const int flags)
dtMeshTile ** m_posLookup
Tile hash lookup.
Definition: DetourNavMesh.h:855
void connectExtOffMeshLinks(dtMeshTile *tile, dtMeshTile *target, int side, bool updateCLinks)
Builds external polygon links for a tile.
dtStatus getPolyFlags(dtPolyRef ref, unsigned short *resultFlags) const
dtClusterRef getClusterRefBase(const dtMeshTile *tile) const
unsigned int m_polyBits
Number of poly bits in the tile ID.
Definition: DetourNavMesh.h:861
int getTilesAt(const int x, const int y, dtMeshTile **tiles, const int maxTiles) const
Returns neighbour tile based on side.
float m_tileHeight
Dimensions of each tile.
Definition: DetourNavMesh.h:848
void linkOffMeshHelper(dtMeshTile *tile0, unsigned int polyIdx0, dtMeshTile *tile1, unsigned int polyIdx1, unsigned char side, unsigned char edge)
Helper for creating links in off-mesh connections.
dtLink & getLink(dtMeshTile *tile, unsigned int linkIdx)
Helper for accessing links.
Definition: DetourNavMesh.h:720
dtStatus init(const dtNavMeshParams *params)
ATOMSUTILS_EXPORT dtNavMesh * dtAllocNavMesh()
Type_uint64 dtTileRef
Definition: DetourNavMesh.h:51
ATOMSUTILS_EXPORT void dtFreeNavMesh(dtNavMesh *navmesh)
Type_uint64 dtPolyRef
Definition: DetourNavMesh.h:47
AtomsCore namespace.
Definition: Base64.h:13
dtStraightPathOptions
Options for dtNavMeshQuery::findStraightPath.
Definition: DetourNavMesh.h:153
@ DT_STRAIGHTPATH_AREA_CROSSINGS
Add a vertex at every polygon edge crossing where area changes.
Definition: DetourNavMesh.h:154
@ DT_STRAIGHTPATH_ALL_CROSSINGS
Add a vertex at every polygon edge crossing.
Definition: DetourNavMesh.h:155
ATOMSUTILS_EXPORT void * dtAlloc(int size, dtAllocHint hint)
@ DT_ALLOC_TEMP
Memory used temporarily within a function.
Definition: DetourAlloc.h:31
Type_uint64 dtClusterRef
A handle to a cluster within a navigation mesh tile.
Definition: DetourNavMesh.h:54
ATOMSUTILS_EXPORT void dtFree(void *ptr)
dtTileFlags
Definition: DetourNavMesh.h:139
@ DT_TILE_FREE_DATA
The navigation mesh owns the tile memory and is responsible for freeing it.
Definition: DetourNavMesh.h:140
dtDetailTriEdgeFlags
Definition: DetourNavMesh.h:170
@ DT_DETAIL_EDGE_BOUNDARY
Detail triangle edge is part of the poly boundary.
Definition: DetourNavMesh.h:171
dtStraightPathFlags
Vertex flags returned by dtNavMeshQuery::findStraightPath.
Definition: DetourNavMesh.h:145
@ DT_STRAIGHTPATH_END
The vertex is the end position in the path.
Definition: DetourNavMesh.h:147
@ DT_STRAIGHTPATH_START
The vertex is the start position in the path.
Definition: DetourNavMesh.h:146
@ DT_STRAIGHTPATH_OFFMESH_CONNECTION
The vertex is the start of an off-mesh connection.
Definition: DetourNavMesh.h:148
dtPolyTypes
Flags representing the type of a navigation mesh polygon.
Definition: DetourNavMesh.h:160
@ DT_POLYTYPE_GROUND
The polygon is a standard convex polygon that is part of the surface of the mesh.
Definition: DetourNavMesh.h:162
@ DT_POLYTYPE_OFFMESH_SEGMENT
The polygon is an off-mesh connection consisting of four vertices.
Definition: DetourNavMesh.h:166
@ DT_POLYTYPE_OFFMESH_POINT
The polygon is an off-mesh connection consisting of two vertices.
Definition: DetourNavMesh.h:164
Definition: DetourNavMesh.h:876
Definition: DetourNavMesh.h:238
unsigned short bmax[3]
Maximum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:240
int i
The node's index. (Negative for escape sequence.)
Definition: DetourNavMesh.h:241
unsigned short bmin[3]
Minimum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:239
Cluster of polys.
Definition: DetourNavMesh.h:320
unsigned int numLinks
Number of cluster links.
Definition: DetourNavMesh.h:323
float center[3]
Center pos of cluster.
Definition: DetourNavMesh.h:321
unsigned int firstLink
Link in dtMeshTile.links array.
Definition: DetourNavMesh.h:322
Definition: DetourNavMesh.h:337
int detailMeshCount
The number of sub-meshes in the detail mesh.
Definition: DetourNavMesh.h:347
int x
The x-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:340
int offMeshSegPolyBase
The index of the first polygon which is an segment type off-mesh connection.
Definition: DetourNavMesh.h:357
float bmin[3]
The minimum bounds of the tile's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:362
float walkableClimb
The maximum climb height of the agents using the tile.
Definition: DetourNavMesh.h:361
float bmax[3]
The maximum bounds of the tile's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:363
int offMeshSegVertBase
The index of the first vertex used by segment type off-mesh connection.
Definition: DetourNavMesh.h:358
unsigned int userId
The user defined id of the tile.
Definition: DetourNavMesh.h:343
int detailTriCount
The number of triangles in the detail mesh.
Definition: DetourNavMesh.h:352
int offMeshBase
The index of the first polygon which is an point type off-mesh connection.
Definition: DetourNavMesh.h:356
int vertCount
The number of vertices in the tile.
Definition: DetourNavMesh.h:345
float walkableRadius
The radius of the agents using the tile.
Definition: DetourNavMesh.h:360
int bvNodeCount
The number of bounding volume nodes. (Zero if bounding volumes are disabled.)
Definition: DetourNavMesh.h:353
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:341
float walkableHeight
The height of the agents using the tile.
Definition: DetourNavMesh.h:359
int clusterCount
Number of clusters.
Definition: DetourNavMesh.h:368
int version
Tile data format version number.
Definition: DetourNavMesh.h:339
int magic
Tile magic number. (Used to identify the data format.)
Definition: DetourNavMesh.h:338
float bvQuantFactor
The bounding volume quantization factor.
Definition: DetourNavMesh.h:366
int polyCount
The number of polygons in the tile.
Definition: DetourNavMesh.h:344
int detailVertCount
The number of unique vertices in the detail mesh. (In addition to the polygon vertices....
Definition: DetourNavMesh.h:350
int offMeshConCount
The number of point type off-mesh connections.
Definition: DetourNavMesh.h:354
int layer
The layer of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:342
int offMeshSegConCount
The number of segment type off-mesh connections.
Definition: DetourNavMesh.h:355
int maxLinkCount
The number of allocated links.
Definition: DetourNavMesh.h:346
Definition: DetourNavMesh.h:374
dtPoly * polys
The tile polygons. [Size: dtMeshHeader::polyCount].
Definition: DetourNavMesh.h:379
dtChunkArray< dtLink > dynamicLinksO
Dynamic links array (indices starting from dtMeshHeader::maxLinkCount)
Definition: DetourNavMesh.h:405
int flags
Tile flags. (See: dtTileFlags)
Definition: DetourNavMesh.h:399
dtCluster * clusters
Cluster data.
Definition: DetourNavMesh.h:402
unsigned int dynamicFreeListC
Index of the next free dynamic link.
Definition: DetourNavMesh.h:408
unsigned int salt
Counter describing modifications to the tile.
Definition: DetourNavMesh.h:375
unsigned char * detailTris
The detail mesh's triangles. [(vertA, vertB, vertC) * dtMeshHeader::detailTriCount].
Definition: DetourNavMesh.h:388
float * detailVerts
The detail mesh's unique vertices. [(x, y, z) * dtMeshHeader::detailVertCount].
Definition: DetourNavMesh.h:385
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:378
int dataSize
Size of the tile data.
Definition: DetourNavMesh.h:398
unsigned char * data
The tile data. (Not directly accessed under normal situations.)
Definition: DetourNavMesh.h:397
dtOffMeshConnection * offMeshCons
The tile off-mesh connections. [Size: dtMeshHeader::offMeshConCount].
Definition: DetourNavMesh.h:394
unsigned int linksFreeList
Index to the next free link.
Definition: DetourNavMesh.h:377
float * verts
The tile vertices. [Size: dtMeshHeader::vertCount].
Definition: DetourNavMesh.h:380
dtBVNode * bvTree
Definition: DetourNavMesh.h:392
unsigned short * polyClusters
Cluster Id for each ground type polygon [Size: dtMeshHeader::polyCount].
Definition: DetourNavMesh.h:403
dtLink * links
The tile links. [Size: dtMeshHeader::maxLinkCount].
Definition: DetourNavMesh.h:381
dtMeshTile * next
The next free tile, or the next tile in the spatial grid.
Definition: DetourNavMesh.h:400
dtChunkArray< dtClusterLink > dynamicLinksC
Dynamic links array (indices starting from DT_CLINK_FIRST)
Definition: DetourNavMesh.h:407
dtOffMeshSegmentConnection * offMeshSeg
The tile off-mesh connections. [Size: dtMeshHeader::offMeshSegConCount].
Definition: DetourNavMesh.h:395
dtPolyDetail * detailMeshes
The tile's detail sub-meshes. [Size: dtMeshHeader::detailMeshCount].
Definition: DetourNavMesh.h:382
unsigned int dynamicFreeListO
Index of the next free dynamic link.
Definition: DetourNavMesh.h:406
Definition: DetourNavMesh.h:788
Definition: DetourNavMesh.h:416
int maxPolys
The maximum number of polygons each tile can contain.
Definition: DetourNavMesh.h:421
int maxTiles
The maximum number of tiles the navigation mesh can contain.
Definition: DetourNavMesh.h:420
float tileHeight
The height of each tile. (Along the z-axis.)
Definition: DetourNavMesh.h:419
float orig[3]
The world space origin of the navigation mesh's tile space. [(x, y, z)].
Definition: DetourNavMesh.h:417
float tileWidth
The width of each tile. (Along the x-axis.)
Definition: DetourNavMesh.h:418
Definition: DetourNavMesh.h:282
unsigned char side
End point side.
Definition: DetourNavMesh.h:299
float pos[6]
The endpoints of the connection. [(ax, ay, az, bx, by, bz)].
Definition: DetourNavMesh.h:284
float height
The snap height of endpoints (less than 0 = use step height)
Definition: DetourNavMesh.h:290
bool getBiDirectional() const
Gets the link direction.
Definition: DetourNavMesh.h:312
unsigned char flags
Link flags.
Definition: DetourNavMesh.h:302
void setFlags(unsigned char conFlags)
Sets link flags.
Definition: DetourNavMesh.h:305
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition: DetourNavMesh.h:293
bool getSnapToCheapestArea() const
Gets the link snap mode.
Definition: DetourNavMesh.h:315
unsigned short poly
The polygon reference of the connection within the tile.
Definition: DetourNavMesh.h:296
float rad
The radius of the endpoints. [Limit: >= 0].
Definition: DetourNavMesh.h:287
Definition: DetourNavMesh.h:245
float startB[3]
Start point of segment B.
Definition: DetourNavMesh.h:248
void setFlags(unsigned char conFlags)
Sets link flags.
Definition: DetourNavMesh.h:270
float height
The snap height of endpoints (less than 0 = use step height)
Definition: DetourNavMesh.h:255
float endA[3]
End point of segment A.
Definition: DetourNavMesh.h:247
unsigned char npolys
Number of created polys.
Definition: DetourNavMesh.h:264
float startA[3]
Start point of segment A.
Definition: DetourNavMesh.h:246
float rad
The radius of the endpoints. [Limit: >= 0].
Definition: DetourNavMesh.h:252
float endB[3]
End point of segment B.
Definition: DetourNavMesh.h:249
unsigned short firstPoly
First poly in segment pool (+ header->offMeshSegPolyBase)
Definition: DetourNavMesh.h:261
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition: DetourNavMesh.h:258
bool getBiDirectional() const
Gets the link direction.
Definition: DetourNavMesh.h:276
unsigned char flags
Link flags.
Definition: DetourNavMesh.h:267
Defines the location of detail sub-mesh data within a dtMeshTile.
Definition: DetourNavMesh.h:214
unsigned int vertBase
The offset of the vertices in the dtMeshTile::detailVerts array.
Definition: DetourNavMesh.h:215
unsigned char triCount
The number of triangles in the sub-mesh.
Definition: DetourNavMesh.h:218
unsigned char vertCount
The number of vertices in the sub-mesh.
Definition: DetourNavMesh.h:217
unsigned int triBase
The offset of the triangles in the dtMeshTile::detailTris array.
Definition: DetourNavMesh.h:216
Definition: DetourNavMesh.h:178
unsigned char areaAndtype
Definition: DetourNavMesh.h:197
unsigned short flags
The user defined polygon flags.
Definition: DetourNavMesh.h:190
void setArea(unsigned char a)
Sets the user defined area id. [Limit: < #DT_MAX_AREAS].
Definition: DetourNavMesh.h:200
void setType(unsigned char t)
Sets the polygon type. (See: dtPolyTypes.)
Definition: DetourNavMesh.h:203
unsigned int firstLink
Index to first link in linked list. (Or #DT_NULL_LINK if there is no link.)
Definition: DetourNavMesh.h:180
unsigned short verts[DT_VERTS_PER_POLYGON]
Definition: DetourNavMesh.h:184
unsigned char getType() const
Gets the polygon type. (See: dtPolyTypes)
Definition: DetourNavMesh.h:209
unsigned short neis[DT_VERTS_PER_POLYGON]
Packed data representing neighbor polygons references and flags for each edge.
Definition: DetourNavMesh.h:187
unsigned char vertCount
The number of vertices in the polygon.
Definition: DetourNavMesh.h:193
unsigned char getArea() const
Gets the user defined area id.
Definition: DetourNavMesh.h:206