TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DetourNavMeshBuilder.h File Reference
#include "DetourAlloc.h"
+ Include dependency graph for DetourNavMeshBuilder.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dtNavMeshCreateParams
 

Functions

bool dtCreateNavMeshData (dtNavMeshCreateParams *params, unsigned char **outData, int *outDataSize)
 
bool dtNavMeshHeaderSwapEndian (unsigned char *data, const int dataSize)
 
bool dtNavMeshDataSwapEndian (unsigned char *data, const int dataSize)
 

Function Documentation

bool dtNavMeshDataSwapEndian ( unsigned char *  data,
const int   
)

Swaps endianess of the tile data.

Parameters
[in,out]dataThe tile data array.
[in]dataSizeThe size of the data array.
Warning
This function assumes that the header is in the correct endianess already. Call dtNavMeshHeaderSwapEndian() first on the data if the data is expected to be in wrong endianess to start with. Call dtNavMeshHeaderSwapEndian() after the data has been swapped if converting from native to foreign endianess.
688 {
689  // Make sure the data is in right format.
690  dtMeshHeader* header = (dtMeshHeader*)data;
691  if (header->magic != DT_NAVMESH_MAGIC)
692  return false;
693  if (header->version != DT_NAVMESH_VERSION)
694  return false;
695 
696  // Patch header pointers.
697  const int headerSize = dtAlign4(sizeof(dtMeshHeader));
698  const int vertsSize = dtAlign4(sizeof(float)*3*header->vertCount);
699  const int polysSize = dtAlign4(sizeof(dtPoly)*header->polyCount);
700  const int linksSize = dtAlign4(sizeof(dtLink)*(header->maxLinkCount));
701  const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*header->detailMeshCount);
702  const int detailVertsSize = dtAlign4(sizeof(float)*3*header->detailVertCount);
703  const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*header->detailTriCount);
704  const int bvtreeSize = dtAlign4(sizeof(dtBVNode)*header->bvNodeCount);
705  const int offMeshLinksSize = dtAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount);
706 
707  unsigned char* d = data + headerSize;
708  float* verts = (float*)d; d += vertsSize;
709  dtPoly* polys = (dtPoly*)d; d += polysSize;
710  /*dtLink* links = (dtLink*)d;*/ d += linksSize;
711  dtPolyDetail* detailMeshes = (dtPolyDetail*)d; d += detailMeshesSize;
712  float* detailVerts = (float*)d; d += detailVertsSize;
713  /*unsigned char* detailTris = (unsigned char*)d;*/ d += detailTrisSize;
714  dtBVNode* bvTree = (dtBVNode*)d; d += bvtreeSize;
715  dtOffMeshConnection* offMeshCons = (dtOffMeshConnection*)d; d += offMeshLinksSize;
716 
717  // Vertices
718  for (int i = 0; i < header->vertCount*3; ++i)
719  {
720  dtSwapEndian(&verts[i]);
721  }
722 
723  // Polys
724  for (int i = 0; i < header->polyCount; ++i)
725  {
726  dtPoly* p = &polys[i];
727  // poly->firstLink is update when tile is added, no need to swap.
728  for (int j = 0; j < DT_VERTS_PER_POLYGON; ++j)
729  {
730  dtSwapEndian(&p->verts[j]);
731  dtSwapEndian(&p->neis[j]);
732  }
733  dtSwapEndian(&p->flags);
734  }
735 
736  // Links are rebuild when tile is added, no need to swap.
737 
738  // Detail meshes
739  for (int i = 0; i < header->detailMeshCount; ++i)
740  {
741  dtPolyDetail* pd = &detailMeshes[i];
742  dtSwapEndian(&pd->vertBase);
743  dtSwapEndian(&pd->triBase);
744  }
745 
746  // Detail verts
747  for (int i = 0; i < header->detailVertCount*3; ++i)
748  {
749  dtSwapEndian(&detailVerts[i]);
750  }
751 
752  // BV-tree
753  for (int i = 0; i < header->bvNodeCount; ++i)
754  {
755  dtBVNode* node = &bvTree[i];
756  for (int j = 0; j < 3; ++j)
757  {
758  dtSwapEndian(&node->bmin[j]);
759  dtSwapEndian(&node->bmax[j]);
760  }
761  dtSwapEndian(&node->i);
762  }
763 
764  // Off-mesh Connections.
765  for (int i = 0; i < header->offMeshConCount; ++i)
766  {
767  dtOffMeshConnection* con = &offMeshCons[i];
768  for (int j = 0; j < 6; ++j)
769  dtSwapEndian(&con->pos[j]);
770  dtSwapEndian(&con->rad);
771  dtSwapEndian(&con->poly);
772  }
773 
774  return true;
775 }
void dtSwapEndian(unsigned short *v)
Definition: DetourCommon.h:452
unsigned short poly
The polygon reference of the connection within the tile.
Definition: DetourNavMesh.h:231
unsigned short bmax[3]
Maximum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:216
Defines the location of detail sub-mesh data within a dtMeshTile.
Definition: DetourNavMesh.h:189
unsigned short flags
The user defined polygon flags.
Definition: DetourNavMesh.h:166
int offMeshConCount
The number of off-mesh connections.
Definition: DetourNavMesh.h:265
int detailMeshCount
The number of sub-meshes in the detail mesh.
Definition: DetourNavMesh.h:258
unsigned short verts[DT_VERTS_PER_POLYGON]
Definition: DetourNavMesh.h:160
int i
The node's index. (Negative for escape sequence.)
Definition: DetourNavMesh.h:217
Definition: DetourNavMesh.h:213
unsigned int vertBase
The offset of the vertices in the dtMeshTile::detailVerts array.
Definition: DetourNavMesh.h:191
unsigned short bmin[3]
Minimum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:215
Definition: DetourNavMesh.h:247
unsigned short neis[DT_VERTS_PER_POLYGON]
Packed data representing neighbor polygons references and flags for each edge.
Definition: DetourNavMesh.h:163
Definition: DetourNavMesh.h:153
float rad
The radius of the endpoints. [Limit: >= 0].
Definition: DetourNavMesh.h:228
int polyCount
The number of polygons in the tile.
Definition: DetourNavMesh.h:255
int bvNodeCount
The number of bounding volume nodes. (Zero if bounding volumes are disabled.)
Definition: DetourNavMesh.h:264
int version
Tile data format version number.
Definition: DetourNavMesh.h:250
int detailVertCount
The number of unique vertices in the detail mesh. (In addition to the polygon vertices.)
Definition: DetourNavMesh.h:261
int maxLinkCount
The number of allocated links.
Definition: DetourNavMesh.h:257
int magic
Tile magic number. (Used to identify the data format.)
Definition: DetourNavMesh.h:249
int dtAlign4(int x)
Definition: DetourCommon.h:441
int detailTriCount
The number of triangles in the detail mesh.
Definition: DetourNavMesh.h:263
unsigned int triBase
The offset of the triangles in the dtMeshTile::detailTris array.
Definition: DetourNavMesh.h:192
static const int DT_NAVMESH_MAGIC
A magic number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:66
float pos[6]
The endpoints of the connection. [(ax, ay, az, bx, by, bz)].
Definition: DetourNavMesh.h:225
static const int DT_NAVMESH_VERSION
A version number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:69
int vertCount
The number of vertices in the tile.
Definition: DetourNavMesh.h:256
Definition: DetourNavMesh.h:222
static const int DT_VERTS_PER_POLYGON
Definition: DetourNavMesh.h:57

+ Here is the call graph for this function:

bool dtNavMeshHeaderSwapEndian ( unsigned char *  data,
const int  dataSize 
)

Swaps the endianess of the tile data's header (dtMeshHeader).

Parameters
[in,out]dataThe tile data array.
[in]dataSizeThe size of the data array.
636 {
637  dtMeshHeader* header = (dtMeshHeader*)data;
638 
639  int swappedMagic = DT_NAVMESH_MAGIC;
640  int swappedVersion = DT_NAVMESH_VERSION;
641  dtSwapEndian(&swappedMagic);
642  dtSwapEndian(&swappedVersion);
643 
644  if ((header->magic != DT_NAVMESH_MAGIC || header->version != DT_NAVMESH_VERSION) &&
645  (header->magic != swappedMagic || header->version != swappedVersion))
646  {
647  return false;
648  }
649 
650  dtSwapEndian(&header->magic);
651  dtSwapEndian(&header->version);
652  dtSwapEndian(&header->x);
653  dtSwapEndian(&header->y);
654  dtSwapEndian(&header->layer);
655  dtSwapEndian(&header->userId);
656  dtSwapEndian(&header->polyCount);
657  dtSwapEndian(&header->vertCount);
658  dtSwapEndian(&header->maxLinkCount);
659  dtSwapEndian(&header->detailMeshCount);
660  dtSwapEndian(&header->detailVertCount);
661  dtSwapEndian(&header->detailTriCount);
662  dtSwapEndian(&header->bvNodeCount);
663  dtSwapEndian(&header->offMeshConCount);
664  dtSwapEndian(&header->offMeshBase);
665  dtSwapEndian(&header->walkableHeight);
666  dtSwapEndian(&header->walkableRadius);
667  dtSwapEndian(&header->walkableClimb);
668  dtSwapEndian(&header->bmin[0]);
669  dtSwapEndian(&header->bmin[1]);
670  dtSwapEndian(&header->bmin[2]);
671  dtSwapEndian(&header->bmax[0]);
672  dtSwapEndian(&header->bmax[1]);
673  dtSwapEndian(&header->bmax[2]);
674  dtSwapEndian(&header->bvQuantFactor);
675 
676  // Freelist index and pointers are updated when tile is added, no need to swap.
677 
678  return true;
679 }
void dtSwapEndian(unsigned short *v)
Definition: DetourCommon.h:452
float walkableHeight
The height of the agents using the tile.
Definition: DetourNavMesh.h:267
float walkableClimb
The maximum climb height of the agents using the tile.
Definition: DetourNavMesh.h:269
float walkableRadius
The radius of the agents using the tile.
Definition: DetourNavMesh.h:268
float bvQuantFactor
The bounding volume quantization factor.
Definition: DetourNavMesh.h:274
int offMeshConCount
The number of off-mesh connections.
Definition: DetourNavMesh.h:265
float bmax[3]
The maximum bounds of the tile's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:271
int detailMeshCount
The number of sub-meshes in the detail mesh.
Definition: DetourNavMesh.h:258
int offMeshBase
The index of the first polygon which is an off-mesh connection.
Definition: DetourNavMesh.h:266
int layer
The layer of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:253
Definition: DetourNavMesh.h:247
int polyCount
The number of polygons in the tile.
Definition: DetourNavMesh.h:255
int bvNodeCount
The number of bounding volume nodes. (Zero if bounding volumes are disabled.)
Definition: DetourNavMesh.h:264
int x
The x-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:251
float bmin[3]
The minimum bounds of the tile's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:270
int version
Tile data format version number.
Definition: DetourNavMesh.h:250
int detailVertCount
The number of unique vertices in the detail mesh. (In addition to the polygon vertices.)
Definition: DetourNavMesh.h:261
int maxLinkCount
The number of allocated links.
Definition: DetourNavMesh.h:257
unsigned int userId
The user defined id of the tile.
Definition: DetourNavMesh.h:254
int magic
Tile magic number. (Used to identify the data format.)
Definition: DetourNavMesh.h:249
int detailTriCount
The number of triangles in the detail mesh.
Definition: DetourNavMesh.h:263
static const int DT_NAVMESH_MAGIC
A magic number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:66
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:252
static const int DT_NAVMESH_VERSION
A version number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:69
int vertCount
The number of vertices in the tile.
Definition: DetourNavMesh.h:256

+ Here is the call graph for this function: