@esengine/pathfinding 13.1.0 → 13.3.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/{KDTree-2rs2EXvm.d.ts → CollisionResolver-CSgWsegP.d.ts} +122 -86
- package/dist/FlowController-Dc3nuLq5.d.ts +2751 -0
- package/dist/KDTree-BRpn7O8K.d.ts +216 -0
- package/dist/avoidance.d.ts +26 -4
- package/dist/avoidance.js +10 -2
- package/dist/{chunk-JTZP55BJ.js → chunk-3VEX32JO.js} +385 -9
- package/dist/chunk-3VEX32JO.js.map +1 -0
- package/dist/chunk-H5EFZBBT.js +1 -0
- package/dist/chunk-NIKT3PQC.js +3811 -0
- package/dist/chunk-NIKT3PQC.js.map +1 -0
- package/dist/ecs.d.ts +440 -647
- package/dist/ecs.js +1003 -1399
- package/dist/ecs.js.map +1 -1
- package/dist/index.d.ts +153 -611
- package/dist/index.js +1360 -1202
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/IIncrementalPathfinding-3qs7e_pO.d.ts +0 -450
- package/dist/LinearProgram-DyD3pI6v.d.ts +0 -56
- package/dist/chunk-JTZP55BJ.js.map +0 -1
- package/dist/chunk-KEYTX37K.js +0 -1
- package/dist/chunk-VNC2YAAL.js +0 -1650
- package/dist/chunk-VNC2YAAL.js.map +0 -1
- /package/dist/{chunk-KEYTX37K.js.map → chunk-H5EFZBBT.js.map} +0 -0
|
@@ -0,0 +1,2751 @@
|
|
|
1
|
+
import { c as IORCASolverConfig, i as ICollisionResolverConfig } from './CollisionResolver-CSgWsegP.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @zh 寻路系统核心接口
|
|
5
|
+
* @en Pathfinding System Core Interfaces
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @zh 2D 坐标点
|
|
9
|
+
* @en 2D coordinate point
|
|
10
|
+
*/
|
|
11
|
+
interface IPoint {
|
|
12
|
+
readonly x: number;
|
|
13
|
+
readonly y: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @zh 创建点
|
|
17
|
+
* @en Create a point
|
|
18
|
+
*/
|
|
19
|
+
declare function createPoint(x: number, y: number): IPoint;
|
|
20
|
+
/**
|
|
21
|
+
* @zh 路径节点
|
|
22
|
+
* @en Path node
|
|
23
|
+
*/
|
|
24
|
+
interface IPathNode {
|
|
25
|
+
/** @zh 节点唯一标识 @en Unique node identifier */
|
|
26
|
+
readonly id: string | number;
|
|
27
|
+
/** @zh 节点位置 @en Node position */
|
|
28
|
+
readonly position: IPoint;
|
|
29
|
+
/** @zh 移动代价 @en Movement cost */
|
|
30
|
+
readonly cost: number;
|
|
31
|
+
/** @zh 是否可通行 @en Is walkable */
|
|
32
|
+
readonly walkable: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @zh 路径结果
|
|
36
|
+
* @en Path result
|
|
37
|
+
*/
|
|
38
|
+
interface IPathResult {
|
|
39
|
+
/** @zh 是否找到路径 @en Whether path was found */
|
|
40
|
+
readonly found: boolean;
|
|
41
|
+
/** @zh 路径点列表 @en List of path points */
|
|
42
|
+
readonly path: readonly IPoint[];
|
|
43
|
+
/** @zh 路径总代价 @en Total path cost */
|
|
44
|
+
readonly cost: number;
|
|
45
|
+
/** @zh 搜索的节点数 @en Number of nodes searched */
|
|
46
|
+
readonly nodesSearched: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @zh 空路径结果
|
|
50
|
+
* @en Empty path result
|
|
51
|
+
*/
|
|
52
|
+
declare const EMPTY_PATH_RESULT: IPathResult;
|
|
53
|
+
/**
|
|
54
|
+
* @zh 寻路地图接口
|
|
55
|
+
* @en Pathfinding map interface
|
|
56
|
+
*/
|
|
57
|
+
interface IPathfindingMap {
|
|
58
|
+
/**
|
|
59
|
+
* @zh 获取节点的邻居
|
|
60
|
+
* @en Get neighbors of a node
|
|
61
|
+
*/
|
|
62
|
+
getNeighbors(node: IPathNode): IPathNode[];
|
|
63
|
+
/**
|
|
64
|
+
* @zh 获取指定位置的节点
|
|
65
|
+
* @en Get node at position
|
|
66
|
+
*/
|
|
67
|
+
getNodeAt(x: number, y: number): IPathNode | null;
|
|
68
|
+
/**
|
|
69
|
+
* @zh 计算两点间的启发式距离
|
|
70
|
+
* @en Calculate heuristic distance between two points
|
|
71
|
+
*/
|
|
72
|
+
heuristic(a: IPoint, b: IPoint): number;
|
|
73
|
+
/**
|
|
74
|
+
* @zh 计算两个邻居节点间的移动代价
|
|
75
|
+
* @en Calculate movement cost between two neighbor nodes
|
|
76
|
+
*/
|
|
77
|
+
getMovementCost(from: IPathNode, to: IPathNode): number;
|
|
78
|
+
/**
|
|
79
|
+
* @zh 检查位置是否可通行
|
|
80
|
+
* @en Check if position is walkable
|
|
81
|
+
*/
|
|
82
|
+
isWalkable(x: number, y: number): boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @zh 启发式函数类型
|
|
86
|
+
* @en Heuristic function type
|
|
87
|
+
*/
|
|
88
|
+
type HeuristicFunction = (a: IPoint, b: IPoint) => number;
|
|
89
|
+
/**
|
|
90
|
+
* @zh 曼哈顿距离(4方向移动)
|
|
91
|
+
* @en Manhattan distance (4-directional movement)
|
|
92
|
+
*/
|
|
93
|
+
declare function manhattanDistance(a: IPoint, b: IPoint): number;
|
|
94
|
+
/**
|
|
95
|
+
* @zh 欧几里得距离(任意方向移动)
|
|
96
|
+
* @en Euclidean distance (any direction movement)
|
|
97
|
+
*/
|
|
98
|
+
declare function euclideanDistance(a: IPoint, b: IPoint): number;
|
|
99
|
+
/**
|
|
100
|
+
* @zh 切比雪夫距离(8方向移动)
|
|
101
|
+
* @en Chebyshev distance (8-directional movement)
|
|
102
|
+
*/
|
|
103
|
+
declare function chebyshevDistance(a: IPoint, b: IPoint): number;
|
|
104
|
+
/**
|
|
105
|
+
* @zh 八角距离(8方向移动,对角线代价为 √2)
|
|
106
|
+
* @en Octile distance (8-directional, diagonal cost √2)
|
|
107
|
+
*/
|
|
108
|
+
declare function octileDistance(a: IPoint, b: IPoint): number;
|
|
109
|
+
/**
|
|
110
|
+
* @zh 寻路配置
|
|
111
|
+
* @en Pathfinding options
|
|
112
|
+
*/
|
|
113
|
+
interface IPathfindingOptions {
|
|
114
|
+
/** @zh 最大搜索节点数 @en Maximum nodes to search */
|
|
115
|
+
maxNodes?: number;
|
|
116
|
+
/** @zh 启发式权重 (>1 更快但可能非最优) @en Heuristic weight (>1 faster but may be suboptimal) */
|
|
117
|
+
heuristicWeight?: number;
|
|
118
|
+
/** @zh 是否允许对角移动 @en Allow diagonal movement */
|
|
119
|
+
allowDiagonal?: boolean;
|
|
120
|
+
/** @zh 是否避免穿角 @en Avoid corner cutting */
|
|
121
|
+
avoidCorners?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @zh 代理半径,用于生成考虑碰撞体积的路径
|
|
124
|
+
* @en Agent radius, used to generate paths that consider collision volume
|
|
125
|
+
*
|
|
126
|
+
* @zh 如果指定,路径规划器会收缩 portal 宽度并偏移拐点,确保路径与障碍物保持足够距离
|
|
127
|
+
* @en If specified, the path planner will shrink portal widths and offset turning points to ensure sufficient clearance from obstacles
|
|
128
|
+
*/
|
|
129
|
+
agentRadius?: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @zh 默认寻路配置
|
|
133
|
+
* @en Default pathfinding options
|
|
134
|
+
*/
|
|
135
|
+
declare const DEFAULT_PATHFINDING_OPTIONS: Required<IPathfindingOptions>;
|
|
136
|
+
/**
|
|
137
|
+
* @zh 寻路器接口
|
|
138
|
+
* @en Pathfinder interface
|
|
139
|
+
*/
|
|
140
|
+
interface IPathfinder {
|
|
141
|
+
/**
|
|
142
|
+
* @zh 查找路径
|
|
143
|
+
* @en Find path
|
|
144
|
+
*/
|
|
145
|
+
findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
|
|
146
|
+
/**
|
|
147
|
+
* @zh 清理状态(用于重用)
|
|
148
|
+
* @en Clear state (for reuse)
|
|
149
|
+
*/
|
|
150
|
+
clear(): void;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @zh 路径平滑器接口
|
|
154
|
+
* @en Path smoother interface
|
|
155
|
+
*/
|
|
156
|
+
interface IPathSmoother {
|
|
157
|
+
/**
|
|
158
|
+
* @zh 平滑路径
|
|
159
|
+
* @en Smooth path
|
|
160
|
+
*/
|
|
161
|
+
smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @zh 视线检测函数类型
|
|
165
|
+
* @en Line of sight check function type
|
|
166
|
+
*/
|
|
167
|
+
type LineOfSightCheck = (x1: number, y1: number, x2: number, y2: number, map: IPathfindingMap) => boolean;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @zh 增量寻路系统接口
|
|
171
|
+
* @en Incremental Pathfinding System Interfaces
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @zh 增量寻路状态
|
|
176
|
+
* @en Incremental pathfinding state
|
|
177
|
+
*/
|
|
178
|
+
declare enum PathfindingState {
|
|
179
|
+
/** @zh 空闲,等待请求 @en Idle, waiting for request */
|
|
180
|
+
Idle = "idle",
|
|
181
|
+
/** @zh 正在搜索中 @en Search in progress */
|
|
182
|
+
InProgress = "in_progress",
|
|
183
|
+
/** @zh 已暂停 @en Paused */
|
|
184
|
+
Paused = "paused",
|
|
185
|
+
/** @zh 搜索完成,找到路径 @en Completed, path found */
|
|
186
|
+
Completed = "completed",
|
|
187
|
+
/** @zh 搜索失败,无法找到路径 @en Failed, no path found */
|
|
188
|
+
Failed = "failed",
|
|
189
|
+
/** @zh 已取消 @en Cancelled */
|
|
190
|
+
Cancelled = "cancelled"
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @zh 增量寻路请求
|
|
194
|
+
* @en Incremental pathfinding request
|
|
195
|
+
*/
|
|
196
|
+
interface IPathRequest {
|
|
197
|
+
/**
|
|
198
|
+
* @zh 请求唯一标识符
|
|
199
|
+
* @en Unique request identifier
|
|
200
|
+
*/
|
|
201
|
+
readonly id: number;
|
|
202
|
+
/**
|
|
203
|
+
* @zh 起点 X 坐标
|
|
204
|
+
* @en Start X coordinate
|
|
205
|
+
*/
|
|
206
|
+
readonly startX: number;
|
|
207
|
+
/**
|
|
208
|
+
* @zh 起点 Y 坐标
|
|
209
|
+
* @en Start Y coordinate
|
|
210
|
+
*/
|
|
211
|
+
readonly startY: number;
|
|
212
|
+
/**
|
|
213
|
+
* @zh 终点 X 坐标
|
|
214
|
+
* @en End X coordinate
|
|
215
|
+
*/
|
|
216
|
+
readonly endX: number;
|
|
217
|
+
/**
|
|
218
|
+
* @zh 终点 Y 坐标
|
|
219
|
+
* @en End Y coordinate
|
|
220
|
+
*/
|
|
221
|
+
readonly endY: number;
|
|
222
|
+
/**
|
|
223
|
+
* @zh 寻路配置选项
|
|
224
|
+
* @en Pathfinding options
|
|
225
|
+
*/
|
|
226
|
+
readonly options?: IPathfindingOptions;
|
|
227
|
+
/**
|
|
228
|
+
* @zh 优先级(数值越小优先级越高)
|
|
229
|
+
* @en Priority (lower number = higher priority)
|
|
230
|
+
*/
|
|
231
|
+
readonly priority: number;
|
|
232
|
+
/**
|
|
233
|
+
* @zh 创建时间戳
|
|
234
|
+
* @en Creation timestamp
|
|
235
|
+
*/
|
|
236
|
+
readonly createdAt: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @zh 增量寻路进度
|
|
240
|
+
* @en Incremental pathfinding progress
|
|
241
|
+
*/
|
|
242
|
+
interface IPathProgress$1 {
|
|
243
|
+
/**
|
|
244
|
+
* @zh 当前寻路状态
|
|
245
|
+
* @en Current pathfinding state
|
|
246
|
+
*/
|
|
247
|
+
readonly state: PathfindingState;
|
|
248
|
+
/**
|
|
249
|
+
* @zh 已搜索的节点数量
|
|
250
|
+
* @en Number of nodes searched
|
|
251
|
+
*/
|
|
252
|
+
readonly nodesSearched: number;
|
|
253
|
+
/**
|
|
254
|
+
* @zh 开放列表当前大小
|
|
255
|
+
* @en Current open list size
|
|
256
|
+
*/
|
|
257
|
+
readonly openListSize: number;
|
|
258
|
+
/**
|
|
259
|
+
* @zh 估计的搜索进度 (0-1)
|
|
260
|
+
* @en Estimated search progress (0-1)
|
|
261
|
+
*/
|
|
262
|
+
readonly estimatedProgress: number;
|
|
263
|
+
/**
|
|
264
|
+
* @zh 当前最佳部分路径(可选)
|
|
265
|
+
* @en Current best partial path (optional)
|
|
266
|
+
*/
|
|
267
|
+
readonly partialPath?: readonly IPoint[];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @zh 增量寻路结果(扩展自 IPathResult)
|
|
271
|
+
* @en Incremental pathfinding result (extends IPathResult)
|
|
272
|
+
*/
|
|
273
|
+
interface IIncrementalPathResult extends IPathResult {
|
|
274
|
+
/**
|
|
275
|
+
* @zh 关联的请求 ID
|
|
276
|
+
* @en Associated request ID
|
|
277
|
+
*/
|
|
278
|
+
readonly requestId: number;
|
|
279
|
+
/**
|
|
280
|
+
* @zh 完成搜索所用的帧数
|
|
281
|
+
* @en Number of frames used to complete search
|
|
282
|
+
*/
|
|
283
|
+
readonly framesUsed: number;
|
|
284
|
+
/**
|
|
285
|
+
* @zh 是否为部分路径(未到达终点)
|
|
286
|
+
* @en Whether this is a partial path (not reaching goal)
|
|
287
|
+
*/
|
|
288
|
+
readonly isPartial: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @zh 增量寻路请求选项
|
|
292
|
+
* @en Incremental pathfinding request options
|
|
293
|
+
*/
|
|
294
|
+
interface IIncrementalPathfindingOptions extends IPathfindingOptions {
|
|
295
|
+
/**
|
|
296
|
+
* @zh 优先级(数值越小优先级越高,默认 50)
|
|
297
|
+
* @en Priority (lower = higher, default 50)
|
|
298
|
+
*/
|
|
299
|
+
priority?: number;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* @zh 增量寻路器接口
|
|
303
|
+
* @en Incremental pathfinder interface
|
|
304
|
+
*
|
|
305
|
+
* @zh 支持时间切片的寻路器,可跨多帧执行搜索
|
|
306
|
+
* @en Pathfinder with time slicing support, can execute search across multiple frames
|
|
307
|
+
*/
|
|
308
|
+
interface IIncrementalPathfinder {
|
|
309
|
+
/**
|
|
310
|
+
* @zh 请求寻路(非阻塞)
|
|
311
|
+
* @en Request pathfinding (non-blocking)
|
|
312
|
+
*
|
|
313
|
+
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
314
|
+
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
315
|
+
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
316
|
+
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
317
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
318
|
+
* @returns @zh 寻路请求对象 @en Path request object
|
|
319
|
+
*/
|
|
320
|
+
requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
|
|
321
|
+
/**
|
|
322
|
+
* @zh 执行一步搜索
|
|
323
|
+
* @en Execute one step of search
|
|
324
|
+
*
|
|
325
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
326
|
+
* @param maxIterations - @zh 本步最大迭代次数 @en Maximum iterations this step
|
|
327
|
+
* @returns @zh 当前进度 @en Current progress
|
|
328
|
+
*/
|
|
329
|
+
step(requestId: number, maxIterations: number): IPathProgress$1;
|
|
330
|
+
/**
|
|
331
|
+
* @zh 暂停寻路
|
|
332
|
+
* @en Pause pathfinding
|
|
333
|
+
*
|
|
334
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
335
|
+
*/
|
|
336
|
+
pause(requestId: number): void;
|
|
337
|
+
/**
|
|
338
|
+
* @zh 恢复寻路
|
|
339
|
+
* @en Resume pathfinding
|
|
340
|
+
*
|
|
341
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
342
|
+
*/
|
|
343
|
+
resume(requestId: number): void;
|
|
344
|
+
/**
|
|
345
|
+
* @zh 取消寻路
|
|
346
|
+
* @en Cancel pathfinding
|
|
347
|
+
*
|
|
348
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
349
|
+
*/
|
|
350
|
+
cancel(requestId: number): void;
|
|
351
|
+
/**
|
|
352
|
+
* @zh 获取寻路结果(仅当状态为 Completed 或 Failed 时可用)
|
|
353
|
+
* @en Get pathfinding result (only available when state is Completed or Failed)
|
|
354
|
+
*
|
|
355
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
356
|
+
* @returns @zh 寻路结果或 null @en Path result or null
|
|
357
|
+
*/
|
|
358
|
+
getResult(requestId: number): IIncrementalPathResult | null;
|
|
359
|
+
/**
|
|
360
|
+
* @zh 获取当前进度
|
|
361
|
+
* @en Get current progress
|
|
362
|
+
*
|
|
363
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
364
|
+
* @returns @zh 当前进度或 null @en Current progress or null
|
|
365
|
+
*/
|
|
366
|
+
getProgress(requestId: number): IPathProgress$1 | null;
|
|
367
|
+
/**
|
|
368
|
+
* @zh 清理已完成的请求(释放内存)
|
|
369
|
+
* @en Clean up completed request (release memory)
|
|
370
|
+
*
|
|
371
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
372
|
+
*/
|
|
373
|
+
cleanup(requestId: number): void;
|
|
374
|
+
/**
|
|
375
|
+
* @zh 通知障碍物变化(用于动态重规划)
|
|
376
|
+
* @en Notify obstacle change (for dynamic replanning)
|
|
377
|
+
*
|
|
378
|
+
* @param minX - @zh 变化区域最小 X @en Changed area min X
|
|
379
|
+
* @param minY - @zh 变化区域最小 Y @en Changed area min Y
|
|
380
|
+
* @param maxX - @zh 变化区域最大 X @en Changed area max X
|
|
381
|
+
* @param maxY - @zh 变化区域最大 Y @en Changed area max Y
|
|
382
|
+
*/
|
|
383
|
+
notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
384
|
+
/**
|
|
385
|
+
* @zh 清理所有请求
|
|
386
|
+
* @en Clear all requests
|
|
387
|
+
*/
|
|
388
|
+
clear(): void;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* @zh 路径验证结果
|
|
392
|
+
* @en Path validation result
|
|
393
|
+
*/
|
|
394
|
+
interface IPathValidationResult {
|
|
395
|
+
/**
|
|
396
|
+
* @zh 路径是否有效
|
|
397
|
+
* @en Whether the path is valid
|
|
398
|
+
*/
|
|
399
|
+
readonly valid: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* @zh 第一个无效点的索引(-1 表示全部有效)
|
|
402
|
+
* @en Index of first invalid point (-1 if all valid)
|
|
403
|
+
*/
|
|
404
|
+
readonly invalidIndex: number;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* @zh 路径验证器接口
|
|
408
|
+
* @en Path validator interface
|
|
409
|
+
*/
|
|
410
|
+
interface IPathValidator {
|
|
411
|
+
/**
|
|
412
|
+
* @zh 验证路径段的有效性
|
|
413
|
+
* @en Validate path segment validity
|
|
414
|
+
*
|
|
415
|
+
* @param path - @zh 要验证的路径 @en Path to validate
|
|
416
|
+
* @param fromIndex - @zh 起始索引 @en Start index
|
|
417
|
+
* @param toIndex - @zh 结束索引 @en End index
|
|
418
|
+
* @param map - @zh 地图实例 @en Map instance
|
|
419
|
+
* @returns @zh 验证结果 @en Validation result
|
|
420
|
+
*/
|
|
421
|
+
validatePath(path: readonly IPoint[], fromIndex: number, toIndex: number, map: IPathfindingMap): IPathValidationResult;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* @zh 动态重规划配置
|
|
425
|
+
* @en Dynamic replanning configuration
|
|
426
|
+
*/
|
|
427
|
+
interface IReplanningConfig {
|
|
428
|
+
/**
|
|
429
|
+
* @zh 是否启用动态重规划
|
|
430
|
+
* @en Whether dynamic replanning is enabled
|
|
431
|
+
*/
|
|
432
|
+
enabled: boolean;
|
|
433
|
+
/**
|
|
434
|
+
* @zh 路径检查间隔(帧数)
|
|
435
|
+
* @en Path check interval (in frames)
|
|
436
|
+
*/
|
|
437
|
+
checkInterval: number;
|
|
438
|
+
/**
|
|
439
|
+
* @zh 触发重规划的距离阈值
|
|
440
|
+
* @en Distance threshold to trigger replanning
|
|
441
|
+
*/
|
|
442
|
+
distanceThreshold: number;
|
|
443
|
+
/**
|
|
444
|
+
* @zh 向前探测的距离(路径点数)
|
|
445
|
+
* @en Lookahead distance (in path points)
|
|
446
|
+
*/
|
|
447
|
+
lookaheadDistance: number;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* @zh 默认重规划配置
|
|
451
|
+
* @en Default replanning configuration
|
|
452
|
+
*/
|
|
453
|
+
declare const DEFAULT_REPLANNING_CONFIG: IReplanningConfig;
|
|
454
|
+
/**
|
|
455
|
+
* @zh 空进度(用于无效请求)
|
|
456
|
+
* @en Empty progress (for invalid requests)
|
|
457
|
+
*/
|
|
458
|
+
declare const EMPTY_PROGRESS: IPathProgress$1;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* @zh 路径缓存模块
|
|
462
|
+
* @en Path Cache Module
|
|
463
|
+
*
|
|
464
|
+
* @zh 缓存已计算的路径,避免重复计算相同起点终点的路径
|
|
465
|
+
* @en Cache computed paths to avoid recalculating paths with the same start and end points
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @zh 缓存配置
|
|
470
|
+
* @en Cache configuration
|
|
471
|
+
*/
|
|
472
|
+
interface IPathCacheConfig {
|
|
473
|
+
/**
|
|
474
|
+
* @zh 最大缓存条目数
|
|
475
|
+
* @en Maximum number of cache entries
|
|
476
|
+
*/
|
|
477
|
+
maxEntries: number;
|
|
478
|
+
/**
|
|
479
|
+
* @zh 缓存过期时间(毫秒),0 表示不过期
|
|
480
|
+
* @en Cache expiration time in milliseconds, 0 means no expiration
|
|
481
|
+
*/
|
|
482
|
+
ttlMs: number;
|
|
483
|
+
/**
|
|
484
|
+
* @zh 是否启用近似匹配(在一定范围内的起点/终点视为相同)
|
|
485
|
+
* @en Whether to enable approximate matching (start/end within range considered same)
|
|
486
|
+
*/
|
|
487
|
+
enableApproximateMatch: boolean;
|
|
488
|
+
/**
|
|
489
|
+
* @zh 近似匹配范围
|
|
490
|
+
* @en Approximate matching range
|
|
491
|
+
*/
|
|
492
|
+
approximateRange: number;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* @zh 默认缓存配置
|
|
496
|
+
* @en Default cache configuration
|
|
497
|
+
*/
|
|
498
|
+
declare const DEFAULT_PATH_CACHE_CONFIG: IPathCacheConfig;
|
|
499
|
+
/**
|
|
500
|
+
* @zh 路径缓存
|
|
501
|
+
* @en Path Cache
|
|
502
|
+
*
|
|
503
|
+
* @zh 缓存已计算的路径,支持 LRU 淘汰策略和 TTL 过期
|
|
504
|
+
* @en Cache computed paths with LRU eviction and TTL expiration
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const cache = new PathCache({ maxEntries: 500 });
|
|
509
|
+
* const cached = cache.get(0, 0, 10, 10, mapVersion);
|
|
510
|
+
* if (!cached) {
|
|
511
|
+
* const result = pathfinder.findPath(0, 0, 10, 10);
|
|
512
|
+
* cache.set(0, 0, 10, 10, result, mapVersion);
|
|
513
|
+
* }
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
declare class PathCache {
|
|
517
|
+
private readonly config;
|
|
518
|
+
private readonly cache;
|
|
519
|
+
private readonly accessOrder;
|
|
520
|
+
constructor(config?: Partial<IPathCacheConfig>);
|
|
521
|
+
/**
|
|
522
|
+
* @zh 获取缓存的路径
|
|
523
|
+
* @en Get cached path
|
|
524
|
+
*
|
|
525
|
+
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
526
|
+
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
527
|
+
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
528
|
+
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
529
|
+
* @param mapVersion - @zh 地图版本号 @en Map version number
|
|
530
|
+
* @returns @zh 缓存的路径结果或 null @en Cached path result or null
|
|
531
|
+
*/
|
|
532
|
+
get(startX: number, startY: number, endX: number, endY: number, mapVersion: number): IPathResult | null;
|
|
533
|
+
/**
|
|
534
|
+
* @zh 设置缓存路径
|
|
535
|
+
* @en Set cached path
|
|
536
|
+
*
|
|
537
|
+
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
538
|
+
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
539
|
+
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
540
|
+
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
541
|
+
* @param result - @zh 路径结果 @en Path result
|
|
542
|
+
* @param mapVersion - @zh 地图版本号 @en Map version number
|
|
543
|
+
*/
|
|
544
|
+
set(startX: number, startY: number, endX: number, endY: number, result: IPathResult, mapVersion: number): void;
|
|
545
|
+
/**
|
|
546
|
+
* @zh 使所有缓存失效
|
|
547
|
+
* @en Invalidate all cache
|
|
548
|
+
*/
|
|
549
|
+
invalidateAll(): void;
|
|
550
|
+
/**
|
|
551
|
+
* @zh 使指定区域的缓存失效
|
|
552
|
+
* @en Invalidate cache for specified region
|
|
553
|
+
*
|
|
554
|
+
* @param minX - @zh 最小 X 坐标 @en Minimum X coordinate
|
|
555
|
+
* @param minY - @zh 最小 Y 坐标 @en Minimum Y coordinate
|
|
556
|
+
* @param maxX - @zh 最大 X 坐标 @en Maximum X coordinate
|
|
557
|
+
* @param maxY - @zh 最大 Y 坐标 @en Maximum Y coordinate
|
|
558
|
+
*/
|
|
559
|
+
invalidateRegion(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
560
|
+
/**
|
|
561
|
+
* @zh 获取缓存统计信息
|
|
562
|
+
* @en Get cache statistics
|
|
563
|
+
*/
|
|
564
|
+
getStats(): {
|
|
565
|
+
size: number;
|
|
566
|
+
maxSize: number;
|
|
567
|
+
hitRate?: number;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* @zh 清理过期条目
|
|
571
|
+
* @en Clean up expired entries
|
|
572
|
+
*/
|
|
573
|
+
cleanup(): void;
|
|
574
|
+
private generateKey;
|
|
575
|
+
private isValid;
|
|
576
|
+
private getApproximate;
|
|
577
|
+
private adjustPathForApproximate;
|
|
578
|
+
private updateAccessOrder;
|
|
579
|
+
private removeFromAccessOrder;
|
|
580
|
+
private evictLRU;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* @zh 创建路径缓存
|
|
584
|
+
* @en Create path cache
|
|
585
|
+
*
|
|
586
|
+
* @param config - @zh 缓存配置 @en Cache configuration
|
|
587
|
+
* @returns @zh 路径缓存实例 @en Path cache instance
|
|
588
|
+
*/
|
|
589
|
+
declare function createPathCache(config?: Partial<IPathCacheConfig>): PathCache;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* @zh 增量 A* 寻路算法实现
|
|
593
|
+
* @en Incremental A* Pathfinding Algorithm Implementation
|
|
594
|
+
*/
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* @zh 增量寻路器配置
|
|
598
|
+
* @en Incremental pathfinder configuration
|
|
599
|
+
*/
|
|
600
|
+
interface IIncrementalPathfinderConfig {
|
|
601
|
+
/**
|
|
602
|
+
* @zh 是否启用路径缓存
|
|
603
|
+
* @en Whether to enable path caching
|
|
604
|
+
*/
|
|
605
|
+
enableCache?: boolean;
|
|
606
|
+
/**
|
|
607
|
+
* @zh 缓存配置
|
|
608
|
+
* @en Cache configuration
|
|
609
|
+
*/
|
|
610
|
+
cacheConfig?: Partial<IPathCacheConfig>;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* @zh 增量 A* 寻路器
|
|
614
|
+
* @en Incremental A* Pathfinder
|
|
615
|
+
*
|
|
616
|
+
* @zh 支持时间切片的 A* 算法实现,可跨多帧执行搜索
|
|
617
|
+
* @en A* algorithm implementation with time slicing, can execute search across multiple frames
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```typescript
|
|
621
|
+
* const map = createGridMap(100, 100);
|
|
622
|
+
* const pathfinder = createIncrementalAStarPathfinder(map);
|
|
623
|
+
*
|
|
624
|
+
* // Request path (non-blocking)
|
|
625
|
+
* const request = pathfinder.requestPath(0, 0, 99, 99);
|
|
626
|
+
*
|
|
627
|
+
* // Process over multiple frames
|
|
628
|
+
* function gameLoop() {
|
|
629
|
+
* const progress = pathfinder.step(request.id, 100);
|
|
630
|
+
*
|
|
631
|
+
* if (progress.state === PathfindingState.Completed) {
|
|
632
|
+
* const result = pathfinder.getResult(request.id);
|
|
633
|
+
* console.log('Path found:', result?.path);
|
|
634
|
+
* } else if (progress.state === PathfindingState.InProgress) {
|
|
635
|
+
* requestAnimationFrame(gameLoop);
|
|
636
|
+
* }
|
|
637
|
+
* }
|
|
638
|
+
* gameLoop();
|
|
639
|
+
* ```
|
|
640
|
+
*/
|
|
641
|
+
declare class IncrementalAStarPathfinder implements IIncrementalPathfinder {
|
|
642
|
+
private readonly map;
|
|
643
|
+
private readonly sessions;
|
|
644
|
+
private nextRequestId;
|
|
645
|
+
private readonly affectedRegions;
|
|
646
|
+
private readonly maxRegionAge;
|
|
647
|
+
private readonly cache;
|
|
648
|
+
private readonly enableCache;
|
|
649
|
+
private mapVersion;
|
|
650
|
+
private cacheHits;
|
|
651
|
+
private cacheMisses;
|
|
652
|
+
/**
|
|
653
|
+
* @zh 创建增量 A* 寻路器
|
|
654
|
+
* @en Create incremental A* pathfinder
|
|
655
|
+
*
|
|
656
|
+
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
657
|
+
* @param config - @zh 配置选项 @en Configuration options
|
|
658
|
+
*/
|
|
659
|
+
constructor(map: IPathfindingMap, config?: IIncrementalPathfinderConfig);
|
|
660
|
+
/**
|
|
661
|
+
* @zh 请求寻路(非阻塞)
|
|
662
|
+
* @en Request pathfinding (non-blocking)
|
|
663
|
+
*/
|
|
664
|
+
requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
|
|
665
|
+
/**
|
|
666
|
+
* @zh 执行一步搜索
|
|
667
|
+
* @en Execute one step of search
|
|
668
|
+
*/
|
|
669
|
+
step(requestId: number, maxIterations: number): IPathProgress$1;
|
|
670
|
+
/**
|
|
671
|
+
* @zh 暂停寻路
|
|
672
|
+
* @en Pause pathfinding
|
|
673
|
+
*/
|
|
674
|
+
pause(requestId: number): void;
|
|
675
|
+
/**
|
|
676
|
+
* @zh 恢复寻路
|
|
677
|
+
* @en Resume pathfinding
|
|
678
|
+
*/
|
|
679
|
+
resume(requestId: number): void;
|
|
680
|
+
/**
|
|
681
|
+
* @zh 取消寻路
|
|
682
|
+
* @en Cancel pathfinding
|
|
683
|
+
*/
|
|
684
|
+
cancel(requestId: number): void;
|
|
685
|
+
/**
|
|
686
|
+
* @zh 获取寻路结果
|
|
687
|
+
* @en Get pathfinding result
|
|
688
|
+
*/
|
|
689
|
+
getResult(requestId: number): IIncrementalPathResult | null;
|
|
690
|
+
/**
|
|
691
|
+
* @zh 获取当前进度
|
|
692
|
+
* @en Get current progress
|
|
693
|
+
*/
|
|
694
|
+
getProgress(requestId: number): IPathProgress$1 | null;
|
|
695
|
+
/**
|
|
696
|
+
* @zh 清理已完成的请求
|
|
697
|
+
* @en Clean up completed request
|
|
698
|
+
*/
|
|
699
|
+
cleanup(requestId: number): void;
|
|
700
|
+
/**
|
|
701
|
+
* @zh 通知障碍物变化
|
|
702
|
+
* @en Notify obstacle change
|
|
703
|
+
*/
|
|
704
|
+
notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
705
|
+
/**
|
|
706
|
+
* @zh 清理所有请求
|
|
707
|
+
* @en Clear all requests
|
|
708
|
+
*/
|
|
709
|
+
clear(): void;
|
|
710
|
+
/**
|
|
711
|
+
* @zh 清空路径缓存
|
|
712
|
+
* @en Clear path cache
|
|
713
|
+
*/
|
|
714
|
+
clearCache(): void;
|
|
715
|
+
/**
|
|
716
|
+
* @zh 获取缓存统计信息
|
|
717
|
+
* @en Get cache statistics
|
|
718
|
+
*/
|
|
719
|
+
getCacheStats(): {
|
|
720
|
+
enabled: boolean;
|
|
721
|
+
hits: number;
|
|
722
|
+
misses: number;
|
|
723
|
+
hitRate: number;
|
|
724
|
+
size: number;
|
|
725
|
+
};
|
|
726
|
+
/**
|
|
727
|
+
* @zh 检查会话是否被障碍物变化影响
|
|
728
|
+
* @en Check if session is affected by obstacle change
|
|
729
|
+
*/
|
|
730
|
+
isAffectedByChange(requestId: number): boolean;
|
|
731
|
+
/**
|
|
732
|
+
* @zh 清除会话的变化标记
|
|
733
|
+
* @en Clear session's change flag
|
|
734
|
+
*/
|
|
735
|
+
clearChangeFlag(requestId: number): void;
|
|
736
|
+
/**
|
|
737
|
+
* @zh 展开邻居节点
|
|
738
|
+
* @en Expand neighbor nodes
|
|
739
|
+
*/
|
|
740
|
+
private expandNeighbors;
|
|
741
|
+
/**
|
|
742
|
+
* @zh 创建进度对象
|
|
743
|
+
* @en Create progress object
|
|
744
|
+
*/
|
|
745
|
+
private createProgress;
|
|
746
|
+
/**
|
|
747
|
+
* @zh 构建路径结果
|
|
748
|
+
* @en Build path result
|
|
749
|
+
*/
|
|
750
|
+
private buildResult;
|
|
751
|
+
/**
|
|
752
|
+
* @zh 创建空结果
|
|
753
|
+
* @en Create empty result
|
|
754
|
+
*/
|
|
755
|
+
private createEmptyResult;
|
|
756
|
+
/**
|
|
757
|
+
* @zh 检查会话是否被区域影响
|
|
758
|
+
* @en Check if session is affected by region
|
|
759
|
+
*/
|
|
760
|
+
private sessionAffectedByRegion;
|
|
761
|
+
/**
|
|
762
|
+
* @zh 清理过期的变化区域
|
|
763
|
+
* @en Clean up expired change regions
|
|
764
|
+
*/
|
|
765
|
+
private cleanupOldRegions;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* @zh 创建增量 A* 寻路器
|
|
769
|
+
* @en Create incremental A* pathfinder
|
|
770
|
+
*
|
|
771
|
+
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
772
|
+
* @returns @zh 增量 A* 寻路器实例 @en Incremental A* pathfinder instance
|
|
773
|
+
*/
|
|
774
|
+
declare function createIncrementalAStarPathfinder(map: IPathfindingMap): IncrementalAStarPathfinder;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* @zh HPA* (Hierarchical Pathfinding A*) 寻路算法实现
|
|
778
|
+
* @en HPA* (Hierarchical Pathfinding A*) Pathfinding Algorithm Implementation
|
|
779
|
+
*
|
|
780
|
+
* @zh HPA* 是一种分层寻路算法,适用于超大地图 (1000x1000+)
|
|
781
|
+
* @en HPA* is a hierarchical pathfinding algorithm suitable for very large maps (1000x1000+)
|
|
782
|
+
*
|
|
783
|
+
* @zh 工作原理:
|
|
784
|
+
* 1. 将地图划分为集群 (clusters)
|
|
785
|
+
* 2. 在集群边界检测入口点 (entrances)
|
|
786
|
+
* 3. 构建抽象图 (abstract graph) 连接入口点
|
|
787
|
+
* 4. 预计算集群内入口点之间的真实路径代价
|
|
788
|
+
* 5. 先在抽象图上寻路,再利用缓存细化为详细路径
|
|
789
|
+
*
|
|
790
|
+
* @en How it works:
|
|
791
|
+
* 1. Divide map into clusters
|
|
792
|
+
* 2. Detect entrances at cluster boundaries
|
|
793
|
+
* 3. Build abstract graph connecting entrances
|
|
794
|
+
* 4. Precompute actual path costs between entrances within clusters
|
|
795
|
+
* 5. First find path on abstract graph, then refine using cached paths
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* @zh HPA* 配置
|
|
800
|
+
* @en HPA* Configuration
|
|
801
|
+
*/
|
|
802
|
+
interface IHPAConfig {
|
|
803
|
+
/**
|
|
804
|
+
* @zh 集群大小(边长)
|
|
805
|
+
* @en Cluster size (side length)
|
|
806
|
+
*/
|
|
807
|
+
clusterSize: number;
|
|
808
|
+
/**
|
|
809
|
+
* @zh 最大入口宽度(超过此宽度会拆分或使用端点策略)
|
|
810
|
+
* @en Maximum entrance width (entrances wider than this will be split or use endpoint strategy)
|
|
811
|
+
*/
|
|
812
|
+
maxEntranceWidth: number;
|
|
813
|
+
/**
|
|
814
|
+
* @zh 是否启用内部路径缓存
|
|
815
|
+
* @en Whether to enable internal path caching
|
|
816
|
+
*/
|
|
817
|
+
cacheInternalPaths: boolean;
|
|
818
|
+
/**
|
|
819
|
+
* @zh 入口策略:'middle' 在中间放节点,'end' 在宽入口两端各放节点
|
|
820
|
+
* @en Entrance strategy: 'middle' places node at center, 'end' places nodes at both ends for wide entrances
|
|
821
|
+
*/
|
|
822
|
+
entranceStrategy?: 'middle' | 'end';
|
|
823
|
+
/**
|
|
824
|
+
* @zh 是否延迟计算 intra-edges(大幅加速预处理,首次查询时计算真实路径)
|
|
825
|
+
* @en Whether to lazily compute intra-edges (greatly speeds up preprocessing, computes actual paths on first query)
|
|
826
|
+
*/
|
|
827
|
+
lazyIntraEdges?: boolean;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* @zh 默认 HPA* 配置
|
|
831
|
+
* @en Default HPA* configuration
|
|
832
|
+
*/
|
|
833
|
+
declare const DEFAULT_HPA_CONFIG: IHPAConfig;
|
|
834
|
+
/**
|
|
835
|
+
* @zh HPA* 寻路器
|
|
836
|
+
* @en HPA* Pathfinder
|
|
837
|
+
*
|
|
838
|
+
* @zh 适用于超大地图的分层寻路算法
|
|
839
|
+
* @en Hierarchical pathfinding algorithm for very large maps
|
|
840
|
+
*
|
|
841
|
+
* @example
|
|
842
|
+
* ```typescript
|
|
843
|
+
* const map = createGridMap(1000, 1000);
|
|
844
|
+
* const pathfinder = new HPAPathfinder(map, { clusterSize: 20 });
|
|
845
|
+
*
|
|
846
|
+
* // Preprocess (do once after map changes)
|
|
847
|
+
* pathfinder.preprocess();
|
|
848
|
+
*
|
|
849
|
+
* // Find path
|
|
850
|
+
* const result = pathfinder.findPath(0, 0, 999, 999);
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
declare class HPAPathfinder implements IPathfinder {
|
|
854
|
+
private readonly map;
|
|
855
|
+
private readonly config;
|
|
856
|
+
private readonly mapWidth;
|
|
857
|
+
private readonly mapHeight;
|
|
858
|
+
private clusters;
|
|
859
|
+
private clusterGrid;
|
|
860
|
+
private clustersX;
|
|
861
|
+
private clustersY;
|
|
862
|
+
private abstractNodes;
|
|
863
|
+
private nodesByCluster;
|
|
864
|
+
private nextNodeId;
|
|
865
|
+
private entranceCount;
|
|
866
|
+
private readonly localPathfinder;
|
|
867
|
+
private readonly pathCache;
|
|
868
|
+
private mapVersion;
|
|
869
|
+
private preprocessed;
|
|
870
|
+
constructor(map: IPathfindingMap, config?: Partial<IHPAConfig>);
|
|
871
|
+
/**
|
|
872
|
+
* @zh 预处理地图(构建抽象图)
|
|
873
|
+
* @en Preprocess map (build abstract graph)
|
|
874
|
+
*/
|
|
875
|
+
preprocess(): void;
|
|
876
|
+
/**
|
|
877
|
+
* @zh 寻找路径
|
|
878
|
+
* @en Find path
|
|
879
|
+
*/
|
|
880
|
+
findPath(startX: number, startY: number, endX: number, endY: number, options?: Partial<IPathfindingOptions>): IPathResult;
|
|
881
|
+
/**
|
|
882
|
+
* @zh 清理状态
|
|
883
|
+
* @en Clear state
|
|
884
|
+
*/
|
|
885
|
+
clear(): void;
|
|
886
|
+
/**
|
|
887
|
+
* @zh 通知地图区域变化
|
|
888
|
+
* @en Notify map region change
|
|
889
|
+
*/
|
|
890
|
+
notifyRegionChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
891
|
+
/**
|
|
892
|
+
* @zh 获取预处理统计信息
|
|
893
|
+
* @en Get preprocessing statistics
|
|
894
|
+
*/
|
|
895
|
+
getStats(): {
|
|
896
|
+
clusters: number;
|
|
897
|
+
entrances: number;
|
|
898
|
+
abstractNodes: number;
|
|
899
|
+
cacheSize: number;
|
|
900
|
+
};
|
|
901
|
+
private getMapBounds;
|
|
902
|
+
/**
|
|
903
|
+
* @zh 构建集群
|
|
904
|
+
* @en Build clusters
|
|
905
|
+
*/
|
|
906
|
+
private buildClusters;
|
|
907
|
+
/**
|
|
908
|
+
* @zh 检测入口并创建抽象节点
|
|
909
|
+
* @en Detect entrances and create abstract nodes
|
|
910
|
+
*/
|
|
911
|
+
private buildEntrances;
|
|
912
|
+
/**
|
|
913
|
+
* @zh 检测并创建两个相邻集群之间的入口
|
|
914
|
+
* @en Detect and create entrances between two adjacent clusters
|
|
915
|
+
*/
|
|
916
|
+
private detectAndCreateEntrances;
|
|
917
|
+
/**
|
|
918
|
+
* @zh 检测边界上的连续可通行区间
|
|
919
|
+
* @en Detect continuous walkable spans on boundary
|
|
920
|
+
*/
|
|
921
|
+
private detectEntranceSpans;
|
|
922
|
+
/**
|
|
923
|
+
* @zh 为入口区间创建抽象节点
|
|
924
|
+
* @en Create abstract nodes for entrance span
|
|
925
|
+
*/
|
|
926
|
+
private createEntranceNodes;
|
|
927
|
+
/**
|
|
928
|
+
* @zh 创建抽象节点
|
|
929
|
+
* @en Create abstract node
|
|
930
|
+
*/
|
|
931
|
+
private createAbstractNode;
|
|
932
|
+
/**
|
|
933
|
+
* @zh 构建所有集群的 intra-edges
|
|
934
|
+
* @en Build intra-edges for all clusters
|
|
935
|
+
*/
|
|
936
|
+
private buildIntraEdges;
|
|
937
|
+
/**
|
|
938
|
+
* @zh 构建单个集群的 intra-edges
|
|
939
|
+
* @en Build intra-edges for single cluster
|
|
940
|
+
*/
|
|
941
|
+
private buildClusterIntraEdges;
|
|
942
|
+
/**
|
|
943
|
+
* @zh 延迟构建 intra-edges(只用启发式距离)
|
|
944
|
+
* @en Build lazy intra-edges (using heuristic distance only)
|
|
945
|
+
*/
|
|
946
|
+
private buildLazyIntraEdges;
|
|
947
|
+
/**
|
|
948
|
+
* @zh 立即构建 intra-edges(计算真实路径)
|
|
949
|
+
* @en Build eager intra-edges (compute actual paths)
|
|
950
|
+
*/
|
|
951
|
+
private buildEagerIntraEdges;
|
|
952
|
+
/**
|
|
953
|
+
* @zh 按需计算 intra-edge 的真实路径
|
|
954
|
+
* @en Compute actual path for intra-edge on demand
|
|
955
|
+
*/
|
|
956
|
+
private computeIntraEdgePath;
|
|
957
|
+
/**
|
|
958
|
+
* @zh 获取指定位置的集群
|
|
959
|
+
* @en Get cluster at position
|
|
960
|
+
*/
|
|
961
|
+
private getClusterAt;
|
|
962
|
+
/**
|
|
963
|
+
* @zh 获取受影响的集群
|
|
964
|
+
* @en Get affected clusters
|
|
965
|
+
*/
|
|
966
|
+
private getAffectedClusters;
|
|
967
|
+
/**
|
|
968
|
+
* @zh 插入临时节点
|
|
969
|
+
* @en Insert temporary node
|
|
970
|
+
*/
|
|
971
|
+
private insertTempNode;
|
|
972
|
+
/**
|
|
973
|
+
* @zh 移除临时节点
|
|
974
|
+
* @en Remove temporary node
|
|
975
|
+
*/
|
|
976
|
+
private removeTempNode;
|
|
977
|
+
/**
|
|
978
|
+
* @zh 在抽象图上进行 A* 搜索
|
|
979
|
+
* @en Perform A* search on abstract graph
|
|
980
|
+
*/
|
|
981
|
+
private abstractSearch;
|
|
982
|
+
/**
|
|
983
|
+
* @zh 重建抽象路径
|
|
984
|
+
* @en Reconstruct abstract path
|
|
985
|
+
*/
|
|
986
|
+
private reconstructPath;
|
|
987
|
+
/**
|
|
988
|
+
* @zh 细化抽象路径为具体路径
|
|
989
|
+
* @en Refine abstract path to concrete path
|
|
990
|
+
*/
|
|
991
|
+
private refinePath;
|
|
992
|
+
/**
|
|
993
|
+
* @zh 追加路径(避免重复点)
|
|
994
|
+
* @en Append path (avoid duplicate points)
|
|
995
|
+
*/
|
|
996
|
+
private appendPath;
|
|
997
|
+
/**
|
|
998
|
+
* @zh 局部寻路
|
|
999
|
+
* @en Local pathfinding
|
|
1000
|
+
*/
|
|
1001
|
+
private findLocalPath;
|
|
1002
|
+
/**
|
|
1003
|
+
* @zh 启发式函数(Octile 距离)
|
|
1004
|
+
* @en Heuristic function (Octile distance)
|
|
1005
|
+
*/
|
|
1006
|
+
private heuristic;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* @zh 创建 HPA* 寻路器
|
|
1010
|
+
* @en Create HPA* pathfinder
|
|
1011
|
+
*
|
|
1012
|
+
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
1013
|
+
* @param config - @zh HPA* 配置 @en HPA* configuration
|
|
1014
|
+
* @returns @zh HPA* 寻路器实例 @en HPA* pathfinder instance
|
|
1015
|
+
*/
|
|
1016
|
+
declare function createHPAPathfinder(map: IPathfindingMap, config?: Partial<IHPAConfig>): HPAPathfinder;
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* @zh 导航网格实现
|
|
1020
|
+
* @en NavMesh Implementation
|
|
1021
|
+
*
|
|
1022
|
+
* @zh 支持动态障碍物:可以临时禁用多边形或添加圆形/矩形障碍物
|
|
1023
|
+
* @en Supports dynamic obstacles: can temporarily disable polygons or add circular/rectangular obstacles
|
|
1024
|
+
*/
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* @zh 动态障碍物类型
|
|
1028
|
+
* @en Dynamic obstacle type
|
|
1029
|
+
*/
|
|
1030
|
+
type ObstacleType = 'circle' | 'rect' | 'polygon';
|
|
1031
|
+
/**
|
|
1032
|
+
* @zh 动态障碍物
|
|
1033
|
+
* @en Dynamic obstacle
|
|
1034
|
+
*/
|
|
1035
|
+
interface IDynamicObstacle {
|
|
1036
|
+
/**
|
|
1037
|
+
* @zh 障碍物 ID
|
|
1038
|
+
* @en Obstacle ID
|
|
1039
|
+
*/
|
|
1040
|
+
readonly id: number;
|
|
1041
|
+
/**
|
|
1042
|
+
* @zh 障碍物类型
|
|
1043
|
+
* @en Obstacle type
|
|
1044
|
+
*/
|
|
1045
|
+
readonly type: ObstacleType;
|
|
1046
|
+
/**
|
|
1047
|
+
* @zh 是否启用
|
|
1048
|
+
* @en Whether enabled
|
|
1049
|
+
*/
|
|
1050
|
+
enabled: boolean;
|
|
1051
|
+
/**
|
|
1052
|
+
* @zh 位置(圆形和矩形的中心)
|
|
1053
|
+
* @en Position (center for circle and rect)
|
|
1054
|
+
*/
|
|
1055
|
+
position: IPoint;
|
|
1056
|
+
/**
|
|
1057
|
+
* @zh 半径(圆形)或半宽/半高(矩形)
|
|
1058
|
+
* @en Radius (circle) or half-width/half-height (rect)
|
|
1059
|
+
*/
|
|
1060
|
+
radius?: number;
|
|
1061
|
+
halfWidth?: number;
|
|
1062
|
+
halfHeight?: number;
|
|
1063
|
+
/**
|
|
1064
|
+
* @zh 顶点(多边形)
|
|
1065
|
+
* @en Vertices (polygon)
|
|
1066
|
+
*/
|
|
1067
|
+
vertices?: readonly IPoint[];
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* @zh 导航多边形
|
|
1071
|
+
* @en Navigation polygon
|
|
1072
|
+
*/
|
|
1073
|
+
interface INavPolygon {
|
|
1074
|
+
/** @zh 多边形ID @en Polygon ID */
|
|
1075
|
+
readonly id: number;
|
|
1076
|
+
/** @zh 顶点列表 @en Vertex list */
|
|
1077
|
+
readonly vertices: readonly IPoint[];
|
|
1078
|
+
/** @zh 中心点 @en Center point */
|
|
1079
|
+
readonly center: IPoint;
|
|
1080
|
+
/** @zh 邻居多边形ID @en Neighbor polygon IDs */
|
|
1081
|
+
readonly neighbors: readonly number[];
|
|
1082
|
+
/** @zh 到邻居的共享边 @en Shared edges to neighbors */
|
|
1083
|
+
readonly portals: ReadonlyMap<number, IPortal>;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* @zh 入口(两个多边形之间的共享边)
|
|
1087
|
+
* @en Portal (shared edge between two polygons)
|
|
1088
|
+
*/
|
|
1089
|
+
interface IPortal {
|
|
1090
|
+
/** @zh 边的左端点 @en Left endpoint of edge */
|
|
1091
|
+
readonly left: IPoint;
|
|
1092
|
+
/** @zh 边的右端点 @en Right endpoint of edge */
|
|
1093
|
+
readonly right: IPoint;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* @zh 导航网格
|
|
1097
|
+
* @en Navigation Mesh
|
|
1098
|
+
*
|
|
1099
|
+
* @zh 使用凸多边形网格进行高效寻路,适合复杂地形
|
|
1100
|
+
* @en Uses convex polygon mesh for efficient pathfinding, suitable for complex terrain
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* const navmesh = new NavMesh();
|
|
1105
|
+
*
|
|
1106
|
+
* // Add polygons
|
|
1107
|
+
* navmesh.addPolygon([
|
|
1108
|
+
* { x: 0, y: 0 }, { x: 10, y: 0 },
|
|
1109
|
+
* { x: 10, y: 10 }, { x: 0, y: 10 }
|
|
1110
|
+
* ]);
|
|
1111
|
+
*
|
|
1112
|
+
* // Build connections
|
|
1113
|
+
* navmesh.build();
|
|
1114
|
+
*
|
|
1115
|
+
* // Find path
|
|
1116
|
+
* const result = navmesh.findPath(1, 1, 8, 8);
|
|
1117
|
+
* ```
|
|
1118
|
+
*/
|
|
1119
|
+
declare class NavMesh implements IPathfindingMap {
|
|
1120
|
+
private polygons;
|
|
1121
|
+
private nodes;
|
|
1122
|
+
private nextId;
|
|
1123
|
+
private obstacles;
|
|
1124
|
+
private nextObstacleId;
|
|
1125
|
+
private disabledPolygons;
|
|
1126
|
+
/**
|
|
1127
|
+
* @zh 添加导航多边形
|
|
1128
|
+
* @en Add navigation polygon
|
|
1129
|
+
*
|
|
1130
|
+
* @returns @zh 多边形ID @en Polygon ID
|
|
1131
|
+
*/
|
|
1132
|
+
addPolygon(vertices: IPoint[], neighbors?: number[]): number;
|
|
1133
|
+
/**
|
|
1134
|
+
* @zh 设置两个多边形之间的连接
|
|
1135
|
+
* @en Set connection between two polygons
|
|
1136
|
+
*/
|
|
1137
|
+
setConnection(polyA: number, polyB: number, portal: IPortal): void;
|
|
1138
|
+
/**
|
|
1139
|
+
* @zh 自动检测并建立相邻多边形的连接
|
|
1140
|
+
* @en Auto-detect and build connections between adjacent polygons
|
|
1141
|
+
*/
|
|
1142
|
+
build(): void;
|
|
1143
|
+
/**
|
|
1144
|
+
* @zh 查找两个多边形的共享边
|
|
1145
|
+
* @en Find shared edge between two polygons
|
|
1146
|
+
*/
|
|
1147
|
+
private findSharedEdge;
|
|
1148
|
+
/**
|
|
1149
|
+
* @zh 计算多边形中心
|
|
1150
|
+
* @en Calculate polygon center
|
|
1151
|
+
*/
|
|
1152
|
+
private calculateCenter;
|
|
1153
|
+
/**
|
|
1154
|
+
* @zh 查找包含点的多边形
|
|
1155
|
+
* @en Find polygon containing point
|
|
1156
|
+
*/
|
|
1157
|
+
findPolygonAt(x: number, y: number): INavPolygon | null;
|
|
1158
|
+
/**
|
|
1159
|
+
* @zh 检查点是否在多边形内
|
|
1160
|
+
* @en Check if point is inside polygon
|
|
1161
|
+
*/
|
|
1162
|
+
private isPointInPolygon;
|
|
1163
|
+
getNodeAt(x: number, y: number): IPathNode | null;
|
|
1164
|
+
getNeighbors(node: IPathNode): IPathNode[];
|
|
1165
|
+
heuristic(a: IPoint, b: IPoint): number;
|
|
1166
|
+
getMovementCost(from: IPathNode, to: IPathNode): number;
|
|
1167
|
+
isWalkable(x: number, y: number): boolean;
|
|
1168
|
+
/**
|
|
1169
|
+
* @zh 在导航网格上寻路
|
|
1170
|
+
* @en Find path on navigation mesh
|
|
1171
|
+
*/
|
|
1172
|
+
findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
|
|
1173
|
+
/**
|
|
1174
|
+
* @zh 在多边形图上寻路
|
|
1175
|
+
* @en Find path on polygon graph
|
|
1176
|
+
*
|
|
1177
|
+
* @param start - @zh 起始多边形 @en Start polygon
|
|
1178
|
+
* @param end - @zh 目标多边形 @en End polygon
|
|
1179
|
+
* @param opts - @zh 寻路选项 @en Pathfinding options
|
|
1180
|
+
* @param checkObstacles - @zh 是否检查障碍物 @en Whether to check obstacles
|
|
1181
|
+
*/
|
|
1182
|
+
private findPolygonPath;
|
|
1183
|
+
/**
|
|
1184
|
+
* @zh 使用漏斗算法优化路径(支持代理半径)
|
|
1185
|
+
* @en Optimize path using funnel algorithm (supports agent radius)
|
|
1186
|
+
*
|
|
1187
|
+
* @param start - @zh 起点 @en Start point
|
|
1188
|
+
* @param end - @zh 终点 @en End point
|
|
1189
|
+
* @param polygons - @zh 多边形路径 @en Polygon path
|
|
1190
|
+
* @param agentRadius - @zh 代理半径 @en Agent radius
|
|
1191
|
+
*/
|
|
1192
|
+
private funnelPath;
|
|
1193
|
+
/**
|
|
1194
|
+
* @zh 收缩 portal(将两端点向内移动 agentRadius)
|
|
1195
|
+
* @en Shrink portal (move endpoints inward by agentRadius)
|
|
1196
|
+
*/
|
|
1197
|
+
private shrinkPortal;
|
|
1198
|
+
/**
|
|
1199
|
+
* @zh 偏移拐点以保持与角落的距离
|
|
1200
|
+
* @en Offset turning point to maintain distance from corner
|
|
1201
|
+
*
|
|
1202
|
+
* @param prevApex - @zh 上一个顶点 @en Previous apex
|
|
1203
|
+
* @param cornerOriginal - @zh 原始角落位置 @en Original corner position
|
|
1204
|
+
* @param cornerShrunk - @zh 收缩后的角落位置 @en Shrunk corner position
|
|
1205
|
+
* @param radius - @zh 代理半径 @en Agent radius
|
|
1206
|
+
* @param side - @zh 转向侧 ('left' 或 'right') @en Turn side ('left' or 'right')
|
|
1207
|
+
*/
|
|
1208
|
+
private offsetTurningPoint;
|
|
1209
|
+
/**
|
|
1210
|
+
* @zh 检查两点是否相等
|
|
1211
|
+
* @en Check if two points are equal
|
|
1212
|
+
*/
|
|
1213
|
+
private pointsEqual;
|
|
1214
|
+
/**
|
|
1215
|
+
* @zh 计算三角形面积的两倍(用于判断点的相对位置)
|
|
1216
|
+
* @en Calculate twice the triangle area (for point relative position)
|
|
1217
|
+
*/
|
|
1218
|
+
private triArea2;
|
|
1219
|
+
/**
|
|
1220
|
+
* @zh 计算路径总长度
|
|
1221
|
+
* @en Calculate total path length
|
|
1222
|
+
*/
|
|
1223
|
+
private calculatePathLength;
|
|
1224
|
+
/**
|
|
1225
|
+
* @zh 添加圆形障碍物
|
|
1226
|
+
* @en Add circular obstacle
|
|
1227
|
+
*
|
|
1228
|
+
* @param x - @zh 中心 X @en Center X
|
|
1229
|
+
* @param y - @zh 中心 Y @en Center Y
|
|
1230
|
+
* @param radius - @zh 半径 @en Radius
|
|
1231
|
+
* @returns @zh 障碍物 ID @en Obstacle ID
|
|
1232
|
+
*/
|
|
1233
|
+
addCircleObstacle(x: number, y: number, radius: number): number;
|
|
1234
|
+
/**
|
|
1235
|
+
* @zh 添加矩形障碍物
|
|
1236
|
+
* @en Add rectangular obstacle
|
|
1237
|
+
*
|
|
1238
|
+
* @param x - @zh 中心 X @en Center X
|
|
1239
|
+
* @param y - @zh 中心 Y @en Center Y
|
|
1240
|
+
* @param halfWidth - @zh 半宽 @en Half width
|
|
1241
|
+
* @param halfHeight - @zh 半高 @en Half height
|
|
1242
|
+
* @returns @zh 障碍物 ID @en Obstacle ID
|
|
1243
|
+
*/
|
|
1244
|
+
addRectObstacle(x: number, y: number, halfWidth: number, halfHeight: number): number;
|
|
1245
|
+
/**
|
|
1246
|
+
* @zh 添加多边形障碍物
|
|
1247
|
+
* @en Add polygon obstacle
|
|
1248
|
+
*
|
|
1249
|
+
* @param vertices - @zh 顶点列表 @en Vertex list
|
|
1250
|
+
* @returns @zh 障碍物 ID @en Obstacle ID
|
|
1251
|
+
*/
|
|
1252
|
+
addPolygonObstacle(vertices: IPoint[]): number;
|
|
1253
|
+
/**
|
|
1254
|
+
* @zh 移除障碍物
|
|
1255
|
+
* @en Remove obstacle
|
|
1256
|
+
*/
|
|
1257
|
+
removeObstacle(obstacleId: number): boolean;
|
|
1258
|
+
/**
|
|
1259
|
+
* @zh 启用/禁用障碍物
|
|
1260
|
+
* @en Enable/disable obstacle
|
|
1261
|
+
*/
|
|
1262
|
+
setObstacleEnabled(obstacleId: number, enabled: boolean): void;
|
|
1263
|
+
/**
|
|
1264
|
+
* @zh 更新障碍物位置
|
|
1265
|
+
* @en Update obstacle position
|
|
1266
|
+
*/
|
|
1267
|
+
updateObstaclePosition(obstacleId: number, x: number, y: number): void;
|
|
1268
|
+
/**
|
|
1269
|
+
* @zh 获取所有障碍物
|
|
1270
|
+
* @en Get all obstacles
|
|
1271
|
+
*/
|
|
1272
|
+
getObstacles(): IDynamicObstacle[];
|
|
1273
|
+
/**
|
|
1274
|
+
* @zh 获取启用的障碍物
|
|
1275
|
+
* @en Get enabled obstacles
|
|
1276
|
+
*/
|
|
1277
|
+
getEnabledObstacles(): IDynamicObstacle[];
|
|
1278
|
+
/**
|
|
1279
|
+
* @zh 清除所有障碍物
|
|
1280
|
+
* @en Clear all obstacles
|
|
1281
|
+
*/
|
|
1282
|
+
clearObstacles(): void;
|
|
1283
|
+
/**
|
|
1284
|
+
* @zh 禁用多边形
|
|
1285
|
+
* @en Disable polygon
|
|
1286
|
+
*/
|
|
1287
|
+
disablePolygon(polygonId: number): void;
|
|
1288
|
+
/**
|
|
1289
|
+
* @zh 启用多边形
|
|
1290
|
+
* @en Enable polygon
|
|
1291
|
+
*/
|
|
1292
|
+
enablePolygon(polygonId: number): void;
|
|
1293
|
+
/**
|
|
1294
|
+
* @zh 检查多边形是否被禁用
|
|
1295
|
+
* @en Check if polygon is disabled
|
|
1296
|
+
*/
|
|
1297
|
+
isPolygonDisabled(polygonId: number): boolean;
|
|
1298
|
+
/**
|
|
1299
|
+
* @zh 禁用包含指定点的多边形
|
|
1300
|
+
* @en Disable polygon containing specified point
|
|
1301
|
+
*/
|
|
1302
|
+
disablePolygonAt(x: number, y: number): number | null;
|
|
1303
|
+
/**
|
|
1304
|
+
* @zh 清除所有禁用的多边形
|
|
1305
|
+
* @en Clear all disabled polygons
|
|
1306
|
+
*/
|
|
1307
|
+
clearDisabledPolygons(): void;
|
|
1308
|
+
/**
|
|
1309
|
+
* @zh 获取被禁用的多边形 ID 列表
|
|
1310
|
+
* @en Get list of disabled polygon IDs
|
|
1311
|
+
*/
|
|
1312
|
+
getDisabledPolygons(): number[];
|
|
1313
|
+
/**
|
|
1314
|
+
* @zh 检查点是否在任何障碍物内
|
|
1315
|
+
* @en Check if point is inside any obstacle
|
|
1316
|
+
*/
|
|
1317
|
+
isPointInObstacle(x: number, y: number): boolean;
|
|
1318
|
+
/**
|
|
1319
|
+
* @zh 检查点是否在单个障碍物内
|
|
1320
|
+
* @en Check if point is inside single obstacle
|
|
1321
|
+
*/
|
|
1322
|
+
private isPointInSingleObstacle;
|
|
1323
|
+
/**
|
|
1324
|
+
* @zh 检查线段是否与任何障碍物相交
|
|
1325
|
+
* @en Check if line segment intersects any obstacle
|
|
1326
|
+
*/
|
|
1327
|
+
doesLineIntersectObstacle(x1: number, y1: number, x2: number, y2: number): boolean;
|
|
1328
|
+
/**
|
|
1329
|
+
* @zh 检查线段是否与单个障碍物相交
|
|
1330
|
+
* @en Check if line segment intersects single obstacle
|
|
1331
|
+
*/
|
|
1332
|
+
private doesLineIntersectSingleObstacle;
|
|
1333
|
+
/**
|
|
1334
|
+
* @zh 线段与圆相交检测
|
|
1335
|
+
* @en Line segment circle intersection
|
|
1336
|
+
*/
|
|
1337
|
+
private lineIntersectsCircle;
|
|
1338
|
+
/**
|
|
1339
|
+
* @zh 线段与矩形相交检测
|
|
1340
|
+
* @en Line segment rectangle intersection
|
|
1341
|
+
*/
|
|
1342
|
+
private lineIntersectsRect;
|
|
1343
|
+
/**
|
|
1344
|
+
* @zh 线段与多边形相交检测
|
|
1345
|
+
* @en Line segment polygon intersection
|
|
1346
|
+
*/
|
|
1347
|
+
private lineIntersectsPolygon;
|
|
1348
|
+
/**
|
|
1349
|
+
* @zh 两线段相交检测
|
|
1350
|
+
* @en Two line segments intersection
|
|
1351
|
+
*/
|
|
1352
|
+
private lineSegmentsIntersect;
|
|
1353
|
+
private direction;
|
|
1354
|
+
private onSegment;
|
|
1355
|
+
/**
|
|
1356
|
+
* @zh 检查多边形是否被障碍物阻挡
|
|
1357
|
+
* @en Check if polygon is blocked by obstacle
|
|
1358
|
+
*
|
|
1359
|
+
* @zh 检查以下条件:
|
|
1360
|
+
* @en Checks the following conditions:
|
|
1361
|
+
* - @zh 多边形是否被禁用 @en Whether polygon is disabled
|
|
1362
|
+
* - @zh 多边形中心是否在障碍物内 @en Whether polygon center is inside obstacle
|
|
1363
|
+
* - @zh 多边形任意顶点是否在障碍物内 @en Whether any polygon vertex is inside obstacle
|
|
1364
|
+
* - @zh 多边形任意边是否与障碍物相交 @en Whether any polygon edge intersects obstacle
|
|
1365
|
+
*/
|
|
1366
|
+
isPolygonBlocked(polygonId: number): boolean;
|
|
1367
|
+
/**
|
|
1368
|
+
* @zh 在导航网格上寻路(考虑障碍物)
|
|
1369
|
+
* @en Find path on navigation mesh (considering obstacles)
|
|
1370
|
+
*
|
|
1371
|
+
* @zh 此方法在规划阶段就考虑障碍物,自动绕过被阻挡的多边形
|
|
1372
|
+
* @en This method considers obstacles during planning, automatically avoiding blocked polygons
|
|
1373
|
+
*
|
|
1374
|
+
* @zh 与 findPath 不同,此方法会:
|
|
1375
|
+
* @en Unlike findPath, this method will:
|
|
1376
|
+
* - @zh 在 A* 搜索中跳过被障碍物阻挡的多边形
|
|
1377
|
+
* - @en Skip obstacle-blocked polygons during A* search
|
|
1378
|
+
* - @zh 验证起点和终点不在障碍物内
|
|
1379
|
+
* - @en Verify start and end points are not inside obstacles
|
|
1380
|
+
*/
|
|
1381
|
+
findPathWithObstacles(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
|
|
1382
|
+
/**
|
|
1383
|
+
* @zh 清空导航网格
|
|
1384
|
+
* @en Clear navigation mesh
|
|
1385
|
+
*/
|
|
1386
|
+
clear(): void;
|
|
1387
|
+
/**
|
|
1388
|
+
* @zh 获取所有多边形
|
|
1389
|
+
* @en Get all polygons
|
|
1390
|
+
*/
|
|
1391
|
+
getPolygons(): INavPolygon[];
|
|
1392
|
+
/**
|
|
1393
|
+
* @zh 获取多边形数量
|
|
1394
|
+
* @en Get polygon count
|
|
1395
|
+
*/
|
|
1396
|
+
get polygonCount(): number;
|
|
1397
|
+
/**
|
|
1398
|
+
* @zh 获取障碍物数量
|
|
1399
|
+
* @en Get obstacle count
|
|
1400
|
+
*/
|
|
1401
|
+
get obstacleCount(): number;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* @zh 创建导航网格
|
|
1405
|
+
* @en Create navigation mesh
|
|
1406
|
+
*/
|
|
1407
|
+
declare function createNavMesh(): NavMesh;
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* @zh 路径规划器接口
|
|
1411
|
+
* @en Path Planner Interface
|
|
1412
|
+
*
|
|
1413
|
+
* @zh 统一的全局寻路接口,支持 NavMesh、A*、JPS、HPA*、Flow Field 等算法
|
|
1414
|
+
* @en Unified global pathfinding interface, supports NavMesh, A*, JPS, HPA*, Flow Field, etc.
|
|
1415
|
+
*/
|
|
1416
|
+
/**
|
|
1417
|
+
* @zh 2D 向量
|
|
1418
|
+
* @en 2D Vector
|
|
1419
|
+
*/
|
|
1420
|
+
interface IVector2 {
|
|
1421
|
+
x: number;
|
|
1422
|
+
y: number;
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* @zh 路径规划结果
|
|
1426
|
+
* @en Path planning result
|
|
1427
|
+
*/
|
|
1428
|
+
interface IPathPlanResult {
|
|
1429
|
+
/**
|
|
1430
|
+
* @zh 是否找到路径
|
|
1431
|
+
* @en Whether path was found
|
|
1432
|
+
*/
|
|
1433
|
+
readonly found: boolean;
|
|
1434
|
+
/**
|
|
1435
|
+
* @zh 路径点列表(世界坐标)
|
|
1436
|
+
* @en List of path points (world coordinates)
|
|
1437
|
+
*/
|
|
1438
|
+
readonly path: readonly IVector2[];
|
|
1439
|
+
/**
|
|
1440
|
+
* @zh 路径总代价
|
|
1441
|
+
* @en Total path cost
|
|
1442
|
+
*/
|
|
1443
|
+
readonly cost: number;
|
|
1444
|
+
/**
|
|
1445
|
+
* @zh 搜索的节点数(用于性能监控)
|
|
1446
|
+
* @en Number of nodes searched (for performance monitoring)
|
|
1447
|
+
*/
|
|
1448
|
+
readonly nodesSearched: number;
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* @zh 空路径结果
|
|
1452
|
+
* @en Empty path result
|
|
1453
|
+
*/
|
|
1454
|
+
declare const EMPTY_PLAN_RESULT: IPathPlanResult;
|
|
1455
|
+
/**
|
|
1456
|
+
* @zh 路径规划选项
|
|
1457
|
+
* @en Path planning options
|
|
1458
|
+
*/
|
|
1459
|
+
interface IPathPlanOptions {
|
|
1460
|
+
/**
|
|
1461
|
+
* @zh 代理半径,用于生成考虑碰撞的路径
|
|
1462
|
+
* @en Agent radius, used to generate collision-aware paths
|
|
1463
|
+
*
|
|
1464
|
+
* @zh 如果指定,路径规划器会确保生成的路径与障碍物保持足够距离
|
|
1465
|
+
* @en If specified, the path planner will ensure the generated path maintains sufficient distance from obstacles
|
|
1466
|
+
*/
|
|
1467
|
+
agentRadius?: number;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* @zh 路径规划器接口
|
|
1471
|
+
* @en Path planner interface
|
|
1472
|
+
*
|
|
1473
|
+
* @zh 统一的全局寻路接口,支持 NavMesh、A*、JPS、HPA*、Flow Field 等算法
|
|
1474
|
+
* @en Unified global pathfinding interface, supports NavMesh, A*, JPS, HPA*, Flow Field, etc.
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1477
|
+
* ```typescript
|
|
1478
|
+
* // 使用 NavMesh 规划器
|
|
1479
|
+
* const planner = createNavMeshPathPlanner(navMesh);
|
|
1480
|
+
* const result = planner.findPath({ x: 0, y: 0 }, { x: 100, y: 100 });
|
|
1481
|
+
*
|
|
1482
|
+
* // 使用带半径的路径规划
|
|
1483
|
+
* const result = planner.findPath({ x: 0, y: 0 }, { x: 100, y: 100 }, { agentRadius: 0.5 });
|
|
1484
|
+
*
|
|
1485
|
+
* // 使用 A* 规划器
|
|
1486
|
+
* const planner = createAStarPlanner(gridMap);
|
|
1487
|
+
* const result = planner.findPath({ x: 0, y: 0 }, { x: 50, y: 50 });
|
|
1488
|
+
* ```
|
|
1489
|
+
*/
|
|
1490
|
+
interface IPathPlanner {
|
|
1491
|
+
/**
|
|
1492
|
+
* @zh 规划器类型标识
|
|
1493
|
+
* @en Planner type identifier
|
|
1494
|
+
*/
|
|
1495
|
+
readonly type: string;
|
|
1496
|
+
/**
|
|
1497
|
+
* @zh 查找从起点到终点的路径
|
|
1498
|
+
* @en Find path from start to end
|
|
1499
|
+
*
|
|
1500
|
+
* @param start - @zh 起点世界坐标 @en Start world position
|
|
1501
|
+
* @param end - @zh 终点世界坐标 @en End world position
|
|
1502
|
+
* @param options - @zh 路径规划选项 @en Path planning options
|
|
1503
|
+
* @returns @zh 路径规划结果 @en Path planning result
|
|
1504
|
+
*/
|
|
1505
|
+
findPath(start: IVector2, end: IVector2, options?: IPathPlanOptions): IPathPlanResult;
|
|
1506
|
+
/**
|
|
1507
|
+
* @zh 检查位置是否可通行
|
|
1508
|
+
* @en Check if position is walkable
|
|
1509
|
+
*
|
|
1510
|
+
* @param position - @zh 要检查的位置 @en Position to check
|
|
1511
|
+
* @returns @zh 是否可通行 @en Whether walkable
|
|
1512
|
+
*/
|
|
1513
|
+
isWalkable(position: IVector2): boolean;
|
|
1514
|
+
/**
|
|
1515
|
+
* @zh 获取最近的可通行位置
|
|
1516
|
+
* @en Get nearest walkable position
|
|
1517
|
+
*
|
|
1518
|
+
* @param position - @zh 参考位置 @en Reference position
|
|
1519
|
+
* @returns @zh 最近的可通行位置,如果找不到则返回 null @en Nearest walkable position, or null if not found
|
|
1520
|
+
*/
|
|
1521
|
+
getNearestWalkable(position: IVector2): IVector2 | null;
|
|
1522
|
+
/**
|
|
1523
|
+
* @zh 清理内部状态(用于重用)
|
|
1524
|
+
* @en Clear internal state (for reuse)
|
|
1525
|
+
*/
|
|
1526
|
+
clear(): void;
|
|
1527
|
+
/**
|
|
1528
|
+
* @zh 释放资源
|
|
1529
|
+
* @en Dispose resources
|
|
1530
|
+
*/
|
|
1531
|
+
dispose(): void;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* @zh 寻路状态
|
|
1535
|
+
* @en Pathfinding state
|
|
1536
|
+
*/
|
|
1537
|
+
declare enum PathPlanState {
|
|
1538
|
+
/**
|
|
1539
|
+
* @zh 空闲
|
|
1540
|
+
* @en Idle
|
|
1541
|
+
*/
|
|
1542
|
+
Idle = "idle",
|
|
1543
|
+
/**
|
|
1544
|
+
* @zh 进行中
|
|
1545
|
+
* @en In progress
|
|
1546
|
+
*/
|
|
1547
|
+
InProgress = "in_progress",
|
|
1548
|
+
/**
|
|
1549
|
+
* @zh 已完成
|
|
1550
|
+
* @en Completed
|
|
1551
|
+
*/
|
|
1552
|
+
Completed = "completed",
|
|
1553
|
+
/**
|
|
1554
|
+
* @zh 失败
|
|
1555
|
+
* @en Failed
|
|
1556
|
+
*/
|
|
1557
|
+
Failed = "failed",
|
|
1558
|
+
/**
|
|
1559
|
+
* @zh 已取消
|
|
1560
|
+
* @en Cancelled
|
|
1561
|
+
*/
|
|
1562
|
+
Cancelled = "cancelled"
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* @zh 增量寻路请求
|
|
1566
|
+
* @en Incremental pathfinding request
|
|
1567
|
+
*/
|
|
1568
|
+
interface IIncrementalPathRequest {
|
|
1569
|
+
/**
|
|
1570
|
+
* @zh 请求 ID
|
|
1571
|
+
* @en Request ID
|
|
1572
|
+
*/
|
|
1573
|
+
readonly id: number;
|
|
1574
|
+
/**
|
|
1575
|
+
* @zh 当前状态
|
|
1576
|
+
* @en Current state
|
|
1577
|
+
*/
|
|
1578
|
+
readonly state: PathPlanState;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* @zh 寻路进度信息
|
|
1582
|
+
* @en Pathfinding progress info
|
|
1583
|
+
*/
|
|
1584
|
+
interface IPathProgress {
|
|
1585
|
+
/**
|
|
1586
|
+
* @zh 当前状态
|
|
1587
|
+
* @en Current state
|
|
1588
|
+
*/
|
|
1589
|
+
readonly state: PathPlanState;
|
|
1590
|
+
/**
|
|
1591
|
+
* @zh 估计进度 (0-1)
|
|
1592
|
+
* @en Estimated progress (0-1)
|
|
1593
|
+
*/
|
|
1594
|
+
readonly estimatedProgress: number;
|
|
1595
|
+
/**
|
|
1596
|
+
* @zh 本次步进搜索的节点数
|
|
1597
|
+
* @en Nodes searched in this step
|
|
1598
|
+
*/
|
|
1599
|
+
readonly nodesSearched: number;
|
|
1600
|
+
/**
|
|
1601
|
+
* @zh 累计搜索的节点数
|
|
1602
|
+
* @en Total nodes searched
|
|
1603
|
+
*/
|
|
1604
|
+
readonly totalNodesSearched: number;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* @zh 增量路径规划器接口
|
|
1608
|
+
* @en Incremental path planner interface
|
|
1609
|
+
*
|
|
1610
|
+
* @zh 支持时间切片的路径规划器,可以将寻路计算分散到多帧执行
|
|
1611
|
+
* @en Path planner with time slicing support, can spread pathfinding computation across multiple frames
|
|
1612
|
+
*
|
|
1613
|
+
* @example
|
|
1614
|
+
* ```typescript
|
|
1615
|
+
* const planner = createIncrementalAStarPlanner(gridMap);
|
|
1616
|
+
*
|
|
1617
|
+
* // 请求路径
|
|
1618
|
+
* const request = planner.requestPath({ x: 0, y: 0 }, { x: 100, y: 100 });
|
|
1619
|
+
*
|
|
1620
|
+
* // 每帧执行一定数量的迭代
|
|
1621
|
+
* while (true) {
|
|
1622
|
+
* const progress = planner.step(request.id, 100); // 每帧 100 次迭代
|
|
1623
|
+
* if (progress.state === PathPlanState.Completed) {
|
|
1624
|
+
* const result = planner.getResult(request.id);
|
|
1625
|
+
* break;
|
|
1626
|
+
* }
|
|
1627
|
+
* if (progress.state === PathPlanState.Failed) {
|
|
1628
|
+
* break;
|
|
1629
|
+
* }
|
|
1630
|
+
* await nextFrame();
|
|
1631
|
+
* }
|
|
1632
|
+
*
|
|
1633
|
+
* planner.cleanup(request.id);
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
interface IIncrementalPathPlanner extends IPathPlanner {
|
|
1637
|
+
/**
|
|
1638
|
+
* @zh 是否支持增量计算
|
|
1639
|
+
* @en Whether supports incremental computation
|
|
1640
|
+
*/
|
|
1641
|
+
readonly supportsIncremental: true;
|
|
1642
|
+
/**
|
|
1643
|
+
* @zh 请求路径(异步开始)
|
|
1644
|
+
* @en Request path (async start)
|
|
1645
|
+
*
|
|
1646
|
+
* @param start - @zh 起点 @en Start position
|
|
1647
|
+
* @param end - @zh 终点 @en End position
|
|
1648
|
+
* @param options - @zh 选项 @en Options
|
|
1649
|
+
* @returns @zh 请求对象 @en Request object
|
|
1650
|
+
*/
|
|
1651
|
+
requestPath(start: IVector2, end: IVector2, options?: IPathPlanOptions): IIncrementalPathRequest;
|
|
1652
|
+
/**
|
|
1653
|
+
* @zh 执行指定次数的迭代
|
|
1654
|
+
* @en Execute specified number of iterations
|
|
1655
|
+
*
|
|
1656
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
1657
|
+
* @param iterations - @zh 迭代次数 @en Number of iterations
|
|
1658
|
+
* @returns @zh 进度信息 @en Progress info
|
|
1659
|
+
*/
|
|
1660
|
+
step(requestId: number, iterations: number): IPathProgress;
|
|
1661
|
+
/**
|
|
1662
|
+
* @zh 获取结果
|
|
1663
|
+
* @en Get result
|
|
1664
|
+
*
|
|
1665
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
1666
|
+
* @returns @zh 结果,如果未完成或不存在返回 null @en Result, null if not completed or not found
|
|
1667
|
+
*/
|
|
1668
|
+
getResult(requestId: number): IPathPlanResult | null;
|
|
1669
|
+
/**
|
|
1670
|
+
* @zh 取消请求
|
|
1671
|
+
* @en Cancel request
|
|
1672
|
+
*
|
|
1673
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
1674
|
+
*/
|
|
1675
|
+
cancel(requestId: number): void;
|
|
1676
|
+
/**
|
|
1677
|
+
* @zh 清理请求(释放资源)
|
|
1678
|
+
* @en Cleanup request (release resources)
|
|
1679
|
+
*
|
|
1680
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
1681
|
+
*/
|
|
1682
|
+
cleanup(requestId: number): void;
|
|
1683
|
+
/**
|
|
1684
|
+
* @zh 获取活跃请求数量
|
|
1685
|
+
* @en Get active request count
|
|
1686
|
+
*/
|
|
1687
|
+
getActiveRequestCount(): number;
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* @zh 类型守卫:检查是否为增量路径规划器
|
|
1691
|
+
* @en Type guard: check if is incremental path planner
|
|
1692
|
+
*/
|
|
1693
|
+
declare function isIncrementalPlanner(planner: IPathPlanner): planner is IIncrementalPathPlanner;
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* @zh 局部避让接口
|
|
1697
|
+
* @en Local Avoidance Interface
|
|
1698
|
+
*
|
|
1699
|
+
* @zh 统一的局部避让接口,支持 ORCA、RVO、Steering Behaviors 等算法
|
|
1700
|
+
* @en Unified local avoidance interface, supports ORCA, RVO, Steering Behaviors, etc.
|
|
1701
|
+
*/
|
|
1702
|
+
|
|
1703
|
+
/**
|
|
1704
|
+
* @zh 避让代理数据(算法无关)
|
|
1705
|
+
* @en Avoidance agent data (algorithm-agnostic)
|
|
1706
|
+
*/
|
|
1707
|
+
interface IAvoidanceAgentData {
|
|
1708
|
+
/**
|
|
1709
|
+
* @zh 代理唯一标识
|
|
1710
|
+
* @en Unique agent identifier
|
|
1711
|
+
*/
|
|
1712
|
+
readonly id: number;
|
|
1713
|
+
/**
|
|
1714
|
+
* @zh 当前位置
|
|
1715
|
+
* @en Current position
|
|
1716
|
+
*/
|
|
1717
|
+
readonly position: IVector2;
|
|
1718
|
+
/**
|
|
1719
|
+
* @zh 当前速度
|
|
1720
|
+
* @en Current velocity
|
|
1721
|
+
*/
|
|
1722
|
+
readonly velocity: IVector2;
|
|
1723
|
+
/**
|
|
1724
|
+
* @zh 首选速度(通常指向路径下一点)
|
|
1725
|
+
* @en Preferred velocity (usually towards next path point)
|
|
1726
|
+
*/
|
|
1727
|
+
readonly preferredVelocity: IVector2;
|
|
1728
|
+
/**
|
|
1729
|
+
* @zh 代理半径
|
|
1730
|
+
* @en Agent radius
|
|
1731
|
+
*/
|
|
1732
|
+
readonly radius: number;
|
|
1733
|
+
/**
|
|
1734
|
+
* @zh 最大速度
|
|
1735
|
+
* @en Maximum speed
|
|
1736
|
+
*/
|
|
1737
|
+
readonly maxSpeed: number;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* @zh 静态障碍物数据
|
|
1741
|
+
* @en Static obstacle data
|
|
1742
|
+
*/
|
|
1743
|
+
interface IObstacleData {
|
|
1744
|
+
/**
|
|
1745
|
+
* @zh 障碍物顶点(逆时针顺序)
|
|
1746
|
+
* @en Obstacle vertices (counter-clockwise order)
|
|
1747
|
+
*/
|
|
1748
|
+
readonly vertices: readonly IVector2[];
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* @zh 局部避让计算结果
|
|
1752
|
+
* @en Local avoidance computation result
|
|
1753
|
+
*/
|
|
1754
|
+
interface IAvoidanceResult {
|
|
1755
|
+
/**
|
|
1756
|
+
* @zh 计算得到的新速度
|
|
1757
|
+
* @en Computed new velocity
|
|
1758
|
+
*/
|
|
1759
|
+
readonly velocity: IVector2;
|
|
1760
|
+
/**
|
|
1761
|
+
* @zh 是否找到可行解
|
|
1762
|
+
* @en Whether a feasible solution was found
|
|
1763
|
+
*/
|
|
1764
|
+
readonly feasible: boolean;
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* @zh 局部避让接口
|
|
1768
|
+
* @en Local avoidance interface
|
|
1769
|
+
*
|
|
1770
|
+
* @zh 统一的局部避让接口,支持 ORCA、RVO、Steering Behaviors 等算法
|
|
1771
|
+
* @en Unified local avoidance interface, supports ORCA, RVO, Steering Behaviors, etc.
|
|
1772
|
+
*
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```typescript
|
|
1775
|
+
* // 使用 ORCA 避让
|
|
1776
|
+
* const avoidance = createORCAAvoidance();
|
|
1777
|
+
* const result = avoidance.computeAvoidanceVelocity(
|
|
1778
|
+
* agent, neighbors, obstacles, deltaTime
|
|
1779
|
+
* );
|
|
1780
|
+
*
|
|
1781
|
+
* // 批量计算
|
|
1782
|
+
* const results = avoidance.computeBatchAvoidance(agents, obstacles, deltaTime);
|
|
1783
|
+
* ```
|
|
1784
|
+
*/
|
|
1785
|
+
interface ILocalAvoidance {
|
|
1786
|
+
/**
|
|
1787
|
+
* @zh 避让算法类型标识
|
|
1788
|
+
* @en Avoidance algorithm type identifier
|
|
1789
|
+
*/
|
|
1790
|
+
readonly type: string;
|
|
1791
|
+
/**
|
|
1792
|
+
* @zh 计算代理的避让速度
|
|
1793
|
+
* @en Compute avoidance velocity for agent
|
|
1794
|
+
*
|
|
1795
|
+
* @param agent - @zh 当前代理数据 @en Current agent data
|
|
1796
|
+
* @param neighbors - @zh 邻近代理列表 @en List of neighboring agents
|
|
1797
|
+
* @param obstacles - @zh 静态障碍物列表 @en List of static obstacles
|
|
1798
|
+
* @param deltaTime - @zh 时间步长 @en Time step
|
|
1799
|
+
* @returns @zh 避让计算结果 @en Avoidance computation result
|
|
1800
|
+
*/
|
|
1801
|
+
computeAvoidanceVelocity(agent: IAvoidanceAgentData, neighbors: readonly IAvoidanceAgentData[], obstacles: readonly IObstacleData[], deltaTime: number): IAvoidanceResult;
|
|
1802
|
+
/**
|
|
1803
|
+
* @zh 批量计算多个代理的避让速度(性能优化)
|
|
1804
|
+
* @en Batch compute avoidance velocities for multiple agents (performance optimization)
|
|
1805
|
+
*
|
|
1806
|
+
* @param agents - @zh 代理列表 @en List of agents
|
|
1807
|
+
* @param obstacles - @zh 静态障碍物列表 @en List of static obstacles
|
|
1808
|
+
* @param deltaTime - @zh 时间步长 @en Time step
|
|
1809
|
+
* @returns @zh 每个代理的避让结果(按 ID 索引)@en Avoidance results for each agent (indexed by ID)
|
|
1810
|
+
*/
|
|
1811
|
+
computeBatchAvoidance(agents: readonly IAvoidanceAgentData[], obstacles: readonly IObstacleData[], deltaTime: number): Map<number, IAvoidanceResult>;
|
|
1812
|
+
/**
|
|
1813
|
+
* @zh 释放资源
|
|
1814
|
+
* @en Dispose resources
|
|
1815
|
+
*/
|
|
1816
|
+
dispose(): void;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
/**
|
|
1820
|
+
* @zh 碰撞解决器接口
|
|
1821
|
+
* @en Collision Resolver Interface
|
|
1822
|
+
*
|
|
1823
|
+
* @zh 提供位置级别的硬碰撞检测和解决
|
|
1824
|
+
* @en Provides position-level hard collision detection and resolution
|
|
1825
|
+
*/
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* @zh 碰撞检测结果
|
|
1829
|
+
* @en Collision detection result
|
|
1830
|
+
*/
|
|
1831
|
+
interface ICollisionResult {
|
|
1832
|
+
/**
|
|
1833
|
+
* @zh 是否发生碰撞
|
|
1834
|
+
* @en Whether collision occurred
|
|
1835
|
+
*/
|
|
1836
|
+
readonly collided: boolean;
|
|
1837
|
+
/**
|
|
1838
|
+
* @zh 穿透深度
|
|
1839
|
+
* @en Penetration depth
|
|
1840
|
+
*/
|
|
1841
|
+
readonly penetration: number;
|
|
1842
|
+
/**
|
|
1843
|
+
* @zh 碰撞法线(从障碍物指向代理)
|
|
1844
|
+
* @en Collision normal (pointing from obstacle to agent)
|
|
1845
|
+
*/
|
|
1846
|
+
readonly normal: IVector2;
|
|
1847
|
+
/**
|
|
1848
|
+
* @zh 障碍物上的最近点
|
|
1849
|
+
* @en Closest point on obstacle
|
|
1850
|
+
*/
|
|
1851
|
+
readonly closestPoint: IVector2;
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* @zh 空碰撞结果
|
|
1855
|
+
* @en Empty collision result
|
|
1856
|
+
*/
|
|
1857
|
+
declare const EMPTY_COLLISION_RESULT: ICollisionResult;
|
|
1858
|
+
/**
|
|
1859
|
+
* @zh 碰撞解决器接口
|
|
1860
|
+
* @en Collision resolver interface
|
|
1861
|
+
*
|
|
1862
|
+
* @zh 提供位置级别的硬碰撞检测和解决,作为避让算法失效时的安全保护层
|
|
1863
|
+
* @en Provides position-level hard collision detection and resolution, as safety layer when avoidance fails
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* const resolver = createDefaultCollisionResolver();
|
|
1868
|
+
*
|
|
1869
|
+
* // 检测碰撞
|
|
1870
|
+
* const collision = resolver.detectCollision(position, radius, obstacles);
|
|
1871
|
+
* if (collision.collided) {
|
|
1872
|
+
* // 解决碰撞
|
|
1873
|
+
* const newPos = resolver.resolveCollision(position, radius, obstacles);
|
|
1874
|
+
* }
|
|
1875
|
+
*
|
|
1876
|
+
* // 验证速度
|
|
1877
|
+
* const safeVelocity = resolver.validateVelocity(
|
|
1878
|
+
* position, velocity, radius, obstacles, deltaTime
|
|
1879
|
+
* );
|
|
1880
|
+
* ```
|
|
1881
|
+
*/
|
|
1882
|
+
interface ICollisionResolver {
|
|
1883
|
+
/**
|
|
1884
|
+
* @zh 解决器类型标识
|
|
1885
|
+
* @en Resolver type identifier
|
|
1886
|
+
*/
|
|
1887
|
+
readonly type: string;
|
|
1888
|
+
/**
|
|
1889
|
+
* @zh 检测圆与障碍物的碰撞
|
|
1890
|
+
* @en Detect collision between circle and obstacles
|
|
1891
|
+
*
|
|
1892
|
+
* @param position - @zh 圆心位置 @en Circle center position
|
|
1893
|
+
* @param radius - @zh 圆半径 @en Circle radius
|
|
1894
|
+
* @param obstacles - @zh 障碍物列表 @en List of obstacles
|
|
1895
|
+
* @returns @zh 最严重的碰撞结果 @en Most severe collision result
|
|
1896
|
+
*/
|
|
1897
|
+
detectCollision(position: IVector2, radius: number, obstacles: readonly IObstacleData[]): ICollisionResult;
|
|
1898
|
+
/**
|
|
1899
|
+
* @zh 解决碰撞,返回修正后的位置
|
|
1900
|
+
* @en Resolve collision, return corrected position
|
|
1901
|
+
*
|
|
1902
|
+
* @param position - @zh 当前位置 @en Current position
|
|
1903
|
+
* @param radius - @zh 半径 @en Radius
|
|
1904
|
+
* @param obstacles - @zh 障碍物列表 @en List of obstacles
|
|
1905
|
+
* @returns @zh 修正后的位置 @en Corrected position
|
|
1906
|
+
*/
|
|
1907
|
+
resolveCollision(position: IVector2, radius: number, obstacles: readonly IObstacleData[]): IVector2;
|
|
1908
|
+
/**
|
|
1909
|
+
* @zh 验证速度是否会导致碰撞,返回安全速度
|
|
1910
|
+
* @en Validate velocity won't cause collision, return safe velocity
|
|
1911
|
+
*
|
|
1912
|
+
* @param position - @zh 当前位置 @en Current position
|
|
1913
|
+
* @param velocity - @zh 目标速度 @en Target velocity
|
|
1914
|
+
* @param radius - @zh 半径 @en Radius
|
|
1915
|
+
* @param obstacles - @zh 障碍物列表 @en List of obstacles
|
|
1916
|
+
* @param deltaTime - @zh 时间步长 @en Time step
|
|
1917
|
+
* @returns @zh 安全速度 @en Safe velocity
|
|
1918
|
+
*/
|
|
1919
|
+
validateVelocity(position: IVector2, velocity: IVector2, radius: number, obstacles: readonly IObstacleData[], deltaTime: number): IVector2;
|
|
1920
|
+
/**
|
|
1921
|
+
* @zh 检测两个代理之间的碰撞
|
|
1922
|
+
* @en Detect collision between two agents
|
|
1923
|
+
*
|
|
1924
|
+
* @param posA - @zh 代理 A 位置 @en Agent A position
|
|
1925
|
+
* @param radiusA - @zh 代理 A 半径 @en Agent A radius
|
|
1926
|
+
* @param posB - @zh 代理 B 位置 @en Agent B position
|
|
1927
|
+
* @param radiusB - @zh 代理 B 半径 @en Agent B radius
|
|
1928
|
+
* @returns @zh 碰撞结果 @en Collision result
|
|
1929
|
+
*/
|
|
1930
|
+
detectAgentCollision(posA: IVector2, radiusA: number, posB: IVector2, radiusB: number): ICollisionResult;
|
|
1931
|
+
/**
|
|
1932
|
+
* @zh 释放资源
|
|
1933
|
+
* @en Dispose resources
|
|
1934
|
+
*/
|
|
1935
|
+
dispose(): void;
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
/**
|
|
1939
|
+
* @zh 流量控制器接口
|
|
1940
|
+
* @en Flow Controller Interface
|
|
1941
|
+
*
|
|
1942
|
+
* @zh 管理拥堵区域的代理通行,防止死锁
|
|
1943
|
+
* @en Manages agent passage through congested areas, prevents deadlocks
|
|
1944
|
+
*/
|
|
1945
|
+
|
|
1946
|
+
/**
|
|
1947
|
+
* @zh 通行许可类型
|
|
1948
|
+
* @en Pass permission type
|
|
1949
|
+
*/
|
|
1950
|
+
declare enum PassPermission {
|
|
1951
|
+
/**
|
|
1952
|
+
* @zh 可以通行
|
|
1953
|
+
* @en Can proceed
|
|
1954
|
+
*/
|
|
1955
|
+
Proceed = "proceed",
|
|
1956
|
+
/**
|
|
1957
|
+
* @zh 需要等待
|
|
1958
|
+
* @en Need to wait
|
|
1959
|
+
*/
|
|
1960
|
+
Wait = "wait",
|
|
1961
|
+
/**
|
|
1962
|
+
* @zh 需要让路(减速或侧移)
|
|
1963
|
+
* @en Need to yield (slow down or move aside)
|
|
1964
|
+
*/
|
|
1965
|
+
Yield = "yield"
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* @zh 拥堵区域
|
|
1969
|
+
* @en Congestion zone
|
|
1970
|
+
*/
|
|
1971
|
+
interface ICongestionZone {
|
|
1972
|
+
/**
|
|
1973
|
+
* @zh 区域 ID
|
|
1974
|
+
* @en Zone ID
|
|
1975
|
+
*/
|
|
1976
|
+
id: number;
|
|
1977
|
+
/**
|
|
1978
|
+
* @zh 区域中心
|
|
1979
|
+
* @en Zone center
|
|
1980
|
+
*/
|
|
1981
|
+
center: IVector2;
|
|
1982
|
+
/**
|
|
1983
|
+
* @zh 区域半径
|
|
1984
|
+
* @en Zone radius
|
|
1985
|
+
*/
|
|
1986
|
+
radius: number;
|
|
1987
|
+
/**
|
|
1988
|
+
* @zh 区域内的代理 ID 列表
|
|
1989
|
+
* @en List of agent IDs in the zone
|
|
1990
|
+
*/
|
|
1991
|
+
agentIds: number[];
|
|
1992
|
+
/**
|
|
1993
|
+
* @zh 区域容量(可同时通过的代理数)
|
|
1994
|
+
* @en Zone capacity (agents that can pass simultaneously)
|
|
1995
|
+
*/
|
|
1996
|
+
capacity: number;
|
|
1997
|
+
/**
|
|
1998
|
+
* @zh 拥堵程度 (0-1, 1 表示完全堵塞)
|
|
1999
|
+
* @en Congestion level (0-1, 1 means fully blocked)
|
|
2000
|
+
*/
|
|
2001
|
+
congestionLevel: number;
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* @zh 代理流量数据
|
|
2005
|
+
* @en Agent flow data
|
|
2006
|
+
*/
|
|
2007
|
+
interface IFlowAgentData {
|
|
2008
|
+
/**
|
|
2009
|
+
* @zh 代理 ID
|
|
2010
|
+
* @en Agent ID
|
|
2011
|
+
*/
|
|
2012
|
+
id: number;
|
|
2013
|
+
/**
|
|
2014
|
+
* @zh 当前位置
|
|
2015
|
+
* @en Current position
|
|
2016
|
+
*/
|
|
2017
|
+
position: IVector2;
|
|
2018
|
+
/**
|
|
2019
|
+
* @zh 目标位置
|
|
2020
|
+
* @en Destination position
|
|
2021
|
+
*/
|
|
2022
|
+
destination: IVector2 | null;
|
|
2023
|
+
/**
|
|
2024
|
+
* @zh 当前路径点
|
|
2025
|
+
* @en Current waypoint
|
|
2026
|
+
*/
|
|
2027
|
+
currentWaypoint: IVector2 | null;
|
|
2028
|
+
/**
|
|
2029
|
+
* @zh 代理半径
|
|
2030
|
+
* @en Agent radius
|
|
2031
|
+
*/
|
|
2032
|
+
radius: number;
|
|
2033
|
+
/**
|
|
2034
|
+
* @zh 优先级(数值越小优先级越高)
|
|
2035
|
+
* @en Priority (lower number = higher priority)
|
|
2036
|
+
*/
|
|
2037
|
+
priority: number;
|
|
2038
|
+
/**
|
|
2039
|
+
* @zh 进入拥堵区域的时间戳
|
|
2040
|
+
* @en Timestamp when entered congestion zone
|
|
2041
|
+
*/
|
|
2042
|
+
enterTime?: number;
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* @zh 流量控制结果
|
|
2046
|
+
* @en Flow control result
|
|
2047
|
+
*/
|
|
2048
|
+
interface IFlowControlResult {
|
|
2049
|
+
/**
|
|
2050
|
+
* @zh 通行许可
|
|
2051
|
+
* @en Pass permission
|
|
2052
|
+
*/
|
|
2053
|
+
permission: PassPermission;
|
|
2054
|
+
/**
|
|
2055
|
+
* @zh 如果需要等待,等待位置
|
|
2056
|
+
* @en Wait position if waiting is required
|
|
2057
|
+
*/
|
|
2058
|
+
waitPosition: IVector2 | null;
|
|
2059
|
+
/**
|
|
2060
|
+
* @zh 如果需要让路,建议的速度倍率 (0-1)
|
|
2061
|
+
* @en Suggested speed multiplier if yielding (0-1)
|
|
2062
|
+
*/
|
|
2063
|
+
speedMultiplier: number;
|
|
2064
|
+
/**
|
|
2065
|
+
* @zh 所在的拥堵区域(如果有)
|
|
2066
|
+
* @en Congestion zone the agent is in (if any)
|
|
2067
|
+
*/
|
|
2068
|
+
zone: ICongestionZone | null;
|
|
2069
|
+
/**
|
|
2070
|
+
* @zh 在队列中的位置(0 表示最前)
|
|
2071
|
+
* @en Position in queue (0 means front)
|
|
2072
|
+
*/
|
|
2073
|
+
queuePosition: number;
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* @zh 流量控制器配置
|
|
2077
|
+
* @en Flow controller configuration
|
|
2078
|
+
*/
|
|
2079
|
+
interface IFlowControllerConfig {
|
|
2080
|
+
/**
|
|
2081
|
+
* @zh 拥堵检测半径
|
|
2082
|
+
* @en Congestion detection radius
|
|
2083
|
+
*/
|
|
2084
|
+
detectionRadius?: number;
|
|
2085
|
+
/**
|
|
2086
|
+
* @zh 触发拥堵的最小代理数
|
|
2087
|
+
* @en Minimum agents to trigger congestion
|
|
2088
|
+
*/
|
|
2089
|
+
minAgentsForCongestion?: number;
|
|
2090
|
+
/**
|
|
2091
|
+
* @zh 默认区域容量
|
|
2092
|
+
* @en Default zone capacity
|
|
2093
|
+
*/
|
|
2094
|
+
defaultCapacity?: number;
|
|
2095
|
+
/**
|
|
2096
|
+
* @zh 等待点距离(到拥堵区域边缘的距离)
|
|
2097
|
+
* @en Wait point distance (from congestion zone edge)
|
|
2098
|
+
*/
|
|
2099
|
+
waitPointDistance?: number;
|
|
2100
|
+
/**
|
|
2101
|
+
* @zh 让路速度倍率
|
|
2102
|
+
* @en Yield speed multiplier
|
|
2103
|
+
*/
|
|
2104
|
+
yieldSpeedMultiplier?: number;
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* @zh 默认流量控制器配置
|
|
2108
|
+
* @en Default flow controller configuration
|
|
2109
|
+
*/
|
|
2110
|
+
declare const DEFAULT_FLOW_CONTROLLER_CONFIG: Required<IFlowControllerConfig>;
|
|
2111
|
+
/**
|
|
2112
|
+
* @zh 流量控制器接口
|
|
2113
|
+
* @en Flow controller interface
|
|
2114
|
+
*
|
|
2115
|
+
* @zh 管理代理在拥堵区域的通行顺序,防止死锁和回头现象
|
|
2116
|
+
* @en Manages agent passage order in congested areas, prevents deadlocks and turning back
|
|
2117
|
+
*
|
|
2118
|
+
* @example
|
|
2119
|
+
* ```typescript
|
|
2120
|
+
* const flowController = createFlowController();
|
|
2121
|
+
* navSystem.setFlowController(flowController);
|
|
2122
|
+
*
|
|
2123
|
+
* // 流量控制会自动:
|
|
2124
|
+
* // 1. 检测拥堵区域
|
|
2125
|
+
* // 2. 分配通行优先级
|
|
2126
|
+
* // 3. 管理等待队列
|
|
2127
|
+
* ```
|
|
2128
|
+
*/
|
|
2129
|
+
interface IFlowController {
|
|
2130
|
+
/**
|
|
2131
|
+
* @zh 控制器类型标识
|
|
2132
|
+
* @en Controller type identifier
|
|
2133
|
+
*/
|
|
2134
|
+
readonly type: string;
|
|
2135
|
+
/**
|
|
2136
|
+
* @zh 更新流量控制状态
|
|
2137
|
+
* @en Update flow control state
|
|
2138
|
+
*
|
|
2139
|
+
* @param agents - @zh 所有代理数据 @en All agent data
|
|
2140
|
+
* @param deltaTime - @zh 时间步长 @en Time step
|
|
2141
|
+
*/
|
|
2142
|
+
update(agents: readonly IFlowAgentData[], deltaTime: number): void;
|
|
2143
|
+
/**
|
|
2144
|
+
* @zh 获取代理的流量控制结果
|
|
2145
|
+
* @en Get flow control result for an agent
|
|
2146
|
+
*
|
|
2147
|
+
* @param agentId - @zh 代理 ID @en Agent ID
|
|
2148
|
+
* @returns @zh 流量控制结果 @en Flow control result
|
|
2149
|
+
*/
|
|
2150
|
+
getFlowControl(agentId: number): IFlowControlResult;
|
|
2151
|
+
/**
|
|
2152
|
+
* @zh 获取所有检测到的拥堵区域
|
|
2153
|
+
* @en Get all detected congestion zones
|
|
2154
|
+
*
|
|
2155
|
+
* @returns @zh 拥堵区域列表 @en List of congestion zones
|
|
2156
|
+
*/
|
|
2157
|
+
getCongestionZones(): readonly ICongestionZone[];
|
|
2158
|
+
/**
|
|
2159
|
+
* @zh 手动标记一个区域为拥堵区域
|
|
2160
|
+
* @en Manually mark an area as congestion zone
|
|
2161
|
+
*
|
|
2162
|
+
* @param center - @zh 区域中心 @en Zone center
|
|
2163
|
+
* @param radius - @zh 区域半径 @en Zone radius
|
|
2164
|
+
* @param capacity - @zh 区域容量 @en Zone capacity
|
|
2165
|
+
* @returns @zh 区域 ID @en Zone ID
|
|
2166
|
+
*/
|
|
2167
|
+
addStaticZone(center: IVector2, radius: number, capacity: number): number;
|
|
2168
|
+
/**
|
|
2169
|
+
* @zh 移除手动标记的拥堵区域
|
|
2170
|
+
* @en Remove manually marked congestion zone
|
|
2171
|
+
*
|
|
2172
|
+
* @param zoneId - @zh 区域 ID @en Zone ID
|
|
2173
|
+
*/
|
|
2174
|
+
removeStaticZone(zoneId: number): void;
|
|
2175
|
+
/**
|
|
2176
|
+
* @zh 清除所有状态
|
|
2177
|
+
* @en Clear all state
|
|
2178
|
+
*/
|
|
2179
|
+
clear(): void;
|
|
2180
|
+
/**
|
|
2181
|
+
* @zh 释放资源
|
|
2182
|
+
* @en Dispose resources
|
|
2183
|
+
*/
|
|
2184
|
+
dispose(): void;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
/**
|
|
2188
|
+
* @zh NavMesh 路径规划器适配器
|
|
2189
|
+
* @en NavMesh Path Planner Adapter
|
|
2190
|
+
*
|
|
2191
|
+
* @zh 将现有 NavMesh 适配到 IPathPlanner 接口
|
|
2192
|
+
* @en Adapts existing NavMesh to IPathPlanner interface
|
|
2193
|
+
*/
|
|
2194
|
+
|
|
2195
|
+
/**
|
|
2196
|
+
* @zh NavMesh 路径规划器适配器
|
|
2197
|
+
* @en NavMesh path planner adapter
|
|
2198
|
+
*
|
|
2199
|
+
* @example
|
|
2200
|
+
* ```typescript
|
|
2201
|
+
* const navMesh = createNavMesh();
|
|
2202
|
+
* navMesh.addPolygon([...]);
|
|
2203
|
+
* navMesh.build();
|
|
2204
|
+
*
|
|
2205
|
+
* const planner = createNavMeshPathPlanner(navMesh);
|
|
2206
|
+
* const result = planner.findPath({ x: 0, y: 0 }, { x: 100, y: 100 });
|
|
2207
|
+
* ```
|
|
2208
|
+
*/
|
|
2209
|
+
declare class NavMeshPathPlannerAdapter implements IPathPlanner {
|
|
2210
|
+
private readonly navMesh;
|
|
2211
|
+
readonly type = "navmesh";
|
|
2212
|
+
constructor(navMesh: NavMesh);
|
|
2213
|
+
findPath(start: IVector2, end: IVector2, options?: IPathPlanOptions): IPathPlanResult;
|
|
2214
|
+
isWalkable(position: IVector2): boolean;
|
|
2215
|
+
getNearestWalkable(position: IVector2): IVector2 | null;
|
|
2216
|
+
clear(): void;
|
|
2217
|
+
dispose(): void;
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* @zh 创建 NavMesh 路径规划器
|
|
2221
|
+
* @en Create NavMesh path planner
|
|
2222
|
+
*
|
|
2223
|
+
* @param navMesh - @zh NavMesh 实例 @en NavMesh instance
|
|
2224
|
+
* @returns @zh 路径规划器 @en Path planner
|
|
2225
|
+
*
|
|
2226
|
+
* @example
|
|
2227
|
+
* ```typescript
|
|
2228
|
+
* const planner = createNavMeshPathPlanner(navMesh);
|
|
2229
|
+
* navSystem.setPathPlanner(planner);
|
|
2230
|
+
* ```
|
|
2231
|
+
*/
|
|
2232
|
+
declare function createNavMeshPathPlanner(navMesh: NavMesh): IPathPlanner;
|
|
2233
|
+
|
|
2234
|
+
/**
|
|
2235
|
+
* @zh 网格寻路器适配器
|
|
2236
|
+
* @en Grid Pathfinder Adapter
|
|
2237
|
+
*
|
|
2238
|
+
* @zh 将现有 IPathfinder (A*, JPS, HPA*) 适配到 IPathPlanner 接口
|
|
2239
|
+
* @en Adapts existing IPathfinder (A*, JPS, HPA*) to IPathPlanner interface
|
|
2240
|
+
*/
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* @zh 网格寻路器适配器配置
|
|
2244
|
+
* @en Grid pathfinder adapter configuration
|
|
2245
|
+
*/
|
|
2246
|
+
interface IGridPathfinderAdapterConfig {
|
|
2247
|
+
/**
|
|
2248
|
+
* @zh 网格单元格大小(像素),用于坐标转换
|
|
2249
|
+
* @en Grid cell size (pixels), used for coordinate conversion
|
|
2250
|
+
*
|
|
2251
|
+
* @zh 如果设置了此值,输入的像素坐标会自动转换为网格坐标,输出的网格坐标会转换回像素坐标(单元格中心)
|
|
2252
|
+
* @en If set, input pixel coordinates are converted to grid coordinates, output grid coordinates are converted back to pixel coordinates (cell center)
|
|
2253
|
+
*
|
|
2254
|
+
* @default 1 (no conversion)
|
|
2255
|
+
*/
|
|
2256
|
+
cellSize?: number;
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* @zh 网格寻路器适配器
|
|
2260
|
+
* @en Grid pathfinder adapter
|
|
2261
|
+
*
|
|
2262
|
+
* @zh 将 A*、JPS、HPA* 等网格寻路器适配到统一的 IPathPlanner 接口
|
|
2263
|
+
* @en Adapts A*, JPS, HPA* grid pathfinders to unified IPathPlanner interface
|
|
2264
|
+
*/
|
|
2265
|
+
declare class GridPathfinderAdapter implements IPathPlanner {
|
|
2266
|
+
private readonly pathfinder;
|
|
2267
|
+
private readonly map;
|
|
2268
|
+
private readonly options?;
|
|
2269
|
+
readonly type: string;
|
|
2270
|
+
private readonly cellSize;
|
|
2271
|
+
constructor(pathfinder: IPathfinder, map: IPathfindingMap, options?: IPathfindingOptions | undefined, type?: string, config?: IGridPathfinderAdapterConfig);
|
|
2272
|
+
/**
|
|
2273
|
+
* @zh 像素坐标转网格坐标
|
|
2274
|
+
* @en Convert pixel coordinate to grid coordinate
|
|
2275
|
+
*/
|
|
2276
|
+
private toGridCoord;
|
|
2277
|
+
/**
|
|
2278
|
+
* @zh 网格坐标转像素坐标(单元格中心)
|
|
2279
|
+
* @en Convert grid coordinate to pixel coordinate (cell center)
|
|
2280
|
+
*/
|
|
2281
|
+
private toPixelCoord;
|
|
2282
|
+
findPath(start: IVector2, end: IVector2): IPathPlanResult;
|
|
2283
|
+
isWalkable(position: IVector2): boolean;
|
|
2284
|
+
getNearestWalkable(position: IVector2): IVector2 | null;
|
|
2285
|
+
clear(): void;
|
|
2286
|
+
dispose(): void;
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* @zh 创建 A* 路径规划器
|
|
2290
|
+
* @en Create A* path planner
|
|
2291
|
+
*
|
|
2292
|
+
* @param map - @zh 寻路地图 @en Pathfinding map
|
|
2293
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
2294
|
+
* @param config - @zh 适配器配置(包含 cellSize)@en Adapter config (includes cellSize)
|
|
2295
|
+
* @returns @zh 路径规划器 @en Path planner
|
|
2296
|
+
*
|
|
2297
|
+
* @example
|
|
2298
|
+
* ```typescript
|
|
2299
|
+
* const gridMap = createGridMap(100, 100);
|
|
2300
|
+
* // 如果使用像素坐标,需要指定 cellSize
|
|
2301
|
+
* const planner = createAStarPlanner(gridMap, undefined, { cellSize: 20 });
|
|
2302
|
+
* navSystem.setPathPlanner(planner);
|
|
2303
|
+
* ```
|
|
2304
|
+
*/
|
|
2305
|
+
declare function createAStarPlanner(map: IPathfindingMap, options?: IPathfindingOptions, config?: IGridPathfinderAdapterConfig): IPathPlanner;
|
|
2306
|
+
/**
|
|
2307
|
+
* @zh 创建 JPS 路径规划器
|
|
2308
|
+
* @en Create JPS path planner
|
|
2309
|
+
*
|
|
2310
|
+
* @zh JPS(Jump Point Search)适用于均匀代价的网格地图,比 A* 快 10-100 倍
|
|
2311
|
+
* @en JPS (Jump Point Search) is optimized for uniform-cost grids, 10-100x faster than A*
|
|
2312
|
+
*
|
|
2313
|
+
* @param map - @zh 寻路地图 @en Pathfinding map
|
|
2314
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
2315
|
+
* @param config - @zh 适配器配置(包含 cellSize)@en Adapter config (includes cellSize)
|
|
2316
|
+
* @returns @zh 路径规划器 @en Path planner
|
|
2317
|
+
*
|
|
2318
|
+
* @example
|
|
2319
|
+
* ```typescript
|
|
2320
|
+
* const gridMap = createGridMap(100, 100);
|
|
2321
|
+
* const planner = createJPSPlanner(gridMap, undefined, { cellSize: 20 });
|
|
2322
|
+
* navSystem.setPathPlanner(planner);
|
|
2323
|
+
* ```
|
|
2324
|
+
*/
|
|
2325
|
+
declare function createJPSPlanner(map: IPathfindingMap, options?: IPathfindingOptions, config?: IGridPathfinderAdapterConfig): IPathPlanner;
|
|
2326
|
+
/**
|
|
2327
|
+
* @zh 创建 HPA* 路径规划器
|
|
2328
|
+
* @en Create HPA* path planner
|
|
2329
|
+
*
|
|
2330
|
+
* @zh HPA*(Hierarchical Pathfinding A*)适用于超大地图(1000x1000+)
|
|
2331
|
+
* @en HPA* (Hierarchical Pathfinding A*) is optimized for very large maps (1000x1000+)
|
|
2332
|
+
*
|
|
2333
|
+
* @param map - @zh 寻路地图 @en Pathfinding map
|
|
2334
|
+
* @param hpaConfig - @zh HPA* 配置 @en HPA* configuration
|
|
2335
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
2336
|
+
* @param adapterConfig - @zh 适配器配置(包含 cellSize)@en Adapter config (includes cellSize)
|
|
2337
|
+
* @returns @zh 路径规划器 @en Path planner
|
|
2338
|
+
*
|
|
2339
|
+
* @example
|
|
2340
|
+
* ```typescript
|
|
2341
|
+
* const gridMap = createGridMap(2000, 2000);
|
|
2342
|
+
* const planner = createHPAPlanner(gridMap, { clusterSize: 16 }, undefined, { cellSize: 20 });
|
|
2343
|
+
* navSystem.setPathPlanner(planner);
|
|
2344
|
+
* ```
|
|
2345
|
+
*/
|
|
2346
|
+
declare function createHPAPlanner(map: IPathfindingMap, hpaConfig?: Partial<IHPAConfig>, options?: IPathfindingOptions, adapterConfig?: IGridPathfinderAdapterConfig): IPathPlanner;
|
|
2347
|
+
|
|
2348
|
+
/**
|
|
2349
|
+
* @zh 增量网格寻路器适配器
|
|
2350
|
+
* @en Incremental Grid Pathfinder Adapter
|
|
2351
|
+
*
|
|
2352
|
+
* @zh 将 IncrementalAStarPathfinder 适配到 IIncrementalPathPlanner 接口
|
|
2353
|
+
* @en Adapts IncrementalAStarPathfinder to IIncrementalPathPlanner interface
|
|
2354
|
+
*/
|
|
2355
|
+
|
|
2356
|
+
/**
|
|
2357
|
+
* @zh 增量网格寻路器适配器配置
|
|
2358
|
+
* @en Incremental grid pathfinder adapter configuration
|
|
2359
|
+
*/
|
|
2360
|
+
interface IIncrementalGridPathPlannerConfig extends IIncrementalPathfinderConfig {
|
|
2361
|
+
/**
|
|
2362
|
+
* @zh 网格单元格大小(像素),用于坐标转换
|
|
2363
|
+
* @en Grid cell size (pixels), used for coordinate conversion
|
|
2364
|
+
*
|
|
2365
|
+
* @default 1 (no conversion)
|
|
2366
|
+
*/
|
|
2367
|
+
cellSize?: number;
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* @zh 增量网格寻路器适配器
|
|
2371
|
+
* @en Incremental grid pathfinder adapter
|
|
2372
|
+
*
|
|
2373
|
+
* @zh 将 IncrementalAStarPathfinder 适配到 IIncrementalPathPlanner 接口,支持时间切片
|
|
2374
|
+
* @en Adapts IncrementalAStarPathfinder to IIncrementalPathPlanner interface, supports time slicing
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```typescript
|
|
2378
|
+
* const gridMap = createGridMap(100, 100);
|
|
2379
|
+
* const planner = createIncrementalAStarPlanner(gridMap, { cellSize: 20 });
|
|
2380
|
+
*
|
|
2381
|
+
* // 请求路径(像素坐标)
|
|
2382
|
+
* const request = planner.requestPath({ x: 100, y: 100 }, { x: 500, y: 300 });
|
|
2383
|
+
*
|
|
2384
|
+
* // 每帧执行一定数量的迭代
|
|
2385
|
+
* const progress = planner.step(request.id, 100);
|
|
2386
|
+
* if (progress.state === PathPlanState.Completed) {
|
|
2387
|
+
* const result = planner.getResult(request.id);
|
|
2388
|
+
* // result.path 是像素坐标
|
|
2389
|
+
* }
|
|
2390
|
+
* ```
|
|
2391
|
+
*/
|
|
2392
|
+
declare class IncrementalGridPathPlannerAdapter implements IIncrementalPathPlanner {
|
|
2393
|
+
readonly type: string;
|
|
2394
|
+
readonly supportsIncremental: true;
|
|
2395
|
+
private readonly pathfinder;
|
|
2396
|
+
private readonly map;
|
|
2397
|
+
private readonly options?;
|
|
2398
|
+
private readonly cellSize;
|
|
2399
|
+
/**
|
|
2400
|
+
* @zh 活跃请求 ID 集合(用于跟踪)
|
|
2401
|
+
* @en Active request IDs set (for tracking)
|
|
2402
|
+
*/
|
|
2403
|
+
private readonly activeRequests;
|
|
2404
|
+
/**
|
|
2405
|
+
* @zh 每个请求的累计搜索节点数
|
|
2406
|
+
* @en Accumulated searched nodes per request
|
|
2407
|
+
*/
|
|
2408
|
+
private readonly requestTotalNodes;
|
|
2409
|
+
constructor(map: IPathfindingMap, options?: IPathfindingOptions, config?: IIncrementalGridPathPlannerConfig);
|
|
2410
|
+
/**
|
|
2411
|
+
* @zh 像素坐标转网格坐标
|
|
2412
|
+
* @en Convert pixel coordinate to grid coordinate
|
|
2413
|
+
*/
|
|
2414
|
+
private toGridCoord;
|
|
2415
|
+
/**
|
|
2416
|
+
* @zh 网格坐标转像素坐标(单元格中心)
|
|
2417
|
+
* @en Convert grid coordinate to pixel coordinate (cell center)
|
|
2418
|
+
*/
|
|
2419
|
+
private toPixelCoord;
|
|
2420
|
+
findPath(start: IVector2, end: IVector2, options?: IPathPlanOptions): IPathPlanResult;
|
|
2421
|
+
isWalkable(position: IVector2): boolean;
|
|
2422
|
+
getNearestWalkable(position: IVector2): IVector2 | null;
|
|
2423
|
+
clear(): void;
|
|
2424
|
+
dispose(): void;
|
|
2425
|
+
requestPath(start: IVector2, end: IVector2, options?: IPathPlanOptions): IIncrementalPathRequest;
|
|
2426
|
+
step(requestId: number, iterations: number): IPathProgress;
|
|
2427
|
+
getResult(requestId: number): IPathPlanResult | null;
|
|
2428
|
+
cancel(requestId: number): void;
|
|
2429
|
+
cleanup(requestId: number): void;
|
|
2430
|
+
getActiveRequestCount(): number;
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* @zh 创建增量 A* 路径规划器
|
|
2434
|
+
* @en Create incremental A* path planner
|
|
2435
|
+
*
|
|
2436
|
+
* @zh 支持时间切片的 A* 路径规划器,可以将寻路计算分散到多帧执行
|
|
2437
|
+
* @en A* path planner with time slicing support, can spread pathfinding computation across multiple frames
|
|
2438
|
+
*
|
|
2439
|
+
* @param map - @zh 寻路地图 @en Pathfinding map
|
|
2440
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
2441
|
+
* @param config - @zh 适配器配置(包含 cellSize 和缓存配置)@en Adapter config (includes cellSize and cache config)
|
|
2442
|
+
* @returns @zh 增量路径规划器 @en Incremental path planner
|
|
2443
|
+
*
|
|
2444
|
+
* @example
|
|
2445
|
+
* ```typescript
|
|
2446
|
+
* const gridMap = createGridMap(100, 100);
|
|
2447
|
+
* const planner = createIncrementalAStarPlanner(gridMap, undefined, {
|
|
2448
|
+
* cellSize: 20,
|
|
2449
|
+
* enableCache: true
|
|
2450
|
+
* });
|
|
2451
|
+
*
|
|
2452
|
+
* // 与 NavigationSystem 集成
|
|
2453
|
+
* navSystem.setPathPlanner(planner);
|
|
2454
|
+
*
|
|
2455
|
+
* // 启用时间切片(NavigationSystem 会自动检测)
|
|
2456
|
+
* const navSystem = new NavigationSystem({
|
|
2457
|
+
* enableTimeSlicing: true,
|
|
2458
|
+
* iterationsBudget: 1000,
|
|
2459
|
+
* maxAgentsPerFrame: 10
|
|
2460
|
+
* });
|
|
2461
|
+
* ```
|
|
2462
|
+
*/
|
|
2463
|
+
declare function createIncrementalAStarPlanner(map: IPathfindingMap, options?: IPathfindingOptions, config?: IIncrementalGridPathPlannerConfig): IIncrementalPathPlanner;
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* @zh ORCA 局部避让适配器
|
|
2467
|
+
* @en ORCA Local Avoidance Adapter
|
|
2468
|
+
*
|
|
2469
|
+
* @zh 将现有 ORCA 求解器适配到 ILocalAvoidance 接口
|
|
2470
|
+
* @en Adapts existing ORCA solver to ILocalAvoidance interface
|
|
2471
|
+
*/
|
|
2472
|
+
|
|
2473
|
+
/**
|
|
2474
|
+
* @zh ORCA 默认参数
|
|
2475
|
+
* @en ORCA default parameters
|
|
2476
|
+
*/
|
|
2477
|
+
interface IORCAParams {
|
|
2478
|
+
/**
|
|
2479
|
+
* @zh 邻居检测距离
|
|
2480
|
+
* @en Neighbor detection distance
|
|
2481
|
+
*/
|
|
2482
|
+
neighborDist: number;
|
|
2483
|
+
/**
|
|
2484
|
+
* @zh 最大邻居数量
|
|
2485
|
+
* @en Maximum number of neighbors
|
|
2486
|
+
*/
|
|
2487
|
+
maxNeighbors: number;
|
|
2488
|
+
/**
|
|
2489
|
+
* @zh 代理避让时间视野
|
|
2490
|
+
* @en Time horizon for agent avoidance
|
|
2491
|
+
*/
|
|
2492
|
+
timeHorizon: number;
|
|
2493
|
+
/**
|
|
2494
|
+
* @zh 障碍物避让时间视野
|
|
2495
|
+
* @en Time horizon for obstacle avoidance
|
|
2496
|
+
*/
|
|
2497
|
+
timeHorizonObst: number;
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* @zh ORCA 默认参数值
|
|
2501
|
+
* @en ORCA default parameter values
|
|
2502
|
+
*/
|
|
2503
|
+
declare const DEFAULT_ORCA_PARAMS: IORCAParams;
|
|
2504
|
+
/**
|
|
2505
|
+
* @zh ORCA 局部避让适配器
|
|
2506
|
+
* @en ORCA local avoidance adapter
|
|
2507
|
+
*
|
|
2508
|
+
* @example
|
|
2509
|
+
* ```typescript
|
|
2510
|
+
* const avoidance = createORCAAvoidance();
|
|
2511
|
+
* navSystem.setLocalAvoidance(avoidance);
|
|
2512
|
+
*
|
|
2513
|
+
* // 自定义参数
|
|
2514
|
+
* const avoidance = createORCAAvoidance({
|
|
2515
|
+
* timeStep: 1/60
|
|
2516
|
+
* });
|
|
2517
|
+
* avoidance.setDefaultParams({ timeHorizon: 3.0 });
|
|
2518
|
+
* ```
|
|
2519
|
+
*/
|
|
2520
|
+
declare class ORCALocalAvoidanceAdapter implements ILocalAvoidance {
|
|
2521
|
+
readonly type = "orca";
|
|
2522
|
+
private solver;
|
|
2523
|
+
private kdTree;
|
|
2524
|
+
private defaultParams;
|
|
2525
|
+
constructor(config?: IORCASolverConfig);
|
|
2526
|
+
/**
|
|
2527
|
+
* @zh 设置默认 ORCA 参数
|
|
2528
|
+
* @en Set default ORCA parameters
|
|
2529
|
+
*
|
|
2530
|
+
* @param params - @zh 参数 @en Parameters
|
|
2531
|
+
*/
|
|
2532
|
+
setDefaultParams(params: Partial<IORCAParams>): void;
|
|
2533
|
+
/**
|
|
2534
|
+
* @zh 获取默认 ORCA 参数
|
|
2535
|
+
* @en Get default ORCA parameters
|
|
2536
|
+
*/
|
|
2537
|
+
getDefaultParams(): Readonly<IORCAParams>;
|
|
2538
|
+
computeAvoidanceVelocity(agent: IAvoidanceAgentData, neighbors: readonly IAvoidanceAgentData[], obstacles: readonly IObstacleData[], deltaTime: number): IAvoidanceResult;
|
|
2539
|
+
computeBatchAvoidance(agents: readonly IAvoidanceAgentData[], obstacles: readonly IObstacleData[], deltaTime: number): Map<number, IAvoidanceResult>;
|
|
2540
|
+
dispose(): void;
|
|
2541
|
+
private toORCAAgent;
|
|
2542
|
+
private toORCAObstacle;
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* @zh 创建 ORCA 局部避让
|
|
2546
|
+
* @en Create ORCA local avoidance
|
|
2547
|
+
*
|
|
2548
|
+
* @param config - @zh ORCA 求解器配置 @en ORCA solver configuration
|
|
2549
|
+
* @returns @zh 局部避让实例 @en Local avoidance instance
|
|
2550
|
+
*
|
|
2551
|
+
* @example
|
|
2552
|
+
* ```typescript
|
|
2553
|
+
* const avoidance = createORCAAvoidance();
|
|
2554
|
+
* navSystem.setLocalAvoidance(avoidance);
|
|
2555
|
+
* ```
|
|
2556
|
+
*/
|
|
2557
|
+
declare function createORCAAvoidance(config?: IORCASolverConfig): ORCALocalAvoidanceAdapter;
|
|
2558
|
+
|
|
2559
|
+
/**
|
|
2560
|
+
* @zh 碰撞解决器适配器
|
|
2561
|
+
* @en Collision Resolver Adapter
|
|
2562
|
+
*
|
|
2563
|
+
* @zh 将现有 CollisionResolver 适配到 ICollisionResolver 接口
|
|
2564
|
+
* @en Adapts existing CollisionResolver to ICollisionResolver interface
|
|
2565
|
+
*/
|
|
2566
|
+
|
|
2567
|
+
/**
|
|
2568
|
+
* @zh 碰撞解决器适配器
|
|
2569
|
+
* @en Collision resolver adapter
|
|
2570
|
+
*
|
|
2571
|
+
* @example
|
|
2572
|
+
* ```typescript
|
|
2573
|
+
* const resolver = createDefaultCollisionResolver();
|
|
2574
|
+
* navSystem.setCollisionResolver(resolver);
|
|
2575
|
+
* ```
|
|
2576
|
+
*/
|
|
2577
|
+
declare class CollisionResolverAdapter implements ICollisionResolver {
|
|
2578
|
+
readonly type = "default";
|
|
2579
|
+
private resolver;
|
|
2580
|
+
constructor(config?: ICollisionResolverConfig);
|
|
2581
|
+
detectCollision(position: IVector2, radius: number, obstacles: readonly IObstacleData[]): ICollisionResult;
|
|
2582
|
+
resolveCollision(position: IVector2, radius: number, obstacles: readonly IObstacleData[]): IVector2;
|
|
2583
|
+
validateVelocity(position: IVector2, velocity: IVector2, radius: number, obstacles: readonly IObstacleData[], deltaTime: number): IVector2;
|
|
2584
|
+
detectAgentCollision(posA: IVector2, radiusA: number, posB: IVector2, radiusB: number): ICollisionResult;
|
|
2585
|
+
dispose(): void;
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* @zh 创建默认碰撞解决器
|
|
2589
|
+
* @en Create default collision resolver
|
|
2590
|
+
*
|
|
2591
|
+
* @param config - @zh 配置 @en Configuration
|
|
2592
|
+
* @returns @zh 碰撞解决器 @en Collision resolver
|
|
2593
|
+
*
|
|
2594
|
+
* @example
|
|
2595
|
+
* ```typescript
|
|
2596
|
+
* const resolver = createDefaultCollisionResolver();
|
|
2597
|
+
* navSystem.setCollisionResolver(resolver);
|
|
2598
|
+
*
|
|
2599
|
+
* // 自定义配置
|
|
2600
|
+
* const resolver = createDefaultCollisionResolver({
|
|
2601
|
+
* responseFactor: 1.0,
|
|
2602
|
+
* safetyMargin: 0.01
|
|
2603
|
+
* });
|
|
2604
|
+
* ```
|
|
2605
|
+
*/
|
|
2606
|
+
declare function createDefaultCollisionResolver(config?: ICollisionResolverConfig): ICollisionResolver;
|
|
2607
|
+
|
|
2608
|
+
/**
|
|
2609
|
+
* @zh 流量控制器实现
|
|
2610
|
+
* @en Flow Controller Implementation
|
|
2611
|
+
*
|
|
2612
|
+
* @zh 管理拥堵区域的代理通行,使用 FIFO + 优先级策略防止死锁
|
|
2613
|
+
* @en Manages agent passage through congested areas using FIFO + priority to prevent deadlocks
|
|
2614
|
+
*/
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* @zh 流量控制器
|
|
2618
|
+
* @en Flow Controller
|
|
2619
|
+
*
|
|
2620
|
+
* @zh 检测拥堵区域并管理代理通行顺序
|
|
2621
|
+
* @en Detects congestion zones and manages agent passage order
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* ```typescript
|
|
2625
|
+
* const flowController = createFlowController({
|
|
2626
|
+
* detectionRadius: 3.0,
|
|
2627
|
+
* minAgentsForCongestion: 3,
|
|
2628
|
+
* defaultCapacity: 2
|
|
2629
|
+
* });
|
|
2630
|
+
*
|
|
2631
|
+
* // 每帧更新
|
|
2632
|
+
* flowController.update(agents, deltaTime);
|
|
2633
|
+
*
|
|
2634
|
+
* // 获取代理的流量控制
|
|
2635
|
+
* const result = flowController.getFlowControl(agentId);
|
|
2636
|
+
* if (result.permission === PassPermission.Wait) {
|
|
2637
|
+
* // 移动到等待位置
|
|
2638
|
+
* agent.setDestination(result.waitPosition);
|
|
2639
|
+
* }
|
|
2640
|
+
* ```
|
|
2641
|
+
*/
|
|
2642
|
+
declare class FlowController implements IFlowController {
|
|
2643
|
+
readonly type = "fifo-priority";
|
|
2644
|
+
private config;
|
|
2645
|
+
private zoneStates;
|
|
2646
|
+
private agentZoneMap;
|
|
2647
|
+
private agentResults;
|
|
2648
|
+
private nextZoneId;
|
|
2649
|
+
private currentTime;
|
|
2650
|
+
constructor(config?: IFlowControllerConfig);
|
|
2651
|
+
/**
|
|
2652
|
+
* @zh 更新流量控制状态
|
|
2653
|
+
* @en Update flow control state
|
|
2654
|
+
*/
|
|
2655
|
+
update(agents: readonly IFlowAgentData[], deltaTime: number): void;
|
|
2656
|
+
/**
|
|
2657
|
+
* @zh 获取代理的流量控制结果
|
|
2658
|
+
* @en Get flow control result for an agent
|
|
2659
|
+
*/
|
|
2660
|
+
getFlowControl(agentId: number): IFlowControlResult;
|
|
2661
|
+
/**
|
|
2662
|
+
* @zh 获取所有拥堵区域
|
|
2663
|
+
* @en Get all congestion zones
|
|
2664
|
+
*/
|
|
2665
|
+
getCongestionZones(): readonly ICongestionZone[];
|
|
2666
|
+
/**
|
|
2667
|
+
* @zh 添加静态拥堵区域
|
|
2668
|
+
* @en Add static congestion zone
|
|
2669
|
+
*/
|
|
2670
|
+
addStaticZone(center: IVector2, radius: number, capacity: number): number;
|
|
2671
|
+
/**
|
|
2672
|
+
* @zh 移除静态拥堵区域
|
|
2673
|
+
* @en Remove static congestion zone
|
|
2674
|
+
*/
|
|
2675
|
+
removeStaticZone(zoneId: number): void;
|
|
2676
|
+
/**
|
|
2677
|
+
* @zh 清除所有状态
|
|
2678
|
+
* @en Clear all state
|
|
2679
|
+
*/
|
|
2680
|
+
clear(): void;
|
|
2681
|
+
/**
|
|
2682
|
+
* @zh 释放资源
|
|
2683
|
+
* @en Dispose resources
|
|
2684
|
+
*/
|
|
2685
|
+
dispose(): void;
|
|
2686
|
+
/**
|
|
2687
|
+
* @zh 检测动态拥堵区域
|
|
2688
|
+
* @en Detect dynamic congestion zones
|
|
2689
|
+
*/
|
|
2690
|
+
private detectDynamicCongestion;
|
|
2691
|
+
/**
|
|
2692
|
+
* @zh 聚类代理
|
|
2693
|
+
* @en Cluster agents
|
|
2694
|
+
*/
|
|
2695
|
+
private clusterAgents;
|
|
2696
|
+
/**
|
|
2697
|
+
* @zh 计算聚类中心
|
|
2698
|
+
* @en Compute cluster center
|
|
2699
|
+
*/
|
|
2700
|
+
private computeClusterCenter;
|
|
2701
|
+
/**
|
|
2702
|
+
* @zh 计算聚类半径
|
|
2703
|
+
* @en Compute cluster radius
|
|
2704
|
+
*/
|
|
2705
|
+
private computeClusterRadius;
|
|
2706
|
+
/**
|
|
2707
|
+
* @zh 查找包含点的区域
|
|
2708
|
+
* @en Find zone containing point
|
|
2709
|
+
*/
|
|
2710
|
+
private findZoneContaining;
|
|
2711
|
+
/**
|
|
2712
|
+
* @zh 更新动态区域
|
|
2713
|
+
* @en Update dynamic zone
|
|
2714
|
+
*/
|
|
2715
|
+
private updateDynamicZone;
|
|
2716
|
+
/**
|
|
2717
|
+
* @zh 创建动态区域
|
|
2718
|
+
* @en Create dynamic zone
|
|
2719
|
+
*/
|
|
2720
|
+
private createDynamicZone;
|
|
2721
|
+
/**
|
|
2722
|
+
* @zh 更新区域队列
|
|
2723
|
+
* @en Update zone queues
|
|
2724
|
+
*/
|
|
2725
|
+
private updateZoneQueues;
|
|
2726
|
+
/**
|
|
2727
|
+
* @zh 计算流量控制结果
|
|
2728
|
+
* @en Compute flow control results
|
|
2729
|
+
*/
|
|
2730
|
+
private computeFlowControlResults;
|
|
2731
|
+
/**
|
|
2732
|
+
* @zh 计算等待位置
|
|
2733
|
+
* @en Compute wait position
|
|
2734
|
+
*/
|
|
2735
|
+
private computeWaitPosition;
|
|
2736
|
+
/**
|
|
2737
|
+
* @zh 清理空的动态区域
|
|
2738
|
+
* @en Cleanup empty dynamic zones
|
|
2739
|
+
*/
|
|
2740
|
+
private cleanupEmptyZones;
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* @zh 创建流量控制器
|
|
2744
|
+
* @en Create flow controller
|
|
2745
|
+
*
|
|
2746
|
+
* @param config - @zh 配置参数 @en Configuration
|
|
2747
|
+
* @returns @zh 流量控制器实例 @en Flow controller instance
|
|
2748
|
+
*/
|
|
2749
|
+
declare function createFlowController(config?: IFlowControllerConfig): FlowController;
|
|
2750
|
+
|
|
2751
|
+
export { type IAvoidanceResult as $, type IReplanningConfig as A, PathfindingState as B, DEFAULT_REPLANNING_CONFIG as C, DEFAULT_PATHFINDING_OPTIONS as D, EMPTY_PATH_RESULT as E, EMPTY_PROGRESS as F, IncrementalAStarPathfinder as G, type HeuristicFunction as H, type IPathfinder as I, createIncrementalAStarPathfinder as J, type INavPolygon as K, type LineOfSightCheck as L, type IPortal as M, type IDynamicObstacle as N, type ObstacleType as O, PathCache as P, NavMesh as Q, createNavMesh as R, type IVector2 as S, type IPathPlanResult as T, type IPathPlanOptions as U, type IPathPlanner as V, type IIncrementalPathPlanner as W, type IIncrementalPathRequest as X, type IPathProgress as Y, type IAvoidanceAgentData as Z, type IObstacleData as _, type IPathfindingMap as a, type ILocalAvoidance as a0, type ICollisionResult as a1, type ICollisionResolver as a2, type ICongestionZone as a3, type IFlowAgentData as a4, type IFlowControlResult as a5, type IFlowControllerConfig as a6, type IFlowController as a7, EMPTY_PLAN_RESULT as a8, EMPTY_COLLISION_RESULT as a9, PassPermission as aa, DEFAULT_FLOW_CONTROLLER_CONFIG as ab, PathPlanState as ac, isIncrementalPlanner as ad, NavMeshPathPlannerAdapter as ae, createNavMeshPathPlanner as af, GridPathfinderAdapter as ag, createAStarPlanner as ah, createJPSPlanner as ai, createHPAPlanner as aj, IncrementalGridPathPlannerAdapter as ak, createIncrementalAStarPlanner as al, ORCALocalAvoidanceAdapter as am, createORCAAvoidance as an, DEFAULT_ORCA_PARAMS as ao, CollisionResolverAdapter as ap, createDefaultCollisionResolver as aq, FlowController as ar, createFlowController as as, type IORCAParams as at, type IGridPathfinderAdapterConfig as au, type IIncrementalGridPathPlannerConfig as av, type IPathfindingOptions as b, type IPathResult as c, type IPathNode as d, type IPoint as e, type IPathValidator as f, type IPathValidationResult as g, type IPathSmoother as h, createPoint as i, euclideanDistance as j, chebyshevDistance as k, HPAPathfinder as l, manhattanDistance as m, createHPAPathfinder as n, octileDistance as o, DEFAULT_HPA_CONFIG as p, createPathCache as q, DEFAULT_PATH_CACHE_CONFIG as r, type IPathCacheConfig as s, type IHPAConfig as t, type IPathRequest as u, type IPathProgress$1 as v, type IIncrementalPathResult as w, type IIncrementalPathfinder as x, type IIncrementalPathfindingOptions as y, type IIncrementalPathfinderConfig as z };
|