| 1 |
// This file contains the detail API documentation for |
| 2 |
// elements defined in the Recast.h. |
| 3 |
|
| 4 |
/** |
| 5 |
|
| 6 |
@defgroup recast Recast |
| 7 |
|
| 8 |
Members in this module are used to create mesh data that is then |
| 9 |
used to create Detour navigation meshes. |
| 10 |
|
| 11 |
The are a large number of possible ways to building navigation mesh data. |
| 12 |
One of the simple piplines is as follows: |
| 13 |
|
| 14 |
-# Prepare the input triangle mesh. |
| 15 |
-# Build a #rcHeightfield. |
| 16 |
-# Build a #rcCompactHeightfield. |
| 17 |
-# Build a #rcContourSet. |
| 18 |
-# Build a #rcPolyMesh. |
| 19 |
-# Build a #rcPolyMeshDetail. |
| 20 |
-# Use the rcPolyMesh and rcPolyMeshDetail to build a Detour navigation mesh |
| 21 |
tile. |
| 22 |
|
| 23 |
The general life-cycle of the main classes is as follows: |
| 24 |
|
| 25 |
-# Allocate the object using the Recast allocator. (E.g. #rcAllocHeightfield) |
| 26 |
-# Initialize or build the object. (E.g. #rcCreateHeightfield) |
| 27 |
-# Update the object as needed. (E.g. #rcRasterizeTriangles) |
| 28 |
-# Use the object as part of the pipeline. |
| 29 |
-# Free the object using the Recast allocator. (E.g. #rcFreeHeightField) |
| 30 |
|
| 31 |
@struct rcConfig |
| 32 |
@par |
| 33 |
|
| 34 |
The is a convenience structure that represents an aggregation of parameters |
| 35 |
used at different stages in the Recast build process. Some |
| 36 |
values are derived during the build process. Not all parameters |
| 37 |
are used for all build processes. |
| 38 |
|
| 39 |
Units are usually in voxels (vx) or world units (wu). The units for voxels, |
| 40 |
grid size, and cell size are all based on the values of #cs and #ch. |
| 41 |
|
| 42 |
In this documentation, the term 'field' refers to heightfield and |
| 43 |
contour data structures that define spacial information using an integer |
| 44 |
grid. |
| 45 |
|
| 46 |
The upper and lower limits for the various parameters often depend on |
| 47 |
the platform's floating point accuraccy as well as interdependencies between |
| 48 |
the values of multiple parameters. See the individual parameter |
| 49 |
documentation for details. |
| 50 |
|
| 51 |
@note First you should decide the size of your agent's logical cylinder. |
| 52 |
If your game world uses meters as units, a reasonable starting point for |
| 53 |
a human-sized agent might be a radius of `0.4` and a height of `2.0`. |
| 54 |
|
| 55 |
@var rcConfig::borderSize |
| 56 |
@par |
| 57 |
|
| 58 |
This value represents the the closest the walkable area of the heightfield |
| 59 |
should come to the xz-plane AABB of the field. It does not have any |
| 60 |
impact on the borders around internal obstructions. |
| 61 |
|
| 62 |
@var rcConfig::tileSize |
| 63 |
@par |
| 64 |
|
| 65 |
This field is only used when building multi-tile meshes. |
| 66 |
|
| 67 |
@var rcConfig::cs |
| 68 |
@par |
| 69 |
|
| 70 |
The voxelization cell size #cs defines the voxel size along both axes of |
| 71 |
the ground plane: x and z in Recast. This value is usually derived from the |
| 72 |
character radius `r`. A recommended starting value for #cs is either `r/2` |
| 73 |
or `r/3`. Smaller values of #cs will increase rasterization resolution and |
| 74 |
navmesh detail, but total generation time will increase exponentially. In |
| 75 |
outdoor environments, `r/2` is often good enough. For indoor scenes with |
| 76 |
tight spaces you might want the extra precision, so a value of `r/3` or |
| 77 |
smaller may give better results. |
| 78 |
|
| 79 |
The initial instinct is to reduce this value to something very close to zero |
| 80 |
to maximize the detail of the generated navmesh. This quickly becomes a case |
| 81 |
of diminishing returns, however. Beyond a certain point there's usually not |
| 82 |
much perceptable difference in the generated navmesh, but huge increases in |
| 83 |
generation time. This hinders your ability to quickly iterate on level |
| 84 |
designs and provides little benefit. The general recommendation here is to |
| 85 |
use as large a value for #cs as you can get away with. |
| 86 |
|
| 87 |
#cs and #ch define voxel/grid/cell size. So their values have significant |
| 88 |
side effects on all parameters defined in voxel units. |
| 89 |
|
| 90 |
The minimum value for this parameter depends on the platform's floating point |
| 91 |
accuracy, with the practical minimum usually around 0.05. |
| 92 |
|
| 93 |
@var rcConfig::ch |
| 94 |
@par |
| 95 |
|
| 96 |
The voxelization cell height #ch is defined separately in order to allow for |
| 97 |
greater precision in height tests. A good starting point for #ch is half the |
| 98 |
#cs value. Smaller #ch values ensure that the navmesh properly connects areas |
| 99 |
that are only separated by a small curb or ditch. If small holes are generated |
| 100 |
in your navmesh around where there are discontinuities in height (for example, |
| 101 |
stairs or curbs), you may want to decrease the cell height value to increase |
| 102 |
the vertical rasterization precision of Recast. |
| 103 |
|
| 104 |
#cs and #ch define voxel/grid/cell size. So their values have significant |
| 105 |
side effects on all parameters defined in voxel units. |
| 106 |
|
| 107 |
The minimum value for this parameter depends on the platform's floating point |
| 108 |
accuracy, with the practical minimum usually around 0.05. |
| 109 |
|
| 110 |
@var rcConfig::walkableSlopeAngle |
| 111 |
@par |
| 112 |
|
| 113 |
The parameter #walkableSlopeAngle is to filter out areas of the world where |
| 114 |
the ground slope would be too steep for an agent to traverse. This value is |
| 115 |
defined as a maximum angle in degrees that the surface normal of a polgyon |
| 116 |
can differ from the world's up vector. This value must be within the range |
| 117 |
`[0, 90]`. |
| 118 |
|
| 119 |
The practical upper limit for this parameter is usually around 85 degrees. |
| 120 |
|
| 121 |
@var rcConfig::walkableHeight |
| 122 |
@par |
| 123 |
|
| 124 |
This value defines the worldspace height `h` of the agent in voxels. Th value |
| 125 |
of #walkableHeight should be calculated as `ceil(h / ch)`. Note this is based |
| 126 |
on #ch not #cs since it's a height value. |
| 127 |
|
| 128 |
Permits detection of overhangs in the source geometry that make the geometry |
| 129 |
below un-walkable. The value is usually set to the maximum agent height. |
| 130 |
|
| 131 |
@var rcConfig::walkableClimb |
| 132 |
@par |
| 133 |
|
| 134 |
The #walkableClimb value defines the maximum height of ledges and steps that |
| 135 |
the agent can walk up. Given a designer-defined `maxClimb` distance in world |
| 136 |
units, the value of #walkableClimb should be calculated as `ceil(maxClimb / ch)`. |
| 137 |
Note that this is using #ch not #cs because it's a height-based value. |
| 138 |
|
| 139 |
Allows the mesh to flow over low lying obstructions such as curbs and |
| 140 |
up/down stairways. The value is usually set to how far up/down an agent can step. |
| 141 |
|
| 142 |
@var rcConfig::walkableRadius |
| 143 |
@par |
| 144 |
|
| 145 |
The parameter #walkableRadius defines the worldspace agent radius `r` in voxels. |
| 146 |
Most often, this value of #walkableRadius should be calculated as `ceil(r / cs)`. |
| 147 |
Note this is based on #cs since the agent radius is always parallel to the ground |
| 148 |
plane. |
| 149 |
|
| 150 |
If the #walkableRadius value is greater than zero, the edges of the navmesh will |
| 151 |
be pushed away from all obstacles by this amount. |
| 152 |
|
| 153 |
A non-zero #walkableRadius allows for much simpler runtime navmesh collision checks. |
| 154 |
The game only needs to check that the center point of the agent is contained within |
| 155 |
a navmesh polygon. Without this erosion, runtime navigation checks need to collide |
| 156 |
the geometric projection of the agent's logical cylinder onto the navmesh with the |
| 157 |
boundary edges of the navmesh polygons. |
| 158 |
|
| 159 |
In general, this is the closest any part of the final mesh should get to an |
| 160 |
obstruction in the source geometry. It is usually set to the maximum |
| 161 |
agent radius. |
| 162 |
|
| 163 |
If you want to have tight-fitting navmesh, or want to reuse the same navmesh for |
| 164 |
multiple agents with differing radii, you can use a `walkableRadius` value of zero. |
| 165 |
Be advised though that you will need to perform your own collisions with the navmesh |
| 166 |
edges, and odd edge cases issues in the mesh generation can potentially occur. For |
| 167 |
these reasons, specifying a radius of zero is allowed but is not recommended. |
| 168 |
|
| 169 |
@var rcConfig::maxEdgeLen |
| 170 |
@par |
| 171 |
|
| 172 |
In certain cases, long outer edges may decrease the quality of the resulting |
| 173 |
triangulation, creating very long thin triangles. This can sometimes be |
| 174 |
remedied by limiting the maximum edge length, causing the problematic long |
| 175 |
edges to be broken up into smaller segments. |
| 176 |
|
| 177 |
The parameter #maxEdgeLen defines the maximum edge length and is defined in |
| 178 |
terms of voxels. A good value for #maxEdgeLen is something like |
| 179 |
`walkableRadius * 8`. A good way to adjust this value is to first set it really |
| 180 |
high and see if your data creates long edges. If it does, decrease #maxEdgeLen |
| 181 |
until you find the largest value which improves the resulting tesselation. |
| 182 |
|
| 183 |
Extra vertices will be inserted as needed to keep contour edges below this |
| 184 |
length. A value of zero effectively disables this feature. |
| 185 |
|
| 186 |
@var rcConfig::maxSimplificationError |
| 187 |
@par |
| 188 |
|
| 189 |
When the rasterized areas are converted back to a vectorized representation, |
| 190 |
the #maxSimplificationError describes how loosely the simplification is done. |
| 191 |
The simplification process uses the |
| 192 |
<a href="https://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm">Ramer–Douglas-Peucker algorithm</a>, |
| 193 |
and this value describes the max deviation in voxels. |
| 194 |
|
| 195 |
Good values for #maxSimplificationError are in the range `[1.1, 1.5]`. |
| 196 |
A value of `1.3` is a good starting point and usually yields good results. |
| 197 |
If the value is less than `1.1`, some sawtoothing starts to appear at the |
| 198 |
generated edges. If the value is more than `1.5`, the mesh simplification |
| 199 |
starts to cut some corners it shouldn't. |
| 200 |
|
| 201 |
The effect of this parameter only applies to the xz-plane. |
| 202 |
|
| 203 |
@var rcConfig::minRegionArea |
| 204 |
@par |
| 205 |
|
| 206 |
Watershed partitioning is really prone to noise in the input distance field. |
| 207 |
In order to get nicer areas, the areas are merged and small disconnected areas |
| 208 |
are removed after the water shed partitioning. The parameter #minRegionArea |
| 209 |
describes the minimum isolated region size that is still kept. A region is |
| 210 |
removed if the number of voxels in the region is less than the square of |
| 211 |
#minRegionArea. |
| 212 |
|
| 213 |
Any regions that are smaller than this area will be marked as unwalkable. |
| 214 |
This is useful in removing useless regions that can sometimes form on |
| 215 |
geometry such as table tops, box tops, etc. |
| 216 |
|
| 217 |
@var rcConfig::maxVertsPerPoly |
| 218 |
@par |
| 219 |
|
| 220 |
If the mesh data is to be used to construct a Detour navigation mesh, then the upper limit |
| 221 |
is limited to <= #DT_VERTS_PER_POLYGON. |
| 222 |
|
| 223 |
@var rcConfig::mergeRegionArea |
| 224 |
@par |
| 225 |
|
| 226 |
The triangulation process works best with small, localized voxel regions. |
| 227 |
The parameter #mergeRegionArea controls the maximum voxel area of a region |
| 228 |
that is allowed to be merged with another region. If you see small patches |
| 229 |
missing here and there, you could lower the #minRegionArea value. |
| 230 |
|
| 231 |
@struct rcHeightfield |
| 232 |
@par |
| 233 |
|
| 234 |
The grid of a heightfield is layed out on the xz-plane based on the |
| 235 |
value of #cs. Spans exist within the grid columns with the span |
| 236 |
min/max values at increments of #ch from the base of the grid. The smallest |
| 237 |
possible span size is <tt>(#cs width) * (#cs depth) * (#ch height)</tt>. (Which is a single voxel.) |
| 238 |
|
| 239 |
The standard process for buidling a heightfield is to allocate it using |
| 240 |
#rcAllocHeightfield, initialize it using #rcCreateHeightfield, then |
| 241 |
add spans using the various helper functions such as #rcRasterizeTriangle. |
| 242 |
|
| 243 |
Building a heightfield is one of the first steps in creating a polygon mesh |
| 244 |
from source geometry. After it is populated, it is used to build a |
| 245 |
rcCompactHeightfield. |
| 246 |
|
| 247 |
Example of iterating the spans in a heightfield: |
| 248 |
@code |
| 249 |
// Where hf is a reference to an heightfield object. |
| 250 |
|
| 251 |
const float* orig = hf.bmin; |
| 252 |
const float cs = hf.cs; |
| 253 |
const float ch = hf.ch; |
| 254 |
|
| 255 |
const int w = hf.width; |
| 256 |
const int h = hf.height; |
| 257 |
|
| 258 |
for (int y = 0; y < h; ++y) |
| 259 |
{ |
| 260 |
for (int x = 0; x < w; ++x) |
| 261 |
{ |
| 262 |
// Deriving the minimum corner of the grid location. |
| 263 |
float fx = orig[0] + x*cs; |
| 264 |
float fz = orig[2] + y*cs; |
| 265 |
// The base span in the column. (May be null.) |
| 266 |
const rcSpan* s = hf.spans[x + y*w]; |
| 267 |
while (s) |
| 268 |
{ |
| 269 |
// Detriving the minium and maximum world position of the span. |
| 270 |
float fymin = orig[1]+s->smin*ch; |
| 271 |
float fymax = orig[1] + s->smax*ch; |
| 272 |
// Do other things with the span before moving up the column. |
| 273 |
s = s->next; |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
@endcode |
| 278 |
|
| 279 |
@see rcAllocHeightfield, rcFreeHeightField, rcCreateHeightfield |
| 280 |
|
| 281 |
@struct rcCompactCell |
| 282 |
@par |
| 283 |
|
| 284 |
See the rcCompactHeightfield documentation for an example of how compact cells |
| 285 |
are used to iterate the heightfield. |
| 286 |
|
| 287 |
Useful instances of this type can only by obtained from a #rcCompactHeightfield object. |
| 288 |
|
| 289 |
@see rcCompactHeightfield |
| 290 |
|
| 291 |
@struct rcCompactSpan |
| 292 |
@par |
| 293 |
|
| 294 |
The span represents open, unobstructed space within a compact heightfield column. |
| 295 |
See the rcCompactHeightfield documentation for an example of iterating spans and searching |
| 296 |
span connections. |
| 297 |
|
| 298 |
Useful instances of this type can only by obtained from a #rcCompactHeightfield object. |
| 299 |
|
| 300 |
@see rcCompactHeightfield |
| 301 |
|
| 302 |
|
| 303 |
@struct rcCompactHeightfield |
| 304 |
@par |
| 305 |
|
| 306 |
For this type of heightfield, the spans represent the open (unobstructed) |
| 307 |
space above the solid surfaces of a voxel field. It is usually created from |
| 308 |
a #rcHeightfield object. Data is stored in a compact, efficient manner, |
| 309 |
but the structure is not condusive to adding and removing spans. |
| 310 |
|
| 311 |
The standard process for buidling a compact heightfield is to allocate it |
| 312 |
using #rcAllocCompactHeightfield, build it using #rcBuildCompactHeightfield, |
| 313 |
then run it through the various helper functions to generate neighbor |
| 314 |
and region data. |
| 315 |
|
| 316 |
Connected neighbor spans form non-overlapping surfaces. When neighbor |
| 317 |
information is generated, spans will include data that can be used to |
| 318 |
locate axis-neighbors. Axis-neighbors are connected |
| 319 |
spans that are offset from the current cell column as follows: |
| 320 |
<pre> |
| 321 |
Direction 0 = (-1, 0) |
| 322 |
Direction 1 = (0, 1) |
| 323 |
Direction 2 = (1, 0) |
| 324 |
Direction 3 = (0, -1) |
| 325 |
</pre> |
| 326 |
|
| 327 |
Example of iterating and inspecting spans, including connected neighbors: |
| 328 |
|
| 329 |
@code |
| 330 |
// Where chf is an instance of a rcCompactHeightfield. |
| 331 |
|
| 332 |
const float cs = chf.cs; |
| 333 |
const float ch = chf.ch; |
| 334 |
|
| 335 |
for (int y = 0; y < chf.height; ++y) |
| 336 |
{ |
| 337 |
for (int x = 0; x < chf.width; ++x) |
| 338 |
{ |
| 339 |
// Deriving the minimum corner of the grid location. |
| 340 |
const float fx = chf.bmin[0] + x*cs; |
| 341 |
const float fz = chf.bmin[2] + y*cs; |
| 342 |
|
| 343 |
// Get the cell for the grid location then iterate |
| 344 |
// up the column. |
| 345 |
const rcCompactCell& c = chf.cells[x+y*chf.width]; |
| 346 |
for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i) |
| 347 |
{ |
| 348 |
const rcCompactSpan& s = chf.spans[i]; |
| 349 |
|
| 350 |
Deriving the minimum (floor) of the span. |
| 351 |
const float fy = chf.bmin[1] + (s.y+1)*ch; |
| 352 |
|
| 353 |
// Testing the area assignment of the span. |
| 354 |
if (chf.areas[i] == RC_WALKABLE_AREA) |
| 355 |
{ |
| 356 |
// The span is in the default 'walkable area'. |
| 357 |
} |
| 358 |
else if (chf.areas[i] == RC_NULL_AREA) |
| 359 |
{ |
| 360 |
// The surface is not considered walkable. |
| 361 |
// E.g. It was filtered out during the build processes. |
| 362 |
} |
| 363 |
else |
| 364 |
{ |
| 365 |
// Do something. (Only applicable for custom build |
| 366 |
// build processes.) |
| 367 |
} |
| 368 |
|
| 369 |
// Iterating the connected axis-neighbor spans. |
| 370 |
for (int dir = 0; dir < 4; ++dir) |
| 371 |
{ |
| 372 |
if (rcGetCon(s, dir) != RC_NOT_CONNECTED) |
| 373 |
{ |
| 374 |
// There is a neighbor in this direction. |
| 375 |
const int nx = x + rcGetDirOffsetX(dir); |
| 376 |
const int ny = y + rcGetDirOffsetY(dir); |
| 377 |
const int ni = (int)chf.cells[nx+ny*w].index + rcGetCon(s, 0); |
| 378 |
const rcCompactSpan& ns = chf.spans[ni]; |
| 379 |
// Do something with the neighbor span. |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
@endcode |
| 386 |
|
| 387 |
@see rcAllocCompactHeightfield, rcFreeCompactHeightfield, rcBuildCompactHeightfield |
| 388 |
|
| 389 |
@struct rcContour |
| 390 |
@par |
| 391 |
|
| 392 |
A contour only exists within the context of a #rcContourSet object. |
| 393 |
|
| 394 |
While the height of the contour's border may vary, the contour will always |
| 395 |
form a simple polygon when projected onto the xz-plane. |
| 396 |
|
| 397 |
Example of converting vertices into world space: |
| 398 |
|
| 399 |
@code |
| 400 |
// Where cset is the rcContourSet object to which the contour belongs. |
| 401 |
float worldX = cset.bmin[0] + vertX * cset.cs; |
| 402 |
float worldY = cset.bmin[1] + vertY * cset.ch; |
| 403 |
float worldZ = cset.bmin[2] + vertZ * cset.cs; |
| 404 |
@endcode |
| 405 |
|
| 406 |
@see rcContourSet |
| 407 |
|
| 408 |
@var rcContour::verts |
| 409 |
@par |
| 410 |
|
| 411 |
The simplified contour is a version of the raw contour with all |
| 412 |
'unnecessary' vertices removed. Whether a vertex is |
| 413 |
considered unnecessary depends on the contour build process. |
| 414 |
|
| 415 |
The data format is as follows: (x, y, z, r) * #nverts |
| 416 |
|
| 417 |
A contour edge is formed by the current and next vertex. The r-value |
| 418 |
represents region and connection information for the edge. For example: |
| 419 |
|
| 420 |
@code |
| 421 |
int r = verts[i*4+3]; |
| 422 |
|
| 423 |
int regionId = r & RC_CONTOUR_REG_MASK; |
| 424 |
|
| 425 |
if (r & RC_BORDER_VERTEX) |
| 426 |
{ |
| 427 |
// The edge represents a solid border. |
| 428 |
} |
| 429 |
|
| 430 |
if (r & RC_AREA_BORDER) |
| 431 |
{ |
| 432 |
// The edge represents a transition between different areas. |
| 433 |
} |
| 434 |
@endcode |
| 435 |
|
| 436 |
@var rcContour::rverts |
| 437 |
@par |
| 438 |
|
| 439 |
See #verts for information on element layout. |
| 440 |
|
| 441 |
@struct rcContourSet |
| 442 |
@par |
| 443 |
|
| 444 |
All contours within the set share the minimum bounds and cell sizes of the set. |
| 445 |
|
| 446 |
The standard process for building a contour set is to allocate it |
| 447 |
using #rcAllocContourSet, then initialize it using #rcBuildContours. |
| 448 |
|
| 449 |
@see rcAllocContourSet, rcFreeContourSet, rcBuildContours |
| 450 |
|
| 451 |
@struct rcPolyMesh |
| 452 |
@par |
| 453 |
|
| 454 |
A mesh of potentially overlapping convex polygons of between three |
| 455 |
and #nvp vertices. The mesh exists within the context of an axis-aligned |
| 456 |
bounding box (AABB) with vertices laid out in an evenly spaced grid, based |
| 457 |
on the values of #cs and #ch. |
| 458 |
|
| 459 |
The standard process for building a contour set is to allocate it using |
| 460 |
#rcAllocPolyMesh, the initialize it using #rcBuildPolyMesh |
| 461 |
|
| 462 |
Example of iterating the polygons: |
| 463 |
|
| 464 |
@code |
| 465 |
// Where mesh is a reference to a rcPolyMesh object. |
| 466 |
|
| 467 |
const int nvp = mesh.nvp; |
| 468 |
const float cs = mesh.cs; |
| 469 |
const float ch = mesh.ch; |
| 470 |
const float* orig = mesh.bmin; |
| 471 |
|
| 472 |
for (int i = 0; i < mesh.npolys; ++i) |
| 473 |
{ |
| 474 |
const unsigned short* p = &mesh.polys[i*nvp*2]; |
| 475 |
|
| 476 |
// Iterate the vertices. |
| 477 |
unsigned short vi[3]; // The vertex indices. |
| 478 |
for (int j = 0; j < nvp; ++j) |
| 479 |
{ |
| 480 |
if (p[j] == RC_MESH_NULL_IDX) |
| 481 |
break; // End of vertices. |
| 482 |
|
| 483 |
if (p[j + nvp] == RC_MESH_NULL_IDX) |
| 484 |
{ |
| 485 |
// The edge beginning with this vertex is a solid border. |
| 486 |
} |
| 487 |
else |
| 488 |
{ |
| 489 |
// The edge beginning with this vertex connects to |
| 490 |
// polygon p[j + nvp]. |
| 491 |
} |
| 492 |
|
| 493 |
// Convert to world space. |
| 494 |
const unsigned short* v = &mesh.verts[p[j]*3]; |
| 495 |
const float x = orig[0] + v[0]*cs; |
| 496 |
const float y = orig[1] + v[1]*ch; |
| 497 |
const float z = orig[2] + v[2]*cs; |
| 498 |
// Do something with the vertices. |
| 499 |
} |
| 500 |
} |
| 501 |
@endcode |
| 502 |
|
| 503 |
@see rcAllocPolyMesh, rcFreePolyMesh, rcBuildPolyMesh |
| 504 |
|
| 505 |
@var rcPolyMesh::verts |
| 506 |
@par |
| 507 |
|
| 508 |
The values of #bmin ,#cs, and #ch are used to convert vertex coordinates |
| 509 |
to world space as follows: |
| 510 |
|
| 511 |
@code |
| 512 |
float worldX = bmin[0] + verts[i*3+0] * cs |
| 513 |
float worldY = bmin[1] + verts[i*3+1] * ch |
| 514 |
float worldZ = bmin[2] + verts[i*3+2] * cs |
| 515 |
@endcode |
| 516 |
|
| 517 |
@var rcPolyMesh::polys |
| 518 |
@par |
| 519 |
|
| 520 |
Each entry is <tt>2 * #nvp</tt> in length. The first half of the entry |
| 521 |
contains the indices of the polygon. The first instance of #RC_MESH_NULL_IDX |
| 522 |
indicates the end of the indices for the entry. The second half contains |
| 523 |
indices to neighbor polygons. A value of #RC_MESH_NULL_IDX indicates no |
| 524 |
connection for the associated edge. (I.e. The edge is a solid border.) |
| 525 |
|
| 526 |
For example: |
| 527 |
<pre> |
| 528 |
nvp = 6 |
| 529 |
For the entry: (1, 3, 4, 8, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX, |
| 530 |
18, RC_MESH_NULL_IDX , 21, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX) |
| 531 |
|
| 532 |
(1, 3, 4, 8) defines a polygon with 4 vertices. |
| 533 |
Edge 1->3 is shared with polygon 18. |
| 534 |
Edge 4->8 is shared with polygon 21. |
| 535 |
Edges 3->4 and 4->8 are border edges not shared with any other polygon. |
| 536 |
</pre> |
| 537 |
|
| 538 |
@var rcPolyMesh::areas |
| 539 |
@par |
| 540 |
|
| 541 |
The standard build process assigns the value of #RC_WALKABLE_AREA to all walkable polygons. |
| 542 |
This value can then be changed to meet user requirements. |
| 543 |
|
| 544 |
@struct rcPolyMeshDetail |
| 545 |
@par |
| 546 |
|
| 547 |
The detail mesh is made up of triangle sub-meshes that provide extra |
| 548 |
height detail for each polygon in its assoicated polygon mesh. |
| 549 |
|
| 550 |
The standard process for building a detail mesh is to allocate it |
| 551 |
using #rcAllocPolyMeshDetail, then build it using #rcBuildPolyMeshDetail. |
| 552 |
|
| 553 |
See the individual field definitions for details realted to the structure |
| 554 |
the mesh. |
| 555 |
|
| 556 |
@see rcAllocPolyMeshDetail, rcFreePolyMeshDetail, rcBuildPolyMeshDetail, rcPolyMesh |
| 557 |
|
| 558 |
@var rcPolyMeshDetail::meshes |
| 559 |
@par |
| 560 |
|
| 561 |
[(baseVertIndex, vertCount, baseTriIndex, triCount) * #nmeshes] |
| 562 |
|
| 563 |
Maximum number of vertices per sub-mesh: 127<br/> |
| 564 |
Maximum number of triangles per sub-mesh: 255 |
| 565 |
|
| 566 |
The sub-meshes are stored in the same order as the polygons from the |
| 567 |
rcPolyMesh they represent. E.g. rcPolyMeshDetail sub-mesh 5 is associated |
| 568 |
with #rcPolyMesh polygon 5. |
| 569 |
|
| 570 |
Example of iterating the triangles in a sub-mesh. |
| 571 |
|
| 572 |
@code |
| 573 |
// Where dmesh is a reference to a rcPolyMeshDetail object. |
| 574 |
|
| 575 |
// Iterate the sub-meshes. (One for each source polygon.) |
| 576 |
for (int i = 0; i < dmesh.nmeshes; ++i) |
| 577 |
{ |
| 578 |
const unsigned int* meshDef = &dmesh.meshes[i*4]; |
| 579 |
const unsigned int baseVerts = meshDef[0]; |
| 580 |
const unsigned int baseTri = meshDef[2]; |
| 581 |
const int ntris = (int)meshDef[3]; |
| 582 |
|
| 583 |
const float* verts = &dmesh.verts[baseVerts*3]; |
| 584 |
const unsigned char* tris = &dmesh.tris[baseTri*4]; |
| 585 |
|
| 586 |
// Iterate the sub-mesh's triangles. |
| 587 |
for (int j = 0; j < ntris; ++j) |
| 588 |
{ |
| 589 |
const float x = verts[tris[j*4+0]*3]; |
| 590 |
const float y = verts[tris[j*4+1]*3]; |
| 591 |
const float z = verts[tris[j*4+2]*3]; |
| 592 |
// Do something with the vertex. |
| 593 |
} |
| 594 |
} |
| 595 |
@endcode |
| 596 |
|
| 597 |
@var rcPolyMeshDetail::verts |
| 598 |
@par |
| 599 |
|
| 600 |
[(x, y, z) * #nverts] |
| 601 |
|
| 602 |
The vertices are grouped by sub-mesh and will contain duplicates since |
| 603 |
each sub-mesh is independently defined. |
| 604 |
|
| 605 |
The first group of vertices for each sub-mesh are in the same order as |
| 606 |
the vertices for the sub-mesh's associated PolyMesh polygon. These |
| 607 |
vertices are followed by any additional detail vertices. So it the |
| 608 |
associated polygon has 5 vertices, the sub-mesh will have a minimum |
| 609 |
of 5 vertices and the first 5 vertices will be equivalent to the 5 |
| 610 |
polygon vertices. |
| 611 |
|
| 612 |
@var rcPolyMeshDetail::tris |
| 613 |
@par |
| 614 |
|
| 615 |
[(vertIndexA, vertIndexB, vertIndexC, flags) * #ntris] |
| 616 |
|
| 617 |
The triangles are grouped by sub-mesh. |
| 618 |
|
| 619 |
<b>Vertex Indices</b> |
| 620 |
|
| 621 |
The vertex indices in the triangle array are local to the sub-mesh, not global. |
| 622 |
To translate into an global index in the vertices array, the values must be |
| 623 |
offset by the sub-mesh's base vertex index. |
| 624 |
|
| 625 |
Example: If the baseVertexIndex for the sub-mesh is 5 and the triangle entry |
| 626 |
is (4, 8, 7, 0), then the actual indices for the vertices are (4 + 5, 8 + 5, 7 + 5). |
| 627 |
|
| 628 |
@b Flags |
| 629 |
|
| 630 |
The flags entry indicates which edges are internal and which are external to |
| 631 |
the sub-mesh. Internal edges connect to other triangles within the same sub-mesh. |
| 632 |
External edges represent portals to other sub-meshes or the null region. |
| 633 |
|
| 634 |
Each flag is stored in a 2-bit position. Where position 0 is the lowest 2-bits |
| 635 |
and position 4 is the highest 2-bits: |
| 636 |
|
| 637 |
<tt> |
| 638 |
Position 0: Edge AB (>> 0)<br/> |
| 639 |
Position 1: Edge BC (>> 2)<br/> |
| 640 |
Position 2: Edge CA (>> 4)<br/> |
| 641 |
Position 4: Unused<br/> |
| 642 |
</tt> |
| 643 |
|
| 644 |
Testing can be performed as follows: |
| 645 |
|
| 646 |
@code |
| 647 |
if (((flags >> 2) & 0x3) != 0) |
| 648 |
{ |
| 649 |
// Edge BC is an external edge. |
| 650 |
} |
| 651 |
@endcode |
| 652 |
|
| 653 |
@fn void rcSetCon(rcCompactSpan &s, int dir, int i) |
| 654 |
@par |
| 655 |
|
| 656 |
This function is used by the build process. It is rarely of use to end users. |
| 657 |
|
| 658 |
@see #rcCompactHeightfield, #rcCompactSpan |
| 659 |
|
| 660 |
@fn int rcGetCon(const rcCompactSpan &s, int dir) |
| 661 |
@par |
| 662 |
|
| 663 |
Can be used to locate neighbor spans in a compact heightfield. See the |
| 664 |
#rcCompactHeightfield documentation for details on its use. |
| 665 |
|
| 666 |
@see #rcCompactHeightfield, #rcCompactSpan |
| 667 |
|
| 668 |
@fn int rcGetDirOffsetX(int dir) |
| 669 |
@par |
| 670 |
|
| 671 |
The value of @p dir will be automatically wrapped. So a value of 6 will be interpreted as 2. |
| 672 |
|
| 673 |
See the #rcCompactHeightfield documentation for usage details. |
| 674 |
|
| 675 |
@fn int rcGetDirOffsetY(int dir) |
| 676 |
@par |
| 677 |
|
| 678 |
The value of @p dir will be automatically wrapped. So a value of 6 will be interpreted as 2. |
| 679 |
|
| 680 |
See the #rcCompactHeightfield documentation for usage details. |
| 681 |
|
| 682 |
*/ |