recast-navigation 0.0.6 → 0.0.7

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 +39 -18
  2. package/package.json +4 -3
package/README.md CHANGED
@@ -42,7 +42,7 @@ await init();
42
42
  ```ts
43
43
  import { NavMesh } from 'recast-navigation';
44
44
 
45
- const navMesh = new NavMesh();
45
+ const navMeshGenerator = new NavMeshGenerator();
46
46
 
47
47
  const positions = [
48
48
  /* flat array of positions */
@@ -57,52 +57,62 @@ const navMeshConfig = {
57
57
  /* ... */
58
58
  };
59
59
 
60
- navMesh.build(positions, indices, navMeshConfig);
60
+ const { navMesh } = navMeshGenerator.generate(
61
+ positions,
62
+ indices,
63
+ navMeshConfig
64
+ );
61
65
  ```
62
66
 
63
67
  ### Querying a NavMesh
64
68
 
65
69
  ```ts
66
- const navMesh = new NavMesh();
67
-
68
- /* initialize the NavMesh */
69
- // ...
70
+ const navMeshQuery = new NavMeshQuery({ navMesh });
70
71
 
71
72
  /* get the closest point on the NavMesh to the given position */
72
73
  const position = { x: 0, y: 0, z: 0 };
73
- navMesh.getClosestPoint(position);
74
+ navMeshQuery.getClosestPoint(position);
74
75
 
75
76
  /* get a random point around the given position */
76
77
  const radius = 0.5;
77
- navMesh.getRandomPointAround(position, radius);
78
+ navMeshQuery.getRandomPointAround(position, radius);
78
79
  ```
79
80
 
80
81
  ### Adding Obstacles to a NavMesh
81
82
 
82
83
  Recast Navigation supports creating Box and Cylinder obstacles.
83
84
 
84
- Note that in order to use obstacles, you must specify a `tileSize` in the `NavMeshConfig`.
85
+ Note that in order to use obstacles, you must create a tiled NavMesh. You can do this by specifying a `tileSize` in the `NavMeshConfig`.
85
86
 
86
87
  ```ts
88
+ /* create a tiled NavMesh */
89
+ const { navMesh, tileCache } = navMeshGenerator.generate(positions, indices, {
90
+ /* ... */
91
+ tileSize: 16,
92
+ });
93
+
87
94
  /* add a Box obstacle to the NavMesh */
88
95
  const position = { x: 0, y: 0, z: 0 };
89
96
  const extent = { x: 1, y: 1, z: 1 };
90
97
  const angle = 0;
91
- const boxObstacle = navMesh.addBoxObstacle(position, extent, angle);
98
+ const boxObstacle = tileCache.addBoxObstacle(position, extent, angle);
92
99
 
93
100
  /* add a Cylinder obstacle to the NavMesh */
94
101
  const radius = 1;
95
102
  const height = 1;
96
- const cylinderObstacle = navMesh.addCylinderObstacle(
103
+ const cylinderObstacle = tileCache.addCylinderObstacle(
97
104
  position,
98
105
  radius,
99
106
  height,
100
107
  angle
101
108
  );
102
109
 
110
+ /* update the NavMesh to reflect obstacle changes */
111
+ tileCache.update(navMesh);
112
+
103
113
  /* remove the obstacles from the NavMesh */
104
- navMesh.removeObstacle(boxObstacle);
105
- navMesh.removeObstacle(cylinderObstacle);
114
+ tileCache.removeObstacle(boxObstacle);
115
+ tileCache.removeObstacle(cylinderObstacle);
106
116
  ```
107
117
 
108
118
  ### Crowds and Agents
@@ -131,7 +141,7 @@ crowd.update(dt);
131
141
  Next, you can create and interface with agents in the crowd.
132
142
 
133
143
  ```ts
134
- const initialAgentPosition = navMesh.getRandomPointAround(
144
+ const initialAgentPosition = navMeshQuery.getRandomPointAround(
135
145
  { x: 0, y: 0, z: 0 }, // position
136
146
  2 // radius
137
147
  );
@@ -190,11 +200,22 @@ const { positions, indices } = debugNavMesh.positions;
190
200
 
191
201
  If you are using `@recast-navigation/three`, you can use `NavMeshHelper` and `CrowdHelper` to visualize NavMeshes and Crowds.
192
202
 
193
- ### Exporting and Importing a NavMesh
203
+ ### Exporting and Importing
204
+
205
+ A NavMesh and TileCache can be exported and imported as a Uint8Array.
194
206
 
195
207
  ```ts
196
- const navMeshData: Uint8Array = navMesh.getNavMeshData();
208
+ /* exporting */
209
+ const navMeshExporter = new NavMeshExporter();
210
+
211
+ const navMeshExport: Uint8Array = navMeshExporter.export(
212
+ navMesh,
213
+ tileCache // optional
214
+ );
215
+
216
+ /* importing */
217
+ const navMeshImporter = new NavMeshImporter();
197
218
 
198
- const newNavMesh = new NavMesh();
199
- newNavMesh.buildFromNavMeshData(navMeshData);
219
+ const { navMesh, tileCache } =
220
+ navMeshImporter.import(navMeshExport);
200
221
  ```
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.0.6",
21
+ "version": "0.0.7",
22
22
  "license": "MIT",
23
23
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
24
24
  "bugs": {
@@ -49,8 +49,8 @@
49
49
  "build-storybook": "storybook build"
50
50
  },
51
51
  "dependencies": {
52
- "@recast-navigation/core": "0.0.6",
53
- "@recast-navigation/three": "0.0.6"
52
+ "@recast-navigation/core": "0.0.7",
53
+ "@recast-navigation/three": "0.0.7"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "three": "^0.150.1"
@@ -79,6 +79,7 @@
79
79
  "@types/react-dom": "^18.0.11",
80
80
  "@types/three": "^0.150.0",
81
81
  "babel-loader": "^8.3.0",
82
+ "leva": "^0.9.34",
82
83
  "react": "^18.2.0",
83
84
  "react-dom": "^18.2.0",
84
85
  "rollup": "^3.20.0",