@recast-navigation/core 0.0.6 → 0.0.7

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.
@@ -0,0 +1,44 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ export declare type NavMeshCreateParams = {
3
+ verts: number[];
4
+ vertCount: number;
5
+ polys: number[];
6
+ polyFlags: number[];
7
+ polyAreas: number[];
8
+ polyCount: number;
9
+ nvp: number;
10
+ detailMeshes: number[];
11
+ detailVerts: number[];
12
+ detailVertsCount: number;
13
+ detailTris: number[];
14
+ detailTriCount: number;
15
+ offMeshConVerts: number[];
16
+ offMeshConRad: number[];
17
+ offMeshConFlags: number[];
18
+ offMeshConAreas: number[];
19
+ offMeshConDir: number[];
20
+ offMeshConUserID: number[];
21
+ offMeshConCount: number;
22
+ userId: number;
23
+ tileX: number;
24
+ tileY: number;
25
+ tileLayer: number;
26
+ bmin: number[];
27
+ bmax: number[];
28
+ walkableHeight: number;
29
+ walkableRadius: number;
30
+ walkableClimb: number;
31
+ cs: number;
32
+ ch: number;
33
+ buildBvTree: boolean;
34
+ };
35
+ export declare type CreateNavMeshDataResult = {
36
+ success: boolean;
37
+ navMeshData: readonly number[];
38
+ navMeshDataSize: number;
39
+ };
40
+ export declare class NavMeshBuilder {
41
+ raw: R.NavMeshBuilder;
42
+ constructor();
43
+ createNavMeshData(params: NavMeshCreateParams): CreateNavMeshDataResult;
44
+ }
@@ -0,0 +1,12 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ import { NavMesh } from './nav-mesh';
3
+ import { TileCache } from './tile-cache';
4
+ export declare class NavMeshExporter {
5
+ raw: R.NavMeshExporter;
6
+ constructor();
7
+ /**
8
+ * Returns a NavMesh export that can be used later. The NavMesh must be built before retrieving the data
9
+ * @returns data the Uint8Array that can be saved and reused
10
+ */
11
+ export(navMesh: NavMesh, tileCache?: TileCache): Uint8Array;
12
+ }
@@ -0,0 +1,116 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ import { NavMesh } from './nav-mesh';
3
+ import { TileCache } from './tile-cache';
4
+ export declare type NavMeshConfig = {
5
+ /**
6
+ * The size of the non-navigable border around the heightfield.
7
+ * [Limit: >=0] [Units: vx]
8
+ * @default 0
9
+ */
10
+ borderSize: number;
11
+ /**
12
+ * The width/height size of tile's on the xz-plane.
13
+ * [Limit: >= 0] [Units: vx]
14
+ *
15
+ * If tileSize is provided, a tiled navmesh will be created.
16
+ * If tileSize is not provided, or is set to zero, a solo navmesh will be created.
17
+ *
18
+ * To use obstacles, a tiled navmesh must be generated.
19
+ * @default 0
20
+ */
21
+ tileSize: number;
22
+ /**
23
+ * The xz-plane cell size to use for fields.
24
+ * [Limit: > 0] [Units: wu]
25
+ * @default 0.2
26
+ */
27
+ cs: number;
28
+ /**
29
+ * The y-axis cell size to use for fields.
30
+ * Limit: > 0] [Units: wu]
31
+ * @default 0.2
32
+ */
33
+ ch: number;
34
+ /**
35
+ * The maximum slope that is considered walkable.
36
+ * [Limits: 0 <= value < 90] [Units: Degrees]
37
+ * @default 60
38
+ */
39
+ walkableSlopeAngle: number;
40
+ /**
41
+ * Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable.
42
+ * [Limit: >= 3] [Units: vx]
43
+ * @default 2
44
+ */
45
+ walkableHeight: number;
46
+ /**
47
+ * Maximum ledge height that is considered to still be traversable.
48
+ * [Limit: >=0] [Units: vx]
49
+ * @default 2
50
+ */
51
+ walkableClimb: number;
52
+ /**
53
+ * The distance to erode/shrink the walkable area of the heightfield away from obstructions.
54
+ * [Limit: >=0] [Units: vx]
55
+ * @default 0.5
56
+ */
57
+ walkableRadius: number;
58
+ /**
59
+ * The maximum allowed length for contour edges along the border of the mesh.
60
+ * [Limit: >=0] [Units: vx]
61
+ * @default 12
62
+ */
63
+ maxEdgeLen: number;
64
+ /**
65
+ * The maximum distance a simplfied contour's border edges should deviate the original raw contour.
66
+ * [Limit: >=0] [Units: vx]
67
+ * @default 1.3
68
+ */
69
+ maxSimplificationError: number;
70
+ /**
71
+ * The minimum number of cells allowed to form isolated island areas.
72
+ * [Limit: >=0] [Units: vx]
73
+ * @default 8
74
+ */
75
+ minRegionArea: number;
76
+ /**
77
+ * Any regions with a span count smaller than this value will, if possible, be merged with larger regions.
78
+ * [Limit: >=0] [Units: vx]
79
+ * @default 20
80
+ */
81
+ mergeRegionArea: number;
82
+ /**
83
+ * The maximum number of vertices allowed for polygons generated during the be merged with larger regions.
84
+ * [Limit: >=0] [Units: vx]
85
+ * @default 6
86
+ */
87
+ maxVertsPerPoly: number;
88
+ /**
89
+ * Sets the sampling distance to use when generating the detail mesh. (For height detail only.)
90
+ * [Limits: 0 or >= 0.9] [Units: wu]
91
+ * @default 6
92
+ */
93
+ detailSampleDist: number;
94
+ /**
95
+ * The maximum distance the detail mesh surface should deviate from heightfield data. (For height detail only.)
96
+ * [Limit: >=0] [Units: wu]
97
+ * @default 1
98
+ */
99
+ detailSampleMaxError: number;
100
+ };
101
+ export declare type NavMeshGeneratorResult = {
102
+ success: boolean;
103
+ navMesh: NavMesh;
104
+ tileCache: TileCache;
105
+ };
106
+ export declare class NavMeshGenerator {
107
+ raw: R.NavMeshGenerator;
108
+ constructor();
109
+ /**
110
+ * Builds a NavMesh from the given positions and indices.
111
+ * @param positions a flat array of positions
112
+ * @param indices a flat array of indices
113
+ * @param navMeshConfig optional configuration for the NavMesh
114
+ */
115
+ generate(positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshConfig?: Partial<NavMeshConfig>): NavMeshGeneratorResult;
116
+ }
@@ -0,0 +1,16 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ import { NavMesh } from './nav-mesh';
3
+ import { TileCache } from './tile-cache';
4
+ export declare type NavMeshImporterResult = {
5
+ navMesh: NavMesh;
6
+ tileCache: TileCache;
7
+ };
8
+ export declare class NavMeshImporter {
9
+ raw: R.NavMeshImporter;
10
+ constructor();
11
+ /**
12
+ * Build the navmesh from a previously saved state using getNavMeshExport
13
+ * @param data the Uint8Array returned by `getNavMeshExport`
14
+ */
15
+ import(data: Uint8Array): NavMeshImporterResult;
16
+ }
@@ -0,0 +1,46 @@
1
+ import type R from '@recast-navigation/wasm';
2
+ import { NavMesh } from './nav-mesh';
3
+ import { NavPath, Vector3 } from './utils';
4
+ export declare type NavMeshQueryParams = {
5
+ navMesh: NavMesh;
6
+ /**
7
+ * @default 2048
8
+ */
9
+ maxNodes?: number;
10
+ };
11
+ export declare class NavMeshQuery {
12
+ raw: R.NavMeshQuery;
13
+ constructor({ navMesh, maxNodes }: NavMeshQueryParams);
14
+ /**
15
+ * Returns the closest point on the NavMesh to the given position.
16
+ */
17
+ getClosestPoint(position: Vector3): Vector3;
18
+ /**
19
+ * Returns a random point on the NavMesh within the given radius of the given position.
20
+ */
21
+ getRandomPointAround(position: Vector3, radius: number): Vector3;
22
+ /**
23
+ * Compute the final position from a segment made of destination-position
24
+ */
25
+ moveAlong(position: Vector3, destination: Vector3): Vector3;
26
+ /**
27
+ * Finds a path from the start position to the end position.
28
+ *g
29
+ * @returns an array of Vector3 positions that make up the path, or an empty array if no path was found.
30
+ */
31
+ computePath(start: Vector3, end: Vector3): NavPath;
32
+ /**
33
+ * Gets the Bounding box extent specified by setDefaultQueryExtent
34
+ */
35
+ getDefaultQueryExtent(): Vector3;
36
+ /**
37
+ * Sets the Bounding box extent for doing spatial queries (getClosestPoint, getRandomPointAround, ...)
38
+ * The queries will try to find a solution within those bounds.
39
+ * The default is (1,1,1)
40
+ */
41
+ setDefaultQueryExtent(extent: Vector3): void;
42
+ /**
43
+ * Destroys the NavMeshQuery instance
44
+ */
45
+ destroy(): void;
46
+ }
@@ -1,181 +1,48 @@
1
1
  import type R from '@recast-navigation/wasm';
2
- import { Crowd } from './crowd';
3
2
  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;
30
- /**
31
- * The y-axis cell size to use for fields.
32
- * Limit: > 0] [Units: wu]
33
- * @default 0.2
34
- */
35
- ch: number;
36
- /**
37
- * The maximum slope that is considered walkable.
38
- * [Limits: 0 <= value < 90] [Units: Degrees]
39
- * @default 60
40
- */
41
- walkableSlopeAngle: number;
42
- /**
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
46
- */
47
- walkableHeight: number;
48
- /**
49
- * Maximum ledge height that is considered to still be traversable.
50
- * [Limit: >=0] [Units: vx]
51
- * @default 2
52
- */
53
- walkableClimb: number;
54
- /**
55
- * The distance to erode/shrink the walkable area of the heightfield away from obstructions.
56
- * [Limit: >=0] [Units: vx]
57
- * @default 0.5
58
- */
59
- walkableRadius: number;
60
- /**
61
- * The maximum allowed length for contour edges along the border of the mesh.
62
- * [Limit: >=0] [Units: vx]
63
- * @default 12
64
- */
65
- maxEdgeLen: number;
66
- /**
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
70
- */
71
- maxSimplificationError: number;
72
- /**
73
- * The minimum number of cells allowed to form isolated island areas.
74
- * [Limit: >=0] [Units: vx]
75
- * @default 8
76
- */
77
- minRegionArea: number;
78
- /**
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
82
- */
83
- mergeRegionArea: number;
84
- /**
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
88
- */
89
- maxVertsPerPoly: number;
90
- /**
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
94
- */
95
- detailSampleDist: number;
96
- /**
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
100
- */
101
- detailSampleMaxError: number;
3
+ export declare type NavMeshParams = {
4
+ orig: number[];
5
+ tileWidth: number;
6
+ tileHeight: number;
7
+ maxTiles: number;
8
+ maxPolys: number;
9
+ };
10
+ export declare type NavMeshAddTileResult = {
11
+ status: number;
12
+ tileRef: number;
102
13
  };
103
14
  export declare class NavMesh {
104
15
  raw: R.NavMesh;
105
- obstacles: Map<ObstacleRef, Obstacle>;
106
- constructor();
16
+ constructor(raw?: R.NavMesh);
107
17
  /**
108
- * Updates the NavMesh tile cache by rebuilding tiles touched by unfinished obstacle requests.
109
- * This should be called after adding or removing obstacles.
18
+ * Initializes the NavMesh for use with a single tile.
19
+ * @param data the nav mesh data
20
+ * @param dataSize the size of the nav mesh data
21
+ * @param flags the flags to use when building the nav mesh
22
+ * @returns the status of the operation
110
23
  */
111
- update(): void;
112
- /**
113
- * Destroys the NavMesh.
114
- */
115
- destroy(): void;
24
+ initSolo(data: ReadonlyArray<number>, dataSize: number, flags: number): boolean;
116
25
  /**
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
26
+ * Initializes the NavMesh for use with multiple tiles.
27
+ * @param params parameters for the NavMesh
28
+ * @returns the status of the operation
121
29
  */
122
- build(positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshConfig?: Partial<NavMeshConfig>): void;
30
+ initTiled(params: NavMeshParams): boolean;
123
31
  /**
124
- * Build the navmesh from a previously saved state using getNavMeshData
125
- * @param data the Uint8Array returned by `getNavMeshData`
32
+ * Adds a tile to the NavMesh.
33
+ * @param data the nav mesh data
34
+ * @param dataSize the size of the nav mesh data
35
+ * @param flags the flags to use when building the nav mesh
36
+ * @param lastRef
37
+ * @returns the status of the operation and the reference of the added tile
126
38
  */
127
- buildFromNavMeshData(data: Uint8Array): void;
39
+ addTile(data: number[], dataSize: number, flags: number, lastRef: number): NavMeshAddTileResult;
128
40
  /**
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
41
+ * Destroys the NavMesh.
131
42
  */
132
- getNavMeshData(): Uint8Array;
43
+ destroy(): void;
133
44
  /**
134
45
  * Returns a DebugNavMesh that can be used to visualize the NavMesh.
135
46
  */
136
47
  getDebugNavMesh(): DebugNavMesh;
137
- /**
138
- * Returns the closest point on the NavMesh to the given position.
139
- */
140
- getClosestPoint(position: Vector3): Vector3;
141
- /**
142
- * Returns a random point on the NavMesh within the given radius of the given position.
143
- */
144
- getRandomPointAround(position: Vector3, radius: number): Vector3;
145
- /**
146
- * Compute the final position from a segment made of destination-position
147
- */
148
- moveAlong(position: Vector3, destination: Vector3): Vector3;
149
- /**
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.
153
- */
154
- computePath(start: Vector3, end: Vector3): NavPath;
155
- /**
156
- * Gets the Bounding box extent specified by setDefaultQueryExtent
157
- */
158
- getDefaultQueryExtent(): Vector3;
159
- /**
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)
163
- */
164
- setDefaultQueryExtent(extent: Vector3): void;
165
- /**
166
- * Creates a cylinder obstacle and adds it to the navigation mesh.
167
- */
168
- addCylinderObstacle(position: Vector3, radius: number, height: number): CylinderObstacle;
169
- /**
170
- * Creates a box obstacle and adds it to the navigation mesh.
171
- */
172
- addBoxObstacle(position: Vector3, extent: Vector3, angle: number): BoxObstacle;
173
- /**
174
- * Removes an obstacle from the navigation mesh.
175
- */
176
- removeObstacle(obstacle: Obstacle | ObstacleRef): void;
177
- createCrowd(config: {
178
- maxAgents: number;
179
- maxAgentRadius: number;
180
- }): Crowd;
181
48
  }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  import Recast from '@recast-navigation/wasm';
2
- export declare const Raw: {
2
+ export declare const Wasm: {
3
3
  Recast: typeof Recast;
4
4
  };
5
5
  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.0.7",
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.0.7",
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",