1
This commit is contained in:
parent
7ff62bc87e
commit
ddba1267b8
@ -49,6 +49,71 @@ struct TileCacheData
|
||||
int dataSize;
|
||||
};
|
||||
|
||||
struct rcChunkyTriMeshNode
|
||||
{
|
||||
float bmin[2];
|
||||
float bmax[2];
|
||||
int i;
|
||||
int n;
|
||||
};
|
||||
|
||||
struct rcChunkyTriMesh
|
||||
{
|
||||
inline rcChunkyTriMesh() : nodes(0), nnodes(0), tris(0), ntris(0), maxTrisPerChunk(0) {};
|
||||
inline ~rcChunkyTriMesh() { delete [] nodes; delete [] tris; }
|
||||
|
||||
rcChunkyTriMeshNode* nodes;
|
||||
int nnodes;
|
||||
int* tris;
|
||||
int ntris;
|
||||
int maxTrisPerChunk;
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
#if 0
|
||||
rcChunkyTriMesh(const rcChunkyTriMesh&);
|
||||
rcChunkyTriMesh& operator=(const rcChunkyTriMesh&);
|
||||
#endif
|
||||
};
|
||||
|
||||
inline bool checkOverlapRect(const float amin[2], const float amax[2],
|
||||
const float bmin[2], const float bmax[2])
|
||||
{
|
||||
bool overlap = true;
|
||||
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
|
||||
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
|
||||
return overlap;
|
||||
}
|
||||
|
||||
static int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
|
||||
float bmin[2], float bmax[2],
|
||||
int* ids, const int maxIds)
|
||||
{
|
||||
// Traverse tree
|
||||
int i = 0;
|
||||
int n = 0;
|
||||
while (i < cm->nnodes) {
|
||||
const rcChunkyTriMeshNode* node = &cm->nodes[i];
|
||||
const bool overlap = checkOverlapRect(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool isLeafNode = node->i >= 0;
|
||||
|
||||
if (isLeafNode && overlap) {
|
||||
if (n < maxIds) {
|
||||
ids[n] = i;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (overlap || isLeafNode)
|
||||
i++;
|
||||
else {
|
||||
const int escapeIndex = -node->i;
|
||||
i += escapeIndex;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
struct RasterizationContext
|
||||
{
|
||||
RasterizationContext() :
|
||||
@ -463,7 +528,6 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
|
||||
FastLZCompressor comp;
|
||||
RasterizationContext rc;
|
||||
|
||||
struct rcChunkyTriMesh;
|
||||
#if 1
|
||||
const float* verts = nullptr;
|
||||
const int nverts = 0;
|
||||
@ -505,9 +569,7 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
|
||||
// Allocate array that can hold triangle flags.
|
||||
// If you have multiple meshes you need to process, allocate
|
||||
// and array which can hold the max number of triangles you need to process.
|
||||
#if 0
|
||||
rc.triareas = new unsigned char[chunkyMesh->maxTrisPerChunk];
|
||||
#endif
|
||||
if (!rc.triareas) {
|
||||
#if 0
|
||||
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
|
||||
@ -521,22 +583,18 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
|
||||
tbmax[0] = tcfg.bmax[0];
|
||||
tbmax[1] = tcfg.bmax[2];
|
||||
int cid[512];// TODO: Make grow when returning too many items.
|
||||
#if 1
|
||||
const int ncid = 0;
|
||||
#else
|
||||
const int ncid = rcGetChunksOverlappingRect(chunkyMesh, tbmin, tbmax, cid, 512);
|
||||
#endif
|
||||
if (!ncid) {
|
||||
return 0; // empty
|
||||
}
|
||||
|
||||
for (int i = 0; i < ncid; ++i) {
|
||||
#if 0
|
||||
const rcChunkyTriMeshNode& node = chunkyMesh->nodes[cid[i]];
|
||||
const int* tris = &chunkyMesh->tris[node.i*3];
|
||||
const int ntris = node.n;
|
||||
|
||||
memset(rc.triareas, 0, ntris*sizeof(unsigned char));
|
||||
#if 0
|
||||
rcMarkWalkableTriangles(m_ctx, tcfg.walkableSlopeAngle,
|
||||
verts, nverts, tris, ntris, rc.triareas,
|
||||
SAMPLE_AREAMOD_GROUND);
|
||||
|
Loading…
x
Reference in New Issue
Block a user