mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 17:06:43 +00:00
Use callback to iterate over chunks
This commit is contained in:
parent
db5638bf6d
commit
b477775e16
2 changed files with 49 additions and 50 deletions
|
@ -50,8 +50,8 @@ namespace DetourNavigator
|
||||||
ChunkyTriMesh& operator=(const ChunkyTriMesh&) = delete;
|
ChunkyTriMesh& operator=(const ChunkyTriMesh&) = delete;
|
||||||
|
|
||||||
/// Returns the chunk indices which overlap the input rectable.
|
/// Returns the chunk indices which overlap the input rectable.
|
||||||
template <class OutputIterator>
|
template <class Function>
|
||||||
void getChunksOverlappingRect(const Rect& rect, OutputIterator out) const
|
void forEachChunksOverlappingRect(const Rect& rect, Function&& function) const
|
||||||
{
|
{
|
||||||
// Traverse tree
|
// Traverse tree
|
||||||
for (std::size_t i = 0; i < mNodes.size(); )
|
for (std::size_t i = 0; i < mNodes.size(); )
|
||||||
|
@ -61,7 +61,7 @@ namespace DetourNavigator
|
||||||
const bool isLeafNode = node->mOffset >= 0;
|
const bool isLeafNode = node->mOffset >= 0;
|
||||||
|
|
||||||
if (isLeafNode && overlap)
|
if (isLeafNode && overlap)
|
||||||
*out++ = i;
|
function(i);
|
||||||
|
|
||||||
if (overlap || isLeafNode)
|
if (overlap || isLeafNode)
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -149,62 +149,61 @@ namespace
|
||||||
std::vector<unsigned char> areas(chunkyMesh.getMaxTrisPerChunk(), AreaType_null);
|
std::vector<unsigned char> areas(chunkyMesh.getMaxTrisPerChunk(), AreaType_null);
|
||||||
const osg::Vec2f tileBoundsMin(config.bmin[0], config.bmin[2]);
|
const osg::Vec2f tileBoundsMin(config.bmin[0], config.bmin[2]);
|
||||||
const osg::Vec2f tileBoundsMax(config.bmax[0], config.bmax[2]);
|
const osg::Vec2f tileBoundsMax(config.bmax[0], config.bmax[2]);
|
||||||
std::vector<std::size_t> cids;
|
bool result = false;
|
||||||
chunkyMesh.getChunksOverlappingRect(Rect {tileBoundsMin, tileBoundsMax}, std::back_inserter(cids));
|
|
||||||
|
|
||||||
if (cids.empty())
|
chunkyMesh.forEachChunksOverlappingRect(Rect {tileBoundsMin, tileBoundsMax},
|
||||||
return false;
|
[&] (const std::size_t cid)
|
||||||
|
{
|
||||||
|
const auto chunk = chunkyMesh.getChunk(cid);
|
||||||
|
|
||||||
for (const auto cid : cids)
|
std::fill(
|
||||||
{
|
areas.begin(),
|
||||||
const auto chunk = chunkyMesh.getChunk(cid);
|
std::min(areas.begin() + static_cast<std::ptrdiff_t>(chunk.mSize),
|
||||||
|
areas.end()),
|
||||||
|
AreaType_null
|
||||||
|
);
|
||||||
|
|
||||||
std::fill(
|
rcMarkWalkableTriangles(
|
||||||
areas.begin(),
|
&context,
|
||||||
std::min(areas.begin() + static_cast<std::ptrdiff_t>(chunk.mSize),
|
config.walkableSlopeAngle,
|
||||||
areas.end()),
|
recastMesh.getVertices().data(),
|
||||||
AreaType_null
|
static_cast<int>(recastMesh.getVerticesCount()),
|
||||||
);
|
chunk.mIndices,
|
||||||
|
static_cast<int>(chunk.mSize),
|
||||||
|
areas.data()
|
||||||
|
);
|
||||||
|
|
||||||
rcMarkWalkableTriangles(
|
for (std::size_t i = 0; i < chunk.mSize; ++i)
|
||||||
&context,
|
areas[i] = chunk.mAreaTypes[i];
|
||||||
config.walkableSlopeAngle,
|
|
||||||
recastMesh.getVertices().data(),
|
|
||||||
static_cast<int>(recastMesh.getVerticesCount()),
|
|
||||||
chunk.mIndices,
|
|
||||||
static_cast<int>(chunk.mSize),
|
|
||||||
areas.data()
|
|
||||||
);
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < chunk.mSize; ++i)
|
rcClearUnwalkableTriangles(
|
||||||
areas[i] = chunk.mAreaTypes[i];
|
&context,
|
||||||
|
config.walkableSlopeAngle,
|
||||||
|
recastMesh.getVertices().data(),
|
||||||
|
static_cast<int>(recastMesh.getVerticesCount()),
|
||||||
|
chunk.mIndices,
|
||||||
|
static_cast<int>(chunk.mSize),
|
||||||
|
areas.data()
|
||||||
|
);
|
||||||
|
|
||||||
rcClearUnwalkableTriangles(
|
const auto trianglesRasterized = rcRasterizeTriangles(
|
||||||
&context,
|
&context,
|
||||||
config.walkableSlopeAngle,
|
recastMesh.getVertices().data(),
|
||||||
recastMesh.getVertices().data(),
|
static_cast<int>(recastMesh.getVerticesCount()),
|
||||||
static_cast<int>(recastMesh.getVerticesCount()),
|
chunk.mIndices,
|
||||||
chunk.mIndices,
|
areas.data(),
|
||||||
static_cast<int>(chunk.mSize),
|
static_cast<int>(chunk.mSize),
|
||||||
areas.data()
|
solid,
|
||||||
);
|
config.walkableClimb
|
||||||
|
);
|
||||||
|
|
||||||
const auto trianglesRasterized = rcRasterizeTriangles(
|
if (!trianglesRasterized)
|
||||||
&context,
|
throw NavigatorException("Failed to create rasterize triangles from recast mesh for navmesh");
|
||||||
recastMesh.getVertices().data(),
|
|
||||||
static_cast<int>(recastMesh.getVerticesCount()),
|
|
||||||
chunk.mIndices,
|
|
||||||
areas.data(),
|
|
||||||
static_cast<int>(chunk.mSize),
|
|
||||||
solid,
|
|
||||||
config.walkableClimb
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!trianglesRasterized)
|
result = true;
|
||||||
throw NavigatorException("Failed to create rasterize triangles from recast mesh for navmesh");
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rasterizeWaterTriangles(rcContext& context, const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
void rasterizeWaterTriangles(rcContext& context, const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,
|
||||||
|
|
Loading…
Reference in a new issue