I use neighbors to build a tile, the tile partition is ok. But the
nonwalkable region is wrong.
http://postimage.org/image/hyd9gv673/
I mark the terrain triangles as walkable area, and mark the bounding
box of tree as nonwalkable area,
unsigned char* buildTileMesh(int tx, int ty, const float* bmin, const
float* bmax, int& dataSize)
{
......
if (!rcCreateHeightfield(m_ctx, *solid, cfg.width, cfg.height,
cfg.bmin, cfg.bmax, cfg.cs,
cfg.ch))
{
m_ctx->log(RC_LOG_ERROR, "buildNavigation: Could not create solid
heightfield.");
return 0;
}
for (int j = -1; j <= 1; ++j)
{
for (int i = -1; i <= 1; ++i)
{
if (ty+j >= 0 && ty+j < 16 && tx+i >= 0 && tx+i < 16)
{
const TriangleList& walkable = m_Walkable[ty+j][tx+i];
const TriangleList&nonWalkable = m_NonWalkable[ty+j][tx+i];
if (walkable.ntris > 0)
{
unsigned char* triareas = new unsigned char[walkable.ntris];
memset(triareas, 0, walkable.ntris*sizeof(unsigned char));
rcMarkWalkableTriangles(m_ctx, cfg.walkableSlopeAngle,
walkable.verts, walkable.nverts, walkable.tris, walkable.ntris,
triareas);
rcRasterizeTriangles(m_ctx, walkable.verts, walkable.nverts,
walkable.tris, triareas, walkable.ntris, *solid, cfg.walkableClimb);
delete [] triareas;
}
if (nonWalkable.ntris > 0)
{
unsigned char* triareas = new unsigned char[nonWalkable.ntris];
memset(triareas, 0, nonWalkable.ntris*sizeof(unsigned char));
rcRasterizeTriangles(m_ctx, nonWalkable.verts,
nonWalkable.nverts, nonWalkable.tris, triareas, nonWalkable.ntris,
*solid, cfg.walkableClimb);
delete [] triareas;
}
}
}
}
// Once all geometry is rasterized, we do initial pass of filtering
to
// remove unwanted overhangs caused by the conservative rasterization
// as well as filter spans where the character cannot possibly stand.
rcFilterLowHangingWalkableObstacles(m_ctx, cfg.walkableClimb,
*solid);
......
}