The raw contours will match the region outlines exactly. The maxError
and maxEdgeLen
parameters control how closely the simplified contours will match the raw contours.
Simplified contours are generated such that the vertices for portals between areas match up. (They are considered mandatory vertices.)
830 const int w = chf.
width;
841 const float pad = borderSize*chf.
cs;
869 for (
int y = 0;
y < h; ++
y)
871 for (
int x = 0;
x < w; ++
x)
876 unsigned char res = 0;
883 for (
int dir = 0; dir < 4; ++dir)
885 unsigned short r = 0;
896 flags[i] = res ^ 0xf;
906 for (
int y = 0;
y < h; ++
y)
908 for (
int x = 0;
x < w; ++
x)
913 if (flags[i] == 0 || flags[i] == 0xf)
918 const unsigned short reg = chf.
spans[i].
reg;
919 if (!reg || (reg & RC_BORDER_REG))
921 const unsigned char area = chf.
areas[i];
924 simplified.resize(0);
938 if (simplified.size()/4 >= 3)
940 if (cset.
nconts >= maxContours)
944 const int oldMax = maxContours;
947 for (
int j = 0; j < cset.
nconts; ++j)
949 newConts[j] = cset.
conts[j];
955 cset.
conts = newConts;
957 ctx->
log(
RC_LOG_WARNING,
"rcBuildContours: Expanding max contours from %d to %d.", oldMax, maxContours);
962 cont->
nverts = simplified.size()/4;
969 memcpy(cont->
verts, &simplified[0],
sizeof(
int)*cont->
nverts*4);
973 for (
int j = 0; j < cont->
nverts; ++j)
975 int* v = &cont->
verts[j*4];
981 cont->
nrverts = verts.size()/4;
988 memcpy(cont->
rverts, &verts[0],
sizeof(
int)*cont->
nrverts*4);
992 for (
int j = 0; j < cont->
nrverts; ++j)
994 int* v = &cont->
rverts[j*4];
1018 for (
int i = 0; i < cset.
nconts; ++i)
1035 ctx->
log(
RC_LOG_ERROR,
"rcBuildContours: Out of memory 'regions' (%d).", nregions);
1048 for (
int i = 0; i < cset.
nconts; ++i)
1054 if (regions[cont.
reg].outline)
1055 ctx->
log(
RC_LOG_ERROR,
"rcBuildContours: Multiple outlines for region %d.", cont.
reg);
1056 regions[cont.
reg].outline = &cont;
1060 regions[cont.
reg].nholes++;
1064 for (
int i = 0; i < nregions; i++)
1066 if (regions[i].nholes > 0)
1068 regions[i].holes = &holes[index];
1069 index += regions[i].nholes;
1070 regions[i].nholes = 0;
1073 for (
int i = 0; i < cset.
nconts; ++i)
1082 for (
int i = 0; i < nregions; i++)
1085 if (!reg.
nholes)
continue;
1096 ctx->
log(
RC_LOG_ERROR,
"rcBuildContours: Bad outline for region %d, contour simplification is likely too aggressive.", i);
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:372
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:308
#define rcAssert
Definition: RecastAssert.h:30
The total time to build the contours. (See: rcBuildContours)
Definition: Recast.h:47
static void simplifyContour(rcIntArray &points, rcIntArray &simplified, const float maxError, const int maxEdgeLen, const int buildFlags)
Definition: RecastContour.cpp:210
int borderSize
The AABB border size used during the build of the field. (See: rcConfig::borderSize) ...
Definition: Recast.h:312
unsigned short maxRegions
The maximum region id of any span within the field.
Definition: Recast.h:314
Represents a span of unobstructed space within a compact heightfield.
Definition: Recast.h:295
int nrverts
The number of vertices in the raw contour.
Definition: Recast.h:361
static int calcAreaOfPolygon2D(const int *verts, const int nverts)
Definition: RecastContour.cpp:454
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
static const int RC_NOT_CONNECTED
Definition: Recast.h:547
unsigned short reg
The id of the region the span belongs to. (Or zero if not in a region.)
Definition: Recast.h:298
int nverts
The number of vertices in the simplified contour.
Definition: Recast.h:359
rcCompactCell * cells
Array of cells. [Size: width*height].
Definition: Recast.h:319
int rcGetDirOffsetY(int dir)
Definition: Recast.h:1048
rcCompactSpan * spans
Array of spans. [Size: spanCount].
Definition: Recast.h:320
int * rverts
Raw contour vertex and connection data. [Size: 4 * nrverts].
Definition: Recast.h:360
int rcGetCon(const rcCompactSpan &s, int dir)
Definition: Recast.h:1028
unsigned int index
Index to the first span in the column.
Definition: Recast.h:290
rcContour * conts
An array of the contours in the set. [Size: nconts].
Definition: Recast.h:370
int height
The height of the set. (Along the z-axis in cell units.)
Definition: Recast.h:377
Provides information on the content of a cell column in a compact heightfield.
Definition: Recast.h:288
The time to trace the boundaries of the contours. (See: rcBuildContours)
Definition: Recast.h:49
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 void walkContour(int x, int y, int i, rcCompactHeightfield &chf, unsigned char *flags, rcIntArray &points)
Definition: RecastContour.cpp:104
Represents a simple, non-overlapping contour in field space.
Definition: Recast.h:356
unsigned int count
Number of spans in the column.
Definition: Recast.h:291
An error log entry.
Definition: Recast.h:31
Definition: RecastAlloc.h:105
static void removeDegenerateSegments(rcIntArray &simplified)
Definition: RecastContour.cpp:580
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
unsigned char area
The area id of the contour.
Definition: Recast.h:363
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
int rcGetDirOffsetX(int dir)
Definition: Recast.h:1038
rcContour * contour
Definition: RecastContour.cpp:652
unsigned char * areas
Array containing area id data. [Size: spanCount].
Definition: Recast.h:322
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:373
G3D::int16 y
Definition: Vector2int16.h:38
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:316
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:307
unsigned short reg
The region id of the contour.
Definition: Recast.h:362
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
Definition: RecastContour.cpp:656
void startTimer(const rcTimerLabel label)
Definition: Recast.h:131
int spanCount
The number of spans in the heightfield.
Definition: Recast.h:309
Memory will persist after a function call.
Definition: RecastAlloc.h:26
rcContourHole * holes
Definition: RecastContour.cpp:659
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:317
Definition: RecastContour.cpp:650
int width
The width of the set. (Along the x-axis in cell units.)
Definition: Recast.h:376
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:318
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
uint8 flags
Definition: DisableMgr.cpp:44
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
G3D::int16 x
Definition: Vector2int16.h:37
void stopTimer(const rcTimerLabel label)
Definition: Recast.h:135
int nholes
Definition: RecastContour.cpp:660
rcContour * outline
Definition: RecastContour.cpp:658
static const unsigned short RC_BORDER_REG
Definition: Recast.h:498
A warning log entry.
Definition: Recast.h:30
A simple dynamic array of integers.
Definition: RecastAlloc.h:61
The time to simplify the contours. (See: rcBuildContours)
Definition: Recast.h:51
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:315
static void mergeRegionHoles(rcContext *ctx, rcContourRegion ®ion)
Definition: RecastContour.cpp:722