996 int maxVertsPerCont = 0;
997 for (
int i = 0; i < cset.
nconts; ++i)
1006 if (maxVertices >= 0xfffe)
1008 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Too many vertices %d.", maxVertices);
1015 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'vflags' (%d).", maxVertices);
1018 memset(vflags, 0, maxVertices);
1023 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'mesh.verts' (%d).", maxVertices);
1029 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'mesh.polys' (%d).", maxTris*nvp*2);
1035 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'mesh.regs' (%d).", maxTris);
1041 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'mesh.areas' (%d).", maxTris);
1050 memset(mesh.
verts, 0,
sizeof(
unsigned short)*maxVertices*3);
1051 memset(mesh.
polys, 0xff,
sizeof(
unsigned short)*maxTris*nvp*2);
1052 memset(mesh.
regs, 0,
sizeof(
unsigned short)*maxTris);
1053 memset(mesh.
areas, 0,
sizeof(
unsigned char)*maxTris);
1058 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'nextVert' (%d).", maxVertices);
1061 memset(nextVert, 0,
sizeof(
int)*maxVertices);
1075 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'indices' (%d).", maxVertsPerCont);
1081 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'tris' (%d).", maxVertsPerCont*3);
1087 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Out of memory 'polys' (%d).", maxVertsPerCont*nvp);
1090 unsigned short* tmpPoly = &polys[maxVertsPerCont*nvp];
1092 for (
int i = 0; i < cset.
nconts; ++i)
1101 for (
int j = 0; j < cont.
nverts; ++j)
1123 for (
int j = 0; j < cont.
nverts; ++j)
1125 const int* v = &cont.
verts[j*4];
1126 indices[j] =
addVertex((
unsigned short)v[0], (
unsigned short)v[1], (
unsigned short)v[2],
1131 vflags[indices[j]] = 1;
1137 memset(polys, 0xff, maxVertsPerCont*nvp*
sizeof(
unsigned short));
1138 for (
int j = 0; j < ntris; ++j)
1140 int* t = &tris[j*3];
1141 if (t[0] != t[1] && t[0] != t[2] && t[1] != t[2])
1143 polys[npolys*nvp+0] = (
unsigned short)indices[t[0]];
1144 polys[npolys*nvp+1] = (
unsigned short)indices[t[1]];
1145 polys[npolys*nvp+2] = (
unsigned short)indices[t[2]];
1158 int bestMergeVal = 0;
1159 int bestPa = 0, bestPb = 0, bestEa = 0, bestEb = 0;
1161 for (
int j = 0; j < npolys-1; ++j)
1163 unsigned short* pj = &polys[j*nvp];
1164 for (
int k = j+1; k < npolys; ++k)
1166 unsigned short* pk = &polys[k*nvp];
1169 if (v > bestMergeVal)
1180 if (bestMergeVal > 0)
1183 unsigned short* pa = &polys[bestPa*nvp];
1184 unsigned short*
pb = &polys[bestPb*nvp];
1185 mergePolys(pa, pb, bestEa, bestEb, tmpPoly, nvp);
1186 unsigned short* lastPoly = &polys[(npolys-1)*nvp];
1188 memcpy(pb, lastPoly,
sizeof(
unsigned short)*nvp);
1200 for (
int j = 0; j < npolys; ++j)
1202 unsigned short* p = &mesh.
polys[mesh.
npolys*nvp*2];
1203 unsigned short* q = &polys[j*nvp];
1204 for (
int k = 0; k < nvp; ++k)
1209 if (mesh.
npolys > maxTris)
1219 for (
int i = 0; i < mesh.
nverts; ++i)
1225 if (!
removeVertex(ctx, mesh, (
unsigned short)i, maxTris))
1228 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: Failed to remove edge vertex %d.", i);
1234 for (
int j = i; j < mesh.
nverts; ++j)
1235 vflags[j] = vflags[j+1];
1250 const int w = cset.
width;
1251 const int h = cset.
height;
1252 for (
int i = 0; i < mesh.
npolys; ++i)
1254 unsigned short* p = &mesh.
polys[i*2*nvp];
1255 for (
int j = 0; j < nvp; ++j)
1263 const unsigned short* va = &mesh.
verts[p[j]*3];
1264 const unsigned short* vb = &mesh.
verts[p[nj]*3];
1266 if ((
int)va[0] == 0 && (
int)vb[0] == 0)
1267 p[nvp+j] = 0x8000 | 0;
1268 else if ((
int)va[2] == h && (
int)vb[2] == h)
1269 p[nvp+j] = 0x8000 | 1;
1270 else if ((
int)va[0] == w && (
int)vb[0] == w)
1271 p[nvp+j] = 0x8000 | 2;
1272 else if ((
int)va[2] == 0 && (
int)vb[2] == 0)
1273 p[nvp+j] = 0x8000 | 3;
1285 memset(mesh.
flags, 0,
sizeof(
unsigned short) * mesh.
npolys);
1287 if (mesh.
nverts > 0xffff)
1289 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: The resulting mesh has too many vertices %d (max %d). Data can be corrupted.", mesh.
nverts, 0xffff);
1291 if (mesh.
npolys > 0xffff)
1293 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMesh: The resulting mesh has too many polygons %d (max %d). Data can be corrupted.", mesh.
npolys, 0xffff);
unsigned char * areas
The area id assigned to each polygon. [Length: maxpolys].
Definition: Recast.h:389
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:372
#define rcAssert
Definition: RecastAssert.h:30
int nverts
The number of vertices.
Definition: Recast.h:390
static void mergePolys(unsigned short *pa, unsigned short *pb, int ea, int eb, unsigned short *tmp, const int nvp)
Definition: RecastMesh.cpp:531
int nverts
The number of vertices in the simplified contour.
Definition: Recast.h:359
unsigned short * verts
The mesh vertices. [Form: (x, y, z) * nverts].
Definition: Recast.h:385
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:397
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:395
rcContour * conts
An array of the contours in the set. [Size: nconts].
Definition: Recast.h:370
Definition: BnetFileGenerator.h:49
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:396
int height
The height of the set. (Along the z-axis in cell units.)
Definition: Recast.h:377
static bool canRemoveVertex(rcContext *ctx, rcPolyMesh &mesh, const unsigned short rem)
Definition: RecastMesh.cpp:564
int nconts
The number of contours in the set.
Definition: Recast.h:371
int * verts
Simplified contour vertex and connection data. [Size: 4 * nverts].
Definition: Recast.h:358
static unsigned short addVertex(unsigned short x, unsigned short y, unsigned short z, unsigned short *verts, int *firstVert, int *nextVert, int &nv)
Definition: RecastMesh.cpp:137
Represents a simple, non-overlapping contour in field space.
Definition: Recast.h:356
An error log entry.
Definition: Recast.h:31
Definition: RecastAlloc.h:105
static int triangulate(int n, const int *verts, int *indices, int *tris)
Definition: RecastMesh.cpp:339
unsigned char area
The area id of the contour.
Definition: Recast.h:363
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
static bool removeVertex(rcContext *ctx, rcPolyMesh &mesh, const unsigned short rem, const int maxTris)
Definition: RecastMesh.cpp:666
static const unsigned short RC_MESH_NULL_IDX
Definition: Recast.h:533
static const int RC_BORDER_VERTEX
Definition: Recast.h:507
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:373
unsigned short reg
The region id of the contour.
Definition: Recast.h:362
static int getPolyMergeValue(unsigned short *pa, unsigned short *pb, const unsigned short *verts, int &ea, int &eb, const int nvp)
Definition: RecastMesh.cpp:467
void rcVcopy(float *dest, const float *v)
Definition: Recast.h:677
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:374
void startTimer(const rcTimerLabel label)
Definition: Recast.h:131
static bool buildMeshAdjacency(unsigned short *polys, const int npolys, const int nverts, const int vertsPerPoly)
Definition: RecastMesh.cpp:34
Memory will persist after a function call.
Definition: RecastAlloc.h:26
unsigned short * flags
The user defined flags for each polygon. [Length: maxpolys].
Definition: Recast.h:388
int width
The width of the set. (Along the x-axis in cell units.)
Definition: Recast.h:376
The time to build the polygon mesh. (See: rcBuildPolyMesh)
Definition: Recast.h:61
int borderSize
The AABB border size used to generate the source data from which the mesh was derived.
Definition: Recast.h:398
Memory used temporarily within a function.
Definition: RecastAlloc.h:27
T rcMax(T a, T b)
Definition: Recast.h:572
void log(const rcLogCategory category, const char *format,...)
Definition: Recast.cpp:55
static const int VERTEX_BUCKET_COUNT
Definition: RecastMesh.cpp:126
int borderSize
The AABB border size used to generate the source data from which the contours were derived...
Definition: Recast.h:378
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:375
int npolys
The number of polygons.
Definition: Recast.h:391
void stopTimer(const rcTimerLabel label)
Definition: Recast.h:135
int maxpolys
The number of allocated polygons.
Definition: Recast.h:392
unsigned short * regs
The region id assigned to each polygon. [Length: maxpolys].
Definition: Recast.h:387
A warning log entry.
Definition: Recast.h:30
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:394
int nvp
The maximum number of vertices per polygon.
Definition: Recast.h:393
unsigned short * polys
Polygon and neighbor data. [Length: maxpolys * 2 * nvp].
Definition: Recast.h:386