Debian Codegraph @

Recast/Include/Recast.h

raw symbols ◀ ▶ SCIP
4 Debian patches touch this file
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18
19 #ifndef RECAST_H
20 #define RECAST_H
21
22 /// The value of PI used by Recast.
23 static const float RC_PI = 3.14159265f;
24
25 /// Used to ignore unused function parameters and silence any compiler warnings.
26 template<class T> void rcIgnoreUnused(const T&) { }
27
28 /// Recast log categories.
29 /// @see rcContext
30 enum rcLogCategory
31 {
32 RC_LOG_PROGRESS = 1, ///< A progress log entry.
33 RC_LOG_WARNING, ///< A warning log entry.
34 RC_LOG_ERROR ///< An error log entry.
35 };
36
37 /// Recast performance timer categories.
38 /// @see rcContext
39 enum rcTimerLabel
40 {
41 /// The user defined total time of the build.
42 RC_TIMER_TOTAL,
43 /// A user defined build time.
44 RC_TIMER_TEMP,
45 /// The time to rasterize the triangles. (See: #rcRasterizeTriangle)
46 RC_TIMER_RASTERIZE_TRIANGLES,
47 /// The time to build the compact heightfield. (See: #rcBuildCompactHeightfield)
48 RC_TIMER_BUILD_COMPACTHEIGHTFIELD,
49 /// The total time to build the contours. (See: #rcBuildContours)
50 RC_TIMER_BUILD_CONTOURS,
51 /// The time to trace the boundaries of the contours. (See: #rcBuildContours)
52 RC_TIMER_BUILD_CONTOURS_TRACE,
53 /// The time to simplify the contours. (See: #rcBuildContours)
54 RC_TIMER_BUILD_CONTOURS_SIMPLIFY,
55 /// The time to filter ledge spans. (See: #rcFilterLedgeSpans)
56 RC_TIMER_FILTER_BORDER,
57 /// The time to filter low height spans. (See: #rcFilterWalkableLowHeightSpans)
58 RC_TIMER_FILTER_WALKABLE,
59 /// The time to apply the median filter. (See: #rcMedianFilterWalkableArea)
60 RC_TIMER_MEDIAN_AREA,
61 /// The time to filter low obstacles. (See: #rcFilterLowHangingWalkableObstacles)
62 RC_TIMER_FILTER_LOW_OBSTACLES,
63 /// The time to build the polygon mesh. (See: #rcBuildPolyMesh)
64 RC_TIMER_BUILD_POLYMESH,
65 /// The time to merge polygon meshes. (See: #rcMergePolyMeshes)
66 RC_TIMER_MERGE_POLYMESH,
67 /// The time to erode the walkable area. (See: #rcErodeWalkableArea)
68 RC_TIMER_ERODE_AREA,
69 /// The time to mark a box area. (See: #rcMarkBoxArea)
70 RC_TIMER_MARK_BOX_AREA,
71 /// The time to mark a cylinder area. (See: #rcMarkCylinderArea)
72 RC_TIMER_MARK_CYLINDER_AREA,
73 /// The time to mark a convex polygon area. (See: #rcMarkConvexPolyArea)
74 RC_TIMER_MARK_CONVEXPOLY_AREA,
75 /// The total time to build the distance field. (See: #rcBuildDistanceField)
76 RC_TIMER_BUILD_DISTANCEFIELD,
77 /// The time to build the distances of the distance field. (See: #rcBuildDistanceField)
78 RC_TIMER_BUILD_DISTANCEFIELD_DIST,
79 /// The time to blur the distance field. (See: #rcBuildDistanceField)
80 RC_TIMER_BUILD_DISTANCEFIELD_BLUR,
81 /// The total time to build the regions. (See: #rcBuildRegions, #rcBuildRegionsMonotone)
82 RC_TIMER_BUILD_REGIONS,
83 /// The total time to apply the watershed algorithm. (See: #rcBuildRegions)
84 RC_TIMER_BUILD_REGIONS_WATERSHED,
85 /// The time to expand regions while applying the watershed algorithm. (See: #rcBuildRegions)
86 RC_TIMER_BUILD_REGIONS_EXPAND,
87 /// The time to flood regions while applying the watershed algorithm. (See: #rcBuildRegions)
88 RC_TIMER_BUILD_REGIONS_FLOOD,
89 /// The time to filter out small regions. (See: #rcBuildRegions, #rcBuildRegionsMonotone)
90 RC_TIMER_BUILD_REGIONS_FILTER,
91 /// The time to build heightfield layers. (See: #rcBuildHeightfieldLayers)
92 RC_TIMER_BUILD_LAYERS,
93 /// The time to build the polygon mesh detail. (See: #rcBuildPolyMeshDetail)
94 RC_TIMER_BUILD_POLYMESHDETAIL,
95 /// The time to merge polygon mesh details. (See: #rcMergePolyMeshDetails)
96 RC_TIMER_MERGE_POLYMESHDETAIL,
97 /// The maximum number of timers. (Used for iterating timers.)
98 RC_MAX_TIMERS
99 };
100
101 /// Provides an interface for optional logging and performance tracking of the Recast
102 /// build process.
103 ///
104 /// This class does not provide logging or timer functionality on its
105 /// own. Both must be provided by a concrete implementation
106 /// by overriding the protected member functions. Also, this class does not
107 /// provide an interface for extracting log messages. (Only adding them.)
108 /// So concrete implementations must provide one.
109 ///
110 /// If no logging or timers are required, just pass an instance of this
111 /// class through the Recast build process.
112 ///
113 /// @ingroup recast
114 class rcContext
115 {
116 public:
117 /// Constructor.
118 /// @param[in] state TRUE if the logging and performance timers should be enabled. [Default: true]
119 inline rcContext(bool state = true) : m_logEnabled(state), m_timerEnabled(state) {}
120 virtual ~rcContext() {}
121
122 /// Enables or disables logging.
123 /// @param[in] state TRUE if logging should be enabled.
124 inline void enableLog(bool state) { m_logEnabled = state; }
125
126 /// Clears all log entries.
127 inline void resetLog() { if (m_logEnabled) doResetLog(); }
128
129 /// Logs a message.
130 ///
131 /// Example:
132 /// @code
133 /// // Where ctx is an instance of rcContext and filepath is a char array.
134 /// ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath);
135 /// @endcode
136 ///
137 /// @param[in] category The category of the message.
138 /// @param[in] format The message.
139 void log(const rcLogCategory category, const char* format, ...);
140
141 /// Enables or disables the performance timers.
142 /// @param[in] state TRUE if timers should be enabled.
143 inline void enableTimer(bool state) { m_timerEnabled = state; }
144
145 /// Clears all performance timers. (Resets all to unused.)
146 inline void resetTimers() { if (m_timerEnabled) doResetTimers(); }
147
148 /// Starts the specified performance timer.
149 /// @param label The category of the timer.
150 inline void startTimer(const rcTimerLabel label) { if (m_timerEnabled) doStartTimer(label); }
151
152 /// Stops the specified performance timer.
153 /// @param label The category of the timer.
154 inline void stopTimer(const rcTimerLabel label) { if (m_timerEnabled) doStopTimer(label); }
155
156 /// Returns the total accumulated time of the specified performance timer.
157 /// @param label The category of the timer.
158 /// @return The accumulated time of the timer, or -1 if timers are disabled or the timer has never been started.
159 inline int getAccumulatedTime(const rcTimerLabel label) const { return m_timerEnabled ? doGetAccumulatedTime(label) : -1; }
160
161 protected:
162 /// Clears all log entries.
163 virtual void doResetLog();
164
165 /// Logs a message.
166 /// @param[in] category The category of the message.
167 /// @param[in] msg The formatted message.
168 /// @param[in] len The length of the formatted message.
169 virtual void doLog(const rcLogCategory category, const char* msg, const int len) { rcIgnoreUnused(category); rcIgnoreUnused(msg); rcIgnoreUnused(len); }
170
171 /// Clears all timers. (Resets all to unused.)
172 virtual void doResetTimers() {}
173
174 /// Starts the specified performance timer.
175 /// @param[in] label The category of timer.
176 virtual void doStartTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }
177
178 /// Stops the specified performance timer.
179 /// @param[in] label The category of the timer.
180 virtual void doStopTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }
181
182 /// Returns the total accumulated time of the specified performance timer.
183 /// @param[in] label The category of the timer.
184 /// @return The accumulated time of the timer, or -1 if timers are disabled or the timer has never been started.
185 virtual int doGetAccumulatedTime(const rcTimerLabel label) const { rcIgnoreUnused(label); return -1; }
186
187 /// True if logging is enabled.
188 bool m_logEnabled;
189
190 /// True if the performance timers are enabled.
191 bool m_timerEnabled;
192 };
193
194 /// A helper to first start a timer and then stop it when this helper goes out of scope.
195 /// @see rcContext
196 class rcScopedTimer
197 {
198 public:
199 /// Constructs an instance and starts the timer.
200 /// @param[in] ctx The context to use.
201 /// @param[in] label The category of the timer.
202 inline rcScopedTimer(rcContext* ctx, const rcTimerLabel label) : m_ctx(ctx), m_label(label) { m_ctx->startTimer(m_label); }
203 inline ~rcScopedTimer() { m_ctx->stopTimer(m_label); }
204
205 private:
206 // Explicitly disabled copy constructor and copy assignment operator.
207 rcScopedTimer(const rcScopedTimer&);
208 rcScopedTimer& operator=(const rcScopedTimer&);
209
210 rcContext* const m_ctx;
211 const rcTimerLabel m_label;
212 };
213
214 /// Specifies a configuration to use when performing Recast builds.
215 /// @ingroup recast
216 struct rcConfig
217 {
218 /// The width of the field along the x-axis. [Limit: >= 0] [Units: vx]
219 int width;
220
221 /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx]
222 int height;
223
224 /// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx]
225 int tileSize;
226
227 /// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx]
228 int borderSize;
229
230 /// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
231 float cs;
232
233 /// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
234 float ch;
235
236 /// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]
237 float bmin[3];
238
239 /// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]
240 float bmax[3];
241
242 /// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
243 float walkableSlopeAngle;
244
245 /// Minimum floor to 'ceiling' height that will still allow the floor area to
246 /// be considered walkable. [Limit: >= 3] [Units: vx]
247 int walkableHeight;
248
249 /// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
250 int walkableClimb;
251
252 /// The distance to erode/shrink the walkable area of the heightfield away from
253 /// obstructions. [Limit: >=0] [Units: vx]
254 int walkableRadius;
255
256 /// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
257 int maxEdgeLen;
258
259 /// The maximum distance a simplified contour's border edges should deviate
260 /// the original raw contour. [Limit: >=0] [Units: vx]
261 float maxSimplificationError;
262
263 /// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
264 int minRegionArea;
265
266 /// Any regions with a span count smaller than this value will, if possible,
267 /// be merged with larger regions. [Limit: >=0] [Units: vx]
268 int mergeRegionArea;
269
270 /// The maximum number of vertices allowed for polygons generated during the
271 /// contour to polygon conversion process. [Limit: >= 3]
272 int maxVertsPerPoly;
273
274 /// Sets the sampling distance to use when generating the detail mesh.
275 /// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
276 float detailSampleDist;
277
278 /// The maximum distance the detail mesh surface should deviate from heightfield
279 /// data. (For height detail only.) [Limit: >=0] [Units: wu]
280 float detailSampleMaxError;
281 };
282
283 /// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.
284 static const int RC_SPAN_HEIGHT_BITS = 13;
285 /// Defines the maximum value for rcSpan::smin and rcSpan::smax.
286 static const int RC_SPAN_MAX_HEIGHT = (1 << RC_SPAN_HEIGHT_BITS) - 1;
287
288 /// The number of spans allocated per span spool.
289 /// @see rcSpanPool
290 static const int RC_SPANS_PER_POOL = 2048;
291
292 /// Represents a span in a heightfield.
293 /// @see rcHeightfield
294 struct rcSpan
295 {
296 unsigned int smin : RC_SPAN_HEIGHT_BITS; ///< The lower limit of the span. [Limit: < #smax]
297 unsigned int smax : RC_SPAN_HEIGHT_BITS; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT]
298 unsigned int area : 6; ///< The area id assigned to the span.
299 rcSpan* next; ///< The next span higher up in column.
300 };
301
302 /// A memory pool used for quick allocation of spans within a heightfield.
303 /// @see rcHeightfield
304 struct rcSpanPool
305 {
306 rcSpanPool* next; ///< The next span pool.
307 rcSpan items[RC_SPANS_PER_POOL]; ///< Array of spans in the pool.
308 };
309
310 /// A dynamic heightfield representing obstructed space.
311 /// @ingroup recast
312 struct rcHeightfield
313 {
314 rcHeightfield();
315 ~rcHeightfield();
316
317 int width; ///< The width of the heightfield. (Along the x-axis in cell units.)
318 int height; ///< The height of the heightfield. (Along the z-axis in cell units.)
319 float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
320 float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]
321 float cs; ///< The size of each cell. (On the xz-plane.)
322 float ch; ///< The height of each cell. (The minimum increment along the y-axis.)
323 rcSpan** spans; ///< Heightfield of spans (width*height).
•324
325 // memory pool for rcSpan instances.
326 rcSpanPool* pools; ///< Linked list of span pools.
327 rcSpan* freelist; ///< The next free span.
328
329 private:
330 // Explicitly-disabled copy constructor and copy assignment operator.
331 rcHeightfield(const rcHeightfield&);
332 rcHeightfield& operator=(const rcHeightfield&);
333 };
334
335 /// Provides information on the content of a cell column in a compact heightfield.
336 struct rcCompactCell
337 {
338 unsigned int index : 24; ///< Index to the first span in the column.
339 unsigned int count : 8; ///< Number of spans in the column.
340 };
341
342 /// Represents a span of unobstructed space within a compact heightfield.
343 struct rcCompactSpan
344 {
345 unsigned short y; ///< The lower extent of the span. (Measured from the heightfield's base.)
346 unsigned short reg; ///< The id of the region the span belongs to. (Or zero if not in a region.)
347 unsigned int con : 24; ///< Packed neighbor connection data.
348 unsigned int h : 8; ///< The height of the span. (Measured from #y.)
349 };
350
351 /// A compact, static heightfield representing unobstructed space.
352 /// @ingroup recast
353 struct rcCompactHeightfield
354 {
355 rcCompactHeightfield();
356 ~rcCompactHeightfield();
357
358 int width; ///< The width of the heightfield. (Along the x-axis in cell units.)
359 int height; ///< The height of the heightfield. (Along the z-axis in cell units.)
360 int spanCount; ///< The number of spans in the heightfield.
361 int walkableHeight; ///< The walkable height used during the build of the field. (See: rcConfig::walkableHeight)
362 int walkableClimb; ///< The walkable climb used during the build of the field. (See: rcConfig::walkableClimb)
363 int borderSize; ///< The AABB border size used during the build of the field. (See: rcConfig::borderSize)
364 unsigned short maxDistance; ///< The maximum distance value of any span within the field.
365 unsigned short maxRegions; ///< The maximum region id of any span within the field.
366 float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
367 float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]
368 float cs; ///< The size of each cell. (On the xz-plane.)
369 float ch; ///< The height of each cell. (The minimum increment along the y-axis.)
370 rcCompactCell* cells; ///< Array of cells. [Size: #width*#height]
371 rcCompactSpan* spans; ///< Array of spans. [Size: #spanCount]
372 unsigned short* dist; ///< Array containing border distance data. [Size: #spanCount]
373 unsigned char* areas; ///< Array containing area id data. [Size: #spanCount]
374
375 private:
376 // Explicitly-disabled copy constructor and copy assignment operator.
377 rcCompactHeightfield(const rcCompactHeightfield&);
378 rcCompactHeightfield& operator=(const rcCompactHeightfield&);
379 };
380
381 /// Represents a heightfield layer within a layer set.
382 /// @see rcHeightfieldLayerSet
383 struct rcHeightfieldLayer
384 {
385 float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
386 float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]
387 float cs; ///< The size of each cell. (On the xz-plane.)
388 float ch; ///< The height of each cell. (The minimum increment along the y-axis.)
389 int width; ///< The width of the heightfield. (Along the x-axis in cell units.)
390 int height; ///< The height of the heightfield. (Along the z-axis in cell units.)
391 int minx; ///< The minimum x-bounds of usable data.
392 int maxx; ///< The maximum x-bounds of usable data.
393 int miny; ///< The minimum y-bounds of usable data. (Along the z-axis.)
394 int maxy; ///< The maximum y-bounds of usable data. (Along the z-axis.)
395 int hmin; ///< The minimum height bounds of usable data. (Along the y-axis.)
396 int hmax; ///< The maximum height bounds of usable data. (Along the y-axis.)
397 unsigned char* heights; ///< The heightfield. [Size: width * height]
398 unsigned char* areas; ///< Area ids. [Size: Same as #heights]
399 unsigned char* cons; ///< Packed neighbor connection information. [Size: Same as #heights]
400 };
401
402 /// Represents a set of heightfield layers.
403 /// @ingroup recast
404 /// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet
405 struct rcHeightfieldLayerSet
406 {
407 rcHeightfieldLayerSet();
408 ~rcHeightfieldLayerSet();
409
410 rcHeightfieldLayer* layers; ///< The layers in the set. [Size: #nlayers]
411 int nlayers; ///< The number of layers in the set.
412
413 private:
414 // Explicitly-disabled copy constructor and copy assignment operator.
415 rcHeightfieldLayerSet(const rcHeightfieldLayerSet&);
416 rcHeightfieldLayerSet& operator=(const rcHeightfieldLayerSet&);
417 };
418
419 /// Represents a simple, non-overlapping contour in field space.
420 struct rcContour
421 {
422 int* verts; ///< Simplified contour vertex and connection data. [Size: 4 * #nverts]
423 int nverts; ///< The number of vertices in the simplified contour.
424 int* rverts; ///< Raw contour vertex and connection data. [Size: 4 * #nrverts]
425 int nrverts; ///< The number of vertices in the raw contour.
426 unsigned short reg; ///< The region id of the contour.
427 unsigned char area; ///< The area id of the contour.
428 };
429
430 /// Represents a group of related contours.
431 /// @ingroup recast
432 struct rcContourSet
433 {
434 rcContourSet();
435 ~rcContourSet();
436
437 rcContour* conts; ///< An array of the contours in the set. [Size: #nconts]
438 int nconts; ///< The number of contours in the set.
439 float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
440 float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]
441 float cs; ///< The size of each cell. (On the xz-plane.)
442 float ch; ///< The height of each cell. (The minimum increment along the y-axis.)
443 int width; ///< The width of the set. (Along the x-axis in cell units.)
444 int height; ///< The height of the set. (Along the z-axis in cell units.)
445 int borderSize; ///< The AABB border size used to generate the source data from which the contours were derived.
446 float maxError; ///< The max edge error that this contour set was simplified with.
447
448 private:
449 // Explicitly-disabled copy constructor and copy assignment operator.
450 rcContourSet(const rcContourSet&);
451 rcContourSet& operator=(const rcContourSet&);
452 };
453
454 /// Represents a polygon mesh suitable for use in building a navigation mesh.
455 /// @ingroup recast
456 struct rcPolyMesh
457 {
458 rcPolyMesh();
459 ~rcPolyMesh();
460
461 unsigned short* verts; ///< The mesh vertices. [Form: (x, y, z) * #nverts]
462 unsigned short* polys; ///< Polygon and neighbor data. [Length: #maxpolys * 2 * #nvp]
463 unsigned short* regs; ///< The region id assigned to each polygon. [Length: #maxpolys]
464 unsigned short* flags; ///< The user defined flags for each polygon. [Length: #maxpolys]
465 unsigned char* areas; ///< The area id assigned to each polygon. [Length: #maxpolys]
466 int nverts; ///< The number of vertices.
467 int npolys; ///< The number of polygons.
468 int maxpolys; ///< The number of allocated polygons.
469 int nvp; ///< The maximum number of vertices per polygon.
470 float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
471 float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)]
472 float cs; ///< The size of each cell. (On the xz-plane.)
473 float ch; ///< The height of each cell. (The minimum increment along the y-axis.)
474 int borderSize; ///< The AABB border size used to generate the source data from which the mesh was derived.
475 float maxEdgeError; ///< The max error of the polygon edges in the mesh.
476
477 private:
478 // Explicitly-disabled copy constructor and copy assignment operator.
479 rcPolyMesh(const rcPolyMesh&);
480 rcPolyMesh& operator=(const rcPolyMesh&);
481 };
482
483 /// Contains triangle meshes that represent detailed height data associated
484 /// with the polygons in its associated polygon mesh object.
485 /// @ingroup recast
486 struct rcPolyMeshDetail
487 {
488 rcPolyMeshDetail();
489
490 unsigned int* meshes; ///< The sub-mesh data. [Size: 4*#nmeshes]
491 float* verts; ///< The mesh vertices. [Size: 3*#nverts]
492 unsigned char* tris; ///< The mesh triangles. [Size: 4*#ntris]
493 int nmeshes; ///< The number of sub-meshes defined by #meshes.
494 int nverts; ///< The number of vertices in #verts.
495 int ntris; ///< The number of triangles in #tris.
496
497 private:
498 // Explicitly-disabled copy constructor and copy assignment operator.
499 rcPolyMeshDetail(const rcPolyMeshDetail&);
500 rcPolyMeshDetail& operator=(const rcPolyMeshDetail&);
501 };
502
503 /// @name Allocation Functions
504 /// Functions used to allocate and de-allocate Recast objects.
505 /// @see rcAllocSetCustom
506 /// @{
507
508 /// Allocates a heightfield object using the Recast allocator.
509 /// @return A heightfield that is ready for initialization, or null on failure.
510 /// @ingroup recast
511 /// @see rcCreateHeightfield, rcFreeHeightField
512 rcHeightfield* rcAllocHeightfield();
513
514 /// Frees the specified heightfield object using the Recast allocator.
515 /// @param[in] heightfield A heightfield allocated using #rcAllocHeightfield
516 /// @ingroup recast
517 /// @see rcAllocHeightfield
518 void rcFreeHeightField(rcHeightfield* heightfield);
519
520 /// Allocates a compact heightfield object using the Recast allocator.
521 /// @return A compact heightfield that is ready for initialization, or null on failure.
522 /// @ingroup recast
523 /// @see rcBuildCompactHeightfield, rcFreeCompactHeightfield
524 rcCompactHeightfield* rcAllocCompactHeightfield();
525
526 /// Frees the specified compact heightfield object using the Recast allocator.
527 /// @param[in] compactHeightfield A compact heightfield allocated using #rcAllocCompactHeightfield
528 /// @ingroup recast
529 /// @see rcAllocCompactHeightfield
530 void rcFreeCompactHeightfield(rcCompactHeightfield* compactHeightfield);
531
532 /// Allocates a heightfield layer set using the Recast allocator.
533 /// @return A heightfield layer set that is ready for initialization, or null on failure.
534 /// @ingroup recast
535 /// @see rcBuildHeightfieldLayers, rcFreeHeightfieldLayerSet
536 rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet();
537
538 /// Frees the specified heightfield layer set using the Recast allocator.
539 /// @param[in] layerSet A heightfield layer set allocated using #rcAllocHeightfieldLayerSet
540 /// @ingroup recast
541 /// @see rcAllocHeightfieldLayerSet
542 void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* layerSet);
543
544 /// Allocates a contour set object using the Recast allocator.
545 /// @return A contour set that is ready for initialization, or null on failure.
546 /// @ingroup recast
547 /// @see rcBuildContours, rcFreeContourSet
548 rcContourSet* rcAllocContourSet();
549
550 /// Frees the specified contour set using the Recast allocator.
551 /// @param[in] contourSet A contour set allocated using #rcAllocContourSet
552 /// @ingroup recast
553 /// @see rcAllocContourSet
554 void rcFreeContourSet(rcContourSet* contourSet);
555
556 /// Allocates a polygon mesh object using the Recast allocator.
557 /// @return A polygon mesh that is ready for initialization, or null on failure.
558 /// @ingroup recast
559 /// @see rcBuildPolyMesh, rcFreePolyMesh
560 rcPolyMesh* rcAllocPolyMesh();
561
562 /// Frees the specified polygon mesh using the Recast allocator.
563 /// @param[in] polyMesh A polygon mesh allocated using #rcAllocPolyMesh
564 /// @ingroup recast
565 /// @see rcAllocPolyMesh
566 void rcFreePolyMesh(rcPolyMesh* polyMesh);
567
568 /// Allocates a detail mesh object using the Recast allocator.
569 /// @return A detail mesh that is ready for initialization, or null on failure.
570 /// @ingroup recast
571 /// @see rcBuildPolyMeshDetail, rcFreePolyMeshDetail
572 rcPolyMeshDetail* rcAllocPolyMeshDetail();
573
574 /// Frees the specified detail mesh using the Recast allocator.
575 /// @param[in] detailMesh A detail mesh allocated using #rcAllocPolyMeshDetail
576 /// @ingroup recast
577 /// @see rcAllocPolyMeshDetail
578 void rcFreePolyMeshDetail(rcPolyMeshDetail* detailMesh);
579
580 /// @}
581
582 /// Heightfield border flag.
583 /// If a heightfield region ID has this bit set, then the region is a border
584 /// region and its spans are considered un-walkable.
585 /// (Used during the region and contour build process.)
586 /// @see rcCompactSpan::reg
587 static const unsigned short RC_BORDER_REG = 0x8000;
588
589 /// Polygon touches multiple regions.
590 /// If a polygon has this region ID it was merged with or created
591 /// from polygons of different regions during the polymesh
592 /// build step that removes redundant border vertices.
593 /// (Used during the polymesh and detail polymesh build processes)
594 /// @see rcPolyMesh::regs
595 static const unsigned short RC_MULTIPLE_REGS = 0;
596
597 /// Border vertex flag.
598 /// If a region ID has this bit set, then the associated element lies on
599 /// a tile border. If a contour vertex's region ID has this bit set, the
600 /// vertex will later be removed in order to match the segments and vertices
601 /// at tile boundaries.
602 /// (Used during the build process.)
603 /// @see rcCompactSpan::reg, #rcContour::verts, #rcContour::rverts
604 static const int RC_BORDER_VERTEX = 0x10000;
605
606 /// Area border flag.
607 /// If a region ID has this bit set, then the associated element lies on
608 /// the border of an area.
609 /// (Used during the region and contour build process.)
610 /// @see rcCompactSpan::reg, #rcContour::verts, #rcContour::rverts
611 static const int RC_AREA_BORDER = 0x20000;
612
613 /// Contour build flags.
614 /// @see rcBuildContours
615 enum rcBuildContoursFlags
616 {
617 RC_CONTOUR_TESS_WALL_EDGES = 0x01, ///< Tessellate solid (impassable) edges during contour simplification.
618 RC_CONTOUR_TESS_AREA_EDGES = 0x02 ///< Tessellate edges between areas during contour simplification.
619 };
620
621 /// Applied to the region id field of contour vertices in order to extract the region id.
622 /// The region id field of a vertex may have several flags applied to it. So the
623 /// fields value can't be used directly.
624 /// @see rcContour::verts, rcContour::rverts
625 static const int RC_CONTOUR_REG_MASK = 0xffff;
626
627 /// An value which indicates an invalid index within a mesh.
628 /// @note This does not necessarily indicate an error.
629 /// @see rcPolyMesh::polys
630 static const unsigned short RC_MESH_NULL_IDX = 0xffff;
631
632 /// Represents the null area.
633 /// When a data element is given this value it is considered to no longer be
634 /// assigned to a usable area. (E.g. It is un-walkable.)
635 static const unsigned char RC_NULL_AREA = 0;
636
637 /// The default area id used to indicate a walkable polygon.
638 /// This is also the maximum allowed area id, and the only non-null area id
639 /// recognized by some steps in the build process.
640 static const unsigned char RC_WALKABLE_AREA = 63;
641
642 /// The value returned by #rcGetCon if the specified direction is not connected
643 /// to another span. (Has no neighbor.)
644 static const int RC_NOT_CONNECTED = 0x3f;
645
646 /// @name General helper functions
647 /// @{
648
649 /// Swaps the values of the two parameters.
650 /// @param[in,out] a Value A
651 /// @param[in,out] b Value B
652 template<class T> inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }
653
654 /// Returns the minimum of two values.
655 /// @param[in] a Value A
656 /// @param[in] b Value B
657 /// @return The minimum of the two values.
658 template<class T> inline T rcMin(T a, T b) { return a < b ? a : b; }
659
660 /// Returns the maximum of two values.
661 /// @param[in] a Value A
662 /// @param[in] b Value B
663 /// @return The maximum of the two values.
664 template<class T> inline T rcMax(T a, T b) { return a > b ? a : b; }
665
666 /// Returns the absolute value.
667 /// @param[in] a The value.
668 /// @return The absolute value of the specified value.
669 template<class T> inline T rcAbs(T a) { return a < 0 ? -a : a; }
670
671 /// Returns the square of the value.
672 /// @param[in] a The value.
673 /// @return The square of the value.
•674 template<class T> inline T rcSqr(T a) { return a * a; }
675
676 /// Clamps the value to the specified range.
677 /// @param[in] value The value to clamp.
678 /// @param[in] minInclusive The minimum permitted return value.
679 /// @param[in] maxInclusive The maximum permitted return value.
680 /// @return The value, clamped to the specified range.
681 template<class T> inline T rcClamp(T value, T minInclusive, T maxInclusive)
682 {
683 return value < minInclusive ? minInclusive: (value > maxInclusive ? maxInclusive : value);
684 }
685
686 /// Returns the square root of the value.
687 /// @param[in] x The value.
688 /// @return The square root of the vlaue.
689 float rcSqrt(float x);
690
691 /// @}
692 /// @name Vector helper functions.
693 /// @{
694
695 /// Derives the cross product of two vectors. (@p v1 x @p v2)
696 /// @param[out] dest The cross product. [(x, y, z)]
697 /// @param[in] v1 A Vector [(x, y, z)]
698 /// @param[in] v2 A vector [(x, y, z)]
699 inline void rcVcross(float* dest, const float* v1, const float* v2)
700 {
701 dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
702 dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
703 dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
704 }
705
706 /// Derives the dot product of two vectors. (@p v1 . @p v2)
707 /// @param[in] v1 A Vector [(x, y, z)]
708 /// @param[in] v2 A vector [(x, y, z)]
709 /// @return The dot product.
710 inline float rcVdot(const float* v1, const float* v2)
711 {
712 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
713 }
714
715 /// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s))
716 /// @param[out] dest The result vector. [(x, y, z)]
717 /// @param[in] v1 The base vector. [(x, y, z)]
718 /// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)]
719 /// @param[in] s The amount to scale @p v2 by before adding to @p v1.
720 inline void rcVmad(float* dest, const float* v1, const float* v2, const float s)
721 {
722 dest[0] = v1[0]+v2[0]*s;
723 dest[1] = v1[1]+v2[1]*s;
724 dest[2] = v1[2]+v2[2]*s;
725 }
726
727 /// Performs a vector addition. (@p v1 + @p v2)
728 /// @param[out] dest The result vector. [(x, y, z)]
729 /// @param[in] v1 The base vector. [(x, y, z)]
730 /// @param[in] v2 The vector to add to @p v1. [(x, y, z)]
731 inline void rcVadd(float* dest, const float* v1, const float* v2)
732 {
733 dest[0] = v1[0]+v2[0];
734 dest[1] = v1[1]+v2[1];
735 dest[2] = v1[2]+v2[2];
736 }
737
738 /// Performs a vector subtraction. (@p v1 - @p v2)
739 /// @param[out] dest The result vector. [(x, y, z)]
740 /// @param[in] v1 The base vector. [(x, y, z)]
741 /// @param[in] v2 The vector to subtract from @p v1. [(x, y, z)]
742 inline void rcVsub(float* dest, const float* v1, const float* v2)
743 {
744 dest[0] = v1[0]-v2[0];
745 dest[1] = v1[1]-v2[1];
746 dest[2] = v1[2]-v2[2];
747 }
748
749 /// Selects the minimum value of each element from the specified vectors.
750 /// @param[in,out] mn A vector. (Will be updated with the result.) [(x, y, z)]
751 /// @param[in] v A vector. [(x, y, z)]
752 inline void rcVmin(float* mn, const float* v)
753 {
754 mn[0] = rcMin(mn[0], v[0]);
755 mn[1] = rcMin(mn[1], v[1]);
756 mn[2] = rcMin(mn[2], v[2]);
757 }
758
759 /// Selects the maximum value of each element from the specified vectors.
760 /// @param[in,out] mx A vector. (Will be updated with the result.) [(x, y, z)]
761 /// @param[in] v A vector. [(x, y, z)]
762 inline void rcVmax(float* mx, const float* v)
763 {
764 mx[0] = rcMax(mx[0], v[0]);
765 mx[1] = rcMax(mx[1], v[1]);
766 mx[2] = rcMax(mx[2], v[2]);
767 }
768
769 /// Performs a vector copy.
770 /// @param[out] dest The result. [(x, y, z)]
771 /// @param[in] v The vector to copy. [(x, y, z)]
772 inline void rcVcopy(float* dest, const float* v)
773 {
774 dest[0] = v[0];
775 dest[1] = v[1];
776 dest[2] = v[2];
777 }
778
779 /// Returns the distance between two points.
780 /// @param[in] v1 A point. [(x, y, z)]
781 /// @param[in] v2 A point. [(x, y, z)]
782 /// @return The distance between the two points.
783 inline float rcVdist(const float* v1, const float* v2)
784 {
785 float dx = v2[0] - v1[0];
786 float dy = v2[1] - v1[1];
787 float dz = v2[2] - v1[2];
788 return rcSqrt(dx*dx + dy*dy + dz*dz);
789 }
790
791 /// Returns the square of the distance between two points.
792 /// @param[in] v1 A point. [(x, y, z)]
793 /// @param[in] v2 A point. [(x, y, z)]
794 /// @return The square of the distance between the two points.
795 inline float rcVdistSqr(const float* v1, const float* v2)
796 {
797 float dx = v2[0] - v1[0];
798 float dy = v2[1] - v1[1];
799 float dz = v2[2] - v1[2];
800 return dx*dx + dy*dy + dz*dz;
801 }
802
803 /// Normalizes the vector.
804 /// @param[in,out] v The vector to normalize. [(x, y, z)]
805 inline void rcVnormalize(float* v)
806 {
807 float d = 1.0f / rcSqrt(rcSqr(v[0]) + rcSqr(v[1]) + rcSqr(v[2]));
808 v[0] *= d;
809 v[1] *= d;
810 v[2] *= d;
811 }
812
813 /// @}
814 /// @name Heightfield Functions
815 /// @see rcHeightfield
816 /// @{
817
818 /// Calculates the bounding box of an array of vertices.
819 /// @ingroup recast
820 /// @param[in] verts An array of vertices. [(x, y, z) * @p nv]
821 /// @param[in] numVerts The number of vertices in the @p verts array.
822 /// @param[out] minBounds The minimum bounds of the AABB. [(x, y, z)] [Units: wu]
823 /// @param[out] maxBounds The maximum bounds of the AABB. [(x, y, z)] [Units: wu]
824 void rcCalcBounds(const float* verts, int numVerts, float* minBounds, float* maxBounds);
825
826 /// Calculates the grid size based on the bounding box and grid cell size.
827 /// @ingroup recast
828 /// @param[in] minBounds The minimum bounds of the AABB. [(x, y, z)] [Units: wu]
829 /// @param[in] maxBounds The maximum bounds of the AABB. [(x, y, z)] [Units: wu]
830 /// @param[in] cellSize The xz-plane cell size. [Limit: > 0] [Units: wu]
831 /// @param[out] sizeX The width along the x-axis. [Limit: >= 0] [Units: vx]
832 /// @param[out] sizeZ The height along the z-axis. [Limit: >= 0] [Units: vx]
833 void rcCalcGridSize(const float* minBounds, const float* maxBounds, float cellSize, int* sizeX, int* sizeZ);
834
835 /// Initializes a new heightfield.
836 /// See the #rcConfig documentation for more information on the configuration parameters.
837 ///
838 /// @see rcAllocHeightfield, rcHeightfield
839 /// @ingroup recast
840 ///
841 /// @param[in,out] context The build context to use during the operation.
842 /// @param[in,out] heightfield The allocated heightfield to initialize.
843 /// @param[in] sizeX The width of the field along the x-axis. [Limit: >= 0] [Units: vx]
844 /// @param[in] sizeZ The height of the field along the z-axis. [Limit: >= 0] [Units: vx]
845 /// @param[in] minBounds The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]
846 /// @param[in] maxBounds The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]
847 /// @param[in] cellSize The xz-plane cell size to use for the field. [Limit: > 0] [Units: wu]
848 /// @param[in] cellHeight The y-axis cell size to use for field. [Limit: > 0] [Units: wu]
849 /// @returns True if the operation completed successfully.
850 bool rcCreateHeightfield(rcContext* context, rcHeightfield& heightfield, int sizeX, int sizeZ,
851 const float* minBounds, const float* maxBounds,
852 float cellSize, float cellHeight);
853
854 /// Sets the area id of all triangles with a slope below the specified value
855 /// to #RC_WALKABLE_AREA.
856 ///
857 /// Only sets the area id's for the walkable triangles. Does not alter the
858 /// area id's for un-walkable triangles.
859 ///
860 /// See the #rcConfig documentation for more information on the configuration parameters.
861 ///
862 /// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
863 ///
864 /// @ingroup recast
865 /// @param[in,out] context The build context to use during the operation.
866 /// @param[in] walkableSlopeAngle The maximum slope that is considered walkable.
867 /// [Limits: 0 <= value < 90] [Units: Degrees]
868 /// @param[in] verts The vertices. [(x, y, z) * @p nv]
869 /// @param[in] numVerts The number of vertices.
870 /// @param[in] tris The triangle vertex indices. [(vertA, vertB, vertC) * @p nt]
871 /// @param[in] numTris The number of triangles.
872 /// @param[out] triAreaIDs The triangle area ids. [Length: >= @p nt]
873 void rcMarkWalkableTriangles(rcContext* context, float walkableSlopeAngle, const float* verts, int numVerts,
874 const int* tris, int numTris, unsigned char* triAreaIDs);
875
876 /// Sets the area id of all triangles with a slope greater than or equal to the specified value to #RC_NULL_AREA.
877 ///
878 /// Only sets the area id's for the un-walkable triangles. Does not alter the
879 /// area id's for walkable triangles.
880 ///
881 /// See the #rcConfig documentation for more information on the configuration parameters.
882 ///
883 /// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
884 ///
885 /// @ingroup recast
886 /// @param[in,out] context The build context to use during the operation.
887 /// @param[in] walkableSlopeAngle The maximum slope that is considered walkable.
888 /// [Limits: 0 <= value < 90] [Units: Degrees]
889 /// @param[in] verts The vertices. [(x, y, z) * @p nv]
890 /// @param[in] numVerts The number of vertices.
891 /// @param[in] tris The triangle vertex indices. [(vertA, vertB, vertC) * @p nt]
892 /// @param[in] numTris The number of triangles.
893 /// @param[out] triAreaIDs The triangle area ids. [Length: >= @p nt]
894 void rcClearUnwalkableTriangles(rcContext* context, float walkableSlopeAngle, const float* verts, int numVerts,
895 const int* tris, int numTris, unsigned char* triAreaIDs);
896
897 /// Adds a span to the specified heightfield.
898 ///
899 /// The span addition can be set to favor flags. If the span is merged to
900 /// another span and the new @p spanMax is within @p flagMergeThreshold units
901 /// from the existing span, the span flags are merged.
902 ///
903 /// @ingroup recast
904 /// @param[in,out] context The build context to use during the operation.
905 /// @param[in,out] heightfield An initialized heightfield.
906 /// @param[in] x The column x index where the span is to be added.
907 /// [Limits: 0 <= value < rcHeightfield::width]
908 /// @param[in] z The column z index where the span is to be added.
909 /// [Limits: 0 <= value < rcHeightfield::height]
910 /// @param[in] spanMin The minimum height of the span. [Limit: < @p spanMax] [Units: vx]
911 /// @param[in] spanMax The maximum height of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT] [Units: vx]
912 /// @param[in] areaID The area id of the span. [Limit: <= #RC_WALKABLE_AREA)
913 /// @param[in] flagMergeThreshold The merge threshold. [Limit: >= 0] [Units: vx]
914 /// @returns True if the operation completed successfully.
915 bool rcAddSpan(rcContext* context, rcHeightfield& heightfield,
916 int x, int z,
917 unsigned short spanMin, unsigned short spanMax,
918 unsigned char areaID, int flagMergeThreshold);
919
920 /// Rasterizes a single triangle into the specified heightfield.
921 ///
922 /// Calling this for each triangle in a mesh is less efficient than calling rcRasterizeTriangles
923 ///
924 /// No spans will be added if the triangle does not overlap the heightfield grid.
925 ///
926 /// @see rcHeightfield
927 /// @ingroup recast
928 /// @param[in,out] context The build context to use during the operation.
929 /// @param[in] v0 Triangle vertex 0 [(x, y, z)]
930 /// @param[in] v1 Triangle vertex 1 [(x, y, z)]
931 /// @param[in] v2 Triangle vertex 2 [(x, y, z)]
932 /// @param[in] areaID The area id of the triangle. [Limit: <= #RC_WALKABLE_AREA]
933 /// @param[in,out] heightfield An initialized heightfield.
934 /// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.
935 /// [Limit: >= 0] [Units: vx]
936 /// @returns True if the operation completed successfully.
937 bool rcRasterizeTriangle(rcContext* context,
938 const float* v0, const float* v1, const float* v2,
939 unsigned char areaID, rcHeightfield& heightfield, int flagMergeThreshold = 1);
940
941 /// Rasterizes an indexed triangle mesh into the specified heightfield.
942 ///
943 /// Spans will only be added for triangles that overlap the heightfield grid.
944 ///
945 /// @see rcHeightfield
946 /// @ingroup recast
947 /// @param[in,out] context The build context to use during the operation.
948 /// @param[in] verts The vertices. [(x, y, z) * @p nv]
949 /// @param[in] numVerts The number of vertices. (unused) TODO (graham): Remove in next major release
950 /// @param[in] tris The triangle indices. [(vertA, vertB, vertC) * @p nt]
951 /// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]
952 /// @param[in] numTris The number of triangles.
953 /// @param[in,out] heightfield An initialized heightfield.
954 /// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.
955 /// [Limit: >= 0] [Units: vx]
956 /// @returns True if the operation completed successfully.
957 bool rcRasterizeTriangles(rcContext* context,
958 const float* verts, int numVerts,
959 const int* tris, const unsigned char* triAreaIDs, int numTris,
960 rcHeightfield& heightfield, int flagMergeThreshold = 1);
961
962 /// Rasterizes an indexed triangle mesh into the specified heightfield.
963 ///
964 /// Spans will only be added for triangles that overlap the heightfield grid.
965 ///
966 /// @see rcHeightfield
967 /// @ingroup recast
968 /// @param[in,out] context The build context to use during the operation.
969 /// @param[in] verts The vertices. [(x, y, z) * @p nv]
970 /// @param[in] numVerts The number of vertices. (unused) TODO (graham): Remove in next major release
971 /// @param[in] tris The triangle indices. [(vertA, vertB, vertC) * @p nt]
972 /// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]
973 /// @param[in] numTris The number of triangles.
974 /// @param[in,out] heightfield An initialized heightfield.
975 /// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.
976 /// [Limit: >= 0] [Units: vx]
977 /// @returns True if the operation completed successfully.
978 bool rcRasterizeTriangles(rcContext* context,
979 const float* verts, int numVerts,
980 const unsigned short* tris, const unsigned char* triAreaIDs, int numTris,
981 rcHeightfield& heightfield, int flagMergeThreshold = 1);
982
983 /// Rasterizes a triangle list into the specified heightfield.
984 ///
985 /// Expects each triangle to be specified as three sequential vertices of 3 floats.
986 ///
987 /// Spans will only be added for triangles that overlap the heightfield grid.
988 ///
989 /// @see rcHeightfield
990 /// @ingroup recast
991 /// @param[in,out] context The build context to use during the operation.
992 /// @param[in] verts The triangle vertices. [(ax, ay, az, bx, by, bz, cx, by, cx) * @p nt]
993 /// @param[in] triAreaIDs The area id's of the triangles. [Limit: <= #RC_WALKABLE_AREA] [Size: @p nt]
994 /// @param[in] numTris The number of triangles.
995 /// @param[in,out] heightfield An initialized heightfield.
996 /// @param[in] flagMergeThreshold The distance where the walkable flag is favored over the non-walkable flag.
997 /// [Limit: >= 0] [Units: vx]
998 /// @returns True if the operation completed successfully.
999 bool rcRasterizeTriangles(rcContext* context,
1000 const float* verts, const unsigned char* triAreaIDs, int numTris,
1001 rcHeightfield& heightfield, int flagMergeThreshold = 1);
1002
•1003 /// Marks non-walkable spans as walkable if their maximum is within @p walkableClimb of the span below them.
1004 ///
•1005 /// This removes small obstacles and rasterization artifacts that the agent would be able to walk over
1006 /// such as curbs. It also allows agents to move up terraced structures like stairs.
•1007 ///
•1008 /// Obstacle spans are marked walkable if: <tt>obstacleSpan.smax - walkableSpan.smax < walkableClimb</tt>
1009 ///
•1010 /// @warning Will override the effect of #rcFilterLedgeSpans. If both filters are used, call #rcFilterLedgeSpans only after applying this filter.
1011 ///
1012 /// @see rcHeightfield, rcConfig
1013 ///
1014 /// @ingroup recast
•1015 /// @param[in,out] context The build context to use during the operation.
1016 /// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.
1017 /// [Limit: >=0] [Units: vx]
•1018 /// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)
1019 void rcFilterLowHangingWalkableObstacles(rcContext* context, int walkableClimb, rcHeightfield& heightfield);
1020
1021 /// Marks spans that are ledges as not-walkable.
1022 ///
1023 /// A ledge is a span with one or more neighbors whose maximum is further away than @p walkableClimb
1024 /// from the current span's maximum.
1025 /// This method removes the impact of the overestimation of conservative voxelization
1026 /// so the resulting mesh will not have regions hanging in the air over ledges.
1027 ///
1028 /// A span is a ledge if: <tt>rcAbs(currentSpan.smax - neighborSpan.smax) > walkableClimb</tt>
1029 ///
1030 /// @see rcHeightfield, rcConfig
1031 ///
1032 /// @ingroup recast
1033 /// @param[in,out] context The build context to use during the operation.
1034 /// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area to
1035 /// be considered walkable. [Limit: >= 3] [Units: vx]
1036 /// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.
1037 /// [Limit: >=0] [Units: vx]
1038 /// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)
1039 void rcFilterLedgeSpans(rcContext* context, int walkableHeight, int walkableClimb, rcHeightfield& heightfield);
1040
•1041 /// Marks walkable spans as not walkable if the clearance above the span is less than the specified walkableHeight.
1042 ///
1043 /// For this filter, the clearance above the span is the distance from the span's
•1044 /// maximum to the minimum of the next higher span in the same column.
1045 /// If there is no higher span in the column, the clearance is computed as the
1046 /// distance from the top of the span to the maximum heightfield height.
1047 ///
1048 /// @see rcHeightfield, rcConfig
1049 /// @ingroup recast
1050 ///
1051 /// @param[in,out] context The build context to use during the operation.
1052 /// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area to
1053 /// be considered walkable. [Limit: >= 3] [Units: vx]
1054 /// @param[in,out] heightfield A fully built heightfield. (All spans have been added.)
1055 void rcFilterWalkableLowHeightSpans(rcContext* context, int walkableHeight, rcHeightfield& heightfield);
1056
1057 /// Returns the number of spans contained in the specified heightfield.
1058 /// @ingroup recast
1059 /// @param[in,out] context The build context to use during the operation.
1060 /// @param[in] heightfield An initialized heightfield.
1061 /// @returns The number of spans in the heightfield.
1062 int rcGetHeightFieldSpanCount(rcContext* context, const rcHeightfield& heightfield);
1063
1064 /// @}
1065 /// @name Compact Heightfield Functions
1066 /// @see rcCompactHeightfield
1067 /// @{
1068
1069 /// Builds a compact heightfield representing open space, from a heightfield representing solid space.
1070 ///
1071 /// This is just the beginning of the process of fully building a compact heightfield.
1072 /// Various filters may be applied, then the distance field and regions built.
1073 /// E.g: #rcBuildDistanceField and #rcBuildRegions
1074 ///
1075 /// See the #rcConfig documentation for more information on the configuration parameters.
1076 ///
1077 /// @see rcAllocCompactHeightfield, rcHeightfield, rcCompactHeightfield, rcConfig
1078 /// @ingroup recast
1079 ///
1080 /// @param[in,out] context The build context to use during the operation.
1081 /// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area
1082 /// to be considered walkable. [Limit: >= 3] [Units: vx]
1083 /// @param[in] walkableClimb Maximum ledge height that is considered to still be traversable.
1084 /// [Limit: >=0] [Units: vx]
1085 /// @param[in] heightfield The heightfield to be compacted.
1086 /// @param[out] compactHeightfield The resulting compact heightfield. (Must be pre-allocated.)
1087 /// @returns True if the operation completed successfully.
1088 bool rcBuildCompactHeightfield(rcContext* context, int walkableHeight, int walkableClimb,
1089 const rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield);
1090
•1091 /// Erodes the walkable area within the heightfield by the specified radius.
1092 ///
1093 /// Basically, any spans that are closer to a boundary or obstruction than the specified radius
1094 /// are marked as un-walkable.
1095 ///
1096 /// This method is usually called immediately after the heightfield has been built.
1097 ///
1098 /// @see rcCompactHeightfield, rcBuildCompactHeightfield, rcConfig::walkableRadius
1099 /// @ingroup recast
•1100 ///
1101 /// @param[in,out] context The build context to use during the operation.
1102 /// @param[in] erosionRadius The radius of erosion. [Limits: 0 < value < 255] [Units: vx]
1103 /// @param[in,out] compactHeightfield The populated compact heightfield to erode.
1104 /// @returns True if the operation completed successfully.
•1105 bool rcErodeWalkableArea(rcContext* context, int erosionRadius, rcCompactHeightfield& compactHeightfield);
1106
1107 /// Applies a median filter to walkable area types (based on area id), removing noise.
•1108 ///
1109 /// This filter is usually applied after applying area id's using functions
1110 /// such as #rcMarkBoxArea, #rcMarkConvexPolyArea, and #rcMarkCylinderArea.
1111 ///
1112 /// @see rcCompactHeightfield
1113 /// @ingroup recast
•1114 ///
1115 /// @param[in,out] context The build context to use during the operation.
1116 /// @param[in,out] compactHeightfield A populated compact heightfield.
1117 /// @returns True if the operation completed successfully.
•1118 bool rcMedianFilterWalkableArea(rcContext* context, rcCompactHeightfield& compactHeightfield);
1119
1120 /// Applies an area id to all spans within the specified bounding box. (AABB)
•1121 ///
1122 /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
1123 /// @ingroup recast
•1124 ///
1125 /// @param[in,out] context The build context to use during the operation.
1126 /// @param[in] boxMinBounds The minimum extents of the bounding box. [(x, y, z)] [Units: wu]
1127 /// @param[in] boxMaxBounds The maximum extents of the bounding box. [(x, y, z)] [Units: wu]
1128 /// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]
1129 /// @param[in,out] compactHeightfield A populated compact heightfield.
1130 void rcMarkBoxArea(rcContext* context, const float* boxMinBounds, const float* boxMaxBounds, unsigned char areaId,
1131 rcCompactHeightfield& compactHeightfield);
1132
1133 /// Applies the area id to the all spans within the specified convex polygon.
•1134 ///
1135 /// The value of spacial parameters are in world units.
1136 ///
1137 /// The y-values of the polygon vertices are ignored. So the polygon is effectively
1138 /// projected onto the xz-plane, translated to @p minY, and extruded to @p maxY.
1139 ///
1140 /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
1141 /// @ingroup recast
•1142 ///
1143 /// @param[in,out] context The build context to use during the operation.
1144 /// @param[in] verts The vertices of the polygon [For: (x, y, z) * @p numVerts]
1145 /// @param[in] numVerts The number of vertices in the polygon.
1146 /// @param[in] minY The height of the base of the polygon. [Units: wu]
1147 /// @param[in] maxY The height of the top of the polygon. [Units: wu]
1148 /// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]
1149 /// @param[in,out] compactHeightfield A populated compact heightfield.
1150 void rcMarkConvexPolyArea(rcContext* context, const float* verts, int numVerts,
1151 float minY, float maxY, unsigned char areaId,
1152 rcCompactHeightfield& compactHeightfield);
1153
1154 /// Expands a convex polygon along its vertex normals by the given offset amount.
1155 /// Inserts extra vertices to bevel sharp corners.
1156 ///
1157 /// Helper function to offset convex polygons for rcMarkConvexPolyArea.
1158 ///
1159 /// @ingroup recast
•1160 ///
1161 /// @param[in] verts The vertices of the polygon [Form: (x, y, z) * @p numVerts]
1162 /// @param[in] numVerts The number of vertices in the polygon.
1163 /// @param[in] offset How much to offset the polygon by. [Units: wu]
•1164 /// @param[out] outVerts The offset vertices (should hold up to 2 * @p numVerts) [Form: (x, y, z) * return value]
1165 /// @param[in] maxOutVerts The max number of vertices that can be stored to @p outVerts.
1166 /// @returns Number of vertices in the offset polygon or 0 if too few vertices in @p outVerts.
•1167 int rcOffsetPoly(const float* verts, int numVerts, float offset, float* outVerts, int maxOutVerts);
1168
•1169 /// Applies the area id to all spans within the specified y-axis-aligned cylinder.
1170 ///
1171 /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
1172 ///
1173 /// @ingroup recast
•1174 ///
1175 /// @param[in,out] context The build context to use during the operation.
1176 /// @param[in] position The center of the base of the cylinder. [Form: (x, y, z)] [Units: wu]
1177 /// @param[in] radius The radius of the cylinder. [Units: wu] [Limit: > 0]
1178 /// @param[in] height The height of the cylinder. [Units: wu] [Limit: > 0]
1179 /// @param[in] areaId The area id to apply. [Limit: <= #RC_WALKABLE_AREA]
1180 /// @param[in,out] compactHeightfield A populated compact heightfield.
1181 void rcMarkCylinderArea(rcContext* context, const float* position, float radius, float height,
1182 unsigned char areaId, rcCompactHeightfield& compactHeightfield);
1183
1184 /// Builds the distance field for the specified compact heightfield.
1185 /// @ingroup recast
1186 /// @param[in,out] ctx The build context to use during the operation.
1187 /// @param[in,out] chf A populated compact heightfield.
1188 /// @returns True if the operation completed successfully.
1189 bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf);
1190
1191 /// Builds region data for the heightfield using watershed partitioning.
1192 /// @ingroup recast
1193 /// @param[in,out] ctx The build context to use during the operation.
1194 /// @param[in,out] chf A populated compact heightfield.
1195 /// @param[in] borderSize The size of the non-navigable border around the heightfield.
1196 /// [Limit: >=0] [Units: vx]
1197 /// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.
1198 /// [Limit: >=0] [Units: vx].
1199 /// @param[in] mergeRegionArea Any regions with a span count smaller than this value will, if possible,
1200 /// be merged with larger regions. [Limit: >=0] [Units: vx]
1201 /// @returns True if the operation completed successfully.
1202 bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf, int borderSize, int minRegionArea, int mergeRegionArea);
1203
1204 /// Builds region data for the heightfield by partitioning the heightfield in non-overlapping layers.
1205 /// @ingroup recast
1206 /// @param[in,out] ctx The build context to use during the operation.
1207 /// @param[in,out] chf A populated compact heightfield.
1208 /// @param[in] borderSize The size of the non-navigable border around the heightfield.
1209 /// [Limit: >=0] [Units: vx]
1210 /// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.
1211 /// [Limit: >=0] [Units: vx].
1212 /// @returns True if the operation completed successfully.
1213 bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf, int borderSize, int minRegionArea);
1214
1215 /// Builds region data for the heightfield using simple monotone partitioning.
1216 /// @ingroup recast
1217 /// @param[in,out] ctx The build context to use during the operation.
1218 /// @param[in,out] chf A populated compact heightfield.
1219 /// @param[in] borderSize The size of the non-navigable border around the heightfield.
1220 /// [Limit: >=0] [Units: vx]
1221 /// @param[in] minRegionArea The minimum number of cells allowed to form isolated island areas.
1222 /// [Limit: >=0] [Units: vx].
1223 /// @param[in] mergeRegionArea Any regions with a span count smaller than this value will, if possible,
1224 /// be merged with larger regions. [Limit: >=0] [Units: vx]
1225 /// @returns True if the operation completed successfully.
1226 bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,
1227 int borderSize, int minRegionArea, int mergeRegionArea);
1228
1229 /// Sets the neighbor connection data for the specified direction.
1230 /// @param[in] span The span to update.
1231 /// @param[in] direction The direction to set. [Limits: 0 <= value < 4]
1232 /// @param[in] neighborIndex The index of the neighbor span.
1233 inline void rcSetCon(rcCompactSpan& span, int direction, int neighborIndex)
1234 {
1235 const unsigned int shift = (unsigned int)direction * 6;
1236 const unsigned int con = span.con;
1237 span.con = (con & ~(0x3f << shift)) | (((unsigned int)neighborIndex & 0x3f) << shift);
1238 }
1239
1240 /// Gets neighbor connection data for the specified direction.
1241 /// @param[in] span The span to check.
1242 /// @param[in] direction The direction to check. [Limits: 0 <= value < 4]
1243 /// @return The neighbor connection data for the specified direction, or #RC_NOT_CONNECTED if there is no connection.
1244 inline int rcGetCon(const rcCompactSpan& span, int direction)
1245 {
1246 const unsigned int shift = (unsigned int)direction * 6;
1247 return (span.con >> shift) & 0x3f;
1248 }
1249
1250 /// Gets the standard width (x-axis) offset for the specified direction.
1251 /// @param[in] direction The direction. [Limits: 0 <= value < 4]
1252 /// @return The width offset to apply to the current cell position to move in the direction.
1253 inline int rcGetDirOffsetX(int direction)
1254 {
1255 static const int offset[4] = { -1, 0, 1, 0, };
1256 return offset[direction & 0x03];
1257 }
1258
1259 // TODO (graham): Rename this to rcGetDirOffsetZ
1260 /// Gets the standard height (z-axis) offset for the specified direction.
1261 /// @param[in] direction The direction. [Limits: 0 <= value < 4]
1262 /// @return The height offset to apply to the current cell position to move in the direction.
1263 inline int rcGetDirOffsetY(int direction)
1264 {
1265 static const int offset[4] = { 0, 1, 0, -1 };
1266 return offset[direction & 0x03];
1267 }
1268
1269 /// Gets the direction for the specified offset. One of x and y should be 0.
1270 /// @param[in] offsetX The x offset. [Limits: -1 <= value <= 1]
1271 /// @param[in] offsetZ The z offset. [Limits: -1 <= value <= 1]
1272 /// @return The direction that represents the offset.
1273 inline int rcGetDirForOffset(int offsetX, int offsetZ)
1274 {
1275 static const int dirs[5] = { 3, 0, -1, 2, 1 };
1276 return dirs[((offsetZ + 1) << 1) + offsetX];
1277 }
1278
1279 /// @}
1280 /// @name Layer, Contour, Polymesh, and Detail Mesh Functions
1281 /// @see rcHeightfieldLayer, rcContourSet, rcPolyMesh, rcPolyMeshDetail
1282 /// @{
1283
1284 /// Builds a layer set from the specified compact heightfield.
1285 /// @ingroup recast
1286 /// @param[in,out] ctx The build context to use during the operation.
1287 /// @param[in] chf A fully built compact heightfield.
1288 /// @param[in] borderSize The size of the non-navigable border around the heightfield. [Limit: >=0]
1289 /// [Units: vx]
1290 /// @param[in] walkableHeight Minimum floor to 'ceiling' height that will still allow the floor area
1291 /// to be considered walkable. [Limit: >= 3] [Units: vx]
1292 /// @param[out] lset The resulting layer set. (Must be pre-allocated.)
1293 /// @returns True if the operation completed successfully.
1294 bool rcBuildHeightfieldLayers(rcContext* ctx, const rcCompactHeightfield& chf,
1295 int borderSize, int walkableHeight,
1296 rcHeightfieldLayerSet& lset);
1297
1298 /// Builds a contour set from the region outlines in the provided compact heightfield.
1299 /// @ingroup recast
1300 /// @param[in,out] ctx The build context to use during the operation.
1301 /// @param[in] chf A fully built compact heightfield.
1302 /// @param[in] maxError The maximum distance a simplified contour's border edges should deviate
1303 /// the original raw contour. [Limit: >=0] [Units: wu]
1304 /// @param[in] maxEdgeLen The maximum allowed length for contour edges along the border of the mesh.
1305 /// [Limit: >=0] [Units: vx]
1306 /// @param[out] cset The resulting contour set. (Must be pre-allocated.)
1307 /// @param[in] buildFlags The build flags. (See: #rcBuildContoursFlags)
1308 /// @returns True if the operation completed successfully.
1309 bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,
1310 float maxError, int maxEdgeLen,
1311 rcContourSet& cset, int buildFlags = RC_CONTOUR_TESS_WALL_EDGES);
1312
1313 /// Builds a polygon mesh from the provided contours.
1314 /// @ingroup recast
1315 /// @param[in,out] ctx The build context to use during the operation.
1316 /// @param[in] cset A fully built contour set.
1317 /// @param[in] nvp The maximum number of vertices allowed for polygons generated during the
1318 /// contour to polygon conversion process. [Limit: >= 3]
1319 /// @param[out] mesh The resulting polygon mesh. (Must be re-allocated.)
1320 /// @returns True if the operation completed successfully.
1321 bool rcBuildPolyMesh(rcContext* ctx, const rcContourSet& cset, const int nvp, rcPolyMesh& mesh);
1322
1323 /// Merges multiple polygon meshes into a single mesh.
1324 /// @ingroup recast
1325 /// @param[in,out] ctx The build context to use during the operation.
1326 /// @param[in] meshes An array of polygon meshes to merge. [Size: @p nmeshes]
1327 /// @param[in] nmeshes The number of polygon meshes in the meshes array.
1328 /// @param[in] mesh The resulting polygon mesh. (Must be pre-allocated.)
1329 /// @returns True if the operation completed successfully.
1330 bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh);
1331
1332 /// Builds a detail mesh from the provided polygon mesh.
1333 /// @ingroup recast
1334 /// @param[in,out] ctx The build context to use during the operation.
1335 /// @param[in] mesh A fully built polygon mesh.
1336 /// @param[in] chf The compact heightfield used to build the polygon mesh.
1337 /// @param[in] sampleDist Sets the distance to use when sampling the heightfield. [Limit: >=0] [Units: wu]
1338 /// @param[in] sampleMaxError The maximum distance the detail mesh surface should deviate from
1339 /// heightfield data. [Limit: >=0] [Units: wu]
1340 /// @param[out] dmesh The resulting detail mesh. (Must be pre-allocated.)
1341 /// @returns True if the operation completed successfully.
1342 bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompactHeightfield& chf,
1343 float sampleDist, float sampleMaxError,
1344 rcPolyMeshDetail& dmesh);
1345
1346 /// Copies the poly mesh data from src to dst.
1347 /// @ingroup recast
1348 /// @param[in,out] ctx The build context to use during the operation.
1349 /// @param[in] src The source mesh to copy from.
1350 /// @param[out] dst The resulting detail mesh. (Must be pre-allocated, must be empty mesh.)
1351 /// @returns True if the operation completed successfully.
1352 bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst);
1353
1354 /// Merges multiple detail meshes into a single detail mesh.
1355 /// @ingroup recast
1356 /// @param[in,out] ctx The build context to use during the operation.
1357 /// @param[in] meshes An array of detail meshes to merge. [Size: @p nmeshes]
1358 /// @param[in] nmeshes The number of detail meshes in the meshes array.
1359 /// @param[out] mesh The resulting detail mesh. (Must be pre-allocated.)
1360 /// @returns True if the operation completed successfully.
1361 bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int nmeshes, rcPolyMeshDetail& mesh);
1362
1363 /// @}
1364
1365 #endif // RECAST_H
1366
1367 ///////////////////////////////////////////////////////////////////////////
1368
1369 // Due to the large amount of detail documentation for this file,
1370 // the content normally located at the end of the header file has been separated
1371 // out to a file in /Docs/Extern.