@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
package/dist/ecs.d.ts
CHANGED
|
@@ -1,196 +1,237 @@
|
|
|
1
1
|
import { Component, EntitySystem, Entity } from '@esengine/ecs-framework';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { S as IVector2, V as IPathPlanner, a7 as IFlowController, a0 as ILocalAvoidance, a2 as ICollisionResolver, _ as IObstacleData } from './FlowController-Dc3nuLq5.js';
|
|
3
|
+
export { ap as CollisionResolverAdapter, ab as DEFAULT_FLOW_CONTROLLER_CONFIG, ao as DEFAULT_ORCA_PARAMS, ar as FlowController, ag as GridPathfinderAdapter, a3 as ICongestionZone, a4 as IFlowAgentData, a5 as IFlowControlResult, a6 as IFlowControllerConfig, au as IGridPathfinderAdapterConfig, av as IIncrementalGridPathPlannerConfig, at as IORCAParams, ak as IncrementalGridPathPlannerAdapter, ae as NavMeshPathPlannerAdapter, am as ORCALocalAvoidanceAdapter, aa as PassPermission, ah as createAStarPlanner, aq as createDefaultCollisionResolver, as as createFlowController, aj as createHPAPlanner, al as createIncrementalAStarPlanner, ai as createJPSPlanner, af as createNavMeshPathPlanner, an as createORCAAvoidance } from './FlowController-Dc3nuLq5.js';
|
|
4
|
+
import './CollisionResolver-CSgWsegP.js';
|
|
4
5
|
import '@esengine/ecs-framework-math';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* @zh
|
|
8
|
-
* @en
|
|
8
|
+
* @zh 统一导航代理组件
|
|
9
|
+
* @en Unified Navigation Agent Component
|
|
10
|
+
*
|
|
11
|
+
* @zh 算法无关的通用导航属性,配合 NavigationSystem 使用
|
|
12
|
+
* @en Algorithm-agnostic common navigation properties, works with NavigationSystem
|
|
9
13
|
*/
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
|
-
* @zh
|
|
13
|
-
* @en
|
|
16
|
+
* @zh 导航状态
|
|
17
|
+
* @en Navigation state
|
|
18
|
+
*/
|
|
19
|
+
declare enum NavigationState {
|
|
20
|
+
/**
|
|
21
|
+
* @zh 空闲
|
|
22
|
+
* @en Idle
|
|
23
|
+
*/
|
|
24
|
+
Idle = "idle",
|
|
25
|
+
/**
|
|
26
|
+
* @zh 正在导航
|
|
27
|
+
* @en Navigating
|
|
28
|
+
*/
|
|
29
|
+
Navigating = "navigating",
|
|
30
|
+
/**
|
|
31
|
+
* @zh 已到达
|
|
32
|
+
* @en Arrived
|
|
33
|
+
*/
|
|
34
|
+
Arrived = "arrived",
|
|
35
|
+
/**
|
|
36
|
+
* @zh 路径被阻挡
|
|
37
|
+
* @en Path blocked
|
|
38
|
+
*/
|
|
39
|
+
Blocked = "blocked",
|
|
40
|
+
/**
|
|
41
|
+
* @zh 无法到达
|
|
42
|
+
* @en Unreachable
|
|
43
|
+
*/
|
|
44
|
+
Unreachable = "unreachable"
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @zh 统一导航代理组件
|
|
48
|
+
* @en Unified navigation agent component
|
|
14
49
|
*
|
|
15
|
-
* @zh
|
|
16
|
-
* @en
|
|
50
|
+
* @zh 包含算法无关的通用导航属性,不包含算法特定参数
|
|
51
|
+
* @en Contains algorithm-agnostic common navigation properties, no algorithm-specific parameters
|
|
17
52
|
*
|
|
18
53
|
* @example
|
|
19
54
|
* ```typescript
|
|
20
55
|
* const entity = scene.createEntity('Agent');
|
|
21
|
-
* const agent = entity.addComponent(new PathfindingAgentComponent());
|
|
22
56
|
*
|
|
23
|
-
* //
|
|
24
|
-
*
|
|
25
|
-
*
|
|
57
|
+
* // 添加导航代理组件
|
|
58
|
+
* const nav = entity.addComponent(new NavigationAgentComponent());
|
|
59
|
+
* nav.radius = 0.5;
|
|
60
|
+
* nav.maxSpeed = 5.0;
|
|
26
61
|
*
|
|
27
|
-
* //
|
|
28
|
-
*
|
|
62
|
+
* // 设置目标
|
|
63
|
+
* nav.setDestination(100, 200);
|
|
29
64
|
*
|
|
30
|
-
* //
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* // When reached, call agent.advanceWaypoint()
|
|
35
|
-
* }
|
|
65
|
+
* // NavigationSystem 会自动处理:
|
|
66
|
+
* // 1. 使用 IPathPlanner 计算全局路径
|
|
67
|
+
* // 2. 使用 ILocalAvoidance 进行局部避让
|
|
68
|
+
* // 3. 使用 ICollisionResolver 防止穿透
|
|
36
69
|
* ```
|
|
37
70
|
*/
|
|
38
|
-
declare class
|
|
71
|
+
declare class NavigationAgentComponent extends Component {
|
|
39
72
|
/**
|
|
40
|
-
* @zh
|
|
41
|
-
* @en
|
|
73
|
+
* @zh 代理半径
|
|
74
|
+
* @en Agent radius
|
|
42
75
|
*/
|
|
43
|
-
|
|
76
|
+
radius: number;
|
|
44
77
|
/**
|
|
45
|
-
* @zh
|
|
46
|
-
* @en
|
|
78
|
+
* @zh 最大速度
|
|
79
|
+
* @en Maximum speed
|
|
47
80
|
*/
|
|
48
|
-
|
|
81
|
+
maxSpeed: number;
|
|
49
82
|
/**
|
|
50
|
-
* @zh
|
|
51
|
-
* @en
|
|
83
|
+
* @zh 加速度(用于平滑移动)
|
|
84
|
+
* @en Acceleration (for smooth movement)
|
|
52
85
|
*/
|
|
53
|
-
|
|
86
|
+
acceleration: number;
|
|
54
87
|
/**
|
|
55
|
-
* @zh
|
|
56
|
-
* @en
|
|
88
|
+
* @zh 路径点到达阈值
|
|
89
|
+
* @en Waypoint arrival threshold
|
|
57
90
|
*/
|
|
58
|
-
|
|
91
|
+
waypointThreshold: number;
|
|
59
92
|
/**
|
|
60
|
-
* @zh
|
|
61
|
-
* @en
|
|
93
|
+
* @zh 目标到达阈值
|
|
94
|
+
* @en Destination arrival threshold
|
|
62
95
|
*/
|
|
63
|
-
|
|
96
|
+
arrivalThreshold: number;
|
|
64
97
|
/**
|
|
65
|
-
* @zh
|
|
66
|
-
* @en
|
|
98
|
+
* @zh 路径重新计算间隔(秒)
|
|
99
|
+
* @en Path recalculation interval (seconds)
|
|
67
100
|
*/
|
|
68
|
-
|
|
101
|
+
repathInterval: number;
|
|
69
102
|
/**
|
|
70
|
-
* @zh
|
|
71
|
-
* @en
|
|
103
|
+
* @zh 是否启用导航
|
|
104
|
+
* @en Whether navigation is enabled
|
|
72
105
|
*/
|
|
73
|
-
|
|
106
|
+
enabled: boolean;
|
|
74
107
|
/**
|
|
75
|
-
* @zh
|
|
76
|
-
* @en Whether
|
|
108
|
+
* @zh 是否自动重新计算被阻挡的路径
|
|
109
|
+
* @en Whether to auto repath when blocked
|
|
77
110
|
*/
|
|
78
|
-
|
|
111
|
+
autoRepath: boolean;
|
|
79
112
|
/**
|
|
80
|
-
* @zh
|
|
81
|
-
* @en
|
|
113
|
+
* @zh 是否启用平滑转向
|
|
114
|
+
* @en Whether to enable smooth steering
|
|
82
115
|
*/
|
|
83
|
-
|
|
116
|
+
smoothSteering: boolean;
|
|
84
117
|
/**
|
|
85
|
-
* @zh
|
|
86
|
-
* @en
|
|
118
|
+
* @zh 当前位置
|
|
119
|
+
* @en Current position
|
|
87
120
|
*/
|
|
88
|
-
|
|
121
|
+
position: IVector2;
|
|
89
122
|
/**
|
|
90
|
-
* @zh
|
|
91
|
-
* @en Current
|
|
123
|
+
* @zh 当前速度
|
|
124
|
+
* @en Current velocity
|
|
92
125
|
*/
|
|
93
|
-
|
|
126
|
+
velocity: IVector2;
|
|
94
127
|
/**
|
|
95
|
-
* @zh
|
|
96
|
-
* @en
|
|
128
|
+
* @zh 目标位置
|
|
129
|
+
* @en Destination position
|
|
97
130
|
*/
|
|
98
|
-
|
|
131
|
+
destination: IVector2 | null;
|
|
99
132
|
/**
|
|
100
|
-
* @zh
|
|
101
|
-
* @en Current
|
|
133
|
+
* @zh 当前导航状态
|
|
134
|
+
* @en Current navigation state
|
|
102
135
|
*/
|
|
103
|
-
|
|
136
|
+
state: NavigationState;
|
|
104
137
|
/**
|
|
105
|
-
* @zh
|
|
106
|
-
* @en Current path
|
|
138
|
+
* @zh 当前路径
|
|
139
|
+
* @en Current path
|
|
107
140
|
*/
|
|
108
|
-
|
|
141
|
+
path: IVector2[];
|
|
109
142
|
/**
|
|
110
|
-
* @zh
|
|
111
|
-
* @en
|
|
143
|
+
* @zh 当前路径点索引
|
|
144
|
+
* @en Current waypoint index
|
|
112
145
|
*/
|
|
113
|
-
|
|
146
|
+
currentWaypointIndex: number;
|
|
147
|
+
/**
|
|
148
|
+
* @zh 上次重新计算路径的时间
|
|
149
|
+
* @en Last repath time
|
|
150
|
+
*/
|
|
151
|
+
lastRepathTime: number;
|
|
152
|
+
/**
|
|
153
|
+
* @zh 当前增量寻路请求 ID
|
|
154
|
+
* @en Current incremental pathfinding request ID
|
|
155
|
+
*/
|
|
156
|
+
currentRequestId: number;
|
|
114
157
|
/**
|
|
115
158
|
* @zh 寻路进度 (0-1)
|
|
116
159
|
* @en Pathfinding progress (0-1)
|
|
117
160
|
*/
|
|
118
|
-
|
|
161
|
+
pathProgress: number;
|
|
119
162
|
/**
|
|
120
|
-
* @zh
|
|
121
|
-
* @en
|
|
163
|
+
* @zh 优先级(数字越小优先级越高)
|
|
164
|
+
* @en Priority (lower number = higher priority)
|
|
122
165
|
*/
|
|
123
|
-
|
|
166
|
+
priority: number;
|
|
124
167
|
/**
|
|
125
|
-
* @zh
|
|
126
|
-
* @en
|
|
168
|
+
* @zh 是否正在等待路径计算完成
|
|
169
|
+
* @en Whether waiting for path computation to complete
|
|
127
170
|
*/
|
|
128
|
-
|
|
171
|
+
isComputingPath: boolean;
|
|
129
172
|
/**
|
|
130
|
-
* @zh
|
|
131
|
-
* @en
|
|
173
|
+
* @zh 设置位置
|
|
174
|
+
* @en Set position
|
|
175
|
+
*
|
|
176
|
+
* @param x - @zh X 坐标 @en X coordinate
|
|
177
|
+
* @param y - @zh Y 坐标 @en Y coordinate
|
|
132
178
|
*/
|
|
133
|
-
|
|
179
|
+
setPosition(x: number, y: number): void;
|
|
134
180
|
/**
|
|
135
|
-
* @zh
|
|
136
|
-
* @en
|
|
181
|
+
* @zh 设置目标位置
|
|
182
|
+
* @en Set destination
|
|
137
183
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
184
|
+
* @param x - @zh 目标 X 坐标 @en Destination X coordinate
|
|
185
|
+
* @param y - @zh 目标 Y 坐标 @en Destination Y coordinate
|
|
140
186
|
*/
|
|
141
|
-
|
|
187
|
+
setDestination(x: number, y: number): void;
|
|
142
188
|
/**
|
|
143
|
-
* @zh
|
|
144
|
-
* @en
|
|
189
|
+
* @zh 停止导航
|
|
190
|
+
* @en Stop navigation
|
|
145
191
|
*/
|
|
146
|
-
|
|
192
|
+
stop(): void;
|
|
147
193
|
/**
|
|
148
|
-
* @zh
|
|
149
|
-
* @en Get
|
|
194
|
+
* @zh 获取当前路径点
|
|
195
|
+
* @en Get current waypoint
|
|
150
196
|
*
|
|
151
|
-
* @returns @zh
|
|
152
|
-
*/
|
|
153
|
-
getNextWaypoint(): IPoint | null;
|
|
154
|
-
/**
|
|
155
|
-
* @zh 前进到下一个路径点
|
|
156
|
-
* @en Advance to next waypoint
|
|
197
|
+
* @returns @zh 当前路径点,如果没有则返回 null @en Current waypoint, or null if none
|
|
157
198
|
*/
|
|
158
|
-
|
|
199
|
+
getCurrentWaypoint(): IVector2 | null;
|
|
159
200
|
/**
|
|
160
|
-
* @zh
|
|
161
|
-
* @en
|
|
201
|
+
* @zh 获取到目标的距离
|
|
202
|
+
* @en Get distance to destination
|
|
162
203
|
*
|
|
163
|
-
* @returns @zh
|
|
204
|
+
* @returns @zh 到目标的距离,如果没有目标则返回 Infinity @en Distance to destination, or Infinity if no destination
|
|
164
205
|
*/
|
|
165
|
-
|
|
206
|
+
getDistanceToDestination(): number;
|
|
166
207
|
/**
|
|
167
|
-
* @zh
|
|
168
|
-
* @en
|
|
208
|
+
* @zh 获取当前速度大小
|
|
209
|
+
* @en Get current speed
|
|
169
210
|
*
|
|
170
|
-
* @returns @zh
|
|
211
|
+
* @returns @zh 当前速度大小 @en Current speed magnitude
|
|
171
212
|
*/
|
|
172
|
-
|
|
213
|
+
getCurrentSpeed(): number;
|
|
173
214
|
/**
|
|
174
|
-
* @zh
|
|
175
|
-
* @en Check if
|
|
215
|
+
* @zh 检查是否已到达目标
|
|
216
|
+
* @en Check if arrived at destination
|
|
176
217
|
*
|
|
177
|
-
* @returns @zh
|
|
218
|
+
* @returns @zh 是否已到达 @en Whether arrived
|
|
178
219
|
*/
|
|
179
|
-
|
|
220
|
+
hasArrived(): boolean;
|
|
180
221
|
/**
|
|
181
|
-
* @zh
|
|
182
|
-
* @en
|
|
222
|
+
* @zh 检查路径是否被阻挡
|
|
223
|
+
* @en Check if path is blocked
|
|
183
224
|
*
|
|
184
|
-
* @returns @zh
|
|
225
|
+
* @returns @zh 是否被阻挡 @en Whether blocked
|
|
185
226
|
*/
|
|
186
|
-
|
|
227
|
+
isBlocked(): boolean;
|
|
187
228
|
/**
|
|
188
|
-
* @zh
|
|
189
|
-
* @en
|
|
229
|
+
* @zh 检查目标是否无法到达
|
|
230
|
+
* @en Check if destination is unreachable
|
|
190
231
|
*
|
|
191
|
-
* @returns @zh
|
|
232
|
+
* @returns @zh 是否无法到达 @en Whether unreachable
|
|
192
233
|
*/
|
|
193
|
-
|
|
234
|
+
isUnreachable(): boolean;
|
|
194
235
|
/**
|
|
195
236
|
* @zh 重置组件状态
|
|
196
237
|
* @en Reset component state
|
|
@@ -204,681 +245,433 @@ declare class PathfindingAgentComponent extends Component {
|
|
|
204
245
|
}
|
|
205
246
|
|
|
206
247
|
/**
|
|
207
|
-
* @zh
|
|
208
|
-
* @en
|
|
248
|
+
* @zh 统一导航系统
|
|
249
|
+
* @en Unified Navigation System
|
|
250
|
+
*
|
|
251
|
+
* @zh 可插拔的导航系统,支持运行时切换寻路、避让、碰撞检测算法
|
|
252
|
+
* @en Pluggable navigation system, supports runtime swapping of pathfinding, avoidance, and collision detection algorithms
|
|
209
253
|
*/
|
|
210
254
|
|
|
211
255
|
/**
|
|
212
|
-
* @zh
|
|
213
|
-
* @en
|
|
214
|
-
*/
|
|
215
|
-
type PathfindingMapType = 'grid' | 'navmesh';
|
|
216
|
-
/**
|
|
217
|
-
* @zh 寻路地图组件
|
|
218
|
-
* @en Pathfinding Map Component
|
|
219
|
-
*
|
|
220
|
-
* @zh 挂载在场景实体上,持有地图实例和增量寻路器
|
|
221
|
-
* @en Attached to scene entity, holds map instance and incremental pathfinder
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```typescript
|
|
225
|
-
* const mapEntity = scene.createEntity('PathfindingMap');
|
|
226
|
-
* const mapComp = mapEntity.addComponent(new PathfindingMapComponent());
|
|
227
|
-
*
|
|
228
|
-
* // Configure map
|
|
229
|
-
* mapComp.width = 100;
|
|
230
|
-
* mapComp.height = 100;
|
|
231
|
-
* mapComp.iterationsBudget = 2000;
|
|
232
|
-
*
|
|
233
|
-
* // Map and pathfinder will be initialized by PathfindingSystem
|
|
234
|
-
* ```
|
|
256
|
+
* @zh 导航系统配置
|
|
257
|
+
* @en Navigation system configuration
|
|
235
258
|
*/
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @zh 地图类型
|
|
239
|
-
* @en Map type
|
|
240
|
-
*/
|
|
241
|
-
mapType: PathfindingMapType;
|
|
242
|
-
/**
|
|
243
|
-
* @zh 网格宽度(仅 grid 类型)
|
|
244
|
-
* @en Grid width (grid type only)
|
|
245
|
-
*/
|
|
246
|
-
width: number;
|
|
247
|
-
/**
|
|
248
|
-
* @zh 网格高度(仅 grid 类型)
|
|
249
|
-
* @en Grid height (grid type only)
|
|
250
|
-
*/
|
|
251
|
-
height: number;
|
|
252
|
-
/**
|
|
253
|
-
* @zh 是否允许对角移动
|
|
254
|
-
* @en Whether diagonal movement is allowed
|
|
255
|
-
*/
|
|
256
|
-
allowDiagonal: boolean;
|
|
257
|
-
/**
|
|
258
|
-
* @zh 是否避免穿角
|
|
259
|
-
* @en Whether to avoid corner cutting
|
|
260
|
-
*/
|
|
261
|
-
avoidCorners: boolean;
|
|
262
|
-
/**
|
|
263
|
-
* @zh 每帧处理的最大代理数
|
|
264
|
-
* @en Maximum agents processed per frame
|
|
265
|
-
*/
|
|
266
|
-
maxAgentsPerFrame: number;
|
|
259
|
+
interface INavigationSystemConfig {
|
|
267
260
|
/**
|
|
268
|
-
* @zh
|
|
269
|
-
* @en
|
|
270
|
-
*/
|
|
271
|
-
iterationsBudget: number;
|
|
272
|
-
/**
|
|
273
|
-
* @zh 是否启用路径平滑
|
|
274
|
-
* @en Whether path smoothing is enabled
|
|
275
|
-
*/
|
|
276
|
-
enableSmoothing: boolean;
|
|
277
|
-
/**
|
|
278
|
-
* @zh 路径平滑类型
|
|
279
|
-
* @en Path smoothing type
|
|
280
|
-
*/
|
|
281
|
-
smoothingType: 'los' | 'catmullrom' | 'combined';
|
|
282
|
-
/**
|
|
283
|
-
* @zh 是否启用路径缓存
|
|
284
|
-
* @en Whether path caching is enabled
|
|
285
|
-
*/
|
|
286
|
-
enableCache: boolean;
|
|
287
|
-
/**
|
|
288
|
-
* @zh 缓存最大条目数
|
|
289
|
-
* @en Maximum cache entries
|
|
290
|
-
*/
|
|
291
|
-
cacheMaxEntries: number;
|
|
292
|
-
/**
|
|
293
|
-
* @zh 缓存过期时间(毫秒),0 表示不过期
|
|
294
|
-
* @en Cache TTL in milliseconds, 0 means no expiration
|
|
295
|
-
*/
|
|
296
|
-
cacheTtlMs: number;
|
|
297
|
-
/**
|
|
298
|
-
* @zh 是否显示调试信息
|
|
299
|
-
* @en Whether to show debug info
|
|
300
|
-
*/
|
|
301
|
-
debugMode: boolean;
|
|
302
|
-
/**
|
|
303
|
-
* @zh 是否显示网格
|
|
304
|
-
* @en Whether to show grid
|
|
305
|
-
*/
|
|
306
|
-
showGrid: boolean;
|
|
307
|
-
/**
|
|
308
|
-
* @zh 是否显示路径
|
|
309
|
-
* @en Whether to show paths
|
|
310
|
-
*/
|
|
311
|
-
showPaths: boolean;
|
|
312
|
-
/**
|
|
313
|
-
* @zh 地图实例
|
|
314
|
-
* @en Map instance
|
|
315
|
-
*/
|
|
316
|
-
map: IPathfindingMap | null;
|
|
317
|
-
/**
|
|
318
|
-
* @zh 增量寻路器实例
|
|
319
|
-
* @en Incremental pathfinder instance
|
|
320
|
-
*/
|
|
321
|
-
pathfinder: IIncrementalPathfinder | null;
|
|
322
|
-
/**
|
|
323
|
-
* @zh 路径平滑器实例
|
|
324
|
-
* @en Path smoother instance
|
|
325
|
-
*/
|
|
326
|
-
smoother: IPathSmoother | null;
|
|
327
|
-
/**
|
|
328
|
-
* @zh 是否已初始化
|
|
329
|
-
* @en Whether initialized
|
|
261
|
+
* @zh 时间步长
|
|
262
|
+
* @en Time step
|
|
330
263
|
*/
|
|
331
|
-
|
|
264
|
+
timeStep?: number;
|
|
332
265
|
/**
|
|
333
|
-
* @zh
|
|
334
|
-
* @en
|
|
266
|
+
* @zh 是否启用路径规划阶段
|
|
267
|
+
* @en Whether to enable path planning stage
|
|
335
268
|
*/
|
|
336
|
-
|
|
269
|
+
enablePathPlanning?: boolean;
|
|
337
270
|
/**
|
|
338
|
-
* @zh
|
|
339
|
-
* @en
|
|
271
|
+
* @zh 是否启用流量控制阶段
|
|
272
|
+
* @en Whether to enable flow control stage
|
|
340
273
|
*/
|
|
341
|
-
|
|
274
|
+
enableFlowControl?: boolean;
|
|
342
275
|
/**
|
|
343
|
-
* @zh
|
|
344
|
-
* @en
|
|
276
|
+
* @zh 是否启用局部避让阶段
|
|
277
|
+
* @en Whether to enable local avoidance stage
|
|
345
278
|
*/
|
|
346
|
-
|
|
279
|
+
enableLocalAvoidance?: boolean;
|
|
347
280
|
/**
|
|
348
|
-
* @zh
|
|
349
|
-
* @en
|
|
281
|
+
* @zh 是否启用碰撞解决阶段
|
|
282
|
+
* @en Whether to enable collision resolution stage
|
|
350
283
|
*/
|
|
351
|
-
|
|
284
|
+
enableCollisionResolution?: boolean;
|
|
352
285
|
/**
|
|
353
|
-
* @zh
|
|
354
|
-
* @en
|
|
286
|
+
* @zh 是否启用代理间碰撞解决
|
|
287
|
+
* @en Whether to enable agent-agent collision resolution
|
|
355
288
|
*/
|
|
356
|
-
|
|
289
|
+
enableAgentCollisionResolution?: boolean;
|
|
357
290
|
/**
|
|
358
|
-
* @zh
|
|
359
|
-
* @en
|
|
291
|
+
* @zh 是否启用时间切片寻路(需要 IIncrementalPathPlanner)
|
|
292
|
+
* @en Whether to enable time-sliced pathfinding (requires IIncrementalPathPlanner)
|
|
360
293
|
*
|
|
361
|
-
* @
|
|
362
|
-
* @
|
|
363
|
-
* @param walkable - @zh 是否可通行 @en Is walkable
|
|
294
|
+
* @zh 启用后,寻路计算会分散到多帧执行,避免卡顿
|
|
295
|
+
* @en When enabled, pathfinding computation is spread across multiple frames to avoid stuttering
|
|
364
296
|
*/
|
|
365
|
-
|
|
297
|
+
enableTimeSlicing?: boolean;
|
|
366
298
|
/**
|
|
367
|
-
* @zh
|
|
368
|
-
* @en
|
|
299
|
+
* @zh 每帧总迭代预算
|
|
300
|
+
* @en Total iteration budget per frame
|
|
369
301
|
*
|
|
370
|
-
* @
|
|
371
|
-
* @
|
|
372
|
-
* @param width - @zh 宽度 @en Width
|
|
373
|
-
* @param height - @zh 高度 @en Height
|
|
374
|
-
* @param walkable - @zh 是否可通行 @en Is walkable
|
|
375
|
-
*/
|
|
376
|
-
setRectWalkable(x: number, y: number, rectWidth: number, rectHeight: number, walkable: boolean): void;
|
|
377
|
-
/**
|
|
378
|
-
* @zh 检查位置是否可通行
|
|
379
|
-
* @en Check if position is walkable
|
|
302
|
+
* @zh 所有代理共享此预算,根据优先级分配
|
|
303
|
+
* @en All agents share this budget, allocated by priority
|
|
380
304
|
*
|
|
381
|
-
* @
|
|
382
|
-
* @param y - @zh Y 坐标 @en Y coordinate
|
|
383
|
-
* @returns @zh 是否可通行 @en Is walkable
|
|
384
|
-
*/
|
|
385
|
-
isWalkable(x: number, y: number): boolean;
|
|
386
|
-
/**
|
|
387
|
-
* @zh 重置统计信息
|
|
388
|
-
* @en Reset statistics
|
|
305
|
+
* @default 1000
|
|
389
306
|
*/
|
|
390
|
-
|
|
307
|
+
iterationsBudget?: number;
|
|
391
308
|
/**
|
|
392
|
-
* @zh
|
|
393
|
-
* @en
|
|
309
|
+
* @zh 每帧最大处理代理数
|
|
310
|
+
* @en Maximum agents to process per frame
|
|
394
311
|
*
|
|
395
|
-
* @
|
|
396
|
-
|
|
397
|
-
getRemainingBudget(): number;
|
|
398
|
-
/**
|
|
399
|
-
* @zh 获取缓存统计信息
|
|
400
|
-
* @en Get cache statistics
|
|
312
|
+
* @zh 限制每帧处理的代理数量,避免过载
|
|
313
|
+
* @en Limits the number of agents processed per frame to avoid overload
|
|
401
314
|
*
|
|
402
|
-
* @
|
|
315
|
+
* @default 10
|
|
403
316
|
*/
|
|
404
|
-
|
|
405
|
-
enabled: boolean;
|
|
406
|
-
hits: number;
|
|
407
|
-
misses: number;
|
|
408
|
-
hitRate: number;
|
|
409
|
-
};
|
|
317
|
+
maxAgentsPerFrame?: number;
|
|
410
318
|
/**
|
|
411
|
-
* @zh
|
|
412
|
-
* @en
|
|
319
|
+
* @zh 每个代理每帧最大迭代数
|
|
320
|
+
* @en Maximum iterations per agent per frame
|
|
321
|
+
*
|
|
322
|
+
* @default 200
|
|
413
323
|
*/
|
|
414
|
-
|
|
324
|
+
maxIterationsPerAgent?: number;
|
|
415
325
|
}
|
|
416
|
-
|
|
417
326
|
/**
|
|
418
|
-
* @zh
|
|
419
|
-
* @en
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* @zh 寻路系统
|
|
424
|
-
* @en Pathfinding System
|
|
327
|
+
* @zh 统一导航系统
|
|
328
|
+
* @en Unified Navigation System
|
|
425
329
|
*
|
|
426
|
-
* @zh
|
|
427
|
-
* @en
|
|
330
|
+
* @zh 可插拔的导航系统,处理管线:PathPlanning → LocalAvoidance → CollisionResolution
|
|
331
|
+
* @en Pluggable navigation system, pipeline: PathPlanning → LocalAvoidance → CollisionResolution
|
|
428
332
|
*
|
|
429
333
|
* @example
|
|
430
334
|
* ```typescript
|
|
431
|
-
*
|
|
432
|
-
*
|
|
335
|
+
* import {
|
|
336
|
+
* NavigationSystem,
|
|
337
|
+
* NavigationAgentComponent,
|
|
338
|
+
* createNavMeshPathPlanner,
|
|
339
|
+
* createORCAAvoidance,
|
|
340
|
+
* createDefaultCollisionResolver
|
|
341
|
+
* } from '@esengine/pathfinding/ecs';
|
|
342
|
+
*
|
|
343
|
+
* // 创建系统
|
|
344
|
+
* const navSystem = new NavigationSystem();
|
|
345
|
+
*
|
|
346
|
+
* // 配置算法(可选,每个阶段都可以独立启用/禁用)
|
|
347
|
+
* navSystem.setPathPlanner(createNavMeshPathPlanner(navMesh));
|
|
348
|
+
* navSystem.setLocalAvoidance(createORCAAvoidance());
|
|
349
|
+
* navSystem.setCollisionResolver(createDefaultCollisionResolver());
|
|
433
350
|
*
|
|
434
|
-
*
|
|
435
|
-
* const mapEntity = scene.createEntity('Map');
|
|
436
|
-
* mapEntity.addComponent(new PathfindingMapComponent());
|
|
351
|
+
* scene.addSystem(navSystem);
|
|
437
352
|
*
|
|
438
|
-
* //
|
|
353
|
+
* // 添加障碍物
|
|
354
|
+
* navSystem.addObstacle({ vertices: [...] });
|
|
355
|
+
*
|
|
356
|
+
* // 创建代理
|
|
439
357
|
* const agent = scene.createEntity('Agent');
|
|
440
|
-
* const
|
|
441
|
-
*
|
|
358
|
+
* const nav = agent.addComponent(new NavigationAgentComponent());
|
|
359
|
+
* nav.setPosition(0, 0);
|
|
360
|
+
* nav.setDestination(100, 100);
|
|
442
361
|
*
|
|
443
|
-
* //
|
|
362
|
+
* // 运行时切换算法
|
|
363
|
+
* navSystem.setPathPlanner(createJPSPlanner(gridMap));
|
|
364
|
+
* navSystem.setLocalAvoidance(null); // 禁用避让
|
|
444
365
|
* ```
|
|
445
366
|
*/
|
|
446
|
-
declare class
|
|
447
|
-
private
|
|
448
|
-
private
|
|
449
|
-
private
|
|
450
|
-
private
|
|
451
|
-
private
|
|
452
|
-
constructor();
|
|
367
|
+
declare class NavigationSystem extends EntitySystem {
|
|
368
|
+
private config;
|
|
369
|
+
private pathPlanner;
|
|
370
|
+
private flowController;
|
|
371
|
+
private localAvoidance;
|
|
372
|
+
private collisionResolver;
|
|
453
373
|
/**
|
|
454
|
-
* @zh
|
|
455
|
-
* @en
|
|
374
|
+
* @zh 静态障碍物(墙壁、建筑等)- 由 PathPlanner 和 CollisionResolver 处理
|
|
375
|
+
* @en Static obstacles (walls, buildings) - handled by PathPlanner and CollisionResolver
|
|
456
376
|
*/
|
|
457
|
-
|
|
377
|
+
private staticObstacles;
|
|
458
378
|
/**
|
|
459
|
-
* @zh
|
|
460
|
-
* @en
|
|
379
|
+
* @zh 动态障碍物(移动物体等)- 由 ORCA 和 CollisionResolver 处理
|
|
380
|
+
* @en Dynamic obstacles (moving objects) - handled by ORCA and CollisionResolver
|
|
461
381
|
*/
|
|
462
|
-
|
|
382
|
+
private dynamicObstacles;
|
|
383
|
+
private currentTime;
|
|
384
|
+
private agentEnterTimes;
|
|
463
385
|
/**
|
|
464
|
-
* @zh
|
|
465
|
-
* @en
|
|
386
|
+
* @zh 是否为增量寻路器
|
|
387
|
+
* @en Whether the path planner is incremental
|
|
466
388
|
*/
|
|
467
|
-
|
|
389
|
+
private isIncrementalPlanner;
|
|
468
390
|
/**
|
|
469
|
-
* @zh
|
|
470
|
-
* @en
|
|
391
|
+
* @zh 等待寻路的代理队列(按优先级排序)
|
|
392
|
+
* @en Queue of agents waiting for pathfinding (sorted by priority)
|
|
471
393
|
*/
|
|
472
|
-
private
|
|
394
|
+
private pendingPathRequests;
|
|
395
|
+
constructor(config?: INavigationSystemConfig);
|
|
473
396
|
/**
|
|
474
|
-
* @zh
|
|
475
|
-
* @en
|
|
397
|
+
* @zh 设置路径规划器
|
|
398
|
+
* @en Set path planner
|
|
399
|
+
*
|
|
400
|
+
* @param planner - @zh 路径规划器,传入 null 禁用路径规划 @en Path planner, pass null to disable
|
|
401
|
+
*
|
|
402
|
+
* @zh 如果传入 IIncrementalPathPlanner 且启用了时间切片,会自动使用增量寻路
|
|
403
|
+
* @en If passing IIncrementalPathPlanner and time slicing is enabled, will automatically use incremental pathfinding
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```typescript
|
|
407
|
+
* navSystem.setPathPlanner(createNavMeshPathPlanner(navMesh));
|
|
408
|
+
* navSystem.setPathPlanner(createAStarPlanner(gridMap));
|
|
409
|
+
* navSystem.setPathPlanner(createIncrementalAStarPlanner(gridMap)); // 支持时间切片
|
|
410
|
+
* navSystem.setPathPlanner(null); // 禁用
|
|
411
|
+
* ```
|
|
476
412
|
*/
|
|
477
|
-
|
|
413
|
+
setPathPlanner(planner: IPathPlanner | null): void;
|
|
478
414
|
/**
|
|
479
|
-
* @zh
|
|
480
|
-
* @en
|
|
415
|
+
* @zh 获取当前路径规划器
|
|
416
|
+
* @en Get current path planner
|
|
481
417
|
*/
|
|
482
|
-
|
|
418
|
+
getPathPlanner(): IPathPlanner | null;
|
|
483
419
|
/**
|
|
484
|
-
* @zh
|
|
485
|
-
* @en
|
|
420
|
+
* @zh 设置流量控制器
|
|
421
|
+
* @en Set flow controller
|
|
422
|
+
*
|
|
423
|
+
* @param controller - @zh 流量控制器,传入 null 禁用流量控制 @en Flow controller, pass null to disable
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* navSystem.setFlowController(createFlowController());
|
|
428
|
+
* navSystem.setFlowController(null); // 禁用
|
|
429
|
+
* ```
|
|
486
430
|
*/
|
|
487
|
-
|
|
431
|
+
setFlowController(controller: IFlowController | null): void;
|
|
488
432
|
/**
|
|
489
|
-
* @zh
|
|
490
|
-
* @en
|
|
433
|
+
* @zh 获取当前流量控制器
|
|
434
|
+
* @en Get current flow controller
|
|
491
435
|
*/
|
|
492
|
-
|
|
436
|
+
getFlowController(): IFlowController | null;
|
|
493
437
|
/**
|
|
494
|
-
* @zh
|
|
495
|
-
* @en
|
|
438
|
+
* @zh 设置局部避让算法
|
|
439
|
+
* @en Set local avoidance algorithm
|
|
440
|
+
*
|
|
441
|
+
* @param avoidance - @zh 局部避让算法,传入 null 禁用避让 @en Local avoidance, pass null to disable
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* navSystem.setLocalAvoidance(createORCAAvoidance());
|
|
446
|
+
* navSystem.setLocalAvoidance(null); // 禁用
|
|
447
|
+
* ```
|
|
496
448
|
*/
|
|
497
|
-
|
|
449
|
+
setLocalAvoidance(avoidance: ILocalAvoidance | null): void;
|
|
498
450
|
/**
|
|
499
|
-
* @zh
|
|
500
|
-
* @en
|
|
451
|
+
* @zh 获取当前局部避让算法
|
|
452
|
+
* @en Get current local avoidance algorithm
|
|
501
453
|
*/
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* @zh 避让代理组件
|
|
507
|
-
* @en Avoidance Agent Component
|
|
508
|
-
*/
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* @zh 避让代理组件
|
|
512
|
-
* @en Avoidance Agent Component
|
|
513
|
-
*
|
|
514
|
-
* @zh 附加到需要局部避让的实体上,与 ORCA 系统配合使用
|
|
515
|
-
* @en Attach to entities that need local avoidance, works with ORCA system
|
|
516
|
-
*
|
|
517
|
-
* @example
|
|
518
|
-
* ```typescript
|
|
519
|
-
* const entity = scene.createEntity('Monster');
|
|
520
|
-
*
|
|
521
|
-
* // 添加避让代理
|
|
522
|
-
* const avoidance = entity.addComponent(new AvoidanceAgentComponent());
|
|
523
|
-
* avoidance.radius = 0.5;
|
|
524
|
-
* avoidance.maxSpeed = 5.0;
|
|
525
|
-
*
|
|
526
|
-
* // 设置首选速度(朝向目标)
|
|
527
|
-
* avoidance.setPreferredVelocityTowards(targetX, targetY, currentX, currentY);
|
|
528
|
-
*
|
|
529
|
-
* // 系统计算后,使用新速度更新位置
|
|
530
|
-
* // After system computes, use new velocity to update position
|
|
531
|
-
* x += avoidance.newVelocityX * deltaTime;
|
|
532
|
-
* y += avoidance.newVelocityY * deltaTime;
|
|
533
|
-
* ```
|
|
534
|
-
*/
|
|
535
|
-
declare class AvoidanceAgentComponent extends Component {
|
|
454
|
+
getLocalAvoidance(): ILocalAvoidance | null;
|
|
536
455
|
/**
|
|
537
|
-
* @zh
|
|
538
|
-
* @en
|
|
456
|
+
* @zh 设置碰撞解决器
|
|
457
|
+
* @en Set collision resolver
|
|
539
458
|
*
|
|
540
|
-
* @zh
|
|
541
|
-
*
|
|
459
|
+
* @param resolver - @zh 碰撞解决器,传入 null 禁用碰撞解决 @en Collision resolver, pass null to disable
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* navSystem.setCollisionResolver(createDefaultCollisionResolver());
|
|
464
|
+
* navSystem.setCollisionResolver(null); // 禁用
|
|
465
|
+
* ```
|
|
542
466
|
*/
|
|
543
|
-
|
|
467
|
+
setCollisionResolver(resolver: ICollisionResolver | null): void;
|
|
544
468
|
/**
|
|
545
|
-
* @zh
|
|
546
|
-
* @en
|
|
469
|
+
* @zh 获取当前碰撞解决器
|
|
470
|
+
* @en Get current collision resolver
|
|
547
471
|
*/
|
|
548
|
-
|
|
472
|
+
getCollisionResolver(): ICollisionResolver | null;
|
|
549
473
|
/**
|
|
550
|
-
* @zh
|
|
551
|
-
* @en
|
|
474
|
+
* @zh 添加静态障碍物(墙壁、建筑等)
|
|
475
|
+
* @en Add static obstacle (walls, buildings, etc.)
|
|
552
476
|
*
|
|
553
|
-
* @zh
|
|
554
|
-
* @
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* @zh 最大邻居数量
|
|
559
|
-
* @en Maximum number of neighbors to consider
|
|
477
|
+
* @zh 静态障碍物由 PathPlanner 规划路径时考虑,CollisionResolver 防止穿透
|
|
478
|
+
* @zh ORCA 不会处理静态障碍物,因为路径规划已经绑开了它们
|
|
479
|
+
* @en Static obstacles are considered by PathPlanner for routing, CollisionResolver for penetration prevention
|
|
480
|
+
* @en ORCA does NOT process static obstacles since path planning already avoids them
|
|
560
481
|
*
|
|
561
|
-
* @zh
|
|
562
|
-
* @en Limits computation, prioritizes closest neighbors
|
|
482
|
+
* @param obstacle - @zh 障碍物数据 @en Obstacle data
|
|
563
483
|
*/
|
|
564
|
-
|
|
484
|
+
addStaticObstacle(obstacle: IObstacleData): void;
|
|
565
485
|
/**
|
|
566
|
-
* @zh
|
|
567
|
-
* @en
|
|
486
|
+
* @zh 添加动态障碍物(移动物体、临时障碍等)
|
|
487
|
+
* @en Add dynamic obstacle (moving objects, temporary obstacles, etc.)
|
|
568
488
|
*
|
|
569
|
-
* @zh
|
|
570
|
-
* @en
|
|
571
|
-
*/
|
|
572
|
-
timeHorizon: number;
|
|
573
|
-
/**
|
|
574
|
-
* @zh 障碍物避让时间视野(秒)
|
|
575
|
-
* @en Time horizon for obstacle avoidance (seconds)
|
|
576
|
-
*/
|
|
577
|
-
timeHorizonObst: number;
|
|
578
|
-
/**
|
|
579
|
-
* @zh 当前位置 X
|
|
580
|
-
* @en Current position X
|
|
489
|
+
* @zh 动态障碍物由 ORCA 进行局部避让,CollisionResolver 防止穿透
|
|
490
|
+
* @en Dynamic obstacles are handled by ORCA for local avoidance, CollisionResolver for penetration prevention
|
|
581
491
|
*
|
|
582
|
-
* @zh
|
|
583
|
-
* @en If entity has Transform component, system will sync automatically
|
|
584
|
-
*/
|
|
585
|
-
positionX: number;
|
|
586
|
-
/**
|
|
587
|
-
* @zh 当前位置 Y
|
|
588
|
-
* @en Current position Y
|
|
492
|
+
* @param obstacle - @zh 障碍物数据 @en Obstacle data
|
|
589
493
|
*/
|
|
590
|
-
|
|
494
|
+
addDynamicObstacle(obstacle: IObstacleData): void;
|
|
591
495
|
/**
|
|
592
|
-
* @zh
|
|
593
|
-
* @en
|
|
496
|
+
* @zh 移除所有静态障碍物
|
|
497
|
+
* @en Remove all static obstacles
|
|
594
498
|
*/
|
|
595
|
-
|
|
499
|
+
clearStaticObstacles(): void;
|
|
596
500
|
/**
|
|
597
|
-
* @zh
|
|
598
|
-
* @en
|
|
501
|
+
* @zh 移除所有动态障碍物
|
|
502
|
+
* @en Remove all dynamic obstacles
|
|
599
503
|
*/
|
|
600
|
-
|
|
504
|
+
clearDynamicObstacles(): void;
|
|
601
505
|
/**
|
|
602
|
-
* @zh
|
|
603
|
-
* @en
|
|
506
|
+
* @zh 移除所有障碍物(静态和动态)
|
|
507
|
+
* @en Remove all obstacles (static and dynamic)
|
|
604
508
|
*/
|
|
605
|
-
|
|
509
|
+
clearObstacles(): void;
|
|
606
510
|
/**
|
|
607
|
-
* @zh
|
|
608
|
-
* @en
|
|
511
|
+
* @zh 获取静态障碍物列表
|
|
512
|
+
* @en Get static obstacles list
|
|
609
513
|
*/
|
|
610
|
-
|
|
514
|
+
getStaticObstacles(): readonly IObstacleData[];
|
|
611
515
|
/**
|
|
612
|
-
* @zh
|
|
613
|
-
* @en
|
|
516
|
+
* @zh 获取动态障碍物列表
|
|
517
|
+
* @en Get dynamic obstacles list
|
|
614
518
|
*/
|
|
615
|
-
|
|
519
|
+
getDynamicObstacles(): readonly IObstacleData[];
|
|
616
520
|
/**
|
|
617
|
-
* @zh
|
|
618
|
-
* @en
|
|
521
|
+
* @zh 获取所有障碍物列表(静态+动态)
|
|
522
|
+
* @en Get all obstacles list (static + dynamic)
|
|
619
523
|
*/
|
|
620
|
-
|
|
524
|
+
getObstacles(): readonly IObstacleData[];
|
|
621
525
|
/**
|
|
622
|
-
* @zh
|
|
623
|
-
* @en
|
|
526
|
+
* @zh 获取所有障碍物用于碰撞检测
|
|
527
|
+
* @en Get all obstacles for collision detection
|
|
624
528
|
*/
|
|
625
|
-
|
|
529
|
+
private getAllObstaclesForCollision;
|
|
626
530
|
/**
|
|
627
|
-
* @zh
|
|
628
|
-
* @en
|
|
531
|
+
* @zh 设置静态障碍物列表
|
|
532
|
+
* @en Set static obstacles list
|
|
629
533
|
*
|
|
630
|
-
* @zh
|
|
631
|
-
* @en If true, system will automatically assign newVelocity to velocity after computation
|
|
534
|
+
* @param obstacles - @zh 障碍物列表 @en Obstacles list
|
|
632
535
|
*/
|
|
633
|
-
|
|
536
|
+
setStaticObstacles(obstacles: IObstacleData[]): void;
|
|
634
537
|
/**
|
|
635
|
-
* @zh
|
|
636
|
-
* @en Set
|
|
637
|
-
*/
|
|
638
|
-
setPosition(x: number, y: number): void;
|
|
639
|
-
/**
|
|
640
|
-
* @zh 设置当前速度
|
|
641
|
-
* @en Set current velocity
|
|
642
|
-
*/
|
|
643
|
-
setVelocity(x: number, y: number): void;
|
|
644
|
-
/**
|
|
645
|
-
* @zh 设置首选速度
|
|
646
|
-
* @en Set preferred velocity
|
|
647
|
-
*/
|
|
648
|
-
setPreferredVelocity(x: number, y: number): void;
|
|
649
|
-
/**
|
|
650
|
-
* @zh 设置首选速度朝向目标
|
|
651
|
-
* @en Set preferred velocity towards target
|
|
538
|
+
* @zh 设置动态障碍物列表
|
|
539
|
+
* @en Set dynamic obstacles list
|
|
652
540
|
*
|
|
653
|
-
* @param
|
|
654
|
-
* @param targetY - @zh 目标 Y @en Target Y
|
|
655
|
-
* @param currentX - @zh 当前 X(可选,默认使用 positionX)@en Current X (optional, defaults to positionX)
|
|
656
|
-
* @param currentY - @zh 当前 Y(可选,默认使用 positionY)@en Current Y (optional, defaults to positionY)
|
|
657
|
-
*/
|
|
658
|
-
setPreferredVelocityTowards(targetX: number, targetY: number, currentX?: number, currentY?: number): void;
|
|
659
|
-
/**
|
|
660
|
-
* @zh 应用 ORCA 计算的新速度
|
|
661
|
-
* @en Apply new velocity computed by ORCA
|
|
662
|
-
*/
|
|
663
|
-
applyNewVelocity(): void;
|
|
664
|
-
/**
|
|
665
|
-
* @zh 获取新速度的长度
|
|
666
|
-
* @en Get length of new velocity
|
|
667
|
-
*/
|
|
668
|
-
getNewSpeed(): number;
|
|
669
|
-
/**
|
|
670
|
-
* @zh 获取当前速度的长度
|
|
671
|
-
* @en Get length of current velocity
|
|
672
|
-
*/
|
|
673
|
-
getCurrentSpeed(): number;
|
|
674
|
-
/**
|
|
675
|
-
* @zh 停止代理
|
|
676
|
-
* @en Stop the agent
|
|
677
|
-
*/
|
|
678
|
-
stop(): void;
|
|
679
|
-
/**
|
|
680
|
-
* @zh 重置组件状态
|
|
681
|
-
* @en Reset component state
|
|
682
|
-
*/
|
|
683
|
-
reset(): void;
|
|
684
|
-
/**
|
|
685
|
-
* @zh 组件从实体移除时调用
|
|
686
|
-
* @en Called when component is removed from entity
|
|
541
|
+
* @param obstacles - @zh 障碍物列表 @en Obstacles list
|
|
687
542
|
*/
|
|
688
|
-
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* @zh 避让世界组件
|
|
693
|
-
* @en Avoidance World Component
|
|
694
|
-
*/
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* @zh 避让世界组件
|
|
698
|
-
* @en Avoidance World Component
|
|
699
|
-
*
|
|
700
|
-
* @zh 挂载在场景实体上,持有 ORCA 求解器和静态障碍物
|
|
701
|
-
* @en Attached to scene entity, holds ORCA solver and static obstacles
|
|
702
|
-
*
|
|
703
|
-
* @example
|
|
704
|
-
* ```typescript
|
|
705
|
-
* const worldEntity = scene.createEntity('AvoidanceWorld');
|
|
706
|
-
* const world = worldEntity.addComponent(new AvoidanceWorldComponent());
|
|
707
|
-
*
|
|
708
|
-
* // 添加静态障碍物(墙壁)
|
|
709
|
-
* world.addObstacle({
|
|
710
|
-
* vertices: [
|
|
711
|
-
* { x: 0, y: 0 },
|
|
712
|
-
* { x: 10, y: 0 },
|
|
713
|
-
* { x: 10, y: 1 },
|
|
714
|
-
* { x: 0, y: 1 }
|
|
715
|
-
* ]
|
|
716
|
-
* });
|
|
717
|
-
*
|
|
718
|
-
* // LocalAvoidanceSystem 会自动使用此组件
|
|
719
|
-
* ```
|
|
720
|
-
*/
|
|
721
|
-
declare class AvoidanceWorldComponent extends Component {
|
|
722
|
-
/**
|
|
723
|
-
* @zh 默认时间视野(代理)
|
|
724
|
-
* @en Default time horizon for agents
|
|
725
|
-
*/
|
|
726
|
-
defaultTimeHorizon: number;
|
|
543
|
+
setDynamicObstacles(obstacles: IObstacleData[]): void;
|
|
727
544
|
/**
|
|
728
|
-
* @zh
|
|
729
|
-
* @en
|
|
730
|
-
*/
|
|
731
|
-
defaultTimeHorizonObst: number;
|
|
732
|
-
/**
|
|
733
|
-
* @zh 时间步长
|
|
734
|
-
* @en Time step
|
|
545
|
+
* @zh 系统销毁时调用
|
|
546
|
+
* @en Called when system is destroyed
|
|
735
547
|
*/
|
|
736
|
-
|
|
548
|
+
protected onDestroy(): void;
|
|
737
549
|
/**
|
|
738
|
-
* @zh
|
|
739
|
-
* @en
|
|
550
|
+
* @zh 处理实体
|
|
551
|
+
* @en Process entities
|
|
740
552
|
*/
|
|
741
|
-
|
|
553
|
+
protected process(entities: readonly Entity[]): void;
|
|
742
554
|
/**
|
|
743
|
-
* @zh
|
|
744
|
-
* @en
|
|
555
|
+
* @zh 处理等待中的代理
|
|
556
|
+
* @en Handle waiting agent
|
|
745
557
|
*/
|
|
746
|
-
|
|
558
|
+
private handleWaitingAgent;
|
|
747
559
|
/**
|
|
748
|
-
* @zh
|
|
749
|
-
* @en
|
|
560
|
+
* @zh 清理已移除代理的进入时间记录
|
|
561
|
+
* @en Cleanup enter times for removed agents
|
|
750
562
|
*/
|
|
751
|
-
|
|
563
|
+
private cleanupEnterTimes;
|
|
752
564
|
/**
|
|
753
|
-
* @zh
|
|
754
|
-
* @en
|
|
565
|
+
* @zh 处理路径规划(同步模式)
|
|
566
|
+
* @en Process path planning (synchronous mode)
|
|
755
567
|
*/
|
|
756
|
-
|
|
568
|
+
private processPathPlanning;
|
|
757
569
|
/**
|
|
758
|
-
* @zh
|
|
759
|
-
* @en
|
|
570
|
+
* @zh 处理增量路径规划(时间切片模式)
|
|
571
|
+
* @en Process incremental path planning (time slicing mode)
|
|
572
|
+
*
|
|
573
|
+
* @param agents - @zh 代理列表 @en Agent list
|
|
574
|
+
* @param entityMap - @zh 实体 ID 到代理的映射 @en Entity ID to agent mapping
|
|
760
575
|
*/
|
|
761
|
-
|
|
576
|
+
private processIncrementalPathPlanning;
|
|
762
577
|
/**
|
|
763
|
-
* @zh
|
|
764
|
-
* @en
|
|
578
|
+
* @zh 推进路径点
|
|
579
|
+
* @en Advance waypoint
|
|
765
580
|
*/
|
|
766
|
-
|
|
581
|
+
private advanceWaypoint;
|
|
767
582
|
/**
|
|
768
|
-
* @zh
|
|
769
|
-
* @en
|
|
583
|
+
* @zh 计算首选速度
|
|
584
|
+
* @en Calculate preferred velocity
|
|
770
585
|
*/
|
|
771
|
-
|
|
586
|
+
private calculatePreferredVelocity;
|
|
772
587
|
/**
|
|
773
|
-
* @zh
|
|
774
|
-
* @en
|
|
588
|
+
* @zh 构建代理数据
|
|
589
|
+
* @en Build agent data
|
|
775
590
|
*/
|
|
776
|
-
|
|
591
|
+
private buildAgentData;
|
|
777
592
|
/**
|
|
778
|
-
* @zh
|
|
779
|
-
* @en
|
|
780
|
-
*
|
|
781
|
-
* @param obstacle - @zh 障碍物(顶点列表,逆时针顺序)@en Obstacle (vertex list, counter-clockwise)
|
|
593
|
+
* @zh 应用避让结果
|
|
594
|
+
* @en Apply avoidance result
|
|
782
595
|
*/
|
|
783
|
-
|
|
596
|
+
private applyAvoidanceResult;
|
|
784
597
|
/**
|
|
785
|
-
* @zh
|
|
786
|
-
* @en
|
|
787
|
-
*
|
|
788
|
-
* @param x - @zh 左下角 X @en Bottom-left X
|
|
789
|
-
* @param y - @zh 左下角 Y @en Bottom-left Y
|
|
790
|
-
* @param width - @zh 宽度 @en Width
|
|
791
|
-
* @param height - @zh 高度 @en Height
|
|
598
|
+
* @zh 应用平滑转向
|
|
599
|
+
* @en Apply smooth steering
|
|
792
600
|
*/
|
|
793
|
-
|
|
601
|
+
private applySmoothSteering;
|
|
794
602
|
/**
|
|
795
|
-
* @zh
|
|
796
|
-
* @en
|
|
603
|
+
* @zh 检查是否到达目标
|
|
604
|
+
* @en Check if arrived at destination
|
|
797
605
|
*/
|
|
798
|
-
|
|
606
|
+
private checkArrival;
|
|
799
607
|
/**
|
|
800
|
-
* @zh
|
|
801
|
-
* @en
|
|
608
|
+
* @zh 解决代理间碰撞
|
|
609
|
+
* @en Resolve agent-agent collisions
|
|
802
610
|
*/
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* @zh 组件从实体移除时调用
|
|
806
|
-
* @en Called when component is removed from entity
|
|
807
|
-
*/
|
|
808
|
-
onRemovedFromEntity(): void;
|
|
611
|
+
private resolveAgentCollisions;
|
|
809
612
|
}
|
|
810
613
|
|
|
811
614
|
/**
|
|
812
|
-
* @zh
|
|
813
|
-
* @en
|
|
615
|
+
* @zh ORCA 算法配置组件
|
|
616
|
+
* @en ORCA Algorithm Configuration Component
|
|
617
|
+
*
|
|
618
|
+
* @zh 可选组件,仅当使用 ORCA 避让算法时需要,用于覆盖默认 ORCA 参数
|
|
619
|
+
* @en Optional component, only needed when using ORCA avoidance, to override default ORCA parameters
|
|
814
620
|
*/
|
|
815
621
|
|
|
816
622
|
/**
|
|
817
|
-
* @zh
|
|
818
|
-
* @en
|
|
623
|
+
* @zh ORCA 算法配置组件
|
|
624
|
+
* @en ORCA algorithm configuration component
|
|
819
625
|
*
|
|
820
|
-
* @zh
|
|
821
|
-
* @en
|
|
626
|
+
* @zh 可选组件,附加到代理实体上以覆盖默认 ORCA 参数
|
|
627
|
+
* @en Optional component, attach to agent entities to override default ORCA parameters
|
|
822
628
|
*
|
|
823
629
|
* @example
|
|
824
630
|
* ```typescript
|
|
825
|
-
*
|
|
826
|
-
* scene.addSystem(new LocalAvoidanceSystem());
|
|
827
|
-
*
|
|
828
|
-
* // 创建避让世界(可选,用于静态障碍物)
|
|
829
|
-
* const worldEntity = scene.createEntity('AvoidanceWorld');
|
|
830
|
-
* worldEntity.addComponent(new AvoidanceWorldComponent());
|
|
831
|
-
*
|
|
832
|
-
* // 创建代理
|
|
833
|
-
* const agent = scene.createEntity('Agent');
|
|
834
|
-
* const avoidance = agent.addComponent(new AvoidanceAgentComponent());
|
|
835
|
-
*
|
|
836
|
-
* // 可选:同时添加寻路代理,系统会自动同步位置
|
|
837
|
-
* agent.addComponent(new PathfindingAgentComponent());
|
|
631
|
+
* const entity = scene.createEntity('Agent');
|
|
838
632
|
*
|
|
839
|
-
* //
|
|
840
|
-
*
|
|
633
|
+
* // 添加导航代理
|
|
634
|
+
* entity.addComponent(new NavigationAgentComponent());
|
|
841
635
|
*
|
|
842
|
-
* //
|
|
843
|
-
*
|
|
636
|
+
* // 可选:添加 ORCA 配置以自定义参数
|
|
637
|
+
* const orcaConfig = entity.addComponent(new ORCAConfigComponent());
|
|
638
|
+
* orcaConfig.timeHorizon = 3.0; // 更长的预测时间
|
|
639
|
+
* orcaConfig.neighborDist = 20.0; // 更大的邻居检测范围
|
|
844
640
|
* ```
|
|
845
641
|
*/
|
|
846
|
-
declare class
|
|
847
|
-
private worldEntity;
|
|
848
|
-
private worldComponent;
|
|
849
|
-
private solver;
|
|
850
|
-
private kdTree;
|
|
851
|
-
constructor();
|
|
852
|
-
/**
|
|
853
|
-
* @zh 系统初始化
|
|
854
|
-
* @en System initialization
|
|
855
|
-
*/
|
|
856
|
-
protected onInitialize(): void;
|
|
857
|
-
/**
|
|
858
|
-
* @zh 系统激活时调用
|
|
859
|
-
* @en Called when system is enabled
|
|
860
|
-
*/
|
|
861
|
-
protected onEnable(): void;
|
|
642
|
+
declare class ORCAConfigComponent extends Component {
|
|
862
643
|
/**
|
|
863
|
-
* @zh
|
|
864
|
-
* @en
|
|
644
|
+
* @zh 邻居检测距离
|
|
645
|
+
* @en Neighbor detection distance
|
|
646
|
+
*
|
|
647
|
+
* @zh 代理检测邻居的最大距离,更大的值意味着更早开始避让但也更消耗性能
|
|
648
|
+
* @en Maximum distance for detecting neighbors, larger value means earlier avoidance but more performance cost
|
|
865
649
|
*/
|
|
866
|
-
|
|
650
|
+
neighborDist: number;
|
|
867
651
|
/**
|
|
868
|
-
* @zh
|
|
869
|
-
* @en
|
|
652
|
+
* @zh 最大邻居数量
|
|
653
|
+
* @en Maximum number of neighbors
|
|
654
|
+
*
|
|
655
|
+
* @zh 计算避让时考虑的最大邻居数量,更多邻居意味着更精确但也更消耗性能
|
|
656
|
+
* @en Maximum neighbors considered for avoidance, more neighbors means more accurate but slower
|
|
870
657
|
*/
|
|
871
|
-
|
|
658
|
+
maxNeighbors: number;
|
|
872
659
|
/**
|
|
873
|
-
* @zh
|
|
874
|
-
* @en
|
|
660
|
+
* @zh 代理避让时间视野
|
|
661
|
+
* @en Time horizon for agent avoidance
|
|
662
|
+
*
|
|
663
|
+
* @zh 预测其他代理未来位置的时间范围,更长意味着更平滑但可能过度避让
|
|
664
|
+
* @en Time range for predicting other agents' future positions, longer means smoother but may over-avoid
|
|
875
665
|
*/
|
|
876
|
-
|
|
666
|
+
timeHorizon: number;
|
|
877
667
|
/**
|
|
878
|
-
* @zh
|
|
879
|
-
* @en
|
|
668
|
+
* @zh 障碍物避让时间视野
|
|
669
|
+
* @en Time horizon for obstacle avoidance
|
|
670
|
+
*
|
|
671
|
+
* @zh 预测与障碍物碰撞的时间范围,通常比代理视野短
|
|
672
|
+
* @en Time range for predicting obstacle collisions, usually shorter than agent horizon
|
|
880
673
|
*/
|
|
881
|
-
|
|
674
|
+
timeHorizonObst: number;
|
|
882
675
|
}
|
|
883
676
|
|
|
884
|
-
export {
|
|
677
|
+
export { IFlowController, type INavigationSystemConfig, NavigationAgentComponent, NavigationState, NavigationSystem, ORCAConfigComponent };
|