本文整理汇总了C++中dtAllocNavMesh函数的典型用法代码示例。如果您正苦于以下问题:C++ dtAllocNavMesh函数的具体用法?C++ dtAllocNavMesh怎么用?C++ dtAllocNavMesh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dtAllocNavMesh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dtnmBuildSingleTileMesh
EXPORT_API dtStatus dtnmBuildSingleTileMesh(dtNavMeshCreateParams* params
, dtNavMesh** ppNavMesh)
{
if (!params)
return DT_FAILURE + DT_INVALID_PARAM;
unsigned char* navData = 0;
int navDataSize = 0;
if (!dtCreateNavMeshData(params, &navData, &navDataSize))
return DT_FAILURE + DT_INVALID_PARAM;
dtNavMesh* pNavMesh = dtAllocNavMesh();
if (!pNavMesh)
{
dtFree(navData);
return DT_FAILURE + DT_OUT_OF_MEMORY;
}
dtStatus status =
pNavMesh->init(navData, navDataSize, DT_TILE_FREE_DATA);
if (dtStatusFailed(status))
{
dtFreeNavMesh(pNavMesh);
dtFree(navData);
return status;
}
*ppNavMesh = pNavMesh;
return DT_SUCCESS;
}
示例2: makeEmptyNavMesh
NavMeshPtr makeEmptyNavMesh(const Settings& settings)
{
// Max tiles and max polys affect how the tile IDs are caculated.
// There are 22 bits available for identifying a tile and a polygon.
const int polysAndTilesBits = 22;
const auto polysBits = getMinValuableBitsNumber(settings.mMaxPolys);
if (polysBits >= polysAndTilesBits)
throw InvalidArgument("Too many polygons per tile");
const auto tilesBits = polysAndTilesBits - polysBits;
dtNavMeshParams params;
std::fill_n(params.orig, 3, 0.0f);
params.tileWidth = settings.mTileSize * settings.mCellSize;
params.tileHeight = settings.mTileSize * settings.mCellSize;
params.maxTiles = 1 << tilesBits;
params.maxPolys = 1 << polysBits;
NavMeshPtr navMesh(dtAllocNavMesh(), &dtFreeNavMesh);
const auto status = navMesh->init(¶ms);
if (!dtStatusSucceed(status))
throw NavigatorException("Failed to init navmesh");
return navMesh;
}
示例3: sprintf
void CCollideInterface::ActivateMap(uint32 mapid)
{
m_navmaplock.Acquire();
std::map<uint32, NavMeshData*>::iterator itr = m_navdata.find(mapid);
if(itr != m_navdata.end())
++itr->second->refs;
else
{
//load params
char filename[1024];
sprintf(filename, "mmaps/%03i.mmap", mapid);
FILE* f = fopen(filename, "rb");
if(f == NULL)
{
m_navmaplock.Release();
return;
}
dtNavMeshParams params;
fread(¶ms, sizeof(params), 1, f);
fclose(f);
NavMeshData* d = new NavMeshData;
d->mesh = dtAllocNavMesh();
d->query = dtAllocNavMeshQuery();
d->mesh->init(¶ms);
d->query->init(d->mesh, 1024);
d->AddRef();
m_navdata.insert(std::make_pair(mapid, d));
}
m_navmaplock.Release();
}
示例4: dtFreeTileCache
bool OgreDetourTileCache::initTileCache()
{
// BUILD TileCache
dtFreeTileCache(m_tileCache);
dtStatus status;
m_tileCache = dtAllocTileCache();
if (!m_tileCache)
{
m_recast->m_pLog->logMessage("ERROR: buildTiledNavigation: Could not allocate tile cache.");
return false;
}
status = m_tileCache->init(&m_tcparams, m_talloc, m_tcomp, m_tmproc);
if (dtStatusFailed(status))
{
m_recast->m_pLog->logMessage("ERROR: buildTiledNavigation: Could not init tile cache.");
return false;
}
dtFreeNavMesh(m_recast->m_navMesh);
m_recast->m_navMesh = dtAllocNavMesh();
if (!m_recast->m_navMesh)
{
m_recast->m_pLog->logMessage("ERROR: buildTiledNavigation: Could not allocate navmesh.");
return false;
}
// Init multi-tile navmesh parameters
dtNavMeshParams params;
memset(¶ms, 0, sizeof(params));
rcVcopy(params.orig, m_tcparams.orig); // Set world-space origin of tile grid
params.tileWidth = m_tileSize*m_tcparams.cs;
params.tileHeight = m_tileSize*m_tcparams.cs;
params.maxTiles = m_maxTiles;
params.maxPolys = m_maxPolysPerTile;
status = m_recast->m_navMesh->init(¶ms);
if (dtStatusFailed(status))
{
m_recast->m_pLog->logMessage("ERROR: buildTiledNavigation: Could not init navmesh.");
return false;
}
// Init recast navmeshquery with created navmesh (in OgreRecast component)
m_recast->m_navQuery = dtAllocNavMeshQuery();
status = m_recast->m_navQuery->init(m_recast->m_navMesh, 2048);
if (dtStatusFailed(status))
{
m_recast->m_pLog->logMessage("ERROR: buildTiledNavigation: Could not init Detour navmesh query");
return false;
}
return true;
}
示例5: fopen
dtNavMesh* Sample_TileMesh::loadAll(const char* path)
{
FILE* fp = fopen(path, "rb");
if (!fp) return 0;
// Read header.
NavMeshSetHeader header;
fread(&header, sizeof(NavMeshSetHeader), 1, fp);
if (header.magic != NAVMESHSET_MAGIC)
{
fclose(fp);
return 0;
}
if (header.version != NAVMESHSET_VERSION)
{
fclose(fp);
return 0;
}
dtNavMesh* mesh = dtAllocNavMesh();
if (!mesh)
{
fclose(fp);
return 0;
}
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
fclose(fp);
return 0;
}
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
NavMeshTileHeader tileHeader;
fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (!tileHeader.tileRef || !tileHeader.dataSize)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
memset(data, 0, tileHeader.dataSize);
fread(data, tileHeader.dataSize, 1, fp);
mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0);
}
fclose(fp);
return mesh;
}
示例6: dtFreeNavMesh
bool Sample_TileMesh::handleBuild()
{
if (!m_geom || !m_geom->getMesh())
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles.");
return false;
}
dtFreeNavMesh(m_navMesh);
m_navMesh = dtAllocNavMesh();
if (!m_navMesh)
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh.");
return false;
}
dtNavMeshParams params;
rcVcopy(params.orig, m_geom->getNavMeshBoundsMin());
params.tileWidth = m_tileSize*m_cellSize;
params.tileHeight = m_tileSize*m_cellSize;
params.maxTiles = m_maxTiles;
params.maxPolys = m_maxPolysPerTile;
dtStatus status;
status = m_navMesh->init(¶ms);
if (dtStatusFailed(status))
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh.");
return false;
}
status = m_navQuery->init(m_navMesh, 2048);
if (dtStatusFailed(status))
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init Detour navmesh query");
return false;
}
if (m_buildAll)
buildAllTiles();
if (m_tool)
m_tool->init(this);
initToolStates(this);
return true;
}
示例7: getIdString
bool NavMesh::createNavMesh(dtNavMeshCreateParams ¶ms)
{
unsigned char *tileData = NULL;
S32 tileDataSize = 0;
if(!dtCreateNavMeshData(¶ms, &tileData, &tileDataSize))
{
Con::errorf("Could not construct NavMeshData for NavMesh %s", getIdString());
return false;
}
tnm = dtAllocNavMesh();
if(!tnm)
{
Con::errorf("Out of memory allocating dtNavMesh for NavMesh %s", getIdString());
return false;
}
dtStatus s = tnm->init(tileData, tileDataSize, DT_TILE_FREE_DATA);
if(dtStatusFailed(s))
{
Con::errorf("Could not initialise dtNavMesh for NavMesh %s", getIdString());
return false;
}
// Initialise all flags to something helpful.
for(U32 i = 0; i < tnm->getMaxTiles(); ++i)
{
const dtMeshTile* tile = ((const dtNavMesh*)tnm)->getTile(i);
if(!tile->header) continue;
const dtPolyRef base = tnm->getPolyRefBase(tile);
for(U32 j = 0; j < tile->header->polyCount; ++j)
{
const dtPolyRef ref = base | j;
unsigned short f = 0;
tnm->getPolyFlags(ref, &f);
tnm->setPolyFlags(ref, f | 1);
}
}
return true;
}
示例8: dtnmInitTiledNavMesh
EXPORT_API dtStatus dtnmInitTiledNavMesh(dtNavMeshParams* params
, dtNavMesh** ppNavMesh)
{
if (!params)
return DT_FAILURE + DT_INVALID_PARAM;
dtNavMesh* pNavMesh = dtAllocNavMesh();
if (!pNavMesh)
return DT_FAILURE + DT_OUT_OF_MEMORY;
dtStatus status =
pNavMesh->init(params);
if (dtStatusFailed(status))
{
dtFreeNavMesh(pNavMesh);
return status;
}
*ppNavMesh = pNavMesh;
return DT_SUCCESS;
}
示例9: fopen
void Sample_TempObstacles::loadAll(const char* path)
{
FILE* fp = fopen(path, "rb");
if (!fp) return;
// Read header.
TileCacheSetHeader header;
fread(&header, sizeof(TileCacheSetHeader), 1, fp);
if (header.magic != TILECACHESET_MAGIC)
{
fclose(fp);
return;
}
if (header.version != TILECACHESET_VERSION)
{
fclose(fp);
return;
}
m_navMesh = dtAllocNavMesh();
if (!m_navMesh)
{
fclose(fp);
return;
}
dtStatus status = m_navMesh->init(&header.meshParams);
if (dtStatusFailed(status))
{
fclose(fp);
return;
}
m_tileCache = dtAllocTileCache();
if (!m_tileCache)
{
fclose(fp);
return;
}
status = m_tileCache->init(&header.cacheParams, m_talloc, m_tcomp, m_tmproc);
if (dtStatusFailed(status))
{
fclose(fp);
return;
}
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
TileCacheTileHeader tileHeader;
fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (!tileHeader.tileRef || !tileHeader.dataSize)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
memset(data, 0, tileHeader.dataSize);
fread(data, tileHeader.dataSize, 1, fp);
dtCompressedTileRef tile = 0;
m_tileCache->addTile(data, tileHeader.dataSize, DT_COMPRESSEDTILE_FREE_DATA, &tile);
if (tile)
m_tileCache->buildNavMeshTile(tile, m_navMesh);
}
fclose(fp);
}
示例10: cleanup
bool Sample_TileMesh::handleLoadSubTiles()
{
if (!m_geom || !m_geom->getMesh())
{
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified.");
return false;
}
cleanup();
const char* meshFilePath = m_geom->getMesh()->getFileName();
char charBuff[4];
memset(charBuff, 0, sizeof(charBuff));
memcpy(charBuff, &meshFilePath[10], sizeof(char) * 3);
int mapId = atoi(charBuff);
// load and init dtNavMesh - read parameters from file
int pathLen = strlen("Meshes/%03i.mmap") + 1;
char *fileName = new char[pathLen];
snprintf(fileName, pathLen, "Meshes/%03i.mmap", mapId);
FILE* file = fopen(fileName, "rb");
if (!file)
{
delete[] fileName;
return false;
}
dtNavMeshParams params;
int count = fread(¶ms, sizeof(dtNavMeshParams), 1, file);
fclose(file);
if (count != 1)
{
delete[] fileName;
return false;
}
params.maxTiles = 25 * 25 * 9;
dtNavMesh* mesh = dtAllocNavMesh();
if (dtStatusFailed(mesh->init(¶ms)))
{
dtFreeNavMesh(mesh);
delete[] fileName;
return false;
}
delete[] fileName;
memset(charBuff, 0, sizeof(charBuff));
memcpy(charBuff, &meshFilePath[13], sizeof(char) * 2);
int x = atoi(charBuff);
memset(charBuff, 0, sizeof(charBuff));
memcpy(charBuff, &meshFilePath[15], sizeof(char) * 2);
int y = atoi(charBuff);
for (int subRow = 0; subRow < 25; subRow++)
{
for (int subCol = 0; subCol < 25; subCol++)
{
// load this tile :: Meshes/MMMXXYY.mmtile
pathLen = strlen("Meshes/%03i%02i%02i_____%02i%02i.mmtile") + 1;
fileName = new char[pathLen];
snprintf(fileName, pathLen, "Meshes/%03i%02i%02i_____%02i%02i.mmtile", mapId, x, y, subRow, subCol);
file = fopen(fileName, "rb");
if (!file)
{
delete[] fileName;
continue;
}
delete[] fileName;
// read header
MmapTileHeader fileHeader;
if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || fileHeader.mmapMagic != MMAP_MAGIC)
{
fclose(file);
continue;
}
unsigned char* data = (unsigned char*)dtAlloc(fileHeader.size, DT_ALLOC_PERM);
size_t result = fread(data, fileHeader.size, 1, file);
if (!result)
{
fclose(file);
continue;
}
// Fix x/y
dtMeshHeader* header = (dtMeshHeader*)data;
header->x = header->x * 25 + subRow;
header->y = header->y * 25 + subCol;
fclose(file);
dtTileRef tileRef = 0;
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
if (!dtStatusSucceed(mesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
{
dtFree(data);
continue;
}
//.........这里部分代码省略.........
示例11: rcCalcGridSize
bool Sample_TempObstacles::handleBuild()
{
dtStatus status;
if (!m_geom || !m_geom->getMesh())
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles.");
return false;
}
m_tmproc->init(m_geom);
// Init cache
const float* bmin = m_geom->getNavMeshBoundsMin();
const float* bmax = m_geom->getNavMeshBoundsMax();
int gw = 0, gh = 0;
rcCalcGridSize(bmin, bmax, m_cellSize, &gw, &gh);
const int ts = (int)m_tileSize;
const int tw = (gw + ts-1) / ts;
const int th = (gh + ts-1) / ts;
// Generation params.
rcConfig cfg;
memset(&cfg, 0, sizeof(cfg));
cfg.cs = m_cellSize;
cfg.ch = m_cellHeight;
cfg.walkableSlopeAngle = m_agentMaxSlope;
cfg.walkableHeight = (int)ceilf(m_agentHeight / cfg.ch);
cfg.walkableClimb = (int)floorf(m_agentMaxClimb / cfg.ch);
cfg.walkableRadius = (int)ceilf(m_agentRadius / cfg.cs);
cfg.maxEdgeLen = (int)(m_edgeMaxLen / m_cellSize);
cfg.maxSimplificationError = m_edgeMaxError;
cfg.minRegionArea = (int)rcSqr(m_regionMinSize); // Note: area = size*size
cfg.mergeRegionArea = (int)rcSqr(m_regionMergeSize); // Note: area = size*size
cfg.maxVertsPerPoly = (int)m_vertsPerPoly;
cfg.tileSize = (int)m_tileSize;
cfg.borderSize = cfg.walkableRadius + 3; // Reserve enough padding.
cfg.width = cfg.tileSize + cfg.borderSize*2;
cfg.height = cfg.tileSize + cfg.borderSize*2;
cfg.detailSampleDist = m_detailSampleDist < 0.9f ? 0 : m_cellSize * m_detailSampleDist;
cfg.detailSampleMaxError = m_cellHeight * m_detailSampleMaxError;
rcVcopy(cfg.bmin, bmin);
rcVcopy(cfg.bmax, bmax);
// Tile cache params.
dtTileCacheParams tcparams;
memset(&tcparams, 0, sizeof(tcparams));
rcVcopy(tcparams.orig, bmin);
tcparams.cs = m_cellSize;
tcparams.ch = m_cellHeight;
tcparams.width = (int)m_tileSize;
tcparams.height = (int)m_tileSize;
tcparams.walkableHeight = m_agentHeight;
tcparams.walkableRadius = m_agentRadius;
tcparams.walkableClimb = m_agentMaxClimb;
tcparams.maxSimplificationError = m_edgeMaxError;
tcparams.maxTiles = tw*th*EXPECTED_LAYERS_PER_TILE;
tcparams.maxObstacles = 128;
dtFreeTileCache(m_tileCache);
m_tileCache = dtAllocTileCache();
if (!m_tileCache)
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate tile cache.");
return false;
}
status = m_tileCache->init(&tcparams, m_talloc, m_tcomp, m_tmproc);
if (dtStatusFailed(status))
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init tile cache.");
return false;
}
dtFreeNavMesh(m_navMesh);
m_navMesh = dtAllocNavMesh();
if (!m_navMesh)
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh.");
return false;
}
dtNavMeshParams params;
memset(¶ms, 0, sizeof(params));
rcVcopy(params.orig, bmin);
params.tileWidth = m_tileSize*m_cellSize;
params.tileHeight = m_tileSize*m_cellSize;
params.maxTiles = m_maxTiles;
params.maxPolys = m_maxPolysPerTile;
status = m_navMesh->init(¶ms);
if (dtStatusFailed(status))
{
m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh.");
return false;
}
status = m_navQuery->init(m_navMesh, 2048);
if (dtStatusFailed(status))
//.........这里部分代码省略.........
示例12: BotLoadNavMesh
bool BotLoadNavMesh( const char *filename, NavData_t &nav )
{
char mapname[ MAX_QPATH ];
char filePath[ MAX_QPATH ];
char gameName[ MAX_STRING_CHARS ];
fileHandle_t f = 0;
BotLoadOffMeshConnections( filename, &nav );
Cvar_VariableStringBuffer( "mapname", mapname, sizeof( mapname ) );
Cvar_VariableStringBuffer( "fs_game", gameName, sizeof( gameName ) );
Com_sprintf( filePath, sizeof( filePath ), "maps/%s-%s.navMesh", mapname, filename );
Com_Printf( " loading navigation mesh file '%s'...\n", filePath );
int len = FS_FOpenFileRead( filePath, &f, qtrue );
if ( !f )
{
Com_Printf( S_COLOR_RED "ERROR: Cannot open Navigaton Mesh file\n" );
return false;
}
if ( len < 0 )
{
Com_Printf( S_COLOR_RED "ERROR: Negative Length for Navigation Mesh file\n" );
return false;
}
NavMeshSetHeader header;
FS_Read( &header, sizeof( header ), f );
SwapNavMeshSetHeader( header );
if ( header.magic != NAVMESHSET_MAGIC )
{
Com_Printf( S_COLOR_RED "ERROR: File is wrong magic\n" );
FS_FCloseFile( f );
return false;
}
if ( header.version != NAVMESHSET_VERSION )
{
Com_Printf( S_COLOR_RED "ERROR: File is wrong version found: %d want: %d\n", header.version, NAVMESHSET_VERSION );
FS_FCloseFile( f );
return false;
}
nav.mesh = dtAllocNavMesh();
if ( !nav.mesh )
{
Com_Printf( S_COLOR_RED "ERROR: Unable to allocate nav mesh\n" );
FS_FCloseFile( f );
return false;
}
dtStatus status = nav.mesh->init( &header.params );
if ( dtStatusFailed( status ) )
{
Com_Printf( S_COLOR_RED "ERROR: Could not init navmesh\n" );
dtFreeNavMesh( nav.mesh );
nav.mesh = NULL;
FS_FCloseFile( f );
return false;
}
nav.cache = dtAllocTileCache();
if ( !nav.cache )
{
Com_Printf( S_COLOR_RED "ERROR: Could not allocate tile cache\n" );
dtFreeNavMesh( nav.mesh );
nav.mesh = NULL;
FS_FCloseFile( f );
return false;
}
status = nav.cache->init( &header.cacheParams, &alloc, &comp, &nav.process );
if ( dtStatusFailed( status ) )
{
Com_Printf( S_COLOR_RED "ERROR: Could not init tile cache\n" );
dtFreeNavMesh( nav.mesh );
dtFreeTileCache( nav.cache );
nav.mesh = NULL;
nav.cache = NULL;
FS_FCloseFile( f );
return false;
}
for ( int i = 0; i < header.numTiles; i++ )
{
NavMeshTileHeader tileHeader;
FS_Read( &tileHeader, sizeof( tileHeader ), f );
SwapNavMeshTileHeader( tileHeader );
//.........这里部分代码省略.........
示例13: KBE_ASSERT
//-------------------------------------------------------------------------------------
bool NavMeshHandle::_create(int layer, const std::string& resPath, const std::string& res, NavMeshHandle* pNavMeshHandle)
{
KBE_ASSERT(pNavMeshHandle);
FILE* fp = fopen(res.c_str(), "rb");
if (!fp)
{
ERROR_MSG(fmt::format("NavMeshHandle::create: open({}) is error!\n",
Resmgr::getSingleton().matchRes(res)));
return false;
}
DEBUG_MSG(fmt::format("NavMeshHandle::create: ({}), layer={}\n",
res, layer));
bool safeStorage = true;
int pos = 0;
int size = sizeof(NavMeshSetHeader);
fseek(fp, 0, SEEK_END);
size_t flen = ftell(fp);
fseek(fp, 0, SEEK_SET);
uint8* data = new uint8[flen];
if(data == NULL)
{
ERROR_MSG(fmt::format("NavMeshHandle::create: open({}), memory(size={}) error!\n",
Resmgr::getSingleton().matchRes(res), flen));
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
size_t readsize = fread(data, 1, flen, fp);
if(readsize != flen)
{
ERROR_MSG(fmt::format("NavMeshHandle::create: open({}), read(size={} != {}) error!\n",
Resmgr::getSingleton().matchRes(res), readsize, flen));
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
if (readsize < sizeof(NavMeshSetHeader))
{
ERROR_MSG(fmt::format("NavMeshHandle::create: open({}), NavMeshSetHeader is error!\n",
Resmgr::getSingleton().matchRes(res)));
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
NavMeshSetHeader header;
memcpy(&header, data, size);
pos += size;
if (header.version != NavMeshHandle::RCN_NAVMESH_VERSION)
{
ERROR_MSG(fmt::format("NavMeshHandle::create: navmesh version({}) is not match({})!\n",
header.version, ((int)NavMeshHandle::RCN_NAVMESH_VERSION)));
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
dtNavMesh* mesh = dtAllocNavMesh();
if (!mesh)
{
ERROR_MSG("NavMeshHandle::create: dtAllocNavMesh is failed!\n");
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
ERROR_MSG(fmt::format("NavMeshHandle::create: mesh init is error({})!\n", status));
fclose(fp);
SAFE_RELEASE_ARRAY(data);
return false;
}
// Read tiles.
bool success = true;
for (int i = 0; i < header.tileCount; ++i)
{
NavMeshTileHeader tileHeader;
size = sizeof(NavMeshTileHeader);
memcpy(&tileHeader, &data[pos], size);
pos += size;
size = tileHeader.dataSize;
if (!tileHeader.tileRef || !tileHeader.dataSize)
//.........这里部分代码省略.........
示例14: buildMesh
dtNavMesh* buildMesh(InputGeom* geom, WCellBuildContext* wcellContext, int numCores)
{
dtNavMesh* mesh = 0;
if (!geom || !geom->getMesh())
{
CleanupAfterBuild();
wcellContext->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles.");
return 0;
}
mesh = dtAllocNavMesh();
if (!mesh)
{
CleanupAfterBuild();
wcellContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh.");
return 0;
}
// setup some default parameters
rcConfig cfg;
memset(&cfg, 0, sizeof(rcConfig));
const float agentHeight = 2.1f; // most character toons are about this tall
const float agentRadius = 0.6f; // most character toons are about this big around
const float agentClimb = 1.0f; // character toons can step up this far. Seems ridiculously high ...
const float tileSize = 1600.0f/3.0f/16.0f; // The size of one chunk
cfg.cs = 0.1f; // cell size is a sort of resolution -> the bigger the faster
cfg.ch = 0.05f; // cell height -> distance from mesh to ground, if too low, recast will not build essential parts of the mesh for some reason
cfg.walkableSlopeAngle = 50.0f; // max climbable slope, bigger values won't make much of a change
cfg.walkableHeight = (int)ceilf(agentHeight/cfg.ch);// minimum space to ceiling
cfg.walkableClimb = (int)floorf(agentClimb/cfg.ch); // how high the agent can climb in one step
cfg.walkableRadius = (int)ceilf(agentRadius/cfg.cs);// minimum distance to objects
cfg.tileSize = (int)(tileSize/cfg.cs + 0.5f);
cfg.maxEdgeLen = cfg.tileSize/2;;
cfg.borderSize = cfg.walkableRadius + 3;
cfg.width = cfg.tileSize + cfg.borderSize*2;
cfg.height = cfg.tileSize + cfg.borderSize*2;
cfg.maxSimplificationError = 1.3f;
cfg.minRegionArea = (int)rcSqr(8); // Note: area = size*size
cfg.mergeRegionArea = (int)rcSqr(20); // Note: area = size*size
cfg.maxVertsPerPoly = 3;
cfg.detailSampleDist = cfg.cs * 9;
cfg.detailSampleMaxError = cfg.ch * 1.0f;
// default calculations - for some reason not included in basic recast
const float* bmin = geom->getMeshBoundsMin();
const float* bmax = geom->getMeshBoundsMax();
int gw = 0, gh = 0;
rcCalcGridSize(bmin, bmax, cfg.cs, &gw, &gh);
const int ts = cfg.tileSize;
const int tw = (gw + ts-1) / ts;
const int th = (gh + ts-1) / ts;
// Max tiles and max polys affect how the tile IDs are caculated.
// There are 22 bits available for identifying a tile and a polygon.
int tileBits = rcMin((int)ilog2(nextPow2(tw*th)), 14);
if (tileBits > 14) tileBits = 14;
int polyBits = 22 - tileBits;
int maxTiles = 1 << tileBits;
int maxPolysPerTile = 1 << polyBits;
dtNavMeshParams params;
rcVcopy(params.orig, geom->getMeshBoundsMin());
params.tileWidth = cfg.tileSize * cfg.cs;
params.tileHeight = cfg.tileSize * cfg.cs;
params.maxTiles = maxTiles;
params.maxPolys = maxPolysPerTile;
dtStatus status;
status = mesh->init(¶ms);
if (dtStatusFailed(status))
{
CleanupAfterBuild();
wcellContext->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh.");
return 0;
}
// start building
const float tcs = cfg.tileSize*cfg.cs;
wcellContext->startTimer(RC_TIMER_TEMP);
TileAdder Adder;
dispatcher.Reset();
dispatcher.maxHeight = th;
dispatcher.maxWidth = tw;
int numThreads = 0;
numThreads = std::min(2*numCores, 8);
boost::thread *threads[8];
for(int i = 0; i < numThreads; ++i)
{
QuadrantTiler newTiler;
newTiler.geom = geom;
newTiler.cfg = cfg;
newTiler.ctx = *wcellContext;
//.........这里部分代码省略.........
示例15: _navMesh
DetourInterface::DetourInterface(rcPolyMesh* polyMesh,rcPolyMeshDetail* detailMesh,rcdtConfig& config)
: _navMesh(nullptr),
_navQuery(nullptr),
_isMeshBuilt(false)
{
detourCleanup();
unsigned char* navData = 0;
int navDataSize = 0;
if(config.recastConfig->maxVertsPerPoly > DT_VERTS_PER_POLYGON)
{
return;
}
#if defined(DEBUG) || defined(_DEBUG)
std::cout << "Detour - Stage 1" << std::endl;
#endif
for(int i = 0; i < polyMesh->npolys; ++i)
{
if(polyMesh->areas[i] == RC_WALKABLE_AREA)
{
polyMesh->areas[i] = DT_PA_GROUND;
polyMesh->flags[i] = DT_PF_WALK;
}
}
dtNavMeshCreateParams params;
memset(¶ms,0,sizeof(params));
params.verts = polyMesh->verts;
params.vertCount = polyMesh->nverts;
params.polys = polyMesh->polys;
params.polyAreas = polyMesh->areas;
params.polyFlags = polyMesh->flags;
params.polyCount = polyMesh->npolys;
params.nvp = polyMesh->nvp;
params.detailMeshes = detailMesh->meshes;
params.detailVerts = detailMesh->verts;
params.detailVertsCount = detailMesh->nverts;
params.detailTris = detailMesh->tris;
params.detailTriCount = detailMesh->ntris;
//offmesh connections are not implemented. I don't even know what they are!
params.offMeshConCount = 0;
params.walkableHeight = config.userConfig->getAgentHeight();
params.walkableRadius = config.userConfig->getAgentRadius();
params.walkableClimb = config.userConfig->getAgentMaxClimb();
params.buildBvTree = true;
rcVcopy(params.bmin, config.recastConfig->bmin);
rcVcopy(params.bmax, config.recastConfig->bmax);
params.cs = config.recastConfig->cs;
params.ch = config.recastConfig->ch;
#if defined(DEBUG) || defined(_DEBUG)
std::cout << "Detour - Stage 2" << std::endl;
#endif
if(!dtCreateNavMeshData(¶ms,&navData,&navDataSize))
{
std::cout << "Error! Detour - could not build navmesh!" << std::endl;
std::cout << " - " << params.cs << std::endl;
std::cout << " - " << params.ch << std::endl;
std::cout << " - " << params.walkableRadius << std::endl;
//_isMeshBuilt = false;
return;
}
#if defined(DEBUG) || defined(_DEBUG)
std::cout << "Detour - Stage 3" << std::endl;
#endif
_navMesh = dtAllocNavMesh();
if(!_navMesh)
{
dtFree(_navMesh);
std::cout << "Error! Detour - could not create Detour navmesh!" << std::endl;
return;
}
#if defined(DEBUG) || defined(_DEBUG)
std::cout << "Detour - Stage 4" << std::endl;
#endif
dtStatus status;
status = _navMesh->init(navData,navDataSize,DT_TILE_FREE_DATA);
if(dtStatusFailed(status))
{
dtFree(navData);
std::cout << "Error! Could not initialize Detour NavMesh." << std::endl;
return;
}
#if defined(DEBUG) || defined(_DEBUG)
std::cout << "Detour - Stage 5" << std::endl;
#endif
_navQuery = dtAllocNavMeshQuery();
//.........这里部分代码省略.........