mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-10-02 23:15:33 +00:00
Rename rcChunkyTriMesh to just ChunkyTriMesh since it's a class that's part of the demo project, not Recast itself.
This commit is contained in:
@@ -20,28 +20,27 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct rcChunkyTriMeshNode
|
||||
/// A partitioned triangle mesh (AABB tree), where each node contains at max trisPerChunk triangles.
|
||||
struct ChunkyTriMesh
|
||||
{
|
||||
float bmin[2];
|
||||
float bmax[2];
|
||||
int i;
|
||||
int n;
|
||||
};
|
||||
struct Node
|
||||
{
|
||||
float bmin[2];
|
||||
float bmax[2];
|
||||
int i;
|
||||
int n;
|
||||
};
|
||||
|
||||
struct rcChunkyTriMesh
|
||||
{
|
||||
std::vector<rcChunkyTriMeshNode> nodes{};
|
||||
std::vector<Node> nodes{};
|
||||
int nnodes = 0;
|
||||
std::vector<int> tris{};
|
||||
int maxTrisPerChunk = 0;
|
||||
|
||||
bool TryPartitionMesh(const float* verts, const int* tris, int ntris, int trisPerChunk);
|
||||
|
||||
/// Finds the chunk indices that overlap the input rectangle.
|
||||
int GetChunksOverlappingRect(float bmin[2], float bmax[2], int* ids, int maxIds) const;
|
||||
|
||||
/// Returns the chunk indices which overlap the input segment.
|
||||
int GetChunksOverlappingSegment(float segmentStart[2], float segmentEnd[2], int* ids, int maxIds) const;
|
||||
};
|
||||
|
||||
/// Creates partitioned triangle mesh (AABB tree),
|
||||
/// where each node contains at max trisPerChunk triangles.
|
||||
bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris, int trisPerChunk, rcChunkyTriMesh* triMesh);
|
||||
|
||||
@@ -70,7 +70,7 @@ struct BuildSettings
|
||||
|
||||
class InputGeom
|
||||
{
|
||||
rcChunkyTriMesh* chunkyMesh = nullptr;
|
||||
ChunkyTriMesh* chunkyMesh = nullptr;
|
||||
MeshLoaderObj* meshLoader = nullptr;
|
||||
float meshBMin[3] = {};
|
||||
float meshBMax[3] = {};
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
const float* getMeshBoundsMax() const { return meshBMax; }
|
||||
const float* getNavMeshBoundsMin() const { return hasBuildSettings ? buildSettings.navMeshBMin : meshBMin; }
|
||||
const float* getNavMeshBoundsMax() const { return hasBuildSettings ? buildSettings.navMeshBMax : meshBMax; }
|
||||
const rcChunkyTriMesh* getChunkyMesh() const { return chunkyMesh; }
|
||||
const ChunkyTriMesh* getChunkyMesh() const { return chunkyMesh; }
|
||||
const BuildSettings* getBuildSettings() const { return hasBuildSettings ? &buildSettings : 0; }
|
||||
bool raycastMesh(float* src, float* dst, float& tmin);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ void subdivide(
|
||||
int imax,
|
||||
int trisPerChunk,
|
||||
int& curNode,
|
||||
rcChunkyTriMeshNode* nodes,
|
||||
ChunkyTriMesh::Node* nodes,
|
||||
const int maxNodes,
|
||||
int& curTri,
|
||||
int* outTris,
|
||||
@@ -115,7 +115,7 @@ void subdivide(
|
||||
return;
|
||||
}
|
||||
|
||||
rcChunkyTriMeshNode& node = nodes[curNode++];
|
||||
ChunkyTriMesh::Node& node = nodes[curNode++];
|
||||
|
||||
if (inum <= trisPerChunk)
|
||||
{
|
||||
@@ -214,12 +214,12 @@ bool checkOverlapSegment(const float p[2], const float q[2], const float bmin[2]
|
||||
|
||||
}
|
||||
|
||||
bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris, int trisPerChunk, rcChunkyTriMesh* triMesh)
|
||||
bool ChunkyTriMesh::TryPartitionMesh(const float* verts, const int* tris, int ntris, int trisPerChunk)
|
||||
{
|
||||
int nchunks = (ntris + trisPerChunk - 1) / trisPerChunk;
|
||||
|
||||
triMesh->nodes.resize(nchunks * 4);
|
||||
triMesh->tris.resize(ntris * 3);
|
||||
this->nodes.resize(nchunks * 4);
|
||||
this->tris.resize(ntris * 3);
|
||||
|
||||
// Build tree
|
||||
BoundsItem* items = new BoundsItem[ntris];
|
||||
@@ -268,43 +268,43 @@ bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris, int t
|
||||
ntris,
|
||||
trisPerChunk,
|
||||
curNode,
|
||||
triMesh->nodes.data(),
|
||||
this->nodes.data(),
|
||||
nchunks * 4,
|
||||
curTri,
|
||||
triMesh->tris.data(),
|
||||
this->tris.data(),
|
||||
tris);
|
||||
|
||||
delete[] items;
|
||||
|
||||
triMesh->nnodes = curNode;
|
||||
this->nnodes = curNode;
|
||||
|
||||
// Calc max tris per node.
|
||||
triMesh->maxTrisPerChunk = 0;
|
||||
for (int i = 0; i < triMesh->nnodes; ++i)
|
||||
this->maxTrisPerChunk = 0;
|
||||
for (int i = 0; i < this->nnodes; ++i)
|
||||
{
|
||||
rcChunkyTriMeshNode& node = triMesh->nodes[i];
|
||||
Node& node = this->nodes[i];
|
||||
const bool isLeaf = node.i >= 0;
|
||||
if (!isLeaf)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (node.n > triMesh->maxTrisPerChunk)
|
||||
if (node.n > this->maxTrisPerChunk)
|
||||
{
|
||||
triMesh->maxTrisPerChunk = node.n;
|
||||
this->maxTrisPerChunk = node.n;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int rcChunkyTriMesh::GetChunksOverlappingRect(float bmin[2], float bmax[2], int* ids, const int maxIds) const
|
||||
int ChunkyTriMesh::GetChunksOverlappingRect(float bmin[2], float bmax[2], int* ids, const int maxIds) const
|
||||
{
|
||||
// Traverse tree
|
||||
int i = 0;
|
||||
int n = 0;
|
||||
while (i < this->nnodes)
|
||||
{
|
||||
const rcChunkyTriMeshNode* node = &this->nodes[i];
|
||||
const Node* node = &this->nodes[i];
|
||||
const bool overlap = checkOverlapRect(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool isLeafNode = node->i >= 0;
|
||||
|
||||
@@ -331,14 +331,14 @@ int rcChunkyTriMesh::GetChunksOverlappingRect(float bmin[2], float bmax[2], int*
|
||||
return n;
|
||||
}
|
||||
|
||||
int rcChunkyTriMesh::GetChunksOverlappingSegment(float segmentStart[2], float segmentEnd[2], int* ids, const int maxIds) const
|
||||
int ChunkyTriMesh::GetChunksOverlappingSegment(float segmentStart[2], float segmentEnd[2], int* ids, const int maxIds) const
|
||||
{
|
||||
// Traverse tree
|
||||
int i = 0;
|
||||
int n = 0;
|
||||
while (i < this->nnodes)
|
||||
{
|
||||
const rcChunkyTriMeshNode* node = &this->nodes[i];
|
||||
const Node* node = &this->nodes[i];
|
||||
const bool overlap = checkOverlapSegment(segmentStart, segmentEnd, node->bmin, node->bmax);
|
||||
const bool isLeafNode = node->i >= 0;
|
||||
|
||||
|
||||
@@ -159,13 +159,13 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath)
|
||||
|
||||
rcCalcBounds(meshLoader->getVerts(), meshLoader->getVertCount(), meshBMin, meshBMax);
|
||||
|
||||
chunkyMesh = new rcChunkyTriMesh;
|
||||
chunkyMesh = new ChunkyTriMesh;
|
||||
if (!chunkyMesh)
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'm_chunkyMesh'.");
|
||||
return false;
|
||||
}
|
||||
if (!rcCreateChunkyTriMesh(meshLoader->getVerts(), meshLoader->getTris(), meshLoader->getTriCount(), 256, chunkyMesh))
|
||||
if (!chunkyMesh->TryPartitionMesh(meshLoader->getVerts(), meshLoader->getTris(), meshLoader->getTriCount(), 256))
|
||||
{
|
||||
ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Failed to build chunky mesh.");
|
||||
return false;
|
||||
@@ -506,7 +506,7 @@ bool InputGeom::raycastMesh(float* src, float* dst, float& tmin)
|
||||
|
||||
for (int i = 0; i < ncid; ++i)
|
||||
{
|
||||
const rcChunkyTriMeshNode& node = chunkyMesh->nodes[cid[i]];
|
||||
const ChunkyTriMesh::Node& node = chunkyMesh->nodes[cid[i]];
|
||||
const int* tris = &chunkyMesh->tris[node.i * 3];
|
||||
const int ntris = node.n;
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ int Sample_TempObstacles::rasterizeTileLayers(const int tileX, const int tileY,
|
||||
|
||||
const float* verts = inputGeometry->getMesh()->getVerts();
|
||||
const int nverts = inputGeometry->getMesh()->getVertCount();
|
||||
const rcChunkyTriMesh* chunkyMesh = inputGeometry->getChunkyMesh();
|
||||
const ChunkyTriMesh* chunkyMesh = inputGeometry->getChunkyMesh();
|
||||
|
||||
// Tile bounds.
|
||||
const float tcs = cfg.tileSize * cfg.cs;
|
||||
@@ -323,7 +323,7 @@ int Sample_TempObstacles::rasterizeTileLayers(const int tileX, const int tileY,
|
||||
|
||||
for (int i = 0; i < ncid; ++i)
|
||||
{
|
||||
const rcChunkyTriMeshNode& node = chunkyMesh->nodes[cid[i]];
|
||||
const ChunkyTriMesh::Node& node = chunkyMesh->nodes[cid[i]];
|
||||
const int* tris = &chunkyMesh->tris[node.i*3];
|
||||
const int ntris = node.n;
|
||||
|
||||
|
||||
@@ -842,7 +842,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(
|
||||
const float* verts = inputGeometry->getMesh()->getVerts();
|
||||
const int numVerts = inputGeometry->getMesh()->getVertCount();
|
||||
const int numTris = inputGeometry->getMesh()->getTriCount();
|
||||
const rcChunkyTriMesh* chunkyMesh = inputGeometry->getChunkyMesh();
|
||||
const ChunkyTriMesh* chunkyMesh = inputGeometry->getChunkyMesh();
|
||||
|
||||
// Init build configuration from GUI
|
||||
memset(&config, 0, sizeof(config));
|
||||
@@ -955,7 +955,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(
|
||||
|
||||
for (int i = 0; i < numOverlappingChunks; ++i)
|
||||
{
|
||||
const rcChunkyTriMeshNode& node = chunkyMesh->nodes[overlappingChunkIndexes[i]];
|
||||
const ChunkyTriMesh::Node& node = chunkyMesh->nodes[overlappingChunkIndexes[i]];
|
||||
const int* nodeTris = &chunkyMesh->tris[node.i * 3];
|
||||
const int numNodeTris = node.n;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user