Path: blob/master/thirdparty/recastnavigation/Recast/Include/Recast.h
9913 views
//1// Copyright (c) 2009-2010 Mikko Mononen [email protected]2//3// This software is provided 'as-is', without any express or implied4// warranty. In no event will the authors be held liable for any damages5// arising from the use of this software.6// Permission is granted to anyone to use this software for any purpose,7// including commercial applications, and to alter it and redistribute it8// freely, subject to the following restrictions:9// 1. The origin of this software must not be misrepresented; you must not10// claim that you wrote the original software. If you use this software11// in a product, an acknowledgment in the product documentation would be12// appreciated but is not required.13// 2. Altered source versions must be plainly marked as such, and must not be14// misrepresented as being the original software.15// 3. This notice may not be removed or altered from any source distribution.16//1718#ifndef RECAST_H19#define RECAST_H2021/// The value of PI used by Recast.22static const float RC_PI = 3.14159265f;2324/// Used to ignore unused function parameters and silence any compiler warnings.25template<class T> void rcIgnoreUnused(const T&) { }2627/// Recast log categories.28/// @see rcContext29enum rcLogCategory30{31RC_LOG_PROGRESS = 1, ///< A progress log entry.32RC_LOG_WARNING, ///< A warning log entry.33RC_LOG_ERROR ///< An error log entry.34};3536/// Recast performance timer categories.37/// @see rcContext38enum rcTimerLabel39{40/// The user defined total time of the build.41RC_TIMER_TOTAL,42/// A user defined build time.43RC_TIMER_TEMP,44/// The time to rasterize the triangles. (See: #rcRasterizeTriangle)45RC_TIMER_RASTERIZE_TRIANGLES,46/// The time to build the compact heightfield. (See: #rcBuildCompactHeightfield)47RC_TIMER_BUILD_COMPACTHEIGHTFIELD,48/// The total time to build the contours. (See: #rcBuildContours)49RC_TIMER_BUILD_CONTOURS,50/// The time to trace the boundaries of the contours. (See: #rcBuildContours)51RC_TIMER_BUILD_CONTOURS_TRACE,52/// The time to simplify the contours. (See: #rcBuildContours)53RC_TIMER_BUILD_CONTOURS_SIMPLIFY,54/// The time to filter ledge spans. (See: #rcFilterLedgeSpans)55RC_TIMER_FILTER_BORDER,56/// The time to filter low height spans. (See: #rcFilterWalkableLowHeightSpans)57RC_TIMER_FILTER_WALKABLE,58/// The time to apply the median filter. (See: #rcMedianFilterWalkableArea)59RC_TIMER_MEDIAN_AREA,60/// The time to filter low obstacles. (See: #rcFilterLowHangingWalkableObstacles)61RC_TIMER_FILTER_LOW_OBSTACLES,62/// The time to build the polygon mesh. (See: #rcBuildPolyMesh)63RC_TIMER_BUILD_POLYMESH,64/// The time to merge polygon meshes. (See: #rcMergePolyMeshes)65RC_TIMER_MERGE_POLYMESH,66/// The time to erode the walkable area. (See: #rcErodeWalkableArea)67RC_TIMER_ERODE_AREA,68/// The time to mark a box area. (See: #rcMarkBoxArea)69RC_TIMER_MARK_BOX_AREA,70/// The time to mark a cylinder area. (See: #rcMarkCylinderArea)71RC_TIMER_MARK_CYLINDER_AREA,72/// The time to mark a convex polygon area. (See: #rcMarkConvexPolyArea)73RC_TIMER_MARK_CONVEXPOLY_AREA,74/// The total time to build the distance field. (See: #rcBuildDistanceField)75RC_TIMER_BUILD_DISTANCEFIELD,76/// The time to build the distances of the distance field. (See: #rcBuildDistanceField)77RC_TIMER_BUILD_DISTANCEFIELD_DIST,78/// The time to blur the distance field. (See: #rcBuildDistanceField)79RC_TIMER_BUILD_DISTANCEFIELD_BLUR,80/// The total time to build the regions. (See: #rcBuildRegions, #rcBuildRegionsMonotone)81RC_TIMER_BUILD_REGIONS,82/// The total time to apply the watershed algorithm. (See: #rcBuildRegions)83RC_TIMER_BUILD_REGIONS_WATERSHED,84/// The time to expand regions while applying the watershed algorithm. (See: #rcBuildRegions)85RC_TIMER_BUILD_REGIONS_EXPAND,86/// The time to flood regions while applying the watershed algorithm. (See: #rcBuildRegions)87RC_TIMER_BUILD_REGIONS_FLOOD,88/// The time to filter out small regions. (See: #rcBuildRegions, #rcBuildRegionsMonotone)89RC_TIMER_BUILD_REGIONS_FILTER,90/// The time to build heightfield layers. (See: #rcBuildHeightfieldLayers)91RC_TIMER_BUILD_LAYERS,92/// The time to build the polygon mesh detail. (See: #rcBuildPolyMeshDetail)93RC_TIMER_BUILD_POLYMESHDETAIL,94/// The time to merge polygon mesh details. (See: #rcMergePolyMeshDetails)95RC_TIMER_MERGE_POLYMESHDETAIL,96/// The maximum number of timers. (Used for iterating timers.)97RC_MAX_TIMERS98};99100/// Provides an interface for optional logging and performance tracking of the Recast101/// build process.102///103/// This class does not provide logging or timer functionality on its104/// own. Both must be provided by a concrete implementation105/// by overriding the protected member functions. Also, this class does not106/// provide an interface for extracting log messages. (Only adding them.)107/// So concrete implementations must provide one.108///109/// If no logging or timers are required, just pass an instance of this110/// class through the Recast build process.111///112/// @ingroup recast113class rcContext114{115public:116/// Constructor.117/// @param[in] state TRUE if the logging and performance timers should be enabled. [Default: true]118inline rcContext(bool state = true) : m_logEnabled(state), m_timerEnabled(state) {}119virtual ~rcContext() {}120121/// Enables or disables logging.122/// @param[in] state TRUE if logging should be enabled.123inline void enableLog(bool state) { m_logEnabled = state; }124125/// Clears all log entries.126inline void resetLog() { if (m_logEnabled) doResetLog(); }127128/// Logs a message.129///130/// Example:131/// @code132/// // Where ctx is an instance of rcContext and filepath is a char array.133/// ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath);134/// @endcode135///136/// @param[in] category The category of the message.137/// @param[in] format The message.138void log(const rcLogCategory category, const char* format, ...);139140/// Enables or disables the performance timers.141/// @param[in] state TRUE if timers should be enabled.142inline void enableTimer(bool state) { m_timerEnabled = state; }143144/// Clears all performance timers. (Resets all to unused.)145inline void resetTimers() { if (m_timerEnabled) doResetTimers(); }146147/// Starts the specified performance timer.148/// @param label The category of the timer.149inline void startTimer(const rcTimerLabel label) { if (m_timerEnabled) doStartTimer(label); }150151/// Stops the specified performance timer.152/// @param label The category of the timer.153inline void stopTimer(const rcTimerLabel label) { if (m_timerEnabled) doStopTimer(label); }154155/// Returns the total accumulated time of the specified performance timer.156/// @param label The category of the timer.157/// @return The accumulated time of the timer, or -1 if timers are disabled or the timer has never been started.158inline int getAccumulatedTime(const rcTimerLabel label) const { return m_timerEnabled ? doGetAccumulatedTime(label) : -1; }159160protected:161/// Clears all log entries.162virtual void doResetLog();163164/// Logs a message.165/// @param[in] category The category of the message.166/// @param[in] msg The formatted message.167/// @param[in] len The length of the formatted message.168virtual void doLog(const rcLogCategory category, const char* msg, const int len) { rcIgnoreUnused(category); rcIgnoreUnused(msg); rcIgnoreUnused(len); }169170/// Clears all timers. (Resets all to unused.)171virtual void doResetTimers() {}172173/// Starts the specified performance timer.174/// @param[in] label The category of timer.175virtual void doStartTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }176177/// Stops the specified performance timer.178/// @param[in] label The category of the timer.179virtual void doStopTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }180181/// Returns the total accumulated time of the specified performance timer.182/// @param[in] label The category of the timer.183/// @return The accumulated time of the timer, or -1 if timers are disabled or the timer has never been started.184virtual int doGetAccumulatedTime(const rcTimerLabel label) const { rcIgnoreUnused(label); return -1; }185186/// True if logging is enabled.187bool m_logEnabled;188189/// True if the performance timers are enabled.190bool m_timerEnabled;191};192193/// A helper to first start a timer and then stop it when this helper goes out of scope.194/// @see rcContext195class rcScopedTimer196{197public:198/// Constructs an instance and starts the timer.199/// @param[in] ctx The context to use.200/// @param[in] label The category of the timer.201inline rcScopedTimer(rcContext* ctx, const rcTimerLabel label) : m_ctx(ctx), m_label(label) { m_ctx->startTimer(m_label); }202inline ~rcScopedTimer() { m_ctx->stopTimer(m_label); }203204private:205// Explicitly disabled copy constructor and copy assignment operator.206rcScopedTimer(const rcScopedTimer&);207rcScopedTimer& operator=(const rcScopedTimer&);208209rcContext* const m_ctx;210const rcTimerLabel m_label;211};212213/// Specifies a configuration to use when performing Recast builds.214/// @ingroup recast215struct rcConfig216{217/// The width of the field along the x-axis. [Limit: >= 0] [Units: vx]218int width;219220/// The height of the field along the z-axis. [Limit: >= 0] [Units: vx]221int height;222223/// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx]224int tileSize;225226/// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx]227int borderSize;228229/// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]230float cs;231232/// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]233float ch;234235/// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]236float bmin[3];237238/// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]239float bmax[3];240241/// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]242float walkableSlopeAngle;243244/// Minimum floor to 'ceiling' height that will still allow the floor area to245/// be considered walkable. [Limit: >= 3] [Units: vx]246int walkableHeight;247248/// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]249int walkableClimb;250251/// The distance to erode/shrink the walkable area of the heightfield away from252/// obstructions. [Limit: >=0] [Units: vx]253int walkableRadius;254255/// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]256int maxEdgeLen;257258/// The maximum distance a simplified contour's border edges should deviate259/// the original raw contour. [Limit: >=0] [Units: vx]260float maxSimplificationError;261262/// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]263int minRegionArea;264265/// Any regions with a span count smaller than this value will, if possible,266/// be merged with larger regions. [Limit: >=0] [Units: vx]267int mergeRegionArea;268269/// The maximum number of vertices allowed for polygons generated during the270/// contour to polygon conversion process. [Limit: >= 3]271int maxVertsPerPoly;272273/// Sets the sampling distance to use when generating the detail mesh.274/// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]275float detailSampleDist;276277/// The maximum distance the detail mesh surface should deviate from heightfield278/// data. (For height detail only.) [Limit: >=0] [Units: wu]279float detailSampleMaxError;280};281282/// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.283static const int RC_SPAN_HEIGHT_BITS = 13;284/// Defines the maximum value for rcSpan::smin and rcSpan::smax.285static const int RC_SPAN_MAX_HEIGHT = (1 << RC_SPAN_HEIGHT_BITS) - 1;286287/// The number of spans allocated per span spool.288/// @see rcSpanPool289static const int RC_SPANS_PER_POOL = 2048;290291/// Represents a span in a heightfield.292/// @see rcHeightfield293struct rcSpan294{295unsigned int smin : RC_SPAN_HEIGHT_BITS; ///< The lower limit of the span. [Limit: < #smax]296unsigned int smax : RC_SPAN_HEIGHT_BITS; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT]297unsigned int area : 6; ///< The area id assigned to the span.298rcSpan* next; ///< The next span higher up in column.299};300301/// A memory pool used for quick allocation of spans within a heightfield.302/// @see rcHeightfield303struct rcSpanPool304{305rcSpanPool* next; ///< The next span pool.306rcSpan items[RC_SPANS_PER_POOL]; ///< Array of spans in the pool.307};308309/// A dynamic heightfield representing obstructed space.310/// @ingroup recast311struct rcHeightfield312{313rcHeightfield();314~rcHeightfield();315316int width; ///< The width of the heightfield. (Along the x-axis in cell units.)317int height; ///< The height of the heightfield. (Along the z-axis in cell units.)318float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]319float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]320float cs; ///< The size of each cell. (On the xz-plane.)321float ch; ///< The height of each cell. (The minimum increment along the y-axis.)322rcSpan** spans; ///< Heightfield of spans (width*height).323rcSpanPool* pools; ///< Linked list of span pools.324rcSpan* freelist; ///< The next free span.325326private:327// Explicitly-disabled copy constructor and copy assignment operator.328rcHeightfield(const rcHeightfield&);329rcHeightfield& operator=(const rcHeightfield&);330};331332/// Provides information on the content of a cell column in a compact heightfield.333struct rcCompactCell334{335unsigned int index : 24; ///< Index to the first span in the column.336unsigned int count : 8; ///< Number of spans in the column.337};338339/// Represents a span of unobstructed space within a compact heightfield.340struct rcCompactSpan341{342unsigned short y; ///< The lower extent of the span. (Measured from the heightfield's base.)343unsigned short reg; ///< The id of the region the span belongs to. (Or zero if not in a region.)344unsigned int con : 24; ///< Packed neighbor connection data.345unsigned int h : 8; ///< The height of the span. (Measured from #y.)346};347348/// A compact, static heightfield representing unobstructed space.349/// @ingroup recast350struct rcCompactHeightfield351{352rcCompactHeightfield();353~rcCompactHeightfield();354355int width; ///< The width of the heightfield. (Along the x-axis in cell units.)356int height; ///< The height of the heightfield. (Along the z-axis in cell units.)357int spanCount; ///< The number of spans in the heightfield.358int walkableHeight; ///< The walkable height used during the build of the field. (See: rcConfig::walkableHeight)359int walkableClimb; ///< The walkable climb used during the build of the field. (See: rcConfig::walkableClimb)360int borderSize; ///< The AABB border size used during the build of the field. (See: rcConfig::borderSize)361unsigned short maxDistance; ///< The maximum distance value of any span within the field.362unsigned short maxRegions; ///< The maximum region id of any span within the field.363float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]364float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]365float cs; ///< The size of each cell. (On the xz-plane.)366float ch; ///< The height of each cell. (The minimum increment along the y-axis.)367rcCompactCell* cells; ///< Array of cells. [Size: #width*#height]368rcCompactSpan* spans; ///< Array of spans. [Size: #spanCount]369unsigned short* dist; ///< Array containing border distance data. [Size: #spanCount]370unsigned char* areas; ///< Array containing area id data. [Size: #spanCount]371372private:373// Explicitly-disabled copy constructor and copy assignment operator.374rcCompactHeightfield(const rcCompactHeightfield&);375rcCompactHeightfield& operator=(const rcCompactHeightfield&);376};377378/// Represents a heightfield layer within a layer set.379/// @see rcHeightfieldLayerSet380struct rcHeightfieldLayer381{382float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]383float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]384float cs; ///< The size of each cell. (On the xz-plane.)385float ch; ///< The height of each cell. (The minimum increment along the y-axis.)386int width; ///< The width of the heightfield. (Along the x-axis in cell units.)387int height; ///< The height of the heightfield. (Along the z-axis in cell units.)388int minx; ///< The minimum x-bounds of usable data.389int maxx; ///< The maximum x-bounds of usable data.390int miny; ///< The minimum y-bounds of usable data. (Along the z-axis.)391int maxy; ///< The maximum y-bounds of usable data. (Along the z-axis.)392int hmin; ///< The minimum height bounds of usable data. (Along the y-axis.)393int hmax; ///< The maximum height bounds of usable data. (Along the y-axis.)394unsigned char* heights; ///< The heightfield. [Size: width * height]395unsigned char* areas; ///< Area ids. [Size: Same as #heights]396unsigned char* cons; ///< Packed neighbor connection information. [Size: Same as #heights]397};398399/// Represents a set of heightfield layers.400/// @ingroup recast401/// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet402struct rcHeightfieldLayerSet403{404rcHeightfieldLayerSet();405~rcHeightfieldLayerSet();406407rcHeightfieldLayer* layers; ///< The layers in the set. [Size: #nlayers]408int nlayers; ///< The number of layers in the set.409410private:411// Explicitly-disabled copy constructor and copy assignment operator.412rcHeightfieldLayerSet(const rcHeightfieldLayerSet&);413rcHeightfieldLayerSet& operator=(const rcHeightfieldLayerSet&);414};415416/// Represents a simple, non-overlapping contour in field space.417struct rcContour418{419int* verts; ///< Simplified contour vertex and connection data. [Size: 4 * #nverts]420int nverts; ///< The number of vertices in the simplified contour.421int* rverts; ///< Raw contour vertex and connection data. [Size: 4 * #nrverts]422int nrverts; ///< The number of vertices in the raw contour.423unsigned short reg; ///< The region id of the contour.424unsigned char area; ///< The area id of the contour.425};426427/// Represents a group of related contours.428/// @ingroup recast429struct rcContourSet430{431rcContourSet();432~rcContourSet();433434rcContour* conts; ///< An array of the contours in the set. [Size: #nconts]435int nconts; ///< The number of contours in the set.436float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]437float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]438float cs; ///< The size of each cell. (On the xz-plane.)439float ch; ///< The height of each cell. (The minimum increment along the y-axis.)440int width; ///< The width of the set. (Along the x-axis in cell units.)441int height; ///< The height of the set. (Along the z-axis in cell units.)442int borderSize; ///< The AABB border size used to generate the source data from which the contours were derived.443float maxError; ///< The max edge error that this contour set was simplified with.444445private:446// Explicitly-disabled copy constructor and copy assignment operator.447rcContourSet(const rcContourSet&);448rcContourSet& operator=(const rcContourSet&);449};450451/// Represents a polygon mesh suitable for use in building a navigation mesh.452/// @ingroup recast453struct rcPolyMesh454{455rcPolyMesh();456~rcPolyMesh();457458unsigned short* verts; ///< The mesh vertices. [Form: (x, y, z) * #nverts]459unsigned short* polys; ///< Polygon and neighbor data. [Length: #maxpolys * 2 * #nvp]460unsigned short* regs; ///< The region id assigned to each polygon. [Length: #maxpolys]461unsigned short* flags; ///< The user defined flags for each polygon. [Length: #maxpolys]462unsigned char* areas; ///< The area id assigned to each polygon. [Length: #maxpolys]463int nverts; ///< The number of vertices.464int npolys; ///< The number of polygons.465int maxpolys; ///< The number of allocated polygons.466int nvp; ///< The maximum number of vertices per polygon.467float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]468float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]469float cs; ///< The size of each cell. (On the xz-plane.)470float ch; ///< The height of each cell. (The minimum increment along the y-axis.)471int borderSize; ///< The AABB border size used to generate the source data from which the mesh was derived.472float maxEdgeError; ///< The max error of the polygon edges in the mesh.473474private:475// Explicitly-disabled copy constructor and copy assignment operator.476rcPolyMesh(const rcPolyMesh&);477rcPolyMesh& operator=(const rcPolyMesh&);478};479480/// Contains triangle meshes that represent detailed height data associated481/// with the polygons in its associated polygon mesh object.482/// @ingroup recast483struct rcPolyMeshDetail484{485rcPolyMeshDetail();486487unsigned int* meshes; ///< The sub-mesh data. [Size: 4*#nmeshes]488float* verts; ///< The mesh vertices. [Size: 3*#nverts]489unsigned char* tris; ///< The mesh triangles. [Size: 4*#ntris]490int nmeshes; ///< The number of sub-meshes defined by #meshes.491int nverts; ///< The number of vertices in #verts.492int ntris; ///< The number of triangles in #tris.493494private:495// Explicitly-disabled copy constructor and copy assignment operator.496rcPolyMeshDetail(const rcPolyMeshDetail&);497rcPolyMeshDetail& operator=(const rcPolyMeshDetail&);498};499500/// @name Allocation Functions501/// Functions used to allocate and de-allocate Recast objects.502/// @see rcAllocSetCustom503/// @{504505/// Allocates a heightfield object using the Recast allocator.506/// @return A heightfield that is ready for initialization, or null on failure.507/// @ingroup recast508/// @see rcCreateHeightfield, rcFreeHeightField509rcHeightfield* rcAllocHeightfield();510511/// Frees the specified heightfield object using the Recast allocator.512/// @param[in] heightfield A heightfield allocated using #rcAllocHeightfield513/// @ingroup recast514/// @see rcAllocHeightfield515void rcFreeHeightField(rcHeightfield* heightfield);516517/// Allocates a compact heightfield object using the Recast allocator.518/// @return A compact heightfield that is ready for initialization, or null on failure.519/// @ingroup recast520/// @see rcBuildCompactHeightfield, rcFreeCompactHeightfield521rcCompactHeightfield* rcAllocCompactHeightfield();522523/// Frees the specified compact heightfield object using the Recast allocator.524/// @param[in] compactHeightfield A compact heightfield allocated using #rcAllocCompactHeightfield525/// @ingroup recast526/// @see rcAllocCompactHeightfield527void rcFreeCompactHeightfield(rcCompactHeightfield* compactHeightfield);528529/// Allocates a heightfield layer set using the Recast allocator.530/// @return A heightfield layer set that is ready for initialization, or null on failure.531/// @ingroup recast532/// @see rcBuildHeightfieldLayers, rcFreeHeightfieldLayerSet533rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet();534535/// Frees the specified heightfield layer set using the Recast allocator.536/// @param[in] layerSet A heightfield layer set allocated using #rcAllocHeightfieldLayerSet537/// @ingroup recast538/// @see rcAllocHeightfieldLayerSet539void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* layerSet);540541/// Allocates a contour set object using the Recast allocator.542/// @return A contour set that is ready for initialization, or null on failure.543/// @ingroup recast544/// @see rcBuildContours, rcFreeContourSet545rcContourSet* rcAllocContourSet();546547/// Frees the specified contour set using the Recast allocator.548/// @param[in] contourSet A contour set allocated using #rcAllocContourSet549/// @ingroup recast550/// @see rcAllocContourSet551void rcFreeContourSet(rcContourSet* contourSet);552553/// Allocates a polygon mesh object using the Recast allocator.554/// @return A polygon mesh that is ready for initialization, or null on failure.555/// @ingroup recast556/// @see rcBuildPolyMesh, rcFreePolyMesh557rcPolyMesh* rcAllocPolyMesh();558559/// Frees the specified polygon mesh using the Recast allocator.560/// @param[in] polyMesh A polygon mesh allocated using #rcAllocPolyMesh561/// @ingroup recast562/// @see rcAllocPolyMesh563void rcFreePolyMesh(rcPolyMesh* polyMesh);564565/// Allocates a detail mesh object using the Recast allocator.566/// @return A detail mesh that is ready for initialization, or null on failure.567/// @ingroup recast568/// @see rcBuildPolyMeshDetail, rcFreePolyMeshDetail569rcPolyMeshDetail* rcAllocPolyMeshDetail();570571/// Frees the specified detail mesh using the Recast allocator.572/// @param[in] detailMesh A detail mesh allocated using #rcAllocPolyMeshDetail573/// @ingroup recast574/// @see rcAllocPolyMeshDetail575void rcFreePolyMeshDetail(rcPolyMeshDetail* detailMesh);576577/// @}578579/// Heightfield border flag.580/// If a heightfield region ID has this bit set, then the region is a border581/// region and its spans are considered un-walkable.582/// (Used during the region and contour build process.)583/// @see rcCompactSpan::reg584static const unsigned short RC_BORDER_REG = 0x8000;585586/// Polygon touches multiple regions.587/// If a polygon has this region ID it was merged with or created588/// from polygons of different regions during the polymesh589/// build step that removes redundant border vertices.590/// (Used during the polymesh and detail polymesh build processes)591/// @see rcPolyMesh::regs592static const unsigned short RC_MULTIPLE_REGS = 0;593594/// Border vertex flag.595/// If a region ID has this bit set, then the associated element lies on596/// a tile border. If a contour vertex's region ID has this bit set, the597/// vertex will later be removed in order to match the segments and vertices598/// at tile boundaries.599/// (Used during the build process.)600/// @see rcCompactSpan::reg, #rcContour::verts, #rcContour::rverts601static const int RC_BORDER_VERTEX = 0x10000;602603/// Area border flag.604/// If a region ID has this bit set, then the associated element lies on605/// the border of an area.606/// (Used during the region and contour build process.)607/// @see rcCompactSpan::reg, #rcContour::verts, #rcContour::rverts608static const int RC_AREA_BORDER = 0x20000;609610/// Contour build flags.611/// @see rcBuildContours612enum rcBuildContoursFlags613{614RC_CONTOUR_TESS_WALL_EDGES = 0x01, ///< Tessellate solid (impassable) edges during contour simplification.615RC_CONTOUR_TESS_AREA_EDGES = 0x02 ///< Tessellate edges between areas during contour simplification.616};617618/// Applied to the region id field of contour vertices in order to extract the region id.619/// The region id field of a vertex may have several flags applied to it. So the620/// fields value can't be used directly.621/// @see rcContour::verts, rcContour::rverts622static const int RC_CONTOUR_REG_MASK = 0xffff;623624/// An value which indicates an invalid index within a mesh.625/// @note This does not necessarily indicate an error.626/// @see rcPolyMesh::polys627static const unsigned short RC_MESH_NULL_IDX = 0xffff;628629/// Represents the null area.630/// When a data element is given this value it is considered to no longer be631/// assigned to a usable area. (E.g. It is un-walkable.)632static const unsigned char RC_NULL_AREA = 0;633634/// The default area id used to indicate a walkable polygon.635/// This is also the maximum allowed area id, and the only non-null area id636/// recognized by some steps in the build process.637static const unsigned char RC_WALKABLE_AREA = 63;638639/// The value returned by #rcGetCon if the specified direction is not connected640/// to another span. (Has no neighbor.)641static const int RC_NOT_CONNECTED = 0x3f;642643/// @name General helper functions644/// @{645646/// Swaps the values of the two parameters.647/// @param[in,out] a Value A648/// @param[in,out] b Value B649template<class T> inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }650651/// Returns the minimum of two values.652/// @param[in] a Value A653/// @param[in] b Value B654/// @return The minimum of the two values.655template<class T> inline T rcMin(T a, T b) { return a < b ? a : b; }656657/// Returns the maximum of two values.658/// @param[in] a Value A659/// @param[in] b Value B660/// @return The maximum of the two values.661template<class T> inline T rcMax(T a, T b) { return a > b ? a : b; }662663/// Returns the absolute value.664/// @param[in] a The value.665/// @return The absolute value of the specified value.666template<class T> inline T rcAbs(T a) { return a < 0 ? -a : a; }667668/// Returns the square of the value.669/// @param[in] a The value.670/// @return The square of the value.671template<class T> inline T rcSqr(T a) { return a*a; }672673/// Clamps the value to the specified range.674/// @param[in] value The value to clamp.675/// @param[in] minInclusive The minimum permitted return value.676/// @param[in] maxInclusive The maximum permitted return value.677/// @return The value, clamped to the specified range.678template<class T> inline T rcClamp(T value, T minInclusive, T maxInclusive)679{680return value < minInclusive ? minInclusive: (value > maxInclusive ? maxInclusive : value);681}682683/// Returns the square root of the value.684/// @param[in] x The value.685/// @return The square root of the vlaue.686float rcSqrt(float x);687688/// @}689/// @name Vector helper functions.690/// @{691692/// Derives the cross product of two vectors. (@p v1 x @p v2)693/// @param[out] dest The cross product. [(x, y, z)]694/// @param[in] v1 A Vector [(x, y, z)]695/// @param[in] v2 A vector [(x, y, z)]696inline void rcVcross(float* dest, const float* v1, const float* v2)697{698dest[0] = v1[1]*v2[2] - v1[2]*v2[1];699dest[1] = v1[2]*v2[0] - v1[0]*v2[2];700dest[2] = v1[0]*v2[1] - v1[1]*v2[0];701}702703/// Derives the dot product of two vectors. (@p v1 . @p v2)704/// @param[in] v1 A Vector [(x, y, z)]705/// @param[in] v2 A vector [(x, y, z)]706/// @return The dot product.707inline float rcVdot(const float* v1, const float* v2)708{709return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];710}711712/// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s))713/// @param[out] dest The result vector. [(x, y, z)]714/// @param[in] v1 The base vector. [(x, y, z)]715/// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)]716/// @param[in] s The amount to scale @p v2 by before adding to @p v1.717inline void rcVmad(float* dest, const float* v1, const float* v2, const float s)718{719dest[0] = v1[0]+v2[0]*s;720dest[1] = v1[1]+v2[1]*s;721dest[2] = v1[2]+v2[2]*s;722}723724/// Performs a vector addition. (@p v1 + @p v2)725/// @param[out] dest The result vector. [(x, y, z)]726/// @param[in] v1 The base vector. [(x, y, z)]727/// @param[in] v2 The vector to add to @p v1. [(x, y, z)]728inline void rcVadd(float* dest, const float* v1, const float* v2)729{730dest[0] = v1[0]+v2[0];731dest[1] = v1[1]+v2[1];732dest[2] = v1[2]+v2[2];733}734735/// Performs a vector subtraction. (@p v1 - @p v2)736/// @param[out] dest The result vector. [(x, y, z)]737/// @param[in] v1 The base vector. [(x, y, z)]738/// @param[in] v2 The vector to subtract from @p v1. [(x, y, z)]739inline void rcVsub(float* dest, const float* v1, const float* v2)740{741dest[0] = v1[0]-v2[0];742dest[1] = v1[1]-v2[1];743dest[2] = v1[2]-v2[2];744}745746/// Selects the minimum value of each element from the specified vectors.747/// @param[in,out] mn A vector. (Will be updated with the result.) [(x, y, z)]748/// @param[in] v A vector. [(x, y, z)]749inline void rcVmin(float* mn, const float* v)750{751mn[0] = rcMin(mn[0], v[0]);752mn[1] = rcMin(mn[1], v[1]);753mn[2] = rcMin(mn[2], v[2]);754}755756/// Selects the maximum value of each element from the specified vectors.757/// @param[in,out] mx A vector. (Will be updated with the result.) [(x, y, z)]758/// @param[in] v A vector. [(x, y, z)]759inline void rcVmax(float* mx, const float* v)760{761mx[0] = rcMax(mx[0], v[0]);762mx[1] = rcMax(mx[1], v[1]);763mx[2] = rcMax(mx[2], v[2]);764}765766/// Performs a vector copy.767/// @param[out] dest The result. [(x, y, z)]768/// @param[in] v The vector to copy. [(x, y, z)]769inline void rcVcopy(float* dest, const float* v)770{771dest[0] = v[0];772dest[1] = v[1];773dest[2] = v[2];774}775776/// Returns the distance between two points.777/// @param[in] v1 A point. [(x, y, z)]778/// @param[in] v2 A point. [(x, y, z)]779/// @return The distance between the two points.780inline float rcVdist(const float* v1, const float* v2)781{782float dx = v2[0] - v1[0];783float dy = v2[1] - v1[1];784float dz = v2[2] - v1[2];785return rcSqrt(dx*dx + dy*dy + dz*dz);786}787788/// Returns the square of the distance between two points.789/// @param[in] v1 A point. [(x, y, z)]790/// @param[in] v2 A point. [(x, y, z)]791/// @return The square of the distance between the two points.792inline float rcVdistSqr(const float* v1, const float* v2)793{794float dx = v2[0] - v1[0];795float dy = v2[1] - v1[1];796float dz = v2[2] - v1[2];797return dx*dx + dy*dy + dz*dz;798}799800/// Normalizes the vector.801/// @param[in,out] v The vector to normalize. [(x, y, z)]802inline void rcVnormalize(float* v)803{804float d = 1.0f / rcSqrt(rcSqr(v[0]) + rcSqr(v[1]) + rcSqr(v[2]));805v[0] *= d;806v[1] *= d;807v[2] *= d;808}809810/// @}811/// @name Heightfield Functions812/// @see rcHeightfield813/// @{814815/// Calculates the bounding box of an array of vertices.816/// @ingroup recast817/// @param[in] verts An array of vertices. [(x, y, z) * @p nv]818/// @param[in] numVerts The number of vertices in the @p verts array.819/// @param[out] minBounds The minimum bounds of the AABB. [(x, y, z)] [Units: wu]820/// @param[out] maxBounds The maximum bounds of the AABB. [(x, y, z)] [Units: wu]821void rcCalcBounds(const float* verts, int numVerts, float* minBounds, float* maxBounds);822823/// Calculates the grid size based on the bounding box and grid cell size.824/// @ingroup recast825/// @param[in] minBounds The minimum bounds of the AABB. [(x, y, z)] [Units: wu]826/// @param[in] maxBounds The maximum bounds of the AABB. [(x, y, z)] [Units: wu]827/// @param[in] cellSize The xz-plane cell size. [Limit: > 0] [Units: wu]828/// @param[out] sizeX The width along the x-axis. [Limit: >= 0] [Units: vx]829/// @param[out] sizeZ The height along the z-axis. [Limit: >= 0] [Units: vx]830void rcCalcGridSize(const float* minBounds, const float* maxBounds, float cellSize, int* sizeX, int* sizeZ);831832/// Initializes a new heightfield.833/// See the #rcConfig documentation for more information on the configuration parameters.834///835/// @see rcAllocHeightfield, rcHeightfield836/// @ingroup recast837///838/// @param[in,out] context The build context to use during the operation.839/// @param[in,out] heightfield The allocated heightfield to initialize.840/// @param[in] sizeX The width of the field along the x-axis. [Limit: >= 0] [Units: vx]841/// @param[in] sizeZ The height of the field along the z-axis. [Limit: >= 0] [Units: vx]842/// @param[in] minBounds The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]843/// @param[in] maxBounds The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]844/// @param[in] cellSize The xz-plane cell size to use for the field. [Limit: > 0] [Units: wu]845/// @param[in] cellHeight The y-axis cell size to use for field. [Limit: > 0] [Units: wu]846/// @returns True if the operation completed successfully.847bool rcCreateHeightfield(rcContext* context, rcHeightfield& heightfield, int sizeX, int sizeZ,848const float* minBounds, const float* maxBounds,849float cellSize, float cellHeight);850851/// Sets the area id of all triangles with a slope below the specified value852/// to #RC_WALKABLE_AREA.853///854/// Only sets the area id's for the walkable triangles. Does not alter the855/// area id's for un-walkable triangles.856///857/// See the #rcConfig documentation for more information on the configuration parameters.858///859/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles860///861/// @ingroup recast862/// @param[in,out] context The build context to use during the operation.863/// @param[in] walkableSlopeAngle The maximum slope that is considered walkable.864/// [Limits: 0 <= value < 90] [Units: Degrees]865/// @param[in] verts The vertices. [(x, y, z) * @p nv]866/// @param[in] numVerts The number of vertices.867/// @param[in] tris The triangle vertex indices. [(vertA, vertB, vertC) * @p nt]868/// @param[in] numTris The number of triangles.869/// @param[out] triAreaIDs The triangle area ids. [Length: >= @p nt]870void rcMarkWalkableTriangles(rcContext* context, float walkableSlopeAngle, const float* verts, int numVerts,871const int* tris, int numTris, unsigned char* triAreaIDs);872873/// Sets the area id of all triangles with a slope greater than or equal to the specified value to #RC_NULL_AREA.874///875/// Only sets the area id's for the un-walkable triangles. Does not alter the876/// area id's for walkable triangles.877///878/// See the #rcConfig documentation for more information on the configuration parameters.879///880/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles881///882/// @ingroup recast883/// @param[in,out] context The build context to use during the operation.884/// @param[in] walkableSlopeAngle The maximum slope that is considered walkable.885/// [Limits: 0 <= value < 90] [Units: Degrees]886/// @param[in] verts The vertices. [(x, y, z) * @p nv]887/// @param[in] numVerts The number of vertices.888/// @param[in] tris The triangle vertex indices. [(vertA, vertB, vertC) * @p nt]889/// @param[in] numTris The number of triangles.890/// @param[out] triAreaIDs The triangle area ids. [Length: >= @p nt]891void rcClearUnwalkableTriangles(rcContext* context, float walkableSlopeAngle, const float* verts, int numVerts,892const int* tris, int numTris, unsigned char* triAreaIDs);893894/// Adds a span to the specified heightfield.895///896/// The span addition can be set to favor flags. If the span is merged to897/// another span and the new @p spanMax is within @p flagMergeThreshold units898/// from the existing span, the span flags are merged.899///900/// @ingroup recast901/// @param[in,out] context The build context to use during the operation.902/// @param[in,out] heightfield An initialized heightfield.903/// @param[in] x The column x index where the span is to be added.904/// [Limits: 0 <= value < rcHeightfield::width]905/// @param[in] z The column z index where the span is to be added.906/// [Limits: 0 <= value < rcHeightfield::height]907/// @param[in] spanMin The minimum height of the span. [Limit: < @p spanMax] [Units: vx]908/// @param[in] spanMax The maximum height of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT] [Units: vx]909/// @param[in] areaID The area id of the span. [Limit: <= #RC_WALKABLE_AREA)910/// @param[in] flagMergeThreshold The merge threshold. [Limit: >= 0] [Units: vx]911/// @returns True if the operation completed successfully.912bool rcAddSpan(rcContext* context, rcHeightfield& heightfield,913int x, int z,914unsigned short spanMin, unsigned short spanMax,915unsigned char areaID, int flagMergeThreshold);916917/// Rasterizes a single triangle into the specified heightfield.918///919/// Calling this for each triangle in a mesh is less efficient than calling rcRasterizeTriangles920///921/// No spans will be added if the triangle does not overlap the heightfield grid.922///923/// @see rcHeightfield924/// @ingroup recast925/// @param[in,out] context The build context to use during the operation.926/// @param[in] v0 Triangle vertex 0 [(x, y, z)]927/// @param[in] v1 Triangle vertex 1 [(x, y, z)]928/// @param[in] v2 Triangle vertex 2 [(x, y, z)]929/// @param[in] areaID The area id of the triangle. [Limit: <= #RC_WALKABLE_AREA]930/// @param[in,out] heightfield An initialized heightfield.931/// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.932/// [Limit: >= 0] [Units: vx]933/// @returns True if the operation completed successfully.934bool rcRasterizeTriangle(rcContext* context,935const float* v0, const float* v1, const float* v2,936unsigned char areaID, rcHeightfield& heightfield, int flagMergeThreshold = 1);937938/// Rasterizes an indexed triangle mesh into the specified heightfield.939///940/// Spans will only be added for triangles that overlap the heightfield grid.941///942/// @see rcHeightfield943/// @ingroup recast944/// @param[in,out] context The build context to use during the operation.945/// @param[in] verts The vertices. [(x, y, z) * @p nv]946/// @param[in] numVerts The number of vertices. (unused) TODO (graham): Remove in next major release947/// @param[in] tris The triangle indices. [(vertA, vertB, vertC) * @p nt]948/// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]949/// @param[in] numTris The number of triangles.950/// @param[in,out] heightfield An initialized heightfield.951/// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.952/// [Limit: >= 0] [Units: vx]953/// @returns True if the operation completed successfully.954bool rcRasterizeTriangles(rcContext* context,955const float* verts, int numVerts,956const int* tris, const unsigned char* triAreaIDs, int numTris,957rcHeightfield& heightfield, int flagMergeThreshold = 1);958959/// Rasterizes an indexed triangle mesh into the specified heightfield.960///961/// Spans will only be added for triangles that overlap the heightfield grid.962///963/// @see rcHeightfield964/// @ingroup recast965/// @param[in,out] context The build context to use during the operation.966/// @param[in] verts The vertices. [(x, y, z) * @p nv]967/// @param[in] numVerts The number of vertices. (unused) TODO (graham): Remove in next major release968/// @param[in] tris The triangle indices. [(vertA, vertB, vertC) * @p nt]969/// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]970/// @param[in] numTris The number of triangles.971/// @param[in,out] heightfield An initialized heightfield.972/// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.973/// [Limit: >= 0] [Units: vx]974/// @returns True if the operation completed successfully.975bool rcRasterizeTriangles(rcContext* context,976const float* verts, int numVerts,977const unsigned short* tris, const unsigned char* triAreaIDs, int numTris,978rcHeightfield& heightfield, int flagMergeThreshold = 1);979980/// Rasterizes a triangle list into the specified heightfield.981///982/// Expects each triangle to be specified as three sequential vertices of 3 floats.983///984/// Spans will only be added for triangles that overlap the heightfield grid.985///986/// @see rcHeightfield987/// @ingroup recast988/// @param[in,out] context The build context to use during the operation.989/// @param[in] verts The triangle vertices. [(ax, ay, az, bx, by, bz, cx, by, cx) * @p nt]990/// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]991/// @param[in] numTris The number of triangles.992/// @param[in,out] heightfield An initialized heightfield.993/// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.994/// [Limit: >= 0] [Units: vx]995/// @returns True if the operation completed successfully.996bool rcRasterizeTriangles(rcContext* context,997const float* verts, const unsigned char* triAreaIDs, int numTris,998rcHeightfield& heightfield, int flagMergeThreshold = 1);9991000/// Marks non-walkable spans as walkable if their maximum is within @p walkableClimb of a walkable neighbor.1001///1002/// Allows the formation of walkable regions that will flow over low lying1003/// objects such as curbs, and up structures such as stairways.1004///1005/// Two neighboring spans are walkable if: <tt>rcAbs(currentSpan.smax - neighborSpan.smax) < waklableClimb</tt>1006///1007/// @warning Will override the effect of #rcFilterLedgeSpans. So if both filters are used, call1008/// #rcFilterLedgeSpans after calling this filter.1009///1010/// @see rcHeightfield, rcConfig1011///1012/// @ingroup recast1013/// @param[in,out] context The build context to use during the operation.1014/// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.1015/// [Limit: >=0] [Units: vx]1016/// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)1017void rcFilterLowHangingWalkableObstacles(rcContext* context, int walkableClimb, rcHeightfield& heightfield);10181019/// Marks spans that are ledges as not-walkable.1020///1021/// A ledge is a span with one or more neighbors whose maximum is further away than @p walkableClimb1022/// from the current span's maximum.1023/// This method removes the impact of the overestimation of conservative voxelization1024/// so the resulting mesh will not have regions hanging in the air over ledges.1025///1026/// A span is a ledge if: <tt>rcAbs(currentSpan.smax - neighborSpan.smax) > walkableClimb</tt>1027///1028/// @see rcHeightfield, rcConfig1029///1030/// @ingroup recast1031/// @param[in,out] context The build context to use during the operation.1032/// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area to1033/// be considered walkable. [Limit: >= 3] [Units: vx]1034/// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.1035/// [Limit: >=0] [Units: vx]1036/// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)1037void rcFilterLedgeSpans(rcContext* context, int walkableHeight, int walkableClimb, rcHeightfield& heightfield);10381039/// Marks walkable spans as not walkable if the clearance above the span is less than the specified height.1040///1041/// For this filter, the clearance above the span is the distance from the span's1042/// maximum to the next higher span's minimum. (Same grid column.)1043///1044/// @see rcHeightfield, rcConfig1045/// @ingroup recast1046///1047/// @param[in,out] context The build context to use during the operation.1048/// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area to1049/// be considered walkable. [Limit: >= 3] [Units: vx]1050/// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)1051void rcFilterWalkableLowHeightSpans(rcContext* context, int walkableHeight, rcHeightfield& heightfield);10521053/// Returns the number of spans contained in the specified heightfield.1054/// @ingroup recast1055/// @param[in,out] context The build context to use during the operation.1056/// @param[in] heightfield An initialized heightfield.1057/// @returns The number of spans in the heightfield.1058int rcGetHeightFieldSpanCount(rcContext* context, const rcHeightfield& heightfield);10591060/// @}1061/// @name Compact Heightfield Functions1062/// @see rcCompactHeightfield1063/// @{10641065/// Builds a compact heightfield representing open space, from a heightfield representing solid space.1066///1067/// This is just the beginning of the process of fully building a compact heightfield.1068/// Various filters may be applied, then the distance field and regions built.1069/// E.g: #rcBuildDistanceField and #rcBuildRegions1070///1071/// See the #rcConfig documentation for more information on the configuration parameters.1072///1073/// @see rcAllocCompactHeightfield, rcHeightfield, rcCompactHeightfield, rcConfig1074/// @ingroup recast1075///1076/// @param[in,out] context The build context to use during the operation.1077/// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area1078/// to be considered walkable. [Limit: >= 3] [Units: vx]1079/// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.1080/// [Limit: >=0] [Units: vx]1081/// @param[in] heightfield The heightfield to be compacted.1082/// @param[out] compactHeightfield The resulting compact heightfield. (Must be pre-allocated.)1083/// @returns True if the operation completed successfully.1084bool rcBuildCompactHeightfield(rcContext* context, int walkableHeight, int walkableClimb,1085const rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield);10861087/// Erodes the walkable area within the heightfield by the specified radius.1088/// @ingroup recast1089/// @param[in,out] ctx The build context to use during the operation.1090/// @param[in] radius The radius of erosion. [Limits: 0 < value < 255] [Units: vx]1091/// @param[in,out] chf The populated compact heightfield to erode.1092/// @returns True if the operation completed successfully.1093bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf);10941095/// Applies a median filter to walkable area types (based on area id), removing noise.1096/// @ingroup recast1097/// @param[in,out] ctx The build context to use during the operation.1098/// @param[in,out] chf A populated compact heightfield.1099/// @returns True if the operation completed successfully.1100bool rcMedianFilterWalkableArea(rcContext* ctx, rcCompactHeightfield& chf);11011102/// Applies an area id to all spans within the specified bounding box. (AABB)1103/// @ingroup recast1104/// @param[in,out] ctx The build context to use during the operation.1105/// @param[in] bmin The minimum of the bounding box. [(x, y, z)]1106/// @param[in] bmax The maximum of the bounding box. [(x, y, z)]1107/// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]1108/// @param[in,out] chf A populated compact heightfield.1109void rcMarkBoxArea(rcContext* ctx, const float* bmin, const float* bmax, unsigned char areaId,1110rcCompactHeightfield& chf);11111112/// Applies the area id to the all spans within the specified convex polygon.1113/// @ingroup recast1114/// @param[in,out] ctx The build context to use during the operation.1115/// @param[in] verts The vertices of the polygon [Fomr: (x, y, z) * @p nverts]1116/// @param[in] nverts The number of vertices in the polygon.1117/// @param[in] hmin The height of the base of the polygon.1118/// @param[in] hmax The height of the top of the polygon.1119/// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]1120/// @param[in,out] chf A populated compact heightfield.1121void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts,1122const float hmin, const float hmax, unsigned char areaId,1123rcCompactHeightfield& chf);11241125/// Helper function to offset voncex polygons for rcMarkConvexPolyArea.1126/// @ingroup recast1127/// @param[in] verts The vertices of the polygon [Form: (x, y, z) * @p nverts]1128/// @param[in] nverts The number of vertices in the polygon.1129/// @param[in] offset How much to offset the polygon by. [Units: wu]1130/// @param[out] outVerts The offset vertices (should hold up to 2 * @p nverts) [Form: (x, y, z) * return value]1131/// @param[in] maxOutVerts The max number of vertices that can be stored to @p outVerts.1132/// @returns Number of vertices in the offset polygon or 0 if too few vertices in @p outVerts.1133int rcOffsetPoly(const float* verts, const int nverts, const float offset,1134float* outVerts, const int maxOutVerts);11351136/// Applies the area id to all spans within the specified cylinder.1137/// @ingroup recast1138/// @param[in,out] ctx The build context to use during the operation.1139/// @param[in] pos The center of the base of the cylinder. [Form: (x, y, z)]1140/// @param[in] r The radius of the cylinder.1141/// @param[in] h The height of the cylinder.1142/// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]1143/// @param[in,out] chf A populated compact heightfield.1144void rcMarkCylinderArea(rcContext* ctx, const float* pos,1145const float r, const float h, unsigned char areaId,1146rcCompactHeightfield& chf);11471148/// Builds the distance field for the specified compact heightfield.1149/// @ingroup recast1150/// @param[in,out] ctx The build context to use during the operation.1151/// @param[in,out] chf A populated compact heightfield.1152/// @returns True if the operation completed successfully.1153bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf);11541155/// Builds region data for the heightfield using watershed partitioning.1156/// @ingroup recast1157/// @param[in,out] ctx The build context to use during the operation.1158/// @param[in,out] chf A populated compact heightfield.1159/// @param[in] borderSize The size of the non-navigable border around the heightfield.1160/// [Limit: >=0] [Units: vx]1161/// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.1162/// [Limit: >=0] [Units: vx].1163/// @param[in] mergeRegionArea Any regions with a span count smaller than this value will, if possible,1164/// be merged with larger regions. [Limit: >=0] [Units: vx]1165/// @returns True if the operation completed successfully.1166bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, int borderSize, int minRegionArea, int mergeRegionArea);11671168/// Builds region data for the heightfield by partitioning the heightfield in non-overlapping layers.1169/// @ingroup recast1170/// @param[in,out] ctx The build context to use during the operation.1171/// @param[in,out] chf A populated compact heightfield.1172/// @param[in] borderSize The size of the non-navigable border around the heightfield.1173/// [Limit: >=0] [Units: vx]1174/// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.1175/// [Limit: >=0] [Units: vx].1176/// @returns True if the operation completed successfully.1177bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf, int borderSize, int minRegionArea);11781179/// Builds region data for the heightfield using simple monotone partitioning.1180/// @ingroup recast1181/// @param[in,out] ctx The build context to use during the operation.1182/// @param[in,out] chf A populated compact heightfield.1183/// @param[in] borderSize The size of the non-navigable border around the heightfield.1184/// [Limit: >=0] [Units: vx]1185/// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.1186/// [Limit: >=0] [Units: vx].1187/// @param[in] mergeRegionArea Any regions with a span count smaller than this value will, if possible,1188/// be merged with larger regions. [Limit: >=0] [Units: vx]1189/// @returns True if the operation completed successfully.1190bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,1191int borderSize, int minRegionArea, int mergeRegionArea);11921193/// Sets the neighbor connection data for the specified direction.1194/// @param[in] span The span to update.1195/// @param[in] direction The direction to set. [Limits: 0 <= value < 4]1196/// @param[in] neighborIndex The index of the neighbor span.1197inline void rcSetCon(rcCompactSpan& span, int direction, int neighborIndex)1198{1199const unsigned int shift = (unsigned int)direction * 6;1200const unsigned int con = span.con;1201span.con = (con & ~(0x3f << shift)) | (((unsigned int)neighborIndex & 0x3f) << shift);1202}12031204/// Gets neighbor connection data for the specified direction.1205/// @param[in] span The span to check.1206/// @param[in] direction The direction to check. [Limits: 0 <= value < 4]1207/// @return The neighbor connection data for the specified direction, or #RC_NOT_CONNECTED if there is no connection.1208inline int rcGetCon(const rcCompactSpan& span, int direction)1209{1210const unsigned int shift = (unsigned int)direction * 6;1211return (span.con >> shift) & 0x3f;1212}12131214/// Gets the standard width (x-axis) offset for the specified direction.1215/// @param[in] direction The direction. [Limits: 0 <= value < 4]1216/// @return The width offset to apply to the current cell position to move in the direction.1217inline int rcGetDirOffsetX(int direction)1218{1219static const int offset[4] = { -1, 0, 1, 0, };1220return offset[direction & 0x03];1221}12221223// TODO (graham): Rename this to rcGetDirOffsetZ1224/// Gets the standard height (z-axis) offset for the specified direction.1225/// @param[in] direction The direction. [Limits: 0 <= value < 4]1226/// @return The height offset to apply to the current cell position to move in the direction.1227inline int rcGetDirOffsetY(int direction)1228{1229static const int offset[4] = { 0, 1, 0, -1 };1230return offset[direction & 0x03];1231}12321233/// Gets the direction for the specified offset. One of x and y should be 0.1234/// @param[in] offsetX The x offset. [Limits: -1 <= value <= 1]1235/// @param[in] offsetZ The z offset. [Limits: -1 <= value <= 1]1236/// @return The direction that represents the offset.1237inline int rcGetDirForOffset(int offsetX, int offsetZ)1238{1239static const int dirs[5] = { 3, 0, -1, 2, 1 };1240return dirs[((offsetZ + 1) << 1) + offsetX];1241}12421243/// @}1244/// @name Layer, Contour, Polymesh, and Detail Mesh Functions1245/// @see rcHeightfieldLayer, rcContourSet, rcPolyMesh, rcPolyMeshDetail1246/// @{12471248/// Builds a layer set from the specified compact heightfield.1249/// @ingroup recast1250/// @param[in,out] ctx The build context to use during the operation.1251/// @param[in] chf A fully built compact heightfield.1252/// @param[in] borderSize The size of the non-navigable border around the heightfield. [Limit: >=0]1253/// [Units: vx]1254/// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area1255/// to be considered walkable. [Limit: >= 3] [Units: vx]1256/// @param[out] lset The resulting layer set. (Must be pre-allocated.)1257/// @returns True if the operation completed successfully.1258bool rcBuildHeightfieldLayers(rcContext* ctx, const rcCompactHeightfield& chf,1259int borderSize, int walkableHeight,1260rcHeightfieldLayerSet& lset);12611262/// Builds a contour set from the region outlines in the provided compact heightfield.1263/// @ingroup recast1264/// @param[in,out] ctx The build context to use during the operation.1265/// @param[in] chf A fully built compact heightfield.1266/// @param[in] maxError The maximum distance a simplified contour's border edges should deviate1267/// the original raw contour. [Limit: >=0] [Units: wu]1268/// @param[in] maxEdgeLen The maximum allowed length for contour edges along the border of the mesh.1269/// [Limit: >=0] [Units: vx]1270/// @param[out] cset The resulting contour set. (Must be pre-allocated.)1271/// @param[in] buildFlags The build flags. (See: #rcBuildContoursFlags)1272/// @returns True if the operation completed successfully.1273bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,1274float maxError, int maxEdgeLen,1275rcContourSet& cset, int buildFlags = RC_CONTOUR_TESS_WALL_EDGES);12761277/// Builds a polygon mesh from the provided contours.1278/// @ingroup recast1279/// @param[in,out] ctx The build context to use during the operation.1280/// @param[in] cset A fully built contour set.1281/// @param[in] nvp The maximum number of vertices allowed for polygons generated during the1282/// contour to polygon conversion process. [Limit: >= 3]1283/// @param[out] mesh The resulting polygon mesh. (Must be re-allocated.)1284/// @returns True if the operation completed successfully.1285bool rcBuildPolyMesh(rcContext* ctx, const rcContourSet& cset, const int nvp, rcPolyMesh& mesh);12861287/// Merges multiple polygon meshes into a single mesh.1288/// @ingroup recast1289/// @param[in,out] ctx The build context to use during the operation.1290/// @param[in] meshes An array of polygon meshes to merge. [Size: @p nmeshes]1291/// @param[in] nmeshes The number of polygon meshes in the meshes array.1292/// @param[in] mesh The resulting polygon mesh. (Must be pre-allocated.)1293/// @returns True if the operation completed successfully.1294bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh);12951296/// Builds a detail mesh from the provided polygon mesh.1297/// @ingroup recast1298/// @param[in,out] ctx The build context to use during the operation.1299/// @param[in] mesh A fully built polygon mesh.1300/// @param[in] chf The compact heightfield used to build the polygon mesh.1301/// @param[in] sampleDist Sets the distance to use when sampling the heightfield. [Limit: >=0] [Units: wu]1302/// @param[in] sampleMaxError The maximum distance the detail mesh surface should deviate from1303/// heightfield data. [Limit: >=0] [Units: wu]1304/// @param[out] dmesh The resulting detail mesh. (Must be pre-allocated.)1305/// @returns True if the operation completed successfully.1306bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompactHeightfield& chf,1307float sampleDist, float sampleMaxError,1308rcPolyMeshDetail& dmesh);13091310/// Copies the poly mesh data from src to dst.1311/// @ingroup recast1312/// @param[in,out] ctx The build context to use during the operation.1313/// @param[in] src The source mesh to copy from.1314/// @param[out] dst The resulting detail mesh. (Must be pre-allocated, must be empty mesh.)1315/// @returns True if the operation completed successfully.1316bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst);13171318/// Merges multiple detail meshes into a single detail mesh.1319/// @ingroup recast1320/// @param[in,out] ctx The build context to use during the operation.1321/// @param[in] meshes An array of detail meshes to merge. [Size: @p nmeshes]1322/// @param[in] nmeshes The number of detail meshes in the meshes array.1323/// @param[out] mesh The resulting detail mesh. (Must be pre-allocated.)1324/// @returns True if the operation completed successfully.1325bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int nmeshes, rcPolyMeshDetail& mesh);13261327/// @}13281329#endif // RECAST_H13301331///////////////////////////////////////////////////////////////////////////13321333// Due to the large amount of detail documentation for this file,1334// the content normally located at the end of the header file has been separated1335// out to a file in /Docs/Extern.133613371338