recast-navigation 0.6.0 → 0.7.1
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 +60 -74
- package/package.json +4 -7
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
|
|
@@ -69,7 +70,7 @@ const { success, navMesh } = generateSoloNavMesh(
|
|
|
69
70
|
);
|
|
70
71
|
```
|
|
71
72
|
|
|
72
|
-
If you need to do something more advanced, you can use the lower level API to create your own NavMesh generator. See the "
|
|
73
|
+
If you need to do something more advanced, you can use the lower level API to create your own NavMesh generator. See the "Advanced Usage" section for more information.
|
|
73
74
|
|
|
74
75
|
### Querying a NavMesh
|
|
75
76
|
|
|
@@ -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
|
|
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 =
|
|
176
|
-
const agentVelocity =
|
|
177
|
-
const agentNextTargetPath =
|
|
178
|
-
const agentState =
|
|
179
|
-
const agentCorners =
|
|
180
|
-
const agentParameters =
|
|
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
|
-
|
|
142
|
+
agent.goto(targetPosition);
|
|
185
143
|
|
|
186
144
|
/* reset the agents target */
|
|
187
|
-
|
|
145
|
+
agent.resetMoveTarget();
|
|
188
146
|
|
|
189
147
|
/* teleport the agent to a position */
|
|
190
|
-
|
|
148
|
+
agent.teleport(targetPosition);
|
|
191
149
|
|
|
192
150
|
/* update some parameters of the agent */
|
|
193
|
-
|
|
151
|
+
agent.updateParameters({
|
|
194
152
|
maxAcceleration: 4.0,
|
|
195
153
|
});
|
|
196
154
|
|
|
197
155
|
/* set all parameters for an agent */
|
|
198
|
-
|
|
156
|
+
agent.setParameters({
|
|
199
157
|
// any omitted parameters will be set to their default values
|
|
200
158
|
});
|
|
201
159
|
|
|
202
|
-
/*
|
|
203
|
-
crowd.removeAgent(
|
|
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
|
-
###
|
|
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
|
-
|
|
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.
|
|
21
|
+
"version": "0.7.1",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"homepage": "https://github.com/isaac-mason/recast-navigation-js",
|
|
24
24
|
"bugs": {
|
|
@@ -50,11 +50,8 @@
|
|
|
50
50
|
"build-storybook": "storybook build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@recast-navigation/core": "0.
|
|
54
|
-
"@recast-navigation/three": "0.
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"three": "^0.155.0"
|
|
53
|
+
"@recast-navigation/core": "0.7.1",
|
|
54
|
+
"@recast-navigation/three": "0.7.1"
|
|
58
55
|
},
|
|
59
56
|
"devDependencies": {
|
|
60
57
|
"@babel/core": "^7.22.11",
|
|
@@ -63,7 +60,7 @@
|
|
|
63
60
|
"@react-three/csg": "^3.0.0",
|
|
64
61
|
"@react-three/drei": "^9.78.2",
|
|
65
62
|
"@react-three/fiber": "^8.12.0",
|
|
66
|
-
"@rollup/plugin-commonjs": "^
|
|
63
|
+
"@rollup/plugin-commonjs": "^25.0.4",
|
|
67
64
|
"@rollup/plugin-multi-entry": "^6.0.0",
|
|
68
65
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
69
66
|
"@rollup/plugin-terser": "^0.4.3",
|