recast-navigation 0.5.0 → 0.7.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 +59 -73
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -42,6 +42,7 @@ await init();
42
42
  To create a NavMesh, you can use the `generateSoloNavMesh` and `generateTiledNavMesh` functions.
43
43
 
44
44
  The input positions and indices should adhere to OpenGL conventions:
45
+
45
46
  - Use the right-handed coordinate system
46
47
  - Indices should be in counter-clockwise winding order
47
48
  - The `positions` and `indices` arguments should be flat arrays of numbers
@@ -87,49 +88,6 @@ const radius = 0.5;
87
88
  navMeshQuery.getRandomPointAround(position, radius);
88
89
  ```
89
90
 
90
- ### Adding Obstacles to a NavMesh
91
-
92
- Recast Navigation supports creating Box and Cylinder obstacles.
93
-
94
- Note that in order to use obstacles, you must create a tiled NavMesh.
95
-
96
- ```ts
97
- import { generateTiledNavMesh } from 'recast-navigation';
98
-
99
- /* create a tiled NavMesh */
100
- const { success, navMesh, tileCache } = generateTiledNavMesh(
101
- positions,
102
- indices,
103
- {
104
- /* ... */
105
- tileSize: 16,
106
- }
107
- );
108
-
109
- /* add a Box obstacle to the NavMesh */
110
- const position = { x: 0, y: 0, z: 0 };
111
- const extent = { x: 1, y: 1, z: 1 };
112
- const angle = 0;
113
- const boxObstacle = tileCache.addBoxObstacle(position, extent, angle);
114
-
115
- /* add a Cylinder obstacle to the NavMesh */
116
- const radius = 1;
117
- const height = 1;
118
- const cylinderObstacle = tileCache.addCylinderObstacle(
119
- position,
120
- radius,
121
- height,
122
- angle
123
- );
124
-
125
- /* update the NavMesh to reflect obstacle changes */
126
- tileCache.update(navMesh);
127
-
128
- /* remove the obstacles from the NavMesh */
129
- tileCache.removeObstacle(boxObstacle);
130
- tileCache.removeObstacle(cylinderObstacle);
131
- ```
132
-
133
91
  ### Crowds and Agents
134
92
 
135
93
  First, create a `Crowd` instance.
@@ -161,7 +119,7 @@ const initialAgentPosition = navMeshQuery.getRandomPointAround(
161
119
  2 // radius
162
120
  );
163
121
 
164
- const agentIndex = crowd.addAgent(initialAgentPosition, {
122
+ const agent = crowd.addAgent(initialAgentPosition, {
165
123
  radius: 0.5,
166
124
  height: 0.5,
167
125
  maxAcceleration: 4.0,
@@ -172,35 +130,76 @@ const agentIndex = crowd.addAgent(initialAgentPosition, {
172
130
  });
173
131
 
174
132
  /* get information about the agent */
175
- const agentPosition = crowd.getAgentPosition(agentIndex);
176
- const agentVelocity = crowd.getAgentVelocity(agentIndex);
177
- const agentNextTargetPath = crowd.getAgentNextTargetPath(agentIndex);
178
- const agentState = crowd.getAgentState(agentIndex);
179
- const agentCorners = crowd.getAgentCorners(agentIndex);
180
- const agentParameters = crowd.getAgentParameters(agentIndex);
133
+ const agentPosition = agent.position();
134
+ const agentVelocity = agent.velocity();
135
+ const agentNextTargetPath = agent.nextTargetPath();
136
+ const agentState = agent.state();
137
+ const agentCorners = agent.corners();
138
+ const agentParameters = agent.parameters();
181
139
 
182
140
  /* tell the agent to move to a target position */
183
141
  const targetPosition = { x: 0, y: 0, z: 0 };
184
- crowd.goto(agentIndex, targetPosition);
142
+ agent.goto(targetPosition);
185
143
 
186
144
  /* reset the agents target */
187
- crowd.resetMoveTarget(agentIndex);
145
+ agent.resetMoveTarget();
188
146
 
189
147
  /* teleport the agent to a position */
190
- crowd.teleport(agentIndex, targetPosition);
148
+ agent.teleport(targetPosition);
191
149
 
192
150
  /* update some parameters of the agent */
193
- crowd.updateAgentParameters(agentIndex, {
151
+ agent.updateParameters({
194
152
  maxAcceleration: 4.0,
195
153
  });
196
154
 
197
155
  /* set all parameters for an agent */
198
- crowd.setAgentParameters(agentIndex, {
156
+ agent.setParameters({
199
157
  // any omitted parameters will be set to their default values
200
158
  });
201
159
 
202
- /* destroy the agent */
203
- crowd.removeAgent(agentIndex);
160
+ /* remove the agent */
161
+ crowd.removeAgent(agent);
162
+ ```
163
+
164
+ ### Temporary Obstacles
165
+
166
+ Recast Navigation supports creating Box and Cylinder obstacles.
167
+
168
+ Note that in order to use obstacles, you must create a TileCache.
169
+
170
+ `TileCache` assumes small tiles (around 32-64 squared). Using `tileSize` values outside this range may result in unexpected behaviour.
171
+
172
+ ```ts
173
+ import { generateTileCache } from 'recast-navigation';
174
+
175
+ /* create a tile cache */
176
+ const { success, navMesh, tileCache } = generateTileCache(positions, indices, {
177
+ /* ... */
178
+ tileSize: 16,
179
+ });
180
+
181
+ /* add a Box obstacle to the NavMesh */
182
+ const position = { x: 0, y: 0, z: 0 };
183
+ const extent = { x: 1, y: 1, z: 1 };
184
+ const angle = 0;
185
+ const boxObstacle = tileCache.addBoxObstacle(position, extent, angle);
186
+
187
+ /* add a Cylinder obstacle to the NavMesh */
188
+ const radius = 1;
189
+ const height = 1;
190
+ const cylinderObstacle = tileCache.addCylinderObstacle(
191
+ position,
192
+ radius,
193
+ height,
194
+ angle
195
+ );
196
+
197
+ /* update the NavMesh to reflect obstacle changes */
198
+ tileCache.update(navMesh);
199
+
200
+ /* remove the obstacles from the NavMesh */
201
+ tileCache.removeObstacle(boxObstacle);
202
+ tileCache.removeObstacle(cylinderObstacle);
204
203
  ```
205
204
 
206
205
  ### Debugging
@@ -232,21 +231,8 @@ const navMeshExport: Uint8Array = exportNavMesh(
232
231
  const { navMesh, tileCache } = importNavMesh(navMeshExport);
233
232
  ```
234
233
 
235
- ### Escape Hatches
236
-
237
- This library provides a higher level api over Recast, but also exposes a `Raw` api that aims to match the recast and detour libraries as much as possible.
238
-
239
- This functionality is experimental, and not all of recast is exposed yet. You will need to have familiarity with the recast and detour c++ libraries, and you may need to submit an issue or a PR if something you need is not exposed yet.
240
-
241
- Auto-generated documentation can be found here: https://docs.recast-navigation-js.isaacmason.com/variables/index.Raw.html
242
-
243
- ```ts
244
- import { Raw } from 'recast-navigation';
245
-
246
- const navMeshData = Raw.DetourNavMeshBuilder.createNavMeshData(/* ... */);
247
- ```
248
-
249
- The solo and tiled nav mesh generators in this library are adaptations of the `RecastDemo` examples: https://github.com/isaac-mason/recastnavigation/blob/main/RecastDemo/Source/Sample_SoloMesh.cpp
234
+ ### Advanced Usage
250
235
 
251
- You can use the solo and tiled nav mesh generators in this library as the basis of a nav mesh generator suiting your requirements. See: https://github.com/isaac-mason/recast-navigation-js/tree/main/packages/recast-navigation-core/src/generators
236
+ This library provides low-level APIs that aim to match the recast and detour c++ api, allowing you to create custom navigation mesh generators based on your specific needs. See: https://github.com/isaac-mason/recast-navigation-js/tree/main/packages/recast-navigation-core/src/generators
252
237
 
238
+ Please note that this functionality is experimental, and not all everything is exposed. Familiarity with the recast and detour C++ libraries is required. If you require unexposed functionality, please submit an issue or a pull request.
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.5.0",
21
+ "version": "0.7.0",
22
22
  "license": "MIT",
23
23
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
24
24
  "bugs": {
@@ -50,8 +50,8 @@
50
50
  "build-storybook": "storybook build"
51
51
  },
52
52
  "dependencies": {
53
- "@recast-navigation/core": "0.5.0",
54
- "@recast-navigation/three": "0.5.0"
53
+ "@recast-navigation/core": "0.7.0",
54
+ "@recast-navigation/three": "0.7.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "three": "^0.155.0"
@@ -63,7 +63,7 @@
63
63
  "@react-three/csg": "^3.0.0",
64
64
  "@react-three/drei": "^9.78.2",
65
65
  "@react-three/fiber": "^8.12.0",
66
- "@rollup/plugin-commonjs": "^24.0.1",
66
+ "@rollup/plugin-commonjs": "^25.0.4",
67
67
  "@rollup/plugin-multi-entry": "^6.0.0",
68
68
  "@rollup/plugin-node-resolve": "^15.0.1",
69
69
  "@rollup/plugin-terser": "^0.4.3",