@recast-navigation/core 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.
@@ -1,181 +1,335 @@
1
1
  import type R from '@recast-navigation/wasm';
2
- import { Crowd } from './crowd';
3
- import { DebugNavMesh } from './debug-nav-mesh';
4
- import type { BoxObstacle, CylinderObstacle, Obstacle, ObstacleRef } from './obstacle';
5
- import type { NavPath, Vector3 } from './utils';
6
- export declare type NavMeshConfig = {
7
- /**
8
- * The size of the non-navigable border around the heightfield.
9
- * [Limit: >=0] [Units: vx]
10
- * @default 0
11
- */
12
- borderSize: number;
13
- /**
14
- * The width/height size of tile's on the xz-plane.
15
- * [Limit: >= 0] [Units: vx]
16
- *
17
- * If tileSize is provided, a tiled navmesh will be created.
18
- * If tileSize is not provided, or is set to zero, a solo navmesh will be created.
19
- *
20
- * To use obstacles, a tiled navmesh must be generated.
21
- * @default 0
22
- */
23
- tileSize: number;
24
- /**
25
- * The xz-plane cell size to use for fields.
26
- * [Limit: > 0] [Units: wu]
27
- * @default 0.2
28
- */
29
- cs: number;
2
+ import { Vector3 } from './utils';
3
+ export declare class dtPoly {
4
+ raw: R.dtPoly;
5
+ constructor(raw: R.dtPoly);
6
+ firstLink(): number;
7
+ verts(index: number): number;
8
+ neis(index: number): number;
9
+ flags(): number;
10
+ vertCount(): number;
11
+ areaAndType(): number;
12
+ getType(): number;
13
+ }
14
+ export declare class dtPolyDetail {
15
+ raw: R.dtPolyDetail;
16
+ constructor(raw: R.dtPolyDetail);
17
+ vertBase(): number;
18
+ triBase(): number;
19
+ vertCount(): number;
20
+ triCount(): number;
21
+ }
22
+ export declare class dtLink {
23
+ raw: R.dtLink;
24
+ constructor(raw: R.dtLink);
25
+ ref(): number;
26
+ next(): number;
27
+ edge(): number;
28
+ side(): number;
29
+ bmin(): number;
30
+ bmax(): number;
31
+ }
32
+ export declare class dtBVNode {
33
+ raw: R.dtBVNode;
34
+ constructor(raw: R.dtBVNode);
35
+ bmin(): Vector3;
36
+ bmax(): Vector3;
37
+ i(): number;
38
+ }
39
+ export declare class dtOffMeshConnection {
40
+ raw: R.dtOffMeshConnection;
41
+ constructor(raw: R.dtOffMeshConnection);
42
+ pos(index: number): number;
43
+ rad(): number;
44
+ poly(): number;
45
+ flags(): number;
46
+ side(): number;
47
+ userId(): number;
48
+ }
49
+ export declare class dtMeshHeader {
50
+ raw: R.dtMeshHeader;
51
+ constructor(raw: R.dtMeshHeader);
52
+ magic(): number;
53
+ version(): number;
54
+ x(): number;
55
+ y(): number;
56
+ layer(): number;
57
+ userId(): number;
58
+ polyCount(): number;
59
+ vertCount(): number;
60
+ maxLinkCount(): number;
61
+ detailMeshCount(): number;
62
+ detailVertCount(): number;
63
+ detailTriCount(): number;
64
+ bvNodeCount(): number;
65
+ offMeshConCount(): number;
66
+ offMeshBase(): number;
67
+ walkableHeight(): number;
68
+ walkableRadius(): number;
69
+ walkableClimb(): number;
70
+ bmin(index: number): number;
71
+ bmax(index: number): number;
72
+ bvQuantFactor(): number;
73
+ }
74
+ export declare class dtMeshTile {
75
+ raw: R.dtMeshTile;
76
+ constructor(raw: R.dtMeshTile);
77
+ salt(): number;
78
+ linksFreeList(): number;
79
+ header(): dtMeshHeader | null;
80
+ polys(index: number): dtPoly;
81
+ verts(index: number): number;
82
+ links(index: number): dtLink;
83
+ detailMeshes(index: number): dtPolyDetail;
84
+ detailVerts(index: number): number;
85
+ detailTris(index: number): number;
86
+ bvTree(index: number): dtBVNode;
87
+ offMeshCons(index: number): dtOffMeshConnection;
88
+ data(index: number): number;
89
+ dataSize(): number;
90
+ flags(): number;
91
+ next(): dtMeshTile;
92
+ }
93
+ export declare class NavMeshGetTilesAtResult {
94
+ raw: R.NavMeshGetTilesAtResult;
95
+ constructor(raw: R.NavMeshGetTilesAtResult);
96
+ tiles(index: number): dtMeshTile;
97
+ tileCount(): number;
98
+ }
99
+ export declare class NavMeshAddTileResult {
100
+ raw: R.NavMeshAddTileResult;
101
+ constructor(raw: R.NavMeshAddTileResult);
102
+ tileRef(): number;
103
+ status(): number;
104
+ }
105
+ export declare class NavMeshRemoveTileResult {
106
+ raw: R.NavMeshRemoveTileResult;
107
+ constructor(raw: R.NavMeshRemoveTileResult);
108
+ data(): number[];
109
+ dataSize(): number;
110
+ }
111
+ export declare class NavMeshCalcTileLocResult {
112
+ raw: R.NavMeshCalcTileLocResult;
113
+ constructor(raw: R.NavMeshCalcTileLocResult);
114
+ tileX(): number;
115
+ tileY(): number;
116
+ }
117
+ export declare class NavMeshGetTileAndPolyByRefResult {
118
+ raw: R.NavMeshGetTileAndPolyByRefResult;
119
+ constructor(raw: R.NavMeshGetTileAndPolyByRefResult);
120
+ tile(): dtMeshTile;
121
+ poly(): dtPoly;
122
+ status(): number;
123
+ }
124
+ export declare class NavMeshGetOffMeshConnectionPolyEndPointsResult {
125
+ raw: R.NavMeshGetOffMeshConnectionPolyEndPointsResult;
126
+ constructor(raw: R.NavMeshGetOffMeshConnectionPolyEndPointsResult);
127
+ status(): number;
128
+ startPos(): Vector3;
129
+ endPos(): Vector3;
130
+ }
131
+ export declare class NavMeshGetPolyFlagsResult {
132
+ raw: R.NavMeshGetPolyFlagsResult;
133
+ constructor(raw: R.NavMeshGetPolyFlagsResult);
134
+ flags(): number;
135
+ status(): number;
136
+ }
137
+ export declare class NavMeshGetPolyAreaResult {
138
+ raw: R.NavMeshGetPolyAreaResult;
139
+ constructor(raw: R.NavMeshGetPolyAreaResult);
140
+ area(): number;
141
+ status(): number;
142
+ }
143
+ export declare class NavMeshStoreTileStateResult {
144
+ raw: R.NavMeshStoreTileStateResult;
145
+ constructor(raw: R.NavMeshStoreTileStateResult);
146
+ data(): number[];
147
+ dataSize(): number;
148
+ }
149
+ export declare class DebugNavMesh {
150
+ raw: R.DebugNavMesh;
151
+ positions: number[];
152
+ indices: number[];
153
+ constructor(debugNavMesh: R.DebugNavMesh);
154
+ }
155
+ export declare type NavMeshParams = {
156
+ orig: Vector3;
157
+ tileWidth: number;
158
+ tileHeight: number;
159
+ maxTiles: number;
160
+ maxPolys: number;
161
+ };
162
+ export declare class NavMesh {
163
+ raw: R.NavMesh;
164
+ constructor(raw?: R.NavMesh);
30
165
  /**
31
- * The y-axis cell size to use for fields.
32
- * Limit: > 0] [Units: wu]
33
- * @default 0.2
166
+ * Initializes the NavMesh for use with a single tile.
167
+ * @param data the nav mesh data
168
+ * @param dataSize the size of the nav mesh data
169
+ * @param flags the flags to use when building the nav mesh
170
+ * @returns the status of the operation
34
171
  */
35
- ch: number;
172
+ initSolo(data: ReadonlyArray<number>, dataSize: number, flags: number): boolean;
36
173
  /**
37
- * The maximum slope that is considered walkable.
38
- * [Limits: 0 <= value < 90] [Units: Degrees]
39
- * @default 60
174
+ * Initializes the NavMesh for use with multiple tiles.
175
+ * @param params parameters for the NavMesh
176
+ * @returns the status of the operation
40
177
  */
41
- walkableSlopeAngle: number;
178
+ initTiled({ orig, tileWidth, tileHeight, maxTiles, maxPolys, }: NavMeshParams): boolean;
42
179
  /**
43
- * Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable.
44
- * [Limit: >= 3] [Units: vx]
45
- * @default 2
180
+ * Adds a tile to the NavMesh.
181
+ * @param data the nav mesh data
182
+ * @param dataSize the size of the nav mesh data
183
+ * @param flags the flags to use when building the nav mesh
184
+ * @param lastRef
185
+ * @returns the status of the operation and the reference of the added tile
46
186
  */
47
- walkableHeight: number;
187
+ addTile(data: number[], dataSize: number, flags: number, lastRef: number): NavMeshAddTileResult;
48
188
  /**
49
- * Maximum ledge height that is considered to still be traversable.
50
- * [Limit: >=0] [Units: vx]
51
- * @default 2
189
+ * Removes a tile from the NavMesh
190
+ * @param ref the tile ref
191
+ * @returns the nav mesh data, so it can be added back later
52
192
  */
53
- walkableClimb: number;
193
+ removeTile(ref: number): NavMeshRemoveTileResult;
54
194
  /**
55
- * The distance to erode/shrink the walkable area of the heightfield away from obstructions.
56
- * [Limit: >=0] [Units: vx]
57
- * @default 0.5
195
+ * Calculates the tile grid location for the specified world position.
196
+ * @param pos The world position for the query. [(x, y, z)]
197
+ * @returns
58
198
  */
59
- walkableRadius: number;
199
+ calcTileLoc(pos: Vector3): NavMeshCalcTileLocResult;
60
200
  /**
61
- * The maximum allowed length for contour edges along the border of the mesh.
62
- * [Limit: >=0] [Units: vx]
63
- * @default 12
201
+ * Gets the tile at the specified grid location.
202
+ * @param x The tile's x-location. (x, y, layer)
203
+ * @param y The tile's y-location. (x, y, layer)
204
+ * @param layer The tile's layer. (x, y, layer)
205
+ * @returns The tile, or null if the tile does not exist.
64
206
  */
65
- maxEdgeLen: number;
207
+ getTileAt(x: number, y: number, layer: number): dtMeshTile | null;
66
208
  /**
67
- * The maximum distance a simplfied contour's border edges should deviate the original raw contour.
68
- * [Limit: >=0] [Units: vx]
69
- * @default 1.3
209
+ * Gets all tiles at the specified grid location. (All layers.)
210
+ * @param x The tile's x-location. (x, y)
211
+ * @param y The tile's y-location. (x, y)
212
+ * @param maxTiles The maximum tiles the tiles parameter can hold.
70
213
  */
71
- maxSimplificationError: number;
214
+ getTilesAt(x: number, y: number, maxTiles: number): NavMeshGetTilesAtResult;
72
215
  /**
73
- * The minimum number of cells allowed to form isolated island areas.
74
- * [Limit: >=0] [Units: vx]
75
- * @default 8
216
+ * Gets the tile reference for the tile at specified grid location.
217
+ * @param x The tile's x-location. (x, y, layer)
218
+ * @param y The tile's y-location. (x, y, layer)
219
+ * @param layer The tile's layer. (x, y, layer)
220
+ * @returns The tile reference of the tile, or 0 if there is none.
76
221
  */
77
- minRegionArea: number;
222
+ getTileRefAt(x: number, y: number, layer: number): number;
78
223
  /**
79
- * Any regions with a span count smaller than this value will, if possible, be merged with larger regions.
80
- * [Limit: >=0] [Units: vx]
81
- * @default 20
224
+ * Gets the tile reference for the specified tile.
225
+ * @param tile
226
+ * @returns
82
227
  */
83
- mergeRegionArea: number;
228
+ getTileRef(tile: dtMeshTile): number;
84
229
  /**
85
- * The maximum number of vertices allowed for polygons generated during the be merged with larger regions.
86
- * [Limit: >=0] [Units: vx]
87
- * @default 6
230
+ * Gets the tile for the specified tile reference.
231
+ * @param ref The tile reference of the tile to retrieve.
232
+ * @returns The tile for the specified reference, or null if the reference is invalid.
88
233
  */
89
- maxVertsPerPoly: number;
234
+ getTileByRef(ref: number): dtMeshTile | null;
90
235
  /**
91
- * Sets the sampling distance to use when generating the detail mesh. (For height detail only.)
92
- * [Limits: 0 or >= 0.9] [Units: wu]
93
- * @default 6
236
+ * Returns the maximum number of tiles supported by the navigation mesh.
94
237
  */
95
- detailSampleDist: number;
238
+ getMaxTiles(): number;
96
239
  /**
97
- * The maximum distance the detail mesh surface should deviate from heightfield data. (For height detail only.)
98
- * [Limit: >=0] [Units: wu]
99
- * @default 1
240
+ * Gets the tile at the specified index.
241
+ * @param i the tile index. [Limit: 0 >= index < #getMaxTiles()]
242
+ * @returns
100
243
  */
101
- detailSampleMaxError: number;
102
- };
103
- export declare class NavMesh {
104
- raw: R.NavMesh;
105
- obstacles: Map<ObstacleRef, Obstacle>;
106
- constructor();
244
+ getTile(i: number): dtMeshTile;
107
245
  /**
108
- * Updates the NavMesh tile cache by rebuilding tiles touched by unfinished obstacle requests.
109
- * This should be called after adding or removing obstacles.
246
+ * Gets the tile and polygon for the specified polygon reference.
247
+ * @param ref The reference for the a polygon.
248
+ * @returns
110
249
  */
111
- update(): void;
250
+ getTileAndPolyByRef(ref: number): NavMeshGetTileAndPolyByRefResult;
112
251
  /**
113
- * Destroys the NavMesh.
252
+ * Gets the tile and polygon for the specified polygon reference.
253
+ * @param ref A known valid reference for a polygon.
254
+ * @returns
114
255
  */
115
- destroy(): void;
256
+ getTileAndPolyByRefUnsafe(ref: number): NavMeshGetTileAndPolyByRefResult;
116
257
  /**
117
- * Builds a NavMesh from the given positions and indices.
118
- * @param positions a flat array of positions
119
- * @param indices a flat array of indices
120
- * @param navMeshConfig optional configuration for the NavMesh
258
+ * Checks the validity of a polygon reference.
259
+ * @param ref
260
+ * @returns
121
261
  */
122
- build(positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshConfig?: Partial<NavMeshConfig>): void;
262
+ isValidPolyRef(ref: number): boolean;
123
263
  /**
124
- * Build the navmesh from a previously saved state using getNavMeshData
125
- * @param data the Uint8Array returned by `getNavMeshData`
264
+ * Gets the polygon reference for the tile's base polygon.
265
+ * @param tile
266
+ * @returns
126
267
  */
127
- buildFromNavMeshData(data: Uint8Array): void;
268
+ getPolyRefBase(tile: dtMeshTile): number;
128
269
  /**
129
- * Returns the NavMesh data that can be used later. The NavMesh must be built before retrieving the data
130
- * @returns data the Uint8Array that can be saved and reused
270
+ * Gets the endpoints for an off-mesh connection, ordered by "direction of travel".
271
+ * @param prevRef The reference of the polygon before the connection.
272
+ * @param polyRef The reference of the off-mesh connection polygon.
273
+ * @returns
131
274
  */
132
- getNavMeshData(): Uint8Array;
275
+ getOffMeshConnectionPolyEndPoints(prevRef: number, polyRef: number): NavMeshGetOffMeshConnectionPolyEndPointsResult;
133
276
  /**
134
- * Returns a DebugNavMesh that can be used to visualize the NavMesh.
277
+ * Gets the specified off-mesh connection.
278
+ * @param ref The polygon reference of the off-mesh connection.
279
+ * @returns
135
280
  */
136
- getDebugNavMesh(): DebugNavMesh;
281
+ getOffMeshConnectionByRef(ref: number): dtOffMeshConnection;
137
282
  /**
138
- * Returns the closest point on the NavMesh to the given position.
283
+ * Sets the user defined flags for the specified polygon.
284
+ * @param ref The polygon reference.
285
+ * @param flags The new flags for the polygon.
139
286
  */
140
- getClosestPoint(position: Vector3): Vector3;
287
+ setPolyFlags(ref: number, flags: number): number;
141
288
  /**
142
- * Returns a random point on the NavMesh within the given radius of the given position.
289
+ * Gets the user defined flags for the specified polygon.
290
+ * @param ref The polygon reference.
291
+ * @returns
143
292
  */
144
- getRandomPointAround(position: Vector3, radius: number): Vector3;
293
+ getPolyFlags(ref: number): NavMeshGetPolyFlagsResult;
145
294
  /**
146
- * Compute the final position from a segment made of destination-position
295
+ * Sets the user defined area for the specified polygon.
296
+ * @param ref The polygon reference.
297
+ * @param flags The new flags for the polygon.
147
298
  */
148
- moveAlong(position: Vector3, destination: Vector3): Vector3;
299
+ setPolyArea(ref: number, area: number): number;
149
300
  /**
150
- * Finds a path from the start position to the end position.
151
- *
152
- * @returns an array of Vector3 positions that make up the path, or an empty array if no path was found.
301
+ * Gets the user defined area for the specified polygon.
302
+ * @param ref The polygon reference.
303
+ * @returns
153
304
  */
154
- computePath(start: Vector3, end: Vector3): NavPath;
305
+ getPolyArea(ref: number): NavMeshGetPolyAreaResult;
155
306
  /**
156
- * Gets the Bounding box extent specified by setDefaultQueryExtent
307
+ * Gets the size of the buffer required by #storeTileState to store the specified tile's state.
308
+ * @param tile
309
+ * @returns The size of the buffer required to store the state.
157
310
  */
158
- getDefaultQueryExtent(): Vector3;
311
+ getTileStateSize(tile: dtMeshTile): number;
159
312
  /**
160
- * Sets the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
161
- * The queries will try to find a solution within those bounds.
162
- * The default is (1,1,1)
313
+ * Stores the non-structural state of the tile in the specified buffer. (Flags, area ids, etc.)
314
+ * @param tile The tile.
315
+ * @param maxDataSize The size of the data buffer. [Limit: >= #getTileStateSize]
316
+ * @returns
163
317
  */
164
- setDefaultQueryExtent(extent: Vector3): void;
318
+ storeTileState(tile: dtMeshTile, maxDataSize: number): NavMeshStoreTileStateResult;
165
319
  /**
166
- * Creates a cylinder obstacle and adds it to the navigation mesh.
320
+ * Restores the state of the tile.
321
+ * @param tile The tile.
322
+ * @param data The new state. (Obtained from @see storeTileState)
323
+ * @param maxDataSize The size of the state within the data buffer.
324
+ * @returns
167
325
  */
168
- addCylinderObstacle(position: Vector3, radius: number, height: number): CylinderObstacle;
326
+ restoreTileState(tile: dtMeshTile, data: number[], maxDataSize: number): number;
169
327
  /**
170
- * Creates a box obstacle and adds it to the navigation mesh.
328
+ * Returns a DebugNavMesh that can be used to visualize the NavMesh.
171
329
  */
172
- addBoxObstacle(position: Vector3, extent: Vector3, angle: number): BoxObstacle;
330
+ getDebugNavMesh(): DebugNavMesh;
173
331
  /**
174
- * Removes an obstacle from the navigation mesh.
332
+ * Destroys the NavMesh.
175
333
  */
176
- removeObstacle(obstacle: Obstacle | ObstacleRef): void;
177
- createCrowd(config: {
178
- maxAgents: number;
179
- maxAgentRadius: number;
180
- }): Crowd;
334
+ destroy(): void;
181
335
  }
@@ -0,0 +1,48 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ import { NavMesh } from './nav-mesh';
3
+ import { BoxObstacle, CylinderObstacle, Obstacle, ObstacleRef } from './obstacle';
4
+ import { Vector3 } from './utils';
5
+ export declare type TileCacheParams = {
6
+ orig: ReadonlyArray<number>;
7
+ cs: number;
8
+ ch: number;
9
+ width: number;
10
+ height: number;
11
+ walkableHeight: number;
12
+ walkableRadius: number;
13
+ walkableClimb: number;
14
+ maxSimplificationError: number;
15
+ maxTiles: number;
16
+ maxObstacles: number;
17
+ };
18
+ export declare type TileCacheUpdateResult = {
19
+ status: number;
20
+ upToDate: boolean;
21
+ };
22
+ export declare class TileCache {
23
+ raw: R.TileCache;
24
+ obstacles: Map<ObstacleRef, Obstacle>;
25
+ constructor(raw?: R.TileCache);
26
+ /**
27
+ * Initialises the TileCache
28
+ * @param params
29
+ */
30
+ init(params: TileCacheParams): void;
31
+ /**
32
+ * Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests.
33
+ * This should be called after adding or removing obstacles.
34
+ */
35
+ update(navMesh: NavMesh): TileCacheUpdateResult;
36
+ /**
37
+ * Creates a cylinder obstacle and adds it to the navigation mesh.
38
+ */
39
+ addCylinderObstacle(position: Vector3, radius: number, height: number): CylinderObstacle;
40
+ /**
41
+ * Creates a box obstacle and adds it to the navigation mesh.
42
+ */
43
+ addBoxObstacle(position: Vector3, extent: Vector3, angle: number): BoxObstacle;
44
+ /**
45
+ * Removes an obstacle from the navigation mesh.
46
+ */
47
+ removeObstacle(obstacle: Obstacle | ObstacleRef): void;
48
+ }
package/dist/utils.d.ts CHANGED
@@ -11,12 +11,15 @@ export declare const vec3: {
11
11
  y: number;
12
12
  z: number;
13
13
  };
14
- };
15
- export declare type NavPath = Vector3[];
16
- export declare const navPath: {
17
- fromRaw: (v: R.NavPath) => {
14
+ fromArray: ([x, y, z]: number[]) => {
18
15
  x: number;
19
16
  y: number;
20
17
  z: number;
21
- }[];
18
+ };
19
+ toArray: ({ x, y, z }: Vector3) => number[];
20
+ };
21
+ export declare const array: <T>(getter: (index: number) => T, count: number) => T[];
22
+ export declare const emscripten: {
23
+ isNull: (obj: unknown) => boolean;
24
+ getPointer: (obj: unknown) => number;
22
25
  };
@@ -1,5 +1,6 @@
1
1
  import Recast from '@recast-navigation/wasm';
2
- export declare const Raw: {
2
+ export declare const Wasm: {
3
3
  Recast: typeof Recast;
4
+ DtStatus: Recast.DtStatus;
4
5
  };
5
6
  export declare const init: () => Promise<void>;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "email": "isaac@isaacmason.com",
7
7
  "url": "https://isaacmason.com/"
8
8
  },
9
- "version": "0.0.6",
9
+ "version": "0.1.0",
10
10
  "license": "MIT",
11
11
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
12
12
  "bugs": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.18.6",
29
- "@recast-navigation/wasm": "0.0.6",
29
+ "@recast-navigation/wasm": "0.1.0",
30
30
  "@rollup/plugin-commonjs": "^24.0.1",
31
31
  "@rollup/plugin-node-resolve": "^15.0.1",
32
32
  "@rollup/plugin-terser": "^0.4.0",
@@ -1,7 +0,0 @@
1
- import R from '@recast-navigation/wasm';
2
- export declare class DebugNavMesh {
3
- raw: R.DebugNavMesh;
4
- positions: number[];
5
- indices: number[];
6
- constructor(debugNavMesh: R.DebugNavMesh);
7
- }