@recast-navigation/core 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.
package/dist/crowd.d.ts CHANGED
@@ -79,112 +79,133 @@ export type CrowdAgentParams = {
79
79
  */
80
80
  userData: unknown;
81
81
  };
82
- export declare class Crowd {
83
- raw: R.dtCrowd;
82
+ export declare const crowdAgentParamsDefaults: CrowdAgentParams;
83
+ export declare class CrowdAgent {
84
+ crowd: Crowd;
85
+ agentIndex: number;
86
+ raw: R.dtCrowdAgent;
87
+ constructor(crowd: Crowd, agentIndex: number);
84
88
  /**
85
- * The indices of the active agents in the crowd.
89
+ * Updates the agent's target.
90
+ * @param position The new target position.
91
+ * @returns True if the request was successful.
86
92
  */
87
- agents: number[];
93
+ goto(position: Vector3): boolean;
88
94
  /**
89
- * The NavMesh the crowd is interacting with.
95
+ * Resets the current move request for the specified agent.
90
96
  */
91
- navMesh: NavMesh;
97
+ resetMoveTarget(): void;
92
98
  /**
93
- * If delta time in navigation tick update is greater than the time step a number of sub iterations are done.
94
- * If more iterations are need to reach deltatime they will be discarded.
95
- * A value of 0 will set to no maximum and update will use as many substeps as needed.
99
+ * Teleports the agent to the specified position.
100
+ * @param position
96
101
  */
97
- maximumSubStepCount: number;
102
+ teleport(position: Vector3): void;
98
103
  /**
99
- * Get the time step of the navigation tick update.
104
+ * The position of the agent.
105
+ * @returns
100
106
  */
101
- timeStep: number;
107
+ position(): Vector3;
102
108
  /**
103
- * Time factor applied when updating crowd agents (default 1). A value of 0 will pause crowd updates.
109
+ * The velocity of the agent.
110
+ * @returns
104
111
  */
105
- timeFactor: number;
112
+ velocity(): Vector3;
106
113
  /**
107
- * The NavMeshQuery used to find nearest polys for commands
114
+ * Returns the next target position on the path to the target
115
+ * @returns
108
116
  */
109
- navMeshQuery: NavMeshQuery;
110
- constructor({ maxAgents, maxAgentRadius, navMesh }: CrowdParams);
117
+ nextTargetPath(): Vector3;
111
118
  /**
112
- * Adds a new agent to the crowd.
119
+ * Returns the state of the agent.
120
+ *
121
+ * 0 = DT_CROWDAGENT_STATE_INVALID
122
+ * 1 = DT_CROWDAGENT_STATE_WALKING
123
+ * 2 = DT_CROWDAGENT_STATE_OFFMESH
113
124
  */
114
- addAgent(position: Vector3, crowdAgentParams: Partial<CrowdAgentParams>): number;
125
+ state(): number;
115
126
  /**
116
- * Removes the agent from the crowd.
127
+ * Returns the local path corridor corners for the agent
128
+ * @returns
117
129
  */
118
- removeAgent(agentIndex: number): void;
130
+ corners(): Vector3[];
119
131
  /**
120
- * Submits a new move request for the specified agent.
132
+ * Returns the agents parameters.
133
+ * @returns
121
134
  */
122
- goto(agentIndex: number, position: Vector3): boolean;
135
+ parameters(): CrowdAgentParams;
123
136
  /**
124
- * Teleports the agent to the given position.
137
+ * Updates the agent's parameters.
138
+ * Any parameters not specified in the crowdAgentParams object will be unchanged.
139
+ * @param crowdAgentParams agent parameters to update.
125
140
  */
126
- teleport(agentIndex: number, position: Vector3): void;
141
+ updateParameters(crowdAgentParams: Partial<CrowdAgentParams>): void;
127
142
  /**
128
- * Resets the current move request for the specified agent.
143
+ * Sets the agent's parameters.
144
+ * Any parameters not specified in the crowdAgentParams object will be set to their default values.
145
+ * @param crowdAgentParams agent parameters
129
146
  */
130
- resetMoveTarget(agentIndex: number): void;
147
+ setParameters(crowdAgentParams: CrowdAgentParams): void;
148
+ }
149
+ export declare class Crowd {
150
+ raw: R.dtCrowd;
131
151
  /**
132
- * Updates the crowd
152
+ * The agents in the crowd.
133
153
  */
134
- update(deltaTime: number): void;
154
+ agents: {
155
+ [idx: string]: CrowdAgent;
156
+ };
135
157
  /**
136
- * Returns the maximum number of agents that can be managed by the crowd.
158
+ * The NavMesh the crowd is interacting with.
137
159
  */
138
- getAgentCount(): number;
160
+ navMesh: NavMesh;
139
161
  /**
140
- * Returns the number of active agents in the crowd.
162
+ * If delta time in navigation tick update is greater than the time step a number of sub iterations are done.
163
+ * If more iterations are need to reach deltatime they will be discarded.
164
+ * A value of 0 will set to no maximum and update will use as many substeps as needed.
141
165
  */
142
- getActiveAgentCount(): number;
166
+ maximumSubStepCount: number;
143
167
  /**
144
- * Returns the indices of all active agents.
168
+ * Get the time step of the navigation tick update.
145
169
  */
146
- getAgents(): number[];
170
+ timeStep: number;
147
171
  /**
148
- * Returns the position of the specified agent.
172
+ * Time factor applied when updating crowd agents (default 1). A value of 0 will pause crowd updates.
149
173
  */
150
- getAgentPosition(agentIndex: number): Vector3;
174
+ timeFactor: number;
151
175
  /**
152
- * Returns the velocity of the specified agent.
176
+ * The NavMeshQuery used to find nearest polys for commands
153
177
  */
154
- getAgentVelocity(agentIndex: number): Vector3;
178
+ navMeshQuery: NavMeshQuery;
179
+ constructor({ maxAgents, maxAgentRadius, navMesh }: CrowdParams);
155
180
  /**
156
- * Returns the next target position on the path to the specified agents target.
181
+ * Updates the crowd
157
182
  */
158
- getAgentNextTargetPath(agentIndex: number): Vector3;
183
+ update(deltaTime: number): void;
159
184
  /**
160
- * Returns the state of the specified agent.
161
- *
162
- * 0 = DT_CROWDAGENT_STATE_INVALID
163
- * 1 = DT_CROWDAGENT_STATE_WALKING
164
- * 2 = DT_CROWDAGENT_STATE_OFFMESH
185
+ * Adds a new agent to the crowd.
165
186
  */
166
- getAgentState(agentIndex: number): number;
187
+ addAgent(position: Vector3, crowdAgentParams: Partial<CrowdAgentParams>): CrowdAgent;
167
188
  /**
168
- * Returns the local path corridor corners for the specified agent.
189
+ * Gets the agent with the specified index, or null if no agent has the given index.
190
+ * @param agentIndex
191
+ * @returns
169
192
  */
170
- getAgentCorners(agentIndex: number): Vector3[];
193
+ getAgent(agentIndex: number): CrowdAgent | null;
171
194
  /**
172
- * Returns the parameters for the specified agent.
195
+ * Removes the agent from the crowd.
173
196
  */
174
- getAgentParameters(agentIndex: number): CrowdAgentParams;
197
+ removeAgent(agent: number | CrowdAgent): void;
175
198
  /**
176
- * Sets the parameters for the specified agent.
177
- * Any parameters not specified in the crowdAgentParams object will be set to their default values.
178
- * @param agentIndex
179
- * @param crowdAgentParams
199
+ * Returns the maximum number of agents that can be managed by the crowd.
180
200
  */
181
- setAgentParameters(agentIndex: number, crowdAgentParams: Partial<CrowdAgentParams>): void;
201
+ getAgentCount(): number;
182
202
  /**
183
- * Updates the parameters for the specified agent.
184
- * Any parameters not specified in the crowdAgentParams object will be unchanged.
185
- * @param agentIndex
186
- * @param crowdAgentParams
203
+ * Returns the number of active agents in the crowd.
204
+ */
205
+ getActiveAgentCount(): number;
206
+ /**
207
+ * Returns all the agents managed by the crowd.
187
208
  */
188
- updateAgentParameters(agentIndex: number, crowdAgentParams: Partial<CrowdAgentParams>): void;
209
+ getAgents(): CrowdAgent[];
189
210
  destroy(): void;
190
211
  }
package/dist/detour.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type R from './raw-module';
2
- import { Vector3 } from './utils';
2
+ import { RecastPolyMesh, RecastPolyMeshDetail } from './recast';
3
+ import { Vector3, Vector3Tuple } from './utils';
3
4
  export declare class DetourPolyDetail {
4
5
  raw: R.dtPolyDetail;
5
6
  constructor(raw: R.dtPolyDetail);
@@ -60,7 +61,7 @@ export declare class DetourMeshHeader {
60
61
  bmax(index: number): number;
61
62
  bvQuantFactor(): number;
62
63
  }
63
- export declare class dtPoly {
64
+ export declare class DetourPoly {
64
65
  raw: R.dtPoly;
65
66
  constructor(raw: R.dtPoly);
66
67
  firstLink(): number;
@@ -77,7 +78,7 @@ export declare class DetourMeshTile {
77
78
  salt(): number;
78
79
  linksFreeList(): number;
79
80
  header(): DetourMeshHeader | null;
80
- polys(index: number): dtPoly;
81
+ polys(index: number): DetourPoly;
81
82
  verts(index: number): number;
82
83
  links(index: number): DetourLink;
83
84
  detailMeshes(index: number): DetourPolyDetail;
@@ -90,3 +91,68 @@ export declare class DetourMeshTile {
90
91
  flags(): number;
91
92
  next(): DetourMeshTile;
92
93
  }
94
+ export declare const createNavMeshData: (navMeshCreateParams: NavMeshCreateParams) => R.CreateNavMeshDataResult;
95
+ export declare class NavMeshCreateParams {
96
+ raw: R.dtNavMeshCreateParams;
97
+ constructor(raw?: R.dtNavMeshCreateParams);
98
+ setPolyMeshCreateParams(polyMesh: RecastPolyMesh): void;
99
+ setPolyMeshDetailCreateParams(polyMeshDetail: RecastPolyMeshDetail): void;
100
+ setOffMeshConCount(offMeshConCount: number): void;
101
+ verts(index: number): number;
102
+ setVerts(index: number, value: number): void;
103
+ vertCount(): number;
104
+ polys(index: number): number;
105
+ setPolys(index: number, value: number): void;
106
+ polyAreas(index: number): number;
107
+ setPolyAreas(index: number, value: number): void;
108
+ polyFlags(index: number): number;
109
+ setPolyFlags(index: number, value: number): void;
110
+ polyCount(): number;
111
+ nvp(): number;
112
+ setNvp(value: number): void;
113
+ detailMeshes(index: number): number;
114
+ setDetailMeshes(index: number, value: number): void;
115
+ detailVerts(index: number): number;
116
+ setDetailVerts(index: number, value: number): void;
117
+ detailVertsCount(): number;
118
+ detailTris(index: number): number;
119
+ setDetailTris(index: number, value: number): void;
120
+ detailTriCount(): number;
121
+ offMeshConVerts(index: number): number;
122
+ setOffMeshConVerts(index: number, value: number): void;
123
+ offMeshConRad(index: number): number;
124
+ setOffMeshConRad(index: number, value: number): void;
125
+ offMeshConDir(index: number): number;
126
+ setOffMeshConDir(index: number, value: number): void;
127
+ offMeshConAreas(index: number): number;
128
+ setOffMeshConAreas(index: number, value: number): void;
129
+ offMeshConFlags(index: number): number;
130
+ setOffMeshConFlags(index: number, value: number): void;
131
+ offMeshConUserID(index: number): number;
132
+ setOffMeshConUserID(index: number, value: number): void;
133
+ offMeshConCount(): number;
134
+ userId(): number;
135
+ setUserId(value: number): void;
136
+ tileX(): number;
137
+ setTileX(value: number): void;
138
+ tileY(): number;
139
+ setTileY(value: number): void;
140
+ tileLayer(): number;
141
+ setTileLayer(value: number): void;
142
+ boundsMin(): Vector3Tuple;
143
+ setBoundsMin(value: Vector3Tuple): void;
144
+ boundsMax(): Vector3Tuple;
145
+ setBoundsMax(value: Vector3Tuple): void;
146
+ walkableHeight(): number;
147
+ setWalkableHeight(value: number): void;
148
+ walkableRadius(): number;
149
+ setWalkableRadius(value: number): void;
150
+ walkableClimb(): number;
151
+ setWalkableClimb(value: number): void;
152
+ cellSize(): number;
153
+ setCellSize(value: number): void;
154
+ cellHeight(): number;
155
+ setCellHeight(value: number): void;
156
+ buildBvTree(): boolean;
157
+ setBuildBvTree(value: boolean): void;
158
+ }
@@ -1,8 +1,6 @@
1
- export declare const getVertsAndTris: (positions: ArrayLike<number>, indices: ArrayLike<number>) => {
2
- verts: number[];
3
- nVerts: number;
4
- tris: number[];
5
- nTris: number;
6
- bbMin: import("three").Vector3Tuple;
7
- bbMax: import("three").Vector3Tuple;
1
+ export declare const getBoundingBox: (positions: ArrayLike<number>, indices: ArrayLike<number>) => {
2
+ bbMin: import("../utils").Vector3Tuple;
3
+ bbMax: import("../utils").Vector3Tuple;
8
4
  };
5
+ export declare const dtIlog2: (v: number) => number;
6
+ export declare const dtNextPow2: (v: number) => number;
@@ -1,9 +1,10 @@
1
1
  import { NavMesh } from '../nav-mesh';
2
- import { RecastConfigType, RecastCompactHeightfield, RecastContourSet, RecastHeightfield } from '../recast';
2
+ import { RecastConfigType, RecastCompactHeightfield, RecastContourSet, RecastHeightfield, RecastBuildContext } from '../recast';
3
3
  export type SoloNavMeshGeneratorConfig = Omit<RecastConfigType, 'tileSize'>;
4
4
  export declare const soloNavMeshGeneratorConfigDefaults: SoloNavMeshGeneratorConfig;
5
5
  export type SoloNavMeshGeneratorIntermediates = {
6
6
  type: 'solo';
7
+ buildContext: RecastBuildContext;
7
8
  heightfield?: RecastHeightfield;
8
9
  compactHeightfield?: RecastCompactHeightfield;
9
10
  contourSet?: RecastContourSet;
@@ -0,0 +1,50 @@
1
+ import { NavMesh } from '../nav-mesh';
2
+ import { RecastBuildContext, RecastChunkyTriMesh, RecastCompactHeightfield, RecastConfigType, RecastHeightfield, RecastHeightfieldLayerSet } from '../recast';
3
+ import { TileCache } from '../tile-cache';
4
+ export type TileCacheGeneratorConfig = RecastConfigType & {
5
+ /**
6
+ * How many layers (or "floors") each navmesh tile is expected to have.
7
+ */
8
+ expectedLayersPerTile: number;
9
+ /**
10
+ * The max number of obstacles
11
+ */
12
+ maxObstacles: number;
13
+ };
14
+ export declare const tileCacheGeneratorConfigDefaults: TileCacheGeneratorConfig;
15
+ export type TileCacheGeneratorIntermediates = {
16
+ type: 'tilecache';
17
+ buildContext: RecastBuildContext;
18
+ chunkyTriMesh?: RecastChunkyTriMesh;
19
+ tileIntermediates: {
20
+ tileX: number;
21
+ tileY: number;
22
+ heightfield: RecastHeightfield;
23
+ heightfieldLayerSet: RecastHeightfieldLayerSet;
24
+ compactHeightfield: RecastCompactHeightfield;
25
+ }[];
26
+ };
27
+ type TileCacheGeneratorSuccessResult = {
28
+ tileCache: TileCache;
29
+ navMesh: NavMesh;
30
+ success: true;
31
+ intermediates?: TileCacheGeneratorIntermediates;
32
+ };
33
+ type TileCacheGeneratorFailResult = {
34
+ tileCache: undefined;
35
+ navMesh: undefined;
36
+ success: false;
37
+ error: string;
38
+ intermediates?: TileCacheGeneratorIntermediates;
39
+ };
40
+ export type TileCacheGeneratorResult = TileCacheGeneratorSuccessResult | TileCacheGeneratorFailResult;
41
+ /**
42
+ * Builds a TileCache and NavMesh from the given positions and indices.
43
+ * TileCache assumes small tiles (around 32-64 squared) and does some tricks to make the update fast.
44
+ * @param positions a flat array of positions
45
+ * @param indices a flat array of indices
46
+ * @param navMeshConfig optional configuration for the NavMesh
47
+ * @param keepIntermediates if true intermediates will be returned
48
+ */
49
+ export declare const generateTileCache: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TileCacheGeneratorConfig>, keepIntermediates?: boolean) => TileCacheGeneratorResult;
50
+ export {};
@@ -1,48 +1,37 @@
1
1
  import { NavMesh } from '../nav-mesh';
2
- import type R from '../raw-module';
3
- import { RecastCompactHeightfield, RecastConfigType, RecastHeightfield, RecastHeightfieldLayerSet } from '../recast';
4
- import { TileCache } from '../tile-cache';
5
- export type TiledNavMeshGeneratorConfig = RecastConfigType & {
6
- /**
7
- * How many layers (or "floors") each navmesh tile is expected to have.
8
- */
9
- expectedLayersPerTile: number;
10
- /**
11
- * The max number of obstacles
12
- */
13
- maxObstacles: number;
14
- };
2
+ import { RecastBuildContext, RecastChunkyTriMesh, RecastCompactHeightfield, RecastConfigType, RecastContourSet, RecastHeightfield } from '../recast';
3
+ import { Pretty } from '../types';
4
+ export type TiledNavMeshGeneratorConfig = Pretty<RecastConfigType>;
15
5
  export declare const tiledNavMeshGeneratorConfigDefaults: TiledNavMeshGeneratorConfig;
16
6
  export type TiledNavMeshGeneratorIntermediates = {
17
7
  type: 'tiled';
18
- chunkyTriMesh?: R.rcChunkyTriMesh;
8
+ buildContext: RecastBuildContext;
9
+ chunkyTriMesh?: RecastChunkyTriMesh;
19
10
  tileIntermediates: {
20
- tx: number;
21
- ty: number;
22
- heightfield: RecastHeightfield;
23
- heightfieldLayerSet: RecastHeightfieldLayerSet;
24
- compactHeightfield: RecastCompactHeightfield;
11
+ tileX: number;
12
+ tileY: number;
13
+ heightfield?: RecastHeightfield;
14
+ compactHeightfield?: RecastCompactHeightfield;
15
+ contourSet?: RecastContourSet;
25
16
  }[];
26
17
  };
27
18
  type TiledNavMeshGeneratorSuccessResult = {
28
- tileCache: TileCache;
29
19
  navMesh: NavMesh;
30
20
  success: true;
31
21
  intermediates?: TiledNavMeshGeneratorIntermediates;
32
22
  };
33
23
  type TiledNavMeshGeneratorFailResult = {
34
- tileCache: undefined;
35
24
  navMesh: undefined;
36
25
  success: false;
37
- error: string;
38
26
  intermediates?: TiledNavMeshGeneratorIntermediates;
27
+ error: string;
39
28
  };
40
29
  export type TiledNavMeshGeneratorResult = TiledNavMeshGeneratorSuccessResult | TiledNavMeshGeneratorFailResult;
41
30
  /**
42
- * Builds a Tiled NavMesh from the given positions and indices.
31
+ * Builds a Tiled NavMesh
43
32
  * @param positions a flat array of positions
44
33
  * @param indices a flat array of indices
45
- * @param navMeshConfig optional configuration for the NavMesh
34
+ * @param navMeshGeneratorConfig optional configuration for the NavMesh generator
46
35
  * @param keepIntermediates if true intermediates will be returned
47
36
  */
48
37
  export declare const generateTiledNavMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, navMeshGeneratorConfig?: Partial<TiledNavMeshGeneratorConfig>, keepIntermediates?: boolean) => TiledNavMeshGeneratorResult;
@@ -1,2 +1,4 @@
1
+ export * from './common';
1
2
  export * from './generate-solo-nav-mesh';
3
+ export * from './generate-tile-cache';
2
4
  export * from './generate-tiled-nav-mesh';