Made detail mesh optional, create dummy mesh if no data is provided.
This commit is contained in:
parent
18857e3a57
commit
ebd5358010
@ -35,7 +35,7 @@ struct dtNavMeshCreateParams
|
|||||||
const unsigned char* polyAreas; // Array of area ids per polygon.
|
const unsigned char* polyAreas; // Array of area ids per polygon.
|
||||||
int polyCount; // Number of polygons
|
int polyCount; // Number of polygons
|
||||||
int nvp; // Number of verts per polygon.
|
int nvp; // Number of verts per polygon.
|
||||||
// Navmesh Detail
|
// Navmesh Detail (optional)
|
||||||
const unsigned int* detailMeshes; // Detail meshes, uses same format as rcPolyMeshDetail.
|
const unsigned int* detailMeshes; // Detail meshes, uses same format as rcPolyMeshDetail.
|
||||||
const float* detailVerts; // Detail mesh vertices, uses same format as rcPolyMeshDetail (wu).
|
const float* detailVerts; // Detail mesh vertices, uses same format as rcPolyMeshDetail (wu).
|
||||||
int detailVertsCount; // Total number of detail vertices
|
int detailVertsCount; // Total number of detail vertices
|
||||||
|
@ -252,8 +252,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
return false;
|
return false;
|
||||||
if (!params->polyCount || !params->polys)
|
if (!params->polyCount || !params->polys)
|
||||||
return false;
|
return false;
|
||||||
if (!params->detailMeshes || !params->detailVerts || !params->detailTris)
|
// if (!params->detailMeshes || !params->detailVerts || !params->detailTris)
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
const int nvp = params->nvp;
|
const int nvp = params->nvp;
|
||||||
|
|
||||||
@ -323,6 +323,11 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
|
|
||||||
// Find unique detail vertices.
|
// Find unique detail vertices.
|
||||||
int uniqueDetailVertCount = 0;
|
int uniqueDetailVertCount = 0;
|
||||||
|
int detailTriCount = 0;
|
||||||
|
if (params->detailMeshes)
|
||||||
|
{
|
||||||
|
// Has detail mesh, count unique detail vertex count and use input detail tri count.
|
||||||
|
detailTriCount = params->detailTriCount;
|
||||||
for (int i = 0; i < params->polyCount; ++i)
|
for (int i = 0; i < params->polyCount; ++i)
|
||||||
{
|
{
|
||||||
const unsigned short* p = ¶ms->polys[i*nvp*2];
|
const unsigned short* p = ¶ms->polys[i*nvp*2];
|
||||||
@ -336,6 +341,24 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
ndv -= nv;
|
ndv -= nv;
|
||||||
uniqueDetailVertCount += ndv;
|
uniqueDetailVertCount += ndv;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No input detail mesh, build detail mesh from nav polys.
|
||||||
|
uniqueDetailVertCount = 0; // No extra detail verts.
|
||||||
|
detailTriCount = 0;
|
||||||
|
for (int i = 0; i < params->polyCount; ++i)
|
||||||
|
{
|
||||||
|
const unsigned short* p = ¶ms->polys[i*nvp*2];
|
||||||
|
int nv = 0;
|
||||||
|
for (int j = 0; j < nvp; ++j)
|
||||||
|
{
|
||||||
|
if (p[j] == MESH_NULL_IDX) break;
|
||||||
|
nv++;
|
||||||
|
}
|
||||||
|
detailTriCount += nv-2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate data size
|
// Calculate data size
|
||||||
const int headerSize = dtAlign4(sizeof(dtMeshHeader));
|
const int headerSize = dtAlign4(sizeof(dtMeshHeader));
|
||||||
@ -344,7 +367,7 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
const int linksSize = dtAlign4(sizeof(dtLink)*maxLinkCount);
|
const int linksSize = dtAlign4(sizeof(dtLink)*maxLinkCount);
|
||||||
const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*params->polyCount);
|
const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*params->polyCount);
|
||||||
const int detailVertsSize = dtAlign4(sizeof(float)*3*uniqueDetailVertCount);
|
const int detailVertsSize = dtAlign4(sizeof(float)*3*uniqueDetailVertCount);
|
||||||
const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*params->detailTriCount);
|
const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*detailTriCount);
|
||||||
const int bvTreeSize = dtAlign4(sizeof(dtBVNode)*params->polyCount*2);
|
const int bvTreeSize = dtAlign4(sizeof(dtBVNode)*params->polyCount*2);
|
||||||
const int offMeshConsSize = dtAlign4(sizeof(dtOffMeshConnection)*storedOffMeshConCount);
|
const int offMeshConsSize = dtAlign4(sizeof(dtOffMeshConnection)*storedOffMeshConCount);
|
||||||
|
|
||||||
@ -385,7 +408,7 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
dtVcopy(header->bmax, params->bmax);
|
dtVcopy(header->bmax, params->bmax);
|
||||||
header->detailMeshCount = params->polyCount;
|
header->detailMeshCount = params->polyCount;
|
||||||
header->detailVertCount = uniqueDetailVertCount;
|
header->detailVertCount = uniqueDetailVertCount;
|
||||||
header->detailTriCount = params->detailTriCount;
|
header->detailTriCount = detailTriCount;
|
||||||
header->bvQuantFactor = 1.0f / params->cs;
|
header->bvQuantFactor = 1.0f / params->cs;
|
||||||
header->offMeshBase = params->polyCount;
|
header->offMeshBase = params->polyCount;
|
||||||
header->walkableHeight = params->walkableHeight;
|
header->walkableHeight = params->walkableHeight;
|
||||||
@ -488,6 +511,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
// Store detail meshes and vertices.
|
// Store detail meshes and vertices.
|
||||||
// The nav polygon vertices are stored as the first vertices on each mesh.
|
// The nav polygon vertices are stored as the first vertices on each mesh.
|
||||||
// We compress the mesh data by skipping them and using the navmesh coordinates.
|
// We compress the mesh data by skipping them and using the navmesh coordinates.
|
||||||
|
if (params->detailMeshes)
|
||||||
|
{
|
||||||
unsigned short vbase = 0;
|
unsigned short vbase = 0;
|
||||||
for (int i = 0; i < params->polyCount; ++i)
|
for (int i = 0; i < params->polyCount; ++i)
|
||||||
{
|
{
|
||||||
@ -508,6 +533,34 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
|||||||
}
|
}
|
||||||
// Store triangles.
|
// Store triangles.
|
||||||
memcpy(navDTris, params->detailTris, sizeof(unsigned char)*4*params->detailTriCount);
|
memcpy(navDTris, params->detailTris, sizeof(unsigned char)*4*params->detailTriCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create dummy detail mesh by triangulating polys.
|
||||||
|
int tbase = 0;
|
||||||
|
for (int i = 0; i < params->polyCount; ++i)
|
||||||
|
{
|
||||||
|
dtPolyDetail& dtl = navDMeshes[i];
|
||||||
|
const int nv = navPolys[i].vertCount;
|
||||||
|
dtl.vertBase = 0;
|
||||||
|
dtl.vertCount = 0;
|
||||||
|
dtl.triBase = (unsigned int)tbase;
|
||||||
|
dtl.triCount = (unsigned char)(nv-2);
|
||||||
|
// Triangulate polygon (local indices).
|
||||||
|
for (int j = 2; j < nv; ++j)
|
||||||
|
{
|
||||||
|
unsigned char* t = &navDTris[tbase*4];
|
||||||
|
t[0] = 0;
|
||||||
|
t[1] = (unsigned char)(j-1);
|
||||||
|
t[2] = (unsigned char)j;
|
||||||
|
// Bit for each edge that belongs to poly boundary.
|
||||||
|
t[3] = (1<<2);
|
||||||
|
if (j == 2) t[3] |= (1<<0);
|
||||||
|
if (j == nv-1) t[3] |= (1<<4);
|
||||||
|
tbase++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Store and create BVtree.
|
// Store and create BVtree.
|
||||||
// TODO: take detail mesh into account! use byte per bbox extent?
|
// TODO: take detail mesh into account! use byte per bbox extent?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user