Recast Navigation
Navigation-mesh Toolset for Games
rcPolyMesh Struct Reference

Represents a polygon mesh suitable for use in building a navigation mesh. More...

#include <Recast.h>

Public Member Functions

 rcPolyMesh ()
 
 ~rcPolyMesh ()
 

Public Attributes

unsigned short * verts
 The mesh vertices. [Form: (x, y, z) * nverts]. More...
 
unsigned short * polys
 Polygon and neighbor data. [Length: maxpolys * 2 * nvp]. More...
 
unsigned short * regs
 The region id assigned to each polygon. [Length: maxpolys]. More...
 
unsigned short * flags
 The user defined flags for each polygon. [Length: maxpolys]. More...
 
unsigned char * areas
 The area id assigned to each polygon. [Length: maxpolys]. More...
 
int nverts
 The number of vertices. More...
 
int npolys
 The number of polygons. More...
 
int maxpolys
 The number of allocated polygons. More...
 
int nvp
 The maximum number of vertices per polygon. More...
 
float bmin [3]
 The minimum bounds in world space. [(x, y, z)]. More...
 
float bmax [3]
 The maximum bounds in world space. [(x, y, z)]. More...
 
float cs
 The size of each cell. (On the xz-plane.) More...
 
float ch
 The height of each cell. (The minimum increment along the y-axis.) More...
 
int borderSize
 The AABB border size used to generate the source data from which the mesh was derived. More...
 
float maxEdgeError
 The max error of the polygon edges in the mesh. More...
 

Description

Represents a polygon mesh suitable for use in building a navigation mesh.

A mesh of potentially overlapping convex polygons of between three and nvp vertices. The mesh exists within the context of an axis-aligned bounding box (AABB) with vertices laid out in an evenly spaced grid, based on the values of cs and ch.

The standard process for building a contour set is to allocate it using rcAllocPolyMesh, the initialize it using rcBuildPolyMesh

Example of iterating the polygons:

// Where mesh is a reference to a rcPolyMesh object.
const int nvp = mesh.nvp;
const float cs = mesh.cs;
const float ch = mesh.ch;
const float* orig = mesh.bmin;
for (int i = 0; i < mesh.npolys; ++i)
{
const unsigned short* p = &mesh.polys[i*nvp*2];
// Iterate the vertices.
unsigned short vi[3]; // The vertex indices.
for (int j = 0; j < nvp; ++j)
{
if (p[j] == RC_MESH_NULL_IDX)
break; // End of vertices.
if (p[j + nvp] == RC_MESH_NULL_IDX)
{
// The edge beginning with this vertex is a solid border.
}
else
{
// The edge beginning with this vertex connects to
// polygon p[j + nvp].
}
// Convert to world space.
const unsigned short* v = &mesh.verts[p[j]*3];
const float x = orig[0] + v[0]*cs;
const float y = orig[1] + v[1]*ch;
const float z = orig[2] + v[2]*cs;
// Do something with the vertices.
}
}
static const unsigned short RC_MESH_NULL_IDX
An value which indicates an invalid index within a mesh.
Definition: Recast.h:630
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:472
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:473
int nvp
The maximum number of vertices per polygon.
Definition: Recast.h:469
See also
rcAllocPolyMesh, rcFreePolyMesh, rcBuildPolyMesh

Constructor & Destructor Documentation

◆ rcPolyMesh()

rcPolyMesh::rcPolyMesh ( )

◆ ~rcPolyMesh()

rcPolyMesh::~rcPolyMesh ( )

Member Data Documentation

◆ areas

rcPolyMesh::areas

The area id assigned to each polygon. [Length: maxpolys].

The standard build process assigns the value of RC_WALKABLE_AREA to all walkable polygons. This value can then be changed to meet user requirements.

◆ bmax

float rcPolyMesh::bmax[3]

The maximum bounds in world space. [(x, y, z)].

◆ bmin

float rcPolyMesh::bmin[3]

The minimum bounds in world space. [(x, y, z)].

◆ borderSize

int rcPolyMesh::borderSize

The AABB border size used to generate the source data from which the mesh was derived.

◆ ch

float rcPolyMesh::ch

The height of each cell. (The minimum increment along the y-axis.)

◆ cs

float rcPolyMesh::cs

The size of each cell. (On the xz-plane.)

◆ flags

unsigned short* rcPolyMesh::flags

The user defined flags for each polygon. [Length: maxpolys].

◆ maxEdgeError

float rcPolyMesh::maxEdgeError

The max error of the polygon edges in the mesh.

◆ maxpolys

int rcPolyMesh::maxpolys

The number of allocated polygons.

◆ npolys

int rcPolyMesh::npolys

The number of polygons.

◆ nverts

int rcPolyMesh::nverts

The number of vertices.

◆ nvp

int rcPolyMesh::nvp

The maximum number of vertices per polygon.

◆ polys

rcPolyMesh::polys

Polygon and neighbor data. [Length: maxpolys * 2 * nvp].

Each entry is 2 * nvp in length. The first half of the entry contains the indices of the polygon. The first instance of RC_MESH_NULL_IDX indicates the end of the indices for the entry. The second half contains indices to neighbor polygons. A value of RC_MESH_NULL_IDX indicates no connection for the associated edge. (I.e. The edge is a solid border.)

For example:

nvp = 6
For the entry: (1, 3, 4, 8, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX, 
                18, RC_MESH_NULL_IDX , 21, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX, RC_MESH_NULL_IDX)

(1, 3, 4, 8) defines a polygon with 4 vertices.
Edge 1->3 is shared with polygon 18.
Edge 4->8 is shared with polygon 21.
Edges 3->4 and 4->8 are border edges not shared with any other polygon.

◆ regs

unsigned short* rcPolyMesh::regs

The region id assigned to each polygon. [Length: maxpolys].

◆ verts

rcPolyMesh::verts

The mesh vertices. [Form: (x, y, z) * nverts].

The values of bmin ,cs, and ch are used to convert vertex coordinates to world space as follows:

float worldX = bmin[0] + verts[i*3+0] * cs
float worldY = bmin[1] + verts[i*3+1] * ch
float worldZ = bmin[2] + verts[i*3+2] * cs
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:470
unsigned short * verts
The mesh vertices. [Form: (x, y, z) * nverts].
Definition: Recast.h:461

The documentation for this struct was generated from the following files: