recast-navigation 0.18.1 → 0.18.2

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 +25 -4
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -256,7 +256,21 @@ const { success, navMesh, tileCache } = generateTileCache(positions, indices, {
256
256
  /* ... */
257
257
  tileSize: 16,
258
258
  });
259
+ ```
260
+
261
+ You can use `addCylinderObstacle`, `addBoxObstacle`, and `removeObstacle` to add and remove obstacles from the TileCache.
262
+
263
+ After adding or removing obstacles you can call `tileCache.update(navMesh)` to rebuild navmesh tiles.
264
+
265
+ Adding or removing an obstacle will internally create an "obstacle request". TileCache supports queuing up to 64 obstacle requests.
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.
268
+
269
+ If not many obstacle requests occur between updates, an easy pattern is to call `tileCache.update` periodically, such as every game update.
270
+
271
+ If many obstacle requests have been made and you need to avoid reaching the 64 obstacle request limit, you can call `tileCache.update` multiple times, bailing out when `upToDate` is true or after a maximum number of updates.
259
272
 
273
+ ```ts
260
274
  /* add a Box obstacle to the NavMesh */
261
275
  const position = { x: 0, y: 0, z: 0 };
262
276
  const extent = { x: 1, y: 1, z: 1 };
@@ -273,12 +287,19 @@ const cylinderObstacle = tileCache.addCylinderObstacle(
273
287
  angle
274
288
  );
275
289
 
276
- /* update the NavMesh to reflect obstacle changes */
277
- tileCache.update(navMesh);
278
-
279
290
  /* remove the obstacles from the NavMesh */
280
291
  tileCache.removeObstacle(boxObstacle);
281
- tileCache.removeObstacle(cylinderObstacle);
292
+
293
+ /* update to reflect obstacle changes */
294
+ // if few obstacles are added/removed between updates, you could call tileCache.update every game update
295
+ tileCache.update(navMesh);
296
+
297
+ // if your obstacle requests affect many tiles, you may need to call update multiple times
298
+ const maxTileCacheUpdates = 5
299
+ for (let i = 0; i < maxTileCacheUpdates; i++) {
300
+ const { upToDate } = tileCache.update(navMesh);
301
+ if (upToDate) break;
302
+ }
282
303
  ```
283
304
 
284
305
  ### Off Mesh Connections
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.1",
21
+ "version": "0.18.2",
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.1",
70
- "@recast-navigation/generators": "0.18.1",
71
- "@recast-navigation/three": "0.18.1"
69
+ "@recast-navigation/core": "0.18.2",
70
+ "@recast-navigation/generators": "0.18.2",
71
+ "@recast-navigation/three": "0.18.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@babel/core": "^7.23.9",
@@ -88,14 +88,14 @@
88
88
  "@storybook/addon-mdx-gfm": "^8.0.1",
89
89
  "@storybook/react": "^8.0.1",
90
90
  "@storybook/react-vite": "^8.0.1",
91
- "@types/react": "^18.2.69",
91
+ "@types/react": "^18.2.73",
92
92
  "@types/react-dom": "^18.2.8",
93
93
  "@types/three": "^0.160.0",
94
94
  "eslint": "^8.56.0",
95
95
  "leva": "^0.9.35",
96
96
  "react": "^18.2.0",
97
97
  "react-dom": "^18.2.0",
98
- "rollup": "^4.9.2",
98
+ "rollup": "^4.14.0",
99
99
  "rollup-plugin-copy": "^3.4.0",
100
100
  "rollup-plugin-filesize": "^10.0.0",
101
101
  "storybook": "^8.0.1",