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; 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 struct TileCacheData
{ {
unsigned char* data; unsigned char* data;
@ -525,6 +541,11 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
} }
#endif #endif
#if 1
rcContext* ctx = nullptr;
rcAreaModification SAMPLE_AREAMOD_GROUND(SAMPLE_POLYAREA_TYPE_GROUND, SAMPLE_POLYAREA_TYPE_MASK);
#endif
FastLZCompressor comp; FastLZCompressor comp;
RasterizationContext rc; RasterizationContext rc;
@ -560,20 +581,16 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
if (!rc.solid) { if (!rc.solid) {
return 0; return 0;
} }
#if 0 if (!rcCreateHeightfield(ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) {
if (!rcCreateHeightfield(m_ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) {
return 0; return 0;
} }
#endif
// Allocate array that can hold triangle flags. // Allocate array that can hold triangle flags.
// If you have multiple meshes you need to process, allocate // If you have multiple meshes you need to process, allocate
// and array which can hold the max number of triangles you need to process. // and array which can hold the max number of triangles you need to process.
rc.triareas = new unsigned char[chunkyMesh->maxTrisPerChunk]; rc.triareas = new unsigned char[chunkyMesh->maxTrisPerChunk];
if (!rc.triareas) { if (!rc.triareas) {
#if 0 ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
#endif
return 0; return 0;
} }
@ -594,14 +611,13 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
const int ntris = node.n; const int ntris = node.n;
memset(rc.triareas, 0, ntris*sizeof(unsigned char)); memset(rc.triareas, 0, ntris*sizeof(unsigned char));
#if 0 rcMarkWalkableTriangles(ctx, tcfg.walkableSlopeAngle,
rcMarkWalkableTriangles(m_ctx, tcfg.walkableSlopeAngle,
verts, nverts, tris, ntris, rc.triareas, verts, nverts, tris, ntris, rc.triareas,
SAMPLE_AREAMOD_GROUND); 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; return 0;
#endif }
} }
// Once all geometry is rasterized, we do initial pass of filtering to // 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(); rc.chf = rcAllocCompactHeightfield();
if (!rc.chf) { if (!rc.chf) {
#if 0 ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
#endif
return 0; return 0;
} }
#if 0 if (!rcBuildCompactHeightfield(ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) {
if (!rcBuildCompactHeightfield(m_ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) { ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
#endif
return 0; return 0;
} }
#endif
// Erode the walkable area by agent radius. // Erode the walkable area by agent radius.
#if 0 if (!rcErodeWalkableArea(ctx, tcfg.walkableRadius, *rc.chf)) {
if (!rcErodeWalkableArea(m_ctx, tcfg.walkableRadius, *rc.chf)) { ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
#endif
return 0; return 0;
} }
#endif
#if 0 #if 0
// (Optional) Mark areas. // (Optional) Mark areas.
@ -654,19 +660,13 @@ int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
rc.lset = rcAllocHeightfieldLayerSet(); rc.lset = rcAllocHeightfieldLayerSet();
if (!rc.lset) { if (!rc.lset) {
#if 0 ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'.");
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'.");
#endif
return 0; return 0;
} }
#if 0 if (!rcBuildHeightfieldLayers(ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) {
if (!rcBuildHeightfieldLayers(m_ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) { ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers.");
#if 0
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers.");
#endif
return 0; return 0;
} }
#endif
rc.ntiles = 0; rc.ntiles = 0;
for (int i = 0; i < rcMin(rc.lset->nlayers, MAX_LAYERS); ++i) { for (int i = 0; i < rcMin(rc.lset->nlayers, MAX_LAYERS); ++i) {