recast-navigation 0.23.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.
- package/README.md +30 -21
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ This library provides high level APIs that make it easy to get started creating
|
|
|
28
28
|
## Examples
|
|
29
29
|
|
|
30
30
|
Go to the [examples website](https://recast-navigation-js.isaacmason.com) to see the project in action:
|
|
31
|
+
|
|
31
32
|
- live: [https://recast-navigation-js.isaacmason.com](https://recast-navigation-js.isaacmason.com).
|
|
32
33
|
- examples source code: [./packages/recast-navigation/.storybook/stories](./packages/recast-navigation/.storybook/stories).
|
|
33
34
|
|
|
@@ -161,26 +162,24 @@ import { NavMeshQuery } from 'recast-navigation';
|
|
|
161
162
|
|
|
162
163
|
const navMeshQuery = new NavMeshQuery({ navMesh });
|
|
163
164
|
|
|
164
|
-
/*
|
|
165
|
+
/* find the closest point on the NavMesh to the given position */
|
|
165
166
|
const position = { x: 0, y: 0, z: 0 };
|
|
166
|
-
|
|
167
|
+
const { success, status, point, polyRef, isPointOverPoly } =
|
|
168
|
+
navMeshQuery.findClosestPoint(position);
|
|
167
169
|
|
|
168
170
|
/* get a random point around the given position */
|
|
169
171
|
const radius = 0.5;
|
|
170
|
-
|
|
172
|
+
const {
|
|
173
|
+
success,
|
|
174
|
+
status,
|
|
175
|
+
randomPolyRef,
|
|
176
|
+
randomPoint: initialAgentPosition,
|
|
177
|
+
} = navMeshQuery.findRandomPointAroundCircle(position, radius);
|
|
171
178
|
|
|
172
179
|
/* compute a straight path between two points */
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
if (!computePathResult.success) {
|
|
179
|
-
console.log(computePathResult.error);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const path = computePathResult.path; // { x: number, y: number, z: number }[]
|
|
183
|
-
|
|
180
|
+
const start = { x: 0, y: 0, z: 0 };
|
|
181
|
+
const end = { x: 2, y: 0, z: 0 };
|
|
182
|
+
const { success, error, path } = navMeshQuery.computePath(start, end);
|
|
184
183
|
```
|
|
185
184
|
|
|
186
185
|
### Crowds and Agents
|
|
@@ -199,10 +198,15 @@ const crowd = new Crowd({ maxAgents, maxAgentRadius, navMesh });
|
|
|
199
198
|
Next, create and interface with agents in the crowd.
|
|
200
199
|
|
|
201
200
|
```ts
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
const position = { x: 0, y: 0, z: 0 };
|
|
202
|
+
const radius = 2;
|
|
203
|
+
|
|
204
|
+
const {
|
|
205
|
+
success,
|
|
206
|
+
status,
|
|
207
|
+
randomPolyRef,
|
|
208
|
+
randomPoint: initialAgentPosition,
|
|
209
|
+
} = navMeshQuery.findRandomPointAroundCircle(position, radius);
|
|
206
210
|
|
|
207
211
|
const agent = crowd.addAgent(initialAgentPosition, {
|
|
208
212
|
radius: 0.5,
|
|
@@ -275,7 +279,7 @@ const { success, navMesh, tileCache } = generateTileCache(positions, indices, {
|
|
|
275
279
|
});
|
|
276
280
|
```
|
|
277
281
|
|
|
278
|
-
You can use `addCylinderObstacle`, `addBoxObstacle`, and `removeObstacle` to add and remove obstacles from the TileCache.
|
|
282
|
+
You can use `addCylinderObstacle`, `addBoxObstacle`, and `removeObstacle` to add and remove obstacles from the TileCache.
|
|
279
283
|
|
|
280
284
|
After adding or removing obstacles you can call `tileCache.update(navMesh)` to rebuild navmesh tiles.
|
|
281
285
|
|
|
@@ -314,7 +318,7 @@ const removeObstacleResult = tileCache.removeObstacle(boxObstacle);
|
|
|
314
318
|
tileCache.update(navMesh);
|
|
315
319
|
|
|
316
320
|
// if your obstacle requests affect many tiles, you may need to call update multiple times
|
|
317
|
-
const maxTileCacheUpdates = 5
|
|
321
|
+
const maxTileCacheUpdates = 5;
|
|
318
322
|
for (let i = 0; i < maxTileCacheUpdates; i++) {
|
|
319
323
|
const { upToDate } = tileCache.update(navMesh);
|
|
320
324
|
if (upToDate) break;
|
|
@@ -416,7 +420,12 @@ console.log(statusToReadableString(status));
|
|
|
416
420
|
If you need to work with status codes programmatically, you can use these utilities:
|
|
417
421
|
|
|
418
422
|
```ts
|
|
419
|
-
import {
|
|
423
|
+
import {
|
|
424
|
+
statusSucceed,
|
|
425
|
+
statusInProgress,
|
|
426
|
+
statusFailed,
|
|
427
|
+
statusDetail,
|
|
428
|
+
} from 'recast-navigation';
|
|
420
429
|
|
|
421
430
|
// returns true if the status is a success
|
|
422
431
|
const succeeded = statusSucceed(status);
|
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.
|
|
21
|
+
"version": "0.24.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.
|
|
70
|
-
"@recast-navigation/generators": "0.
|
|
71
|
-
"@recast-navigation/three": "0.
|
|
69
|
+
"@recast-navigation/core": "0.24.0",
|
|
70
|
+
"@recast-navigation/generators": "0.24.0",
|
|
71
|
+
"@recast-navigation/three": "0.24.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/core": "^7.24.4",
|