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