recast-navigation 0.0.0-development-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/LICENSE +21 -0
- package/README.md +193 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/package.json +89 -0
- package/three.d.ts +1 -0
- package/three.js +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2022 Isaac Mason
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# recast-navigation
|
|
2
|
+
|
|
3
|
+
### Recast Navigation for JavaScript!
|
|
4
|
+
|
|
5
|
+
A WebAssembly port of [Recast Navigation](https://github.com/recastnavigation/recastnavigation), plus other goodies.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 📐 NavMesh generation
|
|
10
|
+
- 🧭 Path-finding
|
|
11
|
+
- 🧑🤝🧑 Crowd simulation
|
|
12
|
+
- 🌐 Web and Node support
|
|
13
|
+
- 💙 TypeScript friendly
|
|
14
|
+
- 🖇 [Easy integration with three.js via @recast-navigation/three](https://github.com/isaac-mason/recast-navigation-js/tree/main/packages/recast-navigation-three)
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install recast-navigation
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Initialization
|
|
25
|
+
|
|
26
|
+
Before you can use the library, you must initialize it. This is an asynchronous operation.
|
|
27
|
+
|
|
28
|
+
Calling `init()` after the library has already been initialized will return a promise that resolves immediately.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { init } from 'recast-navigation';
|
|
32
|
+
|
|
33
|
+
await init();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Creating a NavMesh
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { NavMesh } from 'recast-navigation';
|
|
40
|
+
|
|
41
|
+
const navMesh = new NavMesh();
|
|
42
|
+
|
|
43
|
+
const positions = [
|
|
44
|
+
/* ... */
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const indices = [
|
|
48
|
+
/* ... */
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const navMeshConfig = {
|
|
52
|
+
/* ... */
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
navMesh.build(positions, indices, navMeshConfig);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Querying a NavMesh
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const navMesh = new NavMesh();
|
|
62
|
+
|
|
63
|
+
/* initialize the NavMesh */
|
|
64
|
+
// ...
|
|
65
|
+
|
|
66
|
+
/* get the closest point on the NavMesh to the given position */
|
|
67
|
+
const position = { x: 0, y: 0, z: 0 };
|
|
68
|
+
navMesh.getClosestPoint(position);
|
|
69
|
+
|
|
70
|
+
/* get a random point around the given position */
|
|
71
|
+
const radius = 0.5;
|
|
72
|
+
navMesh.getRandomPointAround(position, radius);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Adding Obstacles to a NavMesh
|
|
76
|
+
|
|
77
|
+
Recast Navigation supports creating Box and Cylinder obstacles.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
/* add a Box obstacle to the NavMesh */
|
|
81
|
+
const position = { x: 0, y: 0, z: 0 };
|
|
82
|
+
const extent = { x: 1, y: 1, z: 1 };
|
|
83
|
+
const angle = 0;
|
|
84
|
+
const boxObstacleRef = navMesh.addBoxObstacle(position, extent, angle);
|
|
85
|
+
|
|
86
|
+
/* add a Cylinder obstacle to the NavMesh */
|
|
87
|
+
const radius = 1;
|
|
88
|
+
const height = 1;
|
|
89
|
+
const cylinderObstacleRef = navMesh.addCylinderObstacle(
|
|
90
|
+
position,
|
|
91
|
+
radius,
|
|
92
|
+
height,
|
|
93
|
+
angle
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
/* remove the obstacles from the NavMesh */
|
|
97
|
+
navMesh.removeObstacle(boxObstacleRef);
|
|
98
|
+
navMesh.removeObstacle(cylinderObstacleRef);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Crowds and Agents
|
|
102
|
+
|
|
103
|
+
First, create a `Crowd` instance.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Crowd } from 'recast-navigation';
|
|
107
|
+
|
|
108
|
+
const maxAgents = 10;
|
|
109
|
+
const maxAgentRadius = 0.6;
|
|
110
|
+
|
|
111
|
+
const crowd = new Crowd({ maxAgents, maxAgentRadius, navMesh });
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
To update the crowd, first set a timeStep, then call `update` each frame with the delta time.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const dt = 1 / 60;
|
|
118
|
+
crowd.timeStep = dt;
|
|
119
|
+
|
|
120
|
+
// you should call this every frame
|
|
121
|
+
crowd.update(dt);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Next, you can create and interface with agents in the crowd.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const position = { x: 0, y: 0, z: 0 };
|
|
128
|
+
const radius = 0.6;
|
|
129
|
+
|
|
130
|
+
const initialAgentPosition = navMesh.getRandomPointAround(
|
|
131
|
+
{ x: 0, y: 0, z: 0 },
|
|
132
|
+
2
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const agentIndex = crowd.addAgent(initialAgentPosition, {
|
|
136
|
+
radius: 0.5,
|
|
137
|
+
height: 0.5,
|
|
138
|
+
maxAcceleration: 4.0,
|
|
139
|
+
maxSpeed: 1.0,
|
|
140
|
+
collisionQueryRange: 0.5,
|
|
141
|
+
pathOptimizationRange: 0.0,
|
|
142
|
+
separationWeight: 1.0,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/* get information about the agent */
|
|
146
|
+
const agentPosition = crowd.getAgentPosition(agentIndex);
|
|
147
|
+
const agentVelocity = crowd.getAgentVelocity(agentIndex);
|
|
148
|
+
const agentNextTargetPath = crowd.getAgentNextTargetPath(agentIndex);
|
|
149
|
+
const agentState = crowd.getAgentState(agentIndex);
|
|
150
|
+
const agentCorners = crowd.getAgentCorners(agentIndex);
|
|
151
|
+
const agentParameters = crowd.getAgentParameters(agentIndex);
|
|
152
|
+
|
|
153
|
+
/* tell the agent to move to a target position */
|
|
154
|
+
const targetPosition = { x: 0, y: 0, z: 0 };
|
|
155
|
+
crowd.goto(agentIndex, targetPosition);
|
|
156
|
+
|
|
157
|
+
/* teleport the agent to a position */
|
|
158
|
+
crowd.teleport(agentIndex, targetPosition);
|
|
159
|
+
|
|
160
|
+
/* update some parameters of the agent */
|
|
161
|
+
crowd.updateAgentParameters(agentIndex, {
|
|
162
|
+
maxAcceleration: 4.0,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
/* set all parameters for an agent */
|
|
166
|
+
crowd.setAgentParameters(agentIndex, {
|
|
167
|
+
// any omitted parameters will be set to their default values
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/* destroy the agent */
|
|
171
|
+
crowd.removeAgent(agentIndex);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Debugging
|
|
175
|
+
|
|
176
|
+
You can use `getDebugNavMesh` to get a debug representation of the NavMesh.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const debugNavMesh = navMesh.getDebugNavMesh();
|
|
180
|
+
|
|
181
|
+
const { positions, indices } = debugNavMesh.positions;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
If you are using `@recast-navigation/three`, you can use `NavMeshHelper` to easily visualize the NavMesh.
|
|
185
|
+
|
|
186
|
+
### Exporting and Importing a NavMesh
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
const navMeshData: Uint8Array = navMesh.getNavMeshData();
|
|
190
|
+
|
|
191
|
+
const newNavMesh = new NavMesh();
|
|
192
|
+
newNavMesh.buildFromNavMeshData(navMeshData);
|
|
193
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recast-navigation/core';
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "recast-navigation",
|
|
3
|
+
"description": "Recast Navigation for JavaScript!",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"recastnavigation",
|
|
6
|
+
"recast-navigation",
|
|
7
|
+
"recast",
|
|
8
|
+
"detour",
|
|
9
|
+
"navmesh",
|
|
10
|
+
"pathfinding",
|
|
11
|
+
"navigation",
|
|
12
|
+
"crowd-simulation",
|
|
13
|
+
"wasm",
|
|
14
|
+
"webassembly"
|
|
15
|
+
],
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Isaac Mason",
|
|
18
|
+
"email": "isaac@isaacmason.com",
|
|
19
|
+
"url": "https://isaacmason.com/"
|
|
20
|
+
},
|
|
21
|
+
"version": "0.0.0-development-0",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"homepage": "https://github.com/isaac-mason/recast-navigation-js",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/isaac-mason/recast-navigation-js/issues"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./index.js",
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": "./index.js"
|
|
33
|
+
},
|
|
34
|
+
"./three": {
|
|
35
|
+
"import": "./three.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"index.js",
|
|
40
|
+
"index.d.ts",
|
|
41
|
+
"three.js",
|
|
42
|
+
"three.d.ts",
|
|
43
|
+
"LICENSE",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "rollup --config rollup.config.js --bundleConfigAsCjs",
|
|
48
|
+
"storybook": "start-storybook -p 6006",
|
|
49
|
+
"build-storybook": "build-storybook"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@recast-navigation/core": "0.0.0-development-0",
|
|
53
|
+
"@recast-navigation/three": "0.0.0-development-0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"three": "^0.150.1"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@babel/core": "^7.21.3",
|
|
60
|
+
"@mdx-js/react": "^1.6.22",
|
|
61
|
+
"@react-three/csg": "^2.2.0",
|
|
62
|
+
"@react-three/drei": "^9.58.5",
|
|
63
|
+
"@react-three/fiber": "^8.12.0",
|
|
64
|
+
"@rollup/plugin-commonjs": "^24.0.1",
|
|
65
|
+
"@rollup/plugin-multi-entry": "^6.0.0",
|
|
66
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
67
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
68
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
69
|
+
"@storybook/addon-actions": "^6.5.16",
|
|
70
|
+
"@storybook/addon-docs": "^6.5.16",
|
|
71
|
+
"@storybook/addon-essentials": "^6.5.16",
|
|
72
|
+
"@storybook/addon-interactions": "^6.5.16",
|
|
73
|
+
"@storybook/addon-links": "^6.5.16",
|
|
74
|
+
"@storybook/builder-vite": "^0.4.2",
|
|
75
|
+
"@storybook/builder-webpack4": "^6.5.16",
|
|
76
|
+
"@storybook/manager-webpack4": "^6.5.16",
|
|
77
|
+
"@storybook/react": "^6.5.16",
|
|
78
|
+
"@types/react": "^18.0.28",
|
|
79
|
+
"@types/react-dom": "^18.0.11",
|
|
80
|
+
"@types/three": "^0.150.0",
|
|
81
|
+
"babel-loader": "^8.3.0",
|
|
82
|
+
"rollup": "^3.20.0",
|
|
83
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
84
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
85
|
+
"suspend-react": "^0.0.9",
|
|
86
|
+
"three": "^0.150.1"
|
|
87
|
+
},
|
|
88
|
+
"packageManager": "yarn@3.2.2"
|
|
89
|
+
}
|
package/three.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recast-navigation/three';
|
package/three.js
ADDED