Builds navigation mesh tile data from the provided tile creation data.
265 const int nvp = params->
nvp;
269 unsigned char* offMeshConClass = 0;
270 int storedOffMeshConCount = 0;
271 int offMeshConLinkCount = 0;
276 if (!offMeshConClass)
280 float hmin = FLT_MAX;
281 float hmax = -FLT_MAX;
288 hmin =
dtMin(hmin,h);
289 hmax =
dtMax(hmax,h);
294 for (
int i = 0; i < params->
vertCount; ++i)
296 const unsigned short* iv = ¶ms->
verts[i*3];
297 const float h = params->
bmin[1] + iv[1] * params->
ch;
298 hmin =
dtMin(hmin,h);
299 hmax =
dtMax(hmax,h);
304 float bmin[3], bmax[3];
318 if (offMeshConClass[i*2+0] == 0xff)
320 if (p0[1] < bmin[1] || p0[1] > bmax[1])
321 offMeshConClass[i*2+0] = 0;
325 if (offMeshConClass[i*2+0] == 0xff)
326 offMeshConLinkCount++;
327 if (offMeshConClass[i*2+1] == 0xff)
328 offMeshConLinkCount++;
330 if (offMeshConClass[i*2+0] == 0xff)
331 storedOffMeshConCount++;
336 const int totPolyCount = params->
polyCount + storedOffMeshConCount;
337 const int totVertCount = params->
vertCount + storedOffMeshConCount*2;
342 for (
int i = 0; i < params->
polyCount; ++i)
344 const unsigned short* p = ¶ms->
polys[i*2*nvp];
345 for (
int j = 0; j < nvp; ++j)
350 if (p[nvp+j] & 0x8000)
352 unsigned short dir = p[nvp+j] & 0xf;
359 const int maxLinkCount = edgeCount + portalCount*2 + offMeshConLinkCount*2;
362 int uniqueDetailVertCount = 0;
363 int detailTriCount = 0;
368 for (
int i = 0; i < params->
polyCount; ++i)
370 const unsigned short* p = ¶ms->
polys[i*nvp*2];
373 for (
int j = 0; j < nvp; ++j)
379 uniqueDetailVertCount += ndv;
385 uniqueDetailVertCount = 0;
387 for (
int i = 0; i < params->
polyCount; ++i)
389 const unsigned short* p = ¶ms->
polys[i*nvp*2];
391 for (
int j = 0; j < nvp; ++j)
396 detailTriCount += nv-2;
402 const int vertsSize =
dtAlign4(
sizeof(
float)*3*totVertCount);
406 const int detailVertsSize =
dtAlign4(
sizeof(
float)*3*uniqueDetailVertCount);
407 const int detailTrisSize =
dtAlign4(
sizeof(
unsigned char)*4*detailTriCount);
411 const int dataSize = headerSize + vertsSize + polysSize + linksSize +
412 detailMeshesSize + detailVertsSize + detailTrisSize +
413 bvTreeSize + offMeshConsSize;
421 memset(data, 0, dataSize);
423 unsigned char* d = data;
425 float* navVerts = (
float*)d; d += vertsSize;
429 float* navDVerts = (
float*)d; d += detailVertsSize;
430 unsigned char* navDTris = (
unsigned char*)d; d += detailTrisSize;
438 header->
x = params->
tileX;
439 header->
y = params->
tileY;
458 const int offMeshVertsBase = params->
vertCount;
459 const int offMeshPolyBase = params->
polyCount;
463 for (
int i = 0; i < params->
vertCount; ++i)
465 const unsigned short* iv = ¶ms->
verts[i*3];
466 float* v = &navVerts[i*3];
467 v[0] = params->
bmin[0] + iv[0] * params->
cs;
468 v[1] = params->
bmin[1] + iv[1] * params->
ch;
469 v[2] = params->
bmin[2] + iv[2] * params->
cs;
476 if (offMeshConClass[i*2+0] == 0xff)
479 float* v = &navVerts[(offMeshVertsBase + n*2)*3];
488 const unsigned short* src = params->
polys;
489 for (
int i = 0; i < params->
polyCount; ++i)
496 for (
int j = 0; j < nvp; ++j)
499 p->
verts[j] = src[j];
500 if (src[nvp+j] & 0x8000)
503 unsigned short dir = src[nvp+j] & 0xf;
518 p->
neis[j] = src[nvp+j]+1;
530 if (offMeshConClass[i*2+0] == 0xff)
532 dtPoly* p = &navPolys[offMeshPolyBase+n];
534 p->
verts[0] = (
unsigned short)(offMeshVertsBase + n*2+0);
535 p->
verts[1] = (
unsigned short)(offMeshVertsBase + n*2+1);
548 unsigned short vbase = 0;
549 for (
int i = 0; i < params->
polyCount; ++i)
562 memcpy(&navDVerts[vbase*3], ¶ms->
detailVerts[(vb+nv)*3],
sizeof(
float)*3*(ndv-nv));
563 vbase += (
unsigned short)(ndv-nv);
573 for (
int i = 0; i < params->
polyCount; ++i)
579 dtl.
triBase = (
unsigned int)tbase;
580 dtl.
triCount = (
unsigned char)(nv-2);
582 for (
int j = 2; j < nv; ++j)
584 unsigned char* t = &navDTris[tbase*4];
586 t[1] = (
unsigned char)(j-1);
587 t[2] = (
unsigned char)j;
590 if (j == 2) t[3] |= (1<<0);
591 if (j == nv-1) t[3] |= (1<<4);
602 nvp, params->
cs, params->
ch, params->
polyCount*2, navBvtree);
610 if (offMeshConClass[i*2+0] == 0xff)
613 con->
poly = (
unsigned short)(offMeshPolyBase + n);
620 con->
side = offMeshConClass[i*2+1];
630 *outDataSize = dataSize;
int tileLayer
The tile's layer within the layered destination mesh. Limit: >= 0
Definition: DetourNavMeshBuilder.h:86
float cs
The xz-plane cell size of the polygon mesh. [Limit: > 0] [Unit: wu].
Definition: DetourNavMeshBuilder.h:97
unsigned short poly
The polygon reference of the connection within the tile.
Definition: DetourNavMesh.h:231
void * dtAlloc(int size, dtAllocHint hint)
Definition: DetourAlloc.cpp:41
const unsigned char * offMeshConDir
Definition: DetourNavMeshBuilder.h:72
unsigned char side
End point side.
Definition: DetourNavMesh.h:239
Defines the location of detail sub-mesh data within a dtMeshTile.
Definition: DetourNavMesh.h:189
const unsigned char * polyAreas
The user defined area ids assigned to each polygon. [Size: polyCount].
Definition: DetourNavMeshBuilder.h:38
const float * offMeshConVerts
Off-mesh connection vertices. [(ax, ay, az, bx, by, bz) * offMeshConCount] [Unit: wu]...
Definition: DetourNavMeshBuilder.h:61
unsigned short flags
The user defined polygon flags.
Definition: DetourNavMesh.h:166
const unsigned short * polys
The polygon data. [Size: polyCount * 2 * nvp].
Definition: DetourNavMeshBuilder.h:36
int nvp
Number maximum number of vertices per polygon. [Limit: >= 3].
Definition: DetourNavMeshBuilder.h:40
static unsigned short MESH_NULL_IDX
Definition: DetourNavMeshBuilder.cpp:30
unsigned char triCount
The number of triangles in the sub-mesh.
Definition: DetourNavMesh.h:194
float walkableHeight
The agent height. [Unit: wu].
Definition: DetourNavMeshBuilder.h:94
static int createBVTree(const unsigned short *verts, const int, const unsigned short *polys, const int npolys, const int nvp, const float cs, const float ch, const int, dtBVNode *nodes)
Definition: DetourNavMeshBuilder.cpp:172
const unsigned char * detailTris
The detail mesh triangles. [Size: 4 * detailTriCount].
Definition: DetourNavMeshBuilder.h:50
float ch
The y-axis cell height of the polygon mesh. [Limit: > 0] [Unit: wu].
Definition: DetourNavMeshBuilder.h:98
Memory persist after a function call.
Definition: DetourAlloc.h:26
float bmax[3]
The maximum bounds of the tile. [(x, y, z)] [Unit: wu].
Definition: DetourNavMeshBuilder.h:88
unsigned char flags
Definition: DetourNavMesh.h:236
void setArea(unsigned char a)
Sets the user defined area id. [Limit: < DT_MAX_AREAS].
Definition: DetourNavMesh.h:176
static const unsigned int DT_OFFMESH_CON_BIDIR
A flag that indicates that an off-mesh connection can be traversed in both directions. (Is bidirectional.)
Definition: DetourNavMesh.h:87
float walkableClimb
The agent maximum traversable ledge. (Up/Down) [Unit: wu].
Definition: DetourNavMeshBuilder.h:96
unsigned int userId
The user defined id of the tile.
Definition: DetourNavMeshBuilder.h:83
unsigned short verts[DT_VERTS_PER_POLYGON]
Definition: DetourNavMesh.h:160
unsigned char vertCount
The number of vertices in the sub-mesh.
Definition: DetourNavMesh.h:193
const unsigned short * offMeshConFlags
User defined flags assigned to the off-mesh connections. [Size: offMeshConCount]. ...
Definition: DetourNavMeshBuilder.h:65
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built.)
Definition: DetourNavMesh.h:242
Definition: DetourNavMesh.h:213
unsigned int vertBase
The offset of the vertices in the dtMeshTile::detailVerts array.
Definition: DetourNavMesh.h:191
bool buildBvTree
Definition: DetourNavMeshBuilder.h:102
int detailTriCount
The number of triangles in the detail mesh.
Definition: DetourNavMeshBuilder.h:51
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 offMeshConCount
The number of off-mesh connections. [Limit: >= 0].
Definition: DetourNavMeshBuilder.h:76
const unsigned short * verts
The polygon mesh vertices. [(x, y, z) * vertCount] [Unit: vx].
Definition: DetourNavMeshBuilder.h:34
float bmin[3]
The minimum bounds of the tile. [(x, y, z)] [Unit: wu].
Definition: DetourNavMeshBuilder.h:87
T dtMax(T a, T b)
Definition: DetourCommon.h:57
float walkableRadius
The agent radius. [Unit: wu].
Definition: DetourNavMeshBuilder.h:95
const float * detailVerts
The detail mesh vertices. [Size: 3 * detailVertsCount] [Unit: wu].
Definition: DetourNavMeshBuilder.h:48
static const unsigned short DT_EXT_LINK
Definition: DetourNavMesh.h:81
Memory used temporarily within a function.
Definition: DetourAlloc.h:27
void dtVcopy(float *dest, const float *a)
Definition: DetourCommon.h:190
T dtMin(T a, T b)
Definition: DetourCommon.h:51
int tileY
The tile's y-grid location within the multi-tile desitation mesh. (Along the z-axis.)
Definition: DetourNavMeshBuilder.h:85
int polyCount
Number of polygons in the mesh. [Limit: >= 1].
Definition: DetourNavMeshBuilder.h:39
int dtAlign4(int x)
Definition: DetourCommon.h:441
The polygon is an off-mesh connection consisting of two vertices.
Definition: DetourNavMesh.h:147
const unsigned int * detailMeshes
The height detail sub-mesh data. [Size: 4 * polyCount].
Definition: DetourNavMeshBuilder.h:47
unsigned char vertCount
The number of vertices in the polygon.
Definition: DetourNavMesh.h:169
int tileX
The tile's x-grid location within the multi-tile destination mesh. (Along the x-axis.)
Definition: DetourNavMeshBuilder.h:84
static unsigned char classifyOffMeshPoint(const float *pt, const float *bmin, const float *bmax)
Definition: DetourNavMeshBuilder.cpp:217
const unsigned short * polyFlags
The user defined flags assigned to each polygon. [Size: polyCount].
Definition: DetourNavMeshBuilder.h:37
unsigned int triBase
The offset of the triangles in the dtMeshTile::detailTris array.
Definition: DetourNavMesh.h:192
int vertCount
The number vertices in the polygon mesh. [Limit: >= 3].
Definition: DetourNavMeshBuilder.h:35
static const int DT_NAVMESH_MAGIC
A magic number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:66
const float * offMeshConRad
Off-mesh connection radii. [Size: offMeshConCount] [Unit: wu].
Definition: DetourNavMeshBuilder.h:63
const unsigned int * offMeshConUserID
The user defined ids of the off-mesh connection. [Size: offMeshConCount].
Definition: DetourNavMeshBuilder.h:74
float pos[6]
The endpoints of the connection. [(ax, ay, az, bx, by, bz)].
Definition: DetourNavMesh.h:225
int detailVertsCount
The number of vertices in the detail mesh.
Definition: DetourNavMeshBuilder.h:49
void setType(unsigned char t)
Sets the polygon type. (See: dtPolyTypes.)
Definition: DetourNavMesh.h:179
static const int DT_NAVMESH_VERSION
A version number used to detect compatibility of navigation tile data.
Definition: DetourNavMesh.h:69
The polygon is a standard convex polygon that is part of the surface of the mesh. ...
Definition: DetourNavMesh.h:145
Definition: DetourNavMesh.h:200
Definition: DetourNavMesh.h:222
void dtFree(void *ptr)
Definition: DetourAlloc.cpp:46
const unsigned char * offMeshConAreas
User defined area ids assigned to the off-mesh connections. [Size: offMeshConCount].
Definition: DetourNavMeshBuilder.h:67
static const int DT_VERTS_PER_POLYGON
Definition: DetourNavMesh.h:57