recast-navigation 0.18.2 → 0.19.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.
Files changed (2) hide show
  1. package/README.md +49 -6
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  # recast-navigation-js
9
9
 
10
- ### [Try the NavMesh Generator Website!](https://navmesh.isaacmason.com/)
10
+ ### [Examples](https://recast-navigation-js.isaacmason.com) | [NavMesh Generator Website](https://navmesh.isaacmason.com/)
11
11
 
12
12
  - 📐 ‎ NavMesh generation
13
13
  - 🧭 ‎ Pathfinding
@@ -262,9 +262,9 @@ You can use `addCylinderObstacle`, `addBoxObstacle`, and `removeObstacle` to add
262
262
 
263
263
  After adding or removing obstacles you can call `tileCache.update(navMesh)` to rebuild navmesh tiles.
264
264
 
265
- Adding or removing an obstacle will internally create an "obstacle request". TileCache supports queuing up to 64 obstacle requests.
265
+ Adding or removing an obstacle will internally create an "obstacle request". TileCache supports queuing up to 64 obstacle requests. If the requests queue is full, calls to `addCylinderObstacle` and `addBoxObstacle` will fail and return a `dtStatus` status code `DT_BUFFER_TOO_SMALL`.
266
266
 
267
- The `tileCache.update` method returns `upToDate`, whether the tile cache is fully up to date with obstacle requests and tile rebuilds. Each update call processes up to 64 tiles touched by added or removed obstacles. If the tile cache isn't up to date another call will continue processing obstacle requests and tile rebuilds; otherwise it will have no effect.
267
+ The `tileCache.update` method returns `upToDate`, whether the tile cache is fully up to date with obstacle requests and tile rebuilds. If the tile cache isn't up to date another call will continue processing obstacle requests and tile rebuilds; otherwise it will have no effect.
268
268
 
269
269
  If not many obstacle requests occur between updates, an easy pattern is to call `tileCache.update` periodically, such as every game update.
270
270
 
@@ -275,20 +275,22 @@ If many obstacle requests have been made and you need to avoid reaching the 64 o
275
275
  const position = { x: 0, y: 0, z: 0 };
276
276
  const extent = { x: 1, y: 1, z: 1 };
277
277
  const angle = 0;
278
- const boxObstacle = tileCache.addBoxObstacle(position, extent, angle);
278
+ const addBoxObstacleResult = tileCache.addBoxObstacle(position, extent, angle);
279
+ const boxObstacle = addBoxObstacleResult.obstacle;
279
280
 
280
281
  /* add a Cylinder obstacle to the NavMesh */
281
282
  const radius = 1;
282
283
  const height = 1;
283
- const cylinderObstacle = tileCache.addCylinderObstacle(
284
+ const addCylinderObstacleResult = tileCache.addCylinderObstacle(
284
285
  position,
285
286
  radius,
286
287
  height,
287
288
  angle
288
289
  );
290
+ const cylinderObstacle = addCylinderObstacleResult.obstacle;
289
291
 
290
292
  /* remove the obstacles from the NavMesh */
291
- tileCache.removeObstacle(boxObstacle);
293
+ const removeObstacleResult = tileCache.removeObstacle(boxObstacle);
292
294
 
293
295
  /* update to reflect obstacle changes */
294
296
  // if few obstacles are added/removed between updates, you could call tileCache.update every game update
@@ -368,6 +370,8 @@ const { success, navMesh, tileCache } = generateTileCache(
368
370
 
369
371
  ### Debugging
370
372
 
373
+ #### Debug Nav Mesh
374
+
371
375
  You can use `getDebugNavMesh` to get a debug representation of the NavMesh.
372
376
 
373
377
  ```ts
@@ -380,6 +384,45 @@ If you are using three.js, you can use `NavMeshHelper` and `CrowdHelper` to visu
380
384
 
381
385
  See the [`@recast-navigation/three` package README](https://github.com/isaac-mason/recast-navigation-js/tree/main/packages/recast-navigation-three/README.md) for usage information.
382
386
 
387
+ #### Detour Status Codes
388
+
389
+ Many Detour APIs return a `status` property. This is a `dtStatus` enum, which is a number representing the status of the operation.
390
+
391
+ You can use the `dtStatusToReadableString` function to convert a `dtStatus` to a human-readable string.
392
+
393
+ ```ts
394
+ import { dtStatusToReadableString } from 'recast-navigation';
395
+
396
+ console.log(dtStatusToReadableString(status));
397
+ ```
398
+
399
+ If you need to work with status codes programmatically, you can use these utilities:
400
+
401
+ ```ts
402
+ import { Raw } from 'recast-navigation';
403
+
404
+ // returns true if the status is a success
405
+ Raw.Detour.statusSucceed(status);
406
+
407
+ // returns true if the status is in progress
408
+ Raw.Detour.statusInProgress(status);
409
+
410
+ // returns true if the status is a failure
411
+ Raw.Detour.statusFailed(status);
412
+
413
+ // get the detail of the status
414
+ const detail = Raw.Detour.statusDetail(status);
415
+
416
+ // Raw.Detour.WRONG_MAGIC;
417
+ // Raw.Detour.WRONG_VERSION;
418
+ // Raw.Detour.OUT_OF_MEMORY;
419
+ // Raw.Detour.INVALID_PARAM;
420
+ // Raw.Detour.BUFFER_TOO_SMALL;
421
+ // Raw.Detour.OUT_OF_NODES;
422
+ // Raw.Detour.PARTIAL_RESULT;
423
+ // Raw.Detour.ALREADY_OCCUPIED;
424
+ ```
425
+
383
426
  ### Importing and Exporting
384
427
 
385
428
  A NavMesh and TileCache can be imported and exported as a Uint8Array.
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "email": "isaac@isaacmason.com",
19
19
  "url": "https://isaacmason.com/"
20
20
  },
21
- "version": "0.18.2",
21
+ "version": "0.19.0",
22
22
  "license": "MIT",
23
23
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
24
24
  "bugs": {
@@ -66,9 +66,9 @@
66
66
  "lint": "eslint --ext .ts src"
67
67
  },
68
68
  "dependencies": {
69
- "@recast-navigation/core": "0.18.2",
70
- "@recast-navigation/generators": "0.18.2",
71
- "@recast-navigation/three": "0.18.2"
69
+ "@recast-navigation/core": "0.19.0",
70
+ "@recast-navigation/generators": "0.19.0",
71
+ "@recast-navigation/three": "0.19.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@babel/core": "^7.23.9",
@@ -103,7 +103,7 @@
103
103
  "three": "^0.160.0",
104
104
  "three-pathfinding": "^1.2.0",
105
105
  "typescript": "^5.4.3",
106
- "vitest": "^1.2.0"
106
+ "vitest": "^1.4.0"
107
107
  },
108
108
  "packageManager": "yarn@3.2.2"
109
109
  }