This commit is contained in:
aozhiwei 2020-08-13 19:35:53 +08:00
parent ddba1267b8
commit 8f0a1bfc5a

View File

@ -43,6 +43,22 @@ static const int EXPECTED_LAYERS_PER_TILE = 4;
static const int MAX_LAYERS = 32;
/// Mask of the ceil part of the area id (3 lower bits)
/// the 0 value (RC_NULL_AREA) is left unused
static const unsigned char SAMPLE_POLYAREA_TYPE_MASK = 0x07;
/// Value for the kind of ceil "ground"
static const unsigned char SAMPLE_POLYAREA_TYPE_GROUND = 0x1;
/// Value for the kind of ceil "water"
static const unsigned char SAMPLE_POLYAREA_TYPE_WATER = 0x2;
/// Value for the kind of ceil "road"
static const unsigned char SAMPLE_POLYAREA_TYPE_ROAD = 0x3;
/// Value for the kind of ceil "grass"
static const unsigned char SAMPLE_POLYAREA_TYPE_GRASS = 0x4;
/// Flag for door area. Can be combined with area types and jump flag.
static const unsigned char SAMPLE_POLYAREA_FLAG_DOOR = 0x08;
/// Flag for jump area. Can be combined with area types and door flag.
static const unsigned char SAMPLE_POLYAREA_FLAG_JUMP = 0x10;
struct TileCacheData
{
unsigned char* data;
@ -525,6 +541,11 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
}
#endif
#if 1
rcContext* ctx = nullptr;
rcAreaModification SAMPLE_AREAMOD_GROUND(SAMPLE_POLYAREA_TYPE_GROUND, SAMPLE_POLYAREA_TYPE_MASK);
#endif
FastLZCompressor comp;
RasterizationContext rc;
@ -560,20 +581,16 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
if (!rc.solid) {
return 0;
}
#if 0
if (!rcCreateHeightfield(m_ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) {
if (!rcCreateHeightfield(ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) {
return 0;
}
#endif
// 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.
rc.triareas = new unsigned char[chunkyMesh->maxTrisPerChunk];
if (!rc.triareas) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
#endif
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
return 0;
}
@ -594,14 +611,13 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
const int ntris = node.n;
memset(rc.triareas, 0, ntris*sizeof(unsigned char));
#if 0
rcMarkWalkableTriangles(m_ctx, tcfg.walkableSlopeAngle,
rcMarkWalkableTriangles(ctx, tcfg.walkableSlopeAngle,
verts, nverts, tris, ntris, rc.triareas,
SAMPLE_AREAMOD_GROUND);
if (!rcRasterizeTriangles(m_ctx, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb))
if (!rcRasterizeTriangles(ctx, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb)) {
return 0;
#endif
}
}
// Once all geometry is rasterized, we do initial pass of filtering to
@ -618,29 +634,19 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
rc.chf = rcAllocCompactHeightfield();
if (!rc.chf) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
#endif
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
return 0;
}
#if 0
if (!rcBuildCompactHeightfield(m_ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
#endif
if (!rcBuildCompactHeightfield(ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
return 0;
}
#endif
// Erode the walkable area by agent radius.
#if 0
if (!rcErodeWalkableArea(m_ctx, tcfg.walkableRadius, *rc.chf)) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
#endif
if (!rcErodeWalkableArea(ctx, tcfg.walkableRadius, *rc.chf)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
return 0;
}
#endif
#if 0
// (Optional) Mark areas.
@ -654,19 +660,13 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
rc.lset = rcAllocHeightfieldLayerSet();
if (!rc.lset) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'.");
#endif
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'.");
return 0;
}
#if 0
if (!rcBuildHeightfieldLayers(m_ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) {
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers.");
#endif
if (!rcBuildHeightfieldLayers(ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers.");
return 0;
}
#endif
rc.ntiles = 0;
for (int i = 0; i < rcMin(rc.lset->nlayers, MAX_LAYERS); ++i) {