recast-navigation 0.0.6 → 0.1.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 +42 -19
  2. package/package.json +7 -5
package/README.md CHANGED
@@ -40,9 +40,9 @@ await init();
40
40
  ### Creating a NavMesh
41
41
 
42
42
  ```ts
43
- import { NavMesh } from 'recast-navigation';
43
+ import { NavMeshGenerator } 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,64 @@ 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();
70
+ import { NavMeshQuery } from 'recast-navigation';
67
71
 
68
- /* initialize the NavMesh */
69
- // ...
72
+ const navMeshQuery = new NavMeshQuery({ navMesh });
70
73
 
71
74
  /* get the closest point on the NavMesh to the given position */
72
75
  const position = { x: 0, y: 0, z: 0 };
73
- navMesh.getClosestPoint(position);
76
+ navMeshQuery.getClosestPoint(position);
74
77
 
75
78
  /* get a random point around the given position */
76
79
  const radius = 0.5;
77
- navMesh.getRandomPointAround(position, radius);
80
+ navMeshQuery.getRandomPointAround(position, radius);
78
81
  ```
79
82
 
80
83
  ### Adding Obstacles to a NavMesh
81
84
 
82
85
  Recast Navigation supports creating Box and Cylinder obstacles.
83
86
 
84
- Note that in order to use obstacles, you must specify a `tileSize` in the `NavMeshConfig`.
87
+ 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
88
 
86
89
  ```ts
90
+ /* create a tiled NavMesh */
91
+ const { navMesh, tileCache } = navMeshGenerator.generate(positions, indices, {
92
+ /* ... */
93
+ tileSize: 16,
94
+ });
95
+
87
96
  /* add a Box obstacle to the NavMesh */
88
97
  const position = { x: 0, y: 0, z: 0 };
89
98
  const extent = { x: 1, y: 1, z: 1 };
90
99
  const angle = 0;
91
- const boxObstacle = navMesh.addBoxObstacle(position, extent, angle);
100
+ const boxObstacle = tileCache.addBoxObstacle(position, extent, angle);
92
101
 
93
102
  /* add a Cylinder obstacle to the NavMesh */
94
103
  const radius = 1;
95
104
  const height = 1;
96
- const cylinderObstacle = navMesh.addCylinderObstacle(
105
+ const cylinderObstacle = tileCache.addCylinderObstacle(
97
106
  position,
98
107
  radius,
99
108
  height,
100
109
  angle
101
110
  );
102
111
 
112
+ /* update the NavMesh to reflect obstacle changes */
113
+ tileCache.update(navMesh);
114
+
103
115
  /* remove the obstacles from the NavMesh */
104
- navMesh.removeObstacle(boxObstacle);
105
- navMesh.removeObstacle(cylinderObstacle);
116
+ tileCache.removeObstacle(boxObstacle);
117
+ tileCache.removeObstacle(cylinderObstacle);
106
118
  ```
107
119
 
108
120
  ### Crowds and Agents
@@ -131,7 +143,7 @@ crowd.update(dt);
131
143
  Next, you can create and interface with agents in the crowd.
132
144
 
133
145
  ```ts
134
- const initialAgentPosition = navMesh.getRandomPointAround(
146
+ const initialAgentPosition = navMeshQuery.getRandomPointAround(
135
147
  { x: 0, y: 0, z: 0 }, // position
136
148
  2 // radius
137
149
  );
@@ -185,16 +197,27 @@ You can use `getDebugNavMesh` to get a debug representation of the NavMesh.
185
197
  ```ts
186
198
  const debugNavMesh = navMesh.getDebugNavMesh();
187
199
 
188
- const { positions, indices } = debugNavMesh.positions;
200
+ const { positions, indices } = debugNavMesh;
189
201
  ```
190
202
 
191
203
  If you are using `@recast-navigation/three`, you can use `NavMeshHelper` and `CrowdHelper` to visualize NavMeshes and Crowds.
192
204
 
193
- ### Exporting and Importing a NavMesh
205
+ ### Exporting and Importing
206
+
207
+ A NavMesh and TileCache can be exported and imported as a Uint8Array.
194
208
 
195
209
  ```ts
196
- const navMeshData: Uint8Array = navMesh.getNavMeshData();
210
+ /* exporting */
211
+ const navMeshExporter = new NavMeshExporter();
212
+
213
+ const navMeshExport: Uint8Array = navMeshExporter.export(
214
+ navMesh,
215
+ tileCache // optional
216
+ );
217
+
218
+ /* importing */
219
+ const navMeshImporter = new NavMeshImporter();
197
220
 
198
- const newNavMesh = new NavMesh();
199
- newNavMesh.buildFromNavMeshData(navMeshData);
221
+ const { navMesh, tileCache } =
222
+ navMeshImporter.import(navMeshExport);
200
223
  ```
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.1.0",
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.1.0",
53
+ "@recast-navigation/three": "0.1.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "three": "^0.150.1"
@@ -59,7 +59,7 @@
59
59
  "@babel/core": "^7.21.3",
60
60
  "@mdx-js/react": "^1.6.22",
61
61
  "@react-three/csg": "^2.2.0",
62
- "@react-three/drei": "^9.58.5",
62
+ "@react-three/drei": "^9.72.1",
63
63
  "@react-three/fiber": "^8.12.0",
64
64
  "@rollup/plugin-commonjs": "^24.0.1",
65
65
  "@rollup/plugin-multi-entry": "^6.0.0",
@@ -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",
@@ -86,7 +87,8 @@
86
87
  "rollup-plugin-filesize": "^10.0.0",
87
88
  "storybook": "^7.0.2",
88
89
  "suspend-react": "^0.0.9",
89
- "three": "^0.150.1"
90
+ "three": "^0.150.1",
91
+ "three-pathfinding": "^1.2.0"
90
92
  },
91
93
  "packageManager": "yarn@3.2.2"
92
94
  }