This commit is contained in:
aozhiwei 2020-08-14 15:00:43 +08:00
parent d129fb5bb3
commit 24d221d934
2 changed files with 17 additions and 19 deletions

View File

@ -139,9 +139,6 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
FastLZCompressor comp; FastLZCompressor comp;
RasterizationContext rc; RasterizationContext rc;
#if 1
rcContext* ctx = nullptr;
#endif
const float* verts = builder_params.gemo->GetVerts(); const float* verts = builder_params.gemo->GetVerts();
const int nverts = builder_params.gemo->GetVertCount(); const int nverts = builder_params.gemo->GetVertCount();
const rcChunkyTriMesh* chunkyMesh = builder_params.gemo->GetChunkyMesh(); const rcChunkyTriMesh* chunkyMesh = builder_params.gemo->GetChunkyMesh();
@ -168,7 +165,7 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
if (!rc.solid) { if (!rc.solid) {
return 0; return 0;
} }
if (!rcCreateHeightfield(ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) { if (!rcCreateHeightfield(builder_params.ctx, *rc.solid, tcfg.width, tcfg.height, tcfg.bmin, tcfg.bmax, tcfg.cs, tcfg.ch)) {
return 0; return 0;
} }
@ -177,7 +174,7 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
// 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) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'm_triareas' (%d).", chunkyMesh->maxTrisPerChunk);
return 0; return 0;
} }
@ -198,11 +195,11 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
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));
rcMarkWalkableTriangles(ctx, tcfg.walkableSlopeAngle, rcMarkWalkableTriangles(builder_params.ctx, tcfg.walkableSlopeAngle,
verts, nverts, tris, ntris, rc.triareas, verts, nverts, tris, ntris, rc.triareas,
SAMPLE_AREAMOD_GROUND); SAMPLE_AREAMOD_GROUND);
if (!rcRasterizeTriangles(ctx, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb)) { if (!rcRasterizeTriangles(builder_params.ctx, verts, nverts, tris, rc.triareas, ntris, *rc.solid, tcfg.walkableClimb)) {
return 0; return 0;
} }
} }
@ -211,46 +208,46 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
// remove unwanted overhangs caused by the conservative rasterization // remove unwanted overhangs caused by the conservative rasterization
// as well as filter spans where the character cannot possibly stand. // as well as filter spans where the character cannot possibly stand.
if (builder_params.kFilterLowHangingObstacles) { if (builder_params.kFilterLowHangingObstacles) {
rcFilterLowHangingWalkableObstacles(ctx, tcfg.walkableClimb, *rc.solid); rcFilterLowHangingWalkableObstacles(builder_params.ctx, tcfg.walkableClimb, *rc.solid);
} }
if (builder_params.kFilterLedgeSpans) { if (builder_params.kFilterLedgeSpans) {
rcFilterLedgeSpans(ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid); rcFilterLedgeSpans(builder_params.ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid);
} }
if (builder_params.kFilterWalkableLowHeightSpans) { if (builder_params.kFilterWalkableLowHeightSpans) {
rcFilterWalkableLowHeightSpans(ctx, tcfg.walkableHeight, *rc.solid); rcFilterWalkableLowHeightSpans(builder_params.ctx, tcfg.walkableHeight, *rc.solid);
} }
rc.chf = rcAllocCompactHeightfield(); rc.chf = rcAllocCompactHeightfield();
if (!rc.chf) { if (!rc.chf) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'."); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
return 0; return 0;
} }
if (!rcBuildCompactHeightfield(ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) { if (!rcBuildCompactHeightfield(builder_params.ctx, tcfg.walkableHeight, tcfg.walkableClimb, *rc.solid, *rc.chf)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data."); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
return 0; return 0;
} }
// Erode the walkable area by agent radius. // Erode the walkable area by agent radius.
if (!rcErodeWalkableArea(ctx, tcfg.walkableRadius, *rc.chf)) { if (!rcErodeWalkableArea(builder_params.ctx, tcfg.walkableRadius, *rc.chf)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode."); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Could not erode.");
return 0; return 0;
} }
// (Optional) Mark areas. // (Optional) Mark areas.
const ConvexVolume* vols = builder_params.gemo->GetConvexVolumes(); const ConvexVolume* vols = builder_params.gemo->GetConvexVolumes();
for (int i = 0; i < builder_params.gemo->GetConvexVolumeCount(); ++i) { for (int i = 0; i < builder_params.gemo->GetConvexVolumeCount(); ++i) {
rcMarkConvexPolyArea(ctx, vols[i].verts, vols[i].nverts, rcMarkConvexPolyArea(builder_params.ctx, vols[i].verts, vols[i].nverts,
vols[i].hmin, vols[i].hmax, vols[i].hmin, vols[i].hmax,
vols[i].areaMod, *rc.chf); vols[i].areaMod, *rc.chf);
} }
rc.lset = rcAllocHeightfieldLayerSet(); rc.lset = rcAllocHeightfieldLayerSet();
if (!rc.lset) { if (!rc.lset) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'."); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'lset'.");
return 0; return 0;
} }
if (!rcBuildHeightfieldLayers(ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) { if (!rcBuildHeightfieldLayers(builder_params.ctx, *rc.chf, tcfg.borderSize, tcfg.walkableHeight, *rc.lset)) {
ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers."); builder_params.ctx->log(RC_LOG_ERROR, "buildNavigation: Could not build heighfield layers.");
return 0; return 0;
} }

View File

@ -303,6 +303,7 @@ struct BuilderParams
MapInstance* map_instance = nullptr; MapInstance* map_instance = nullptr;
InputGeom* gemo = nullptr; InputGeom* gemo = nullptr;
dtNavMesh* navmesh = nullptr; dtNavMesh* navmesh = nullptr;
rcContext* ctx = nullptr;
dtTileCache* tile_cache = nullptr; dtTileCache* tile_cache = nullptr;
}; };