@recast-navigation/core 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,13 @@ export type NavMeshQueryParams = {
20
20
  };
21
21
  export declare class NavMeshQuery {
22
22
  raw: R.NavMeshQuery;
23
+ /**
24
+ * Default query filter.
25
+ */
23
26
  defaultFilter: QueryFilter;
27
+ /**
28
+ * Default search distance along each axis.
29
+ */
24
30
  defaultQueryHalfExtents: {
25
31
  x: number;
26
32
  y: number;
@@ -31,7 +37,15 @@ export declare class NavMeshQuery {
31
37
  * Finds the polygon nearest to the given position.
32
38
  */
33
39
  findNearestPoly(position: Vector3, options?: {
40
+ /**
41
+ * The polygon filter to apply to the query.
42
+ * @default this.defaultFilter
43
+ */
34
44
  filter?: QueryFilter;
45
+ /**
46
+ * The search distance along each axis. [(x, y, z)]
47
+ * @default this.defaultQueryHalfExtents
48
+ */
35
49
  halfExtents?: Vector3;
36
50
  }): {
37
51
  success: boolean;
@@ -49,10 +63,20 @@ export declare class NavMeshQuery {
49
63
  * @param startRef Reference of polygon to start search from
50
64
  * @param centerPos Center of circle
51
65
  * @param radius Radius of circle
52
- * @param filter The polygon filter to apply to the query
53
- * @param maxResult The maximum number of polygons the result arrays can hold
66
+ * @param options
54
67
  */
55
- findPolysAroundCircle(startRef: number, centerPos: Vector3, radius: number, filter?: QueryFilter, maxResult?: number): {
68
+ findPolysAroundCircle(startRef: number, centerPos: Vector3, radius: number, options?: {
69
+ /**
70
+ * The polygon filter to apply to the query.
71
+ * @default this.defaultFilter
72
+ */
73
+ filter?: QueryFilter;
74
+ /**
75
+ * The maximum number of polygons the result arrays can hold.
76
+ * @default 256
77
+ */
78
+ maxPolys?: number;
79
+ }): {
56
80
  success: boolean;
57
81
  status: number;
58
82
  resultRefs: number[];
@@ -64,10 +88,20 @@ export declare class NavMeshQuery {
64
88
  * Finds polygons that overlap the search box.
65
89
  * @param center The center of the search box
66
90
  * @param halfExtents The search distance along each axis
67
- * @param filter The polygon filter to apply to the query
68
- * @param maxPolys The maximum number of polygons the search result can hold
91
+ * @param options
69
92
  */
70
- queryPolygons(center: Vector3, halfExtents: Vector3, filter?: QueryFilter, maxPolys?: number): {
93
+ queryPolygons(center: Vector3, halfExtents: Vector3, options?: {
94
+ /**
95
+ * The polygon filter to apply to the query.
96
+ * @default this.defaultFilter
97
+ */
98
+ filter?: QueryFilter;
99
+ /**
100
+ * The maximum number of polygons the search result can hold.
101
+ * @default 256
102
+ */
103
+ maxPolys?: number;
104
+ }): {
71
105
  success: boolean;
72
106
  status: number;
73
107
  polyRefs: number[];
@@ -75,6 +109,9 @@ export declare class NavMeshQuery {
75
109
  };
76
110
  /**
77
111
  * Returns the closest point on the given polygon to the given position.
112
+ *
113
+ * @param polyRef The reference of the polygon
114
+ * @param position The position to find the closest point to
78
115
  */
79
116
  closestPointOnPoly(polyRef: number, position: Vector3): {
80
117
  success: boolean;
@@ -90,21 +127,51 @@ export declare class NavMeshQuery {
90
127
  * Returns the closest point on the NavMesh to the given position.
91
128
  */
92
129
  getClosestPoint(position: Vector3, options?: {
130
+ /**
131
+ * The polygon filter to apply to the query.
132
+ * @default this.defaultFilter
133
+ */
93
134
  filter?: QueryFilter;
135
+ /**
136
+ * The search distance along each axis. [(x, y, z)]
137
+ * @default this.defaultQueryHalfExtents
138
+ */
94
139
  halfExtents?: Vector3;
95
140
  }): Vector3;
96
141
  /**
97
142
  * Returns a random point on the NavMesh within the given radius of the given position.
98
143
  */
99
144
  getRandomPointAround(position: Vector3, radius: number, options?: {
145
+ /**
146
+ * The polygon filter to apply to the query.
147
+ * @default this.defaultFilter
148
+ */
100
149
  filter?: QueryFilter;
150
+ /**
151
+ * The search distance along each axis. [(x, y, z)]
152
+ * @default this.defaultQueryHalfExtents
153
+ */
101
154
  halfExtents?: Vector3;
102
155
  }): Vector3;
103
156
  /**
104
157
  * Moves from the start to the end position constrained to the navigation mesh.
158
+ *
159
+ * @param startRef The reference id of the start polygon.
160
+ * @param startPosition A position of the mover within the start polygon.
161
+ * @param endPosition The desired end position of the mover.
162
+ *
163
+ * @returns The result of the move along surface operation.
105
164
  */
106
165
  moveAlongSurface(startRef: number, startPosition: Vector3, endPosition: Vector3, options?: {
166
+ /**
167
+ * The polygon filter to apply to the query.
168
+ * @default this.defaultFilter
169
+ */
107
170
  filter?: QueryFilter;
171
+ /**
172
+ * The maximum number of polygons the output visited array can hold.
173
+ * @default 256
174
+ */
108
175
  maxVisitedSize?: number;
109
176
  }): {
110
177
  success: boolean;
@@ -117,7 +184,31 @@ export declare class NavMeshQuery {
117
184
  visited: number[];
118
185
  };
119
186
  /**
120
- * Gets the height of the polygon at the provided position using the height detail
187
+ * Returns a random point on the navmesh.
188
+ * @param options additional options
189
+ * @returns a random point on the navmesh
190
+ */
191
+ findRandomPoint(options?: {
192
+ /**
193
+ * The polygon filter to apply to the query.
194
+ * @default this.defaultFilter
195
+ */
196
+ filter?: QueryFilter;
197
+ }): {
198
+ success: boolean;
199
+ status: number;
200
+ randomPolyRef: number;
201
+ randomPoint: {
202
+ x: number;
203
+ y: number;
204
+ z: number;
205
+ };
206
+ };
207
+ /**
208
+ * Gets the height of the polygon at the provided position using the height detail.
209
+ *
210
+ * @param polyRef The reference id of the polygon.
211
+ * @param position A position within the xz-bounds of the polygon.
121
212
  */
122
213
  getPolyHeight(polyRef: number, position: Vector3): {
123
214
  success: boolean;
@@ -127,12 +218,235 @@ export declare class NavMeshQuery {
127
218
  /**
128
219
  * Finds a straight path from the start position to the end position.
129
220
  *
221
+ * @param start The start position.
222
+ * @param end The end position.
223
+ *
130
224
  * @returns an array of Vector3 positions that make up the path, or an empty array if no path was found.
131
225
  */
132
226
  computePath(start: Vector3, end: Vector3, options?: {
227
+ /**
228
+ * The polygon filter to apply to the query.
229
+ * @default this.defaultFilter
230
+ */
231
+ filter?: QueryFilter;
232
+ /**
233
+ * The maximum number of polygons the path array can hold. [Limit: >= 1]
234
+ * @default 256
235
+ */
236
+ maxPathPolys?: number;
237
+ /**
238
+ * The maximum number of points the straight path arrays can hold. [Limit: > 0]
239
+ * @default 256
240
+ */
241
+ maxStraightPathPoints?: number;
242
+ }): {
243
+ /**
244
+ * Whether a path was successfully computed.
245
+ */
246
+ success: boolean;
247
+ /**
248
+ * Error information if the path computation failed.
249
+ */
250
+ error?: {
251
+ /**
252
+ * Description of the error.
253
+ */
254
+ name: string;
255
+ /**
256
+ * A dtStatus status code if relevant.
257
+ */
258
+ status?: number;
259
+ };
260
+ /**
261
+ * The result path.
262
+ */
263
+ path: Vector3[];
264
+ };
265
+ /**
266
+ * Finds a path from the start polygon to the end polygon.
267
+ * @param startRef the reference id of the start polygon.
268
+ * @param endRef the reference id of the end polygon.
269
+ * @param startPosition position within the start polygon.
270
+ * @param endPosition position within the end polygon.
271
+ * @param options additional options
272
+ * @returns
273
+ */
274
+ findPath(startRef: number, endRef: number, startPosition: Vector3, endPosition: Vector3, options?: {
275
+ /**
276
+ * The polygon filter to apply to the query.
277
+ * @default this.defaultFilter
278
+ */
133
279
  filter?: QueryFilter;
134
- maxPolyPathLength?: number;
135
- }): Vector3[];
280
+ /**
281
+ * The maximum number of polygons the path array can hold. [Limit: >= 1]
282
+ * @default 256
283
+ */
284
+ maxPathPolys?: number;
285
+ }): {
286
+ success: boolean;
287
+ status: number;
288
+ polys: R.UnsignedIntArray;
289
+ };
290
+ /**
291
+ * Finds the straight path from the start to the end position within the polygon corridor.
292
+ *
293
+ * This method peforms what is often called 'string pulling'.
294
+ *
295
+ * The start position is clamped to the first polygon in the path, and the
296
+ * end position is clamped to the last. So the start and end positions should
297
+ * normally be within or very near the first and last polygons respectively.
298
+ *
299
+ * The returned polygon references represent the reference id of the polygon
300
+ * that is entered at the associated path position. The reference id associated
301
+ * with the end point will always be zero. This allows, for example, matching
302
+ * off-mesh link points to their representative polygons.
303
+ *
304
+ * If the provided result arrays are too small for the entire result set,
305
+ * they will be filled as far as possible from the start toward the end
306
+ * position.
307
+ *
308
+ * @param start path start position
309
+ * @param end path end position
310
+ * @param path an array of polygon references that represent the path corridor
311
+ * @param options additional options
312
+ * @returns the straight path result
313
+ */
314
+ findStraightPath(start: Vector3, end: Vector3, path: R.UnsignedIntArray, options?: {
315
+ /**
316
+ * The maximum number of points the straight path arrays can hold. [Limit: > 0]
317
+ * @default 256
318
+ */
319
+ maxStraightPathPoints?: number;
320
+ /**
321
+ * Options for dtNavMeshQuery::findStraightPath
322
+ *
323
+ * Add a vertex at every polygon edge crossing where area changes.
324
+ * DT_STRAIGHTPATH_AREA_CROSSINGS = 1
325
+ *
326
+ * Add a vertex at every polygon edge crossing.
327
+ * DT_STRAIGHTPATH_ALL_CROSSINGS = 2
328
+ *
329
+ * @default 0
330
+ */
331
+ straightPathOptions?: number;
332
+ }): {
333
+ success: boolean;
334
+ status: number;
335
+ /**
336
+ * The straight path points.
337
+ */
338
+ straightPath: R.FloatArray;
339
+ /**
340
+ * The straight path flags.
341
+ */
342
+ straightPathFlags: R.UnsignedCharArray;
343
+ /**
344
+ * The reference ids of the visited polygons.
345
+ *
346
+ * Raw.Module.DT_STRAIGHTPATH_START
347
+ * Raw.Module.DT_STRAIGHTPATH_END
348
+ * Raw.Module.DT_STRAIGHTPATH_OFFMESH_CONNECTION
349
+ */
350
+ straightPathRefs: R.UnsignedIntArray;
351
+ /**
352
+ * The number of points in the straight path.
353
+ */
354
+ straightPathCount: number;
355
+ };
356
+ /**
357
+ * Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.
358
+ *
359
+ * This method is meant to be used for quick, short distance checks.
360
+ *
361
+ * If the path array is too small to hold the result, it will be filled as far as possible from the start postion toward the end position.
362
+ *
363
+ * The raycast ignores the y-value of the end position. (2D check.) This places significant limits on how it can be used.
364
+ *
365
+ * <b>Using the Hit Parameter (t)</b>
366
+ *
367
+ * If the hit parameter is a very high value, then the ray has hit
368
+ * the end position. In this case the path represents a valid corridor to the
369
+ * end position and the value of hitNormal is undefined.
370
+ *
371
+ * If the hit parameter is zero, then the start position is on the wall that
372
+ * was hit and the value of hitNormal is undefined.
373
+ *
374
+ * If 0 < t < 1.0 then the following applies:
375
+ *
376
+ * ```
377
+ * distanceToHitBorder = distanceToEndPosition * t
378
+ * hitPoint = startPos + (endPos - startPos) * t
379
+ * ```
380
+ *
381
+ * <b>Use Case Restriction</b>
382
+ *
383
+ * Consider a scene where there is a main floor with a second floor balcony that hangs over the main floor.
384
+ * So the first floor mesh extends below the balcony mesh.
385
+ * The start position is somewhere on the first floor.
386
+ * The end position is on the balcony.
387
+ *
388
+ * The raycast will search toward the end position along the first floor mesh.
389
+ * If it reaches the end position's xz-coordinates it will indicate FLT_MAX,(no wall hit), meaning it reached the end position.
390
+ * This is one example of why this method is meant for short distance checks.
391
+ *
392
+ * @param startRef the reference id of the start polygon.
393
+ * @param startPosition a position within the start polygon representing the start of the ray
394
+ * @param endPosition the position to cast the ray toward.
395
+ * @param options additional options
396
+ */
397
+ raycast(startRef: number, startPosition: Vector3, endPosition: Vector3, options?: {
398
+ /**
399
+ * The polygon filter to apply to the query.
400
+ * @default this.defaultFilter
401
+ */
402
+ filter?: QueryFilter;
403
+ /**
404
+ * Determines how the raycast behaves.
405
+ *
406
+ * // Raycast should calculate movement cost along the ray and fill RaycastHit::cost
407
+ * DT_RAYCAST_USE_COSTS = 1
408
+ *
409
+ * @default 0
410
+ */
411
+ raycastOptions?: number;
412
+ /**
413
+ * Optional parent of start ref. Used during for cost calculation.
414
+ */
415
+ prevRef?: number;
416
+ }): {
417
+ /**
418
+ * Whether the raycast was successful.
419
+ */
420
+ success: boolean;
421
+ /**
422
+ * The status of the raycast.
423
+ */
424
+ status: number;
425
+ /**
426
+ * The hit parameter.
427
+ */
428
+ t: number;
429
+ /**
430
+ * The normal of the nearest wall hit.
431
+ */
432
+ hitNormal: Vector3;
433
+ /**
434
+ * The index of the edge on the final polygon where the wall was hit.
435
+ */
436
+ hitEdgeIndex: number;
437
+ /**
438
+ * The reference ids of the visited polygons.
439
+ */
440
+ path: number[];
441
+ /**
442
+ * The maximum number of polygons the path can contain.
443
+ */
444
+ maxPath: number;
445
+ /**
446
+ * The cost of the path until hit.
447
+ */
448
+ pathCost: number;
449
+ };
136
450
  /**
137
451
  * Destroys the NavMeshQuery instance
138
452
  */
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "email": "isaac@isaacmason.com",
7
7
  "url": "https://isaacmason.com/"
8
8
  },
9
- "version": "0.21.0",
9
+ "version": "0.23.0",
10
10
  "license": "MIT",
11
11
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
12
12
  "bugs": {
@@ -26,7 +26,7 @@
26
26
  "lint": "eslint --ext .ts src"
27
27
  },
28
28
  "dependencies": {
29
- "@recast-navigation/wasm": "0.21.0"
29
+ "@recast-navigation/wasm": "0.23.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.24.4",