@esengine/pathfinding 12.1.2 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/IIncrementalPathfinding.ts"],"sourcesContent":["/**\n * @zh 增量寻路系统接口\n * @en Incremental Pathfinding System Interfaces\n */\n\nimport type { IPoint, IPathResult, IPathfindingOptions, IPathfindingMap } from './IPathfinding';\n\n// =============================================================================\n// 状态枚举 | State Enum\n// =============================================================================\n\n/**\n * @zh 增量寻路状态\n * @en Incremental pathfinding state\n */\nexport enum PathfindingState {\n /** @zh 空闲,等待请求 @en Idle, waiting for request */\n Idle = 'idle',\n /** @zh 正在搜索中 @en Search in progress */\n InProgress = 'in_progress',\n /** @zh 已暂停 @en Paused */\n Paused = 'paused',\n /** @zh 搜索完成,找到路径 @en Completed, path found */\n Completed = 'completed',\n /** @zh 搜索失败,无法找到路径 @en Failed, no path found */\n Failed = 'failed',\n /** @zh 已取消 @en Cancelled */\n Cancelled = 'cancelled'\n}\n\n// =============================================================================\n// 请求和进度接口 | Request and Progress Interfaces\n// =============================================================================\n\n/**\n * @zh 增量寻路请求\n * @en Incremental pathfinding request\n */\nexport interface IPathRequest {\n /**\n * @zh 请求唯一标识符\n * @en Unique request identifier\n */\n readonly id: number;\n\n /**\n * @zh 起点 X 坐标\n * @en Start X coordinate\n */\n readonly startX: number;\n\n /**\n * @zh 起点 Y 坐标\n * @en Start Y coordinate\n */\n readonly startY: number;\n\n /**\n * @zh 终点 X 坐标\n * @en End X coordinate\n */\n readonly endX: number;\n\n /**\n * @zh 终点 Y 坐标\n * @en End Y coordinate\n */\n readonly endY: number;\n\n /**\n * @zh 寻路配置选项\n * @en Pathfinding options\n */\n readonly options?: IPathfindingOptions;\n\n /**\n * @zh 优先级(数值越小优先级越高)\n * @en Priority (lower number = higher priority)\n */\n readonly priority: number;\n\n /**\n * @zh 创建时间戳\n * @en Creation timestamp\n */\n readonly createdAt: number;\n}\n\n/**\n * @zh 增量寻路进度\n * @en Incremental pathfinding progress\n */\nexport interface IPathProgress {\n /**\n * @zh 当前寻路状态\n * @en Current pathfinding state\n */\n readonly state: PathfindingState;\n\n /**\n * @zh 已搜索的节点数量\n * @en Number of nodes searched\n */\n readonly nodesSearched: number;\n\n /**\n * @zh 开放列表当前大小\n * @en Current open list size\n */\n readonly openListSize: number;\n\n /**\n * @zh 估计的搜索进度 (0-1)\n * @en Estimated search progress (0-1)\n */\n readonly estimatedProgress: number;\n\n /**\n * @zh 当前最佳部分路径(可选)\n * @en Current best partial path (optional)\n */\n readonly partialPath?: readonly IPoint[];\n}\n\n/**\n * @zh 增量寻路结果(扩展自 IPathResult)\n * @en Incremental pathfinding result (extends IPathResult)\n */\nexport interface IIncrementalPathResult extends IPathResult {\n /**\n * @zh 关联的请求 ID\n * @en Associated request ID\n */\n readonly requestId: number;\n\n /**\n * @zh 完成搜索所用的帧数\n * @en Number of frames used to complete search\n */\n readonly framesUsed: number;\n\n /**\n * @zh 是否为部分路径(未到达终点)\n * @en Whether this is a partial path (not reaching goal)\n */\n readonly isPartial: boolean;\n}\n\n// =============================================================================\n// 增量寻路器接口 | Incremental Pathfinder Interface\n// =============================================================================\n\n/**\n * @zh 增量寻路请求选项\n * @en Incremental pathfinding request options\n */\nexport interface IIncrementalPathfindingOptions extends IPathfindingOptions {\n /**\n * @zh 优先级(数值越小优先级越高,默认 50)\n * @en Priority (lower = higher, default 50)\n */\n priority?: number;\n}\n\n/**\n * @zh 增量寻路器接口\n * @en Incremental pathfinder interface\n *\n * @zh 支持时间切片的寻路器,可跨多帧执行搜索\n * @en Pathfinder with time slicing support, can execute search across multiple frames\n */\nexport interface IIncrementalPathfinder {\n /**\n * @zh 请求寻路(非阻塞)\n * @en Request pathfinding (non-blocking)\n *\n * @param startX - @zh 起点 X 坐标 @en Start X coordinate\n * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate\n * @param endX - @zh 终点 X 坐标 @en End X coordinate\n * @param endY - @zh 终点 Y 坐标 @en End Y coordinate\n * @param options - @zh 寻路选项 @en Pathfinding options\n * @returns @zh 寻路请求对象 @en Path request object\n */\n requestPath(\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n options?: IIncrementalPathfindingOptions\n ): IPathRequest;\n\n /**\n * @zh 执行一步搜索\n * @en Execute one step of search\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @param maxIterations - @zh 本步最大迭代次数 @en Maximum iterations this step\n * @returns @zh 当前进度 @en Current progress\n */\n step(requestId: number, maxIterations: number): IPathProgress;\n\n /**\n * @zh 暂停寻路\n * @en Pause pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n pause(requestId: number): void;\n\n /**\n * @zh 恢复寻路\n * @en Resume pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n resume(requestId: number): void;\n\n /**\n * @zh 取消寻路\n * @en Cancel pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cancel(requestId: number): void;\n\n /**\n * @zh 获取寻路结果(仅当状态为 Completed 或 Failed 时可用)\n * @en Get pathfinding result (only available when state is Completed or Failed)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 寻路结果或 null @en Path result or null\n */\n getResult(requestId: number): IIncrementalPathResult | null;\n\n /**\n * @zh 获取当前进度\n * @en Get current progress\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 当前进度或 null @en Current progress or null\n */\n getProgress(requestId: number): IPathProgress | null;\n\n /**\n * @zh 清理已完成的请求(释放内存)\n * @en Clean up completed request (release memory)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cleanup(requestId: number): void;\n\n /**\n * @zh 通知障碍物变化(用于动态重规划)\n * @en Notify obstacle change (for dynamic replanning)\n *\n * @param minX - @zh 变化区域最小 X @en Changed area min X\n * @param minY - @zh 变化区域最小 Y @en Changed area min Y\n * @param maxX - @zh 变化区域最大 X @en Changed area max X\n * @param maxY - @zh 变化区域最大 Y @en Changed area max Y\n */\n notifyObstacleChange(\n minX: number,\n minY: number,\n maxX: number,\n maxY: number\n ): void;\n\n /**\n * @zh 清理所有请求\n * @en Clear all requests\n */\n clear(): void;\n}\n\n// =============================================================================\n// 路径验证接口 | Path Validation Interface\n// =============================================================================\n\n/**\n * @zh 路径验证结果\n * @en Path validation result\n */\nexport interface IPathValidationResult {\n /**\n * @zh 路径是否有效\n * @en Whether the path is valid\n */\n readonly valid: boolean;\n\n /**\n * @zh 第一个无效点的索引(-1 表示全部有效)\n * @en Index of first invalid point (-1 if all valid)\n */\n readonly invalidIndex: number;\n}\n\n/**\n * @zh 路径验证器接口\n * @en Path validator interface\n */\nexport interface IPathValidator {\n /**\n * @zh 验证路径段的有效性\n * @en Validate path segment validity\n *\n * @param path - @zh 要验证的路径 @en Path to validate\n * @param fromIndex - @zh 起始索引 @en Start index\n * @param toIndex - @zh 结束索引 @en End index\n * @param map - @zh 地图实例 @en Map instance\n * @returns @zh 验证结果 @en Validation result\n */\n validatePath(\n path: readonly IPoint[],\n fromIndex: number,\n toIndex: number,\n map: IPathfindingMap\n ): IPathValidationResult;\n}\n\n// =============================================================================\n// 动态重规划配置 | Dynamic Replanning Configuration\n// =============================================================================\n\n/**\n * @zh 动态重规划配置\n * @en Dynamic replanning configuration\n */\nexport interface IReplanningConfig {\n /**\n * @zh 是否启用动态重规划\n * @en Whether dynamic replanning is enabled\n */\n enabled: boolean;\n\n /**\n * @zh 路径检查间隔(帧数)\n * @en Path check interval (in frames)\n */\n checkInterval: number;\n\n /**\n * @zh 触发重规划的距离阈值\n * @en Distance threshold to trigger replanning\n */\n distanceThreshold: number;\n\n /**\n * @zh 向前探测的距离(路径点数)\n * @en Lookahead distance (in path points)\n */\n lookaheadDistance: number;\n}\n\n/**\n * @zh 默认重规划配置\n * @en Default replanning configuration\n */\nexport const DEFAULT_REPLANNING_CONFIG: IReplanningConfig = {\n enabled: true,\n checkInterval: 10,\n distanceThreshold: 2,\n lookaheadDistance: 5\n};\n\n// =============================================================================\n// 空进度常量 | Empty Progress Constant\n// =============================================================================\n\n/**\n * @zh 空进度(用于无效请求)\n * @en Empty progress (for invalid requests)\n */\nexport const EMPTY_PROGRESS: IPathProgress = {\n state: PathfindingState.Idle,\n nodesSearched: 0,\n openListSize: 0,\n estimatedProgress: 0\n};\n"],"mappings":";;;;;;AAeO,IAAKA,mBAAAA,0BAAAA,mBAAAA;AACsC,EAAAA,kBAAA,MAAA,IAAA;AAET,EAAAA,kBAAA,YAAA,IAAA;AAEd,EAAAA,kBAAA,QAAA,IAAA;AAEqB,EAAAA,kBAAA,WAAA,IAAA;AAEE,EAAAA,kBAAA,QAAA,IAAA;AAEpB,EAAAA,kBAAA,WAAA,IAAA;SAXlBA;;AAsVL,IAAMC,4BAA+C;EACxDC,SAAS;EACTC,eAAe;EACfC,mBAAmB;EACnBC,mBAAmB;AACvB;AAUO,IAAMC,iBAAgC;EACzCC,OAAK;EACLC,eAAe;EACfC,cAAc;EACdC,mBAAmB;AACvB;","names":["PathfindingState","DEFAULT_REPLANNING_CONFIG","enabled","checkInterval","distanceThreshold","lookaheadDistance","EMPTY_PROGRESS","state","nodesSearched","openListSize","estimatedProgress"]}
1
+ {"version":3,"sources":["../src/core/IIncrementalPathfinding.ts"],"sourcesContent":["/**\n * @zh 增量寻路系统接口\n * @en Incremental Pathfinding System Interfaces\n */\n\nimport type { IPoint, IPathResult, IPathfindingOptions, IPathfindingMap } from './IPathfinding';\n\n// =============================================================================\n// 状态枚举 | State Enum\n// =============================================================================\n\n/**\n * @zh 增量寻路状态\n * @en Incremental pathfinding state\n */\nexport enum PathfindingState {\n /** @zh 空闲,等待请求 @en Idle, waiting for request */\n Idle = 'idle',\n /** @zh 正在搜索中 @en Search in progress */\n InProgress = 'in_progress',\n /** @zh 已暂停 @en Paused */\n Paused = 'paused',\n /** @zh 搜索完成,找到路径 @en Completed, path found */\n Completed = 'completed',\n /** @zh 搜索失败,无法找到路径 @en Failed, no path found */\n Failed = 'failed',\n /** @zh 已取消 @en Cancelled */\n Cancelled = 'cancelled'\n}\n\n// =============================================================================\n// 请求和进度接口 | Request and Progress Interfaces\n// =============================================================================\n\n/**\n * @zh 增量寻路请求\n * @en Incremental pathfinding request\n */\nexport interface IPathRequest {\n /**\n * @zh 请求唯一标识符\n * @en Unique request identifier\n */\n readonly id: number;\n\n /**\n * @zh 起点 X 坐标\n * @en Start X coordinate\n */\n readonly startX: number;\n\n /**\n * @zh 起点 Y 坐标\n * @en Start Y coordinate\n */\n readonly startY: number;\n\n /**\n * @zh 终点 X 坐标\n * @en End X coordinate\n */\n readonly endX: number;\n\n /**\n * @zh 终点 Y 坐标\n * @en End Y coordinate\n */\n readonly endY: number;\n\n /**\n * @zh 寻路配置选项\n * @en Pathfinding options\n */\n readonly options?: IPathfindingOptions;\n\n /**\n * @zh 优先级(数值越小优先级越高)\n * @en Priority (lower number = higher priority)\n */\n readonly priority: number;\n\n /**\n * @zh 创建时间戳\n * @en Creation timestamp\n */\n readonly createdAt: number;\n}\n\n/**\n * @zh 增量寻路进度\n * @en Incremental pathfinding progress\n */\nexport interface IPathProgress {\n /**\n * @zh 当前寻路状态\n * @en Current pathfinding state\n */\n readonly state: PathfindingState;\n\n /**\n * @zh 已搜索的节点数量\n * @en Number of nodes searched\n */\n readonly nodesSearched: number;\n\n /**\n * @zh 开放列表当前大小\n * @en Current open list size\n */\n readonly openListSize: number;\n\n /**\n * @zh 估计的搜索进度 (0-1)\n * @en Estimated search progress (0-1)\n */\n readonly estimatedProgress: number;\n\n /**\n * @zh 当前最佳部分路径(可选)\n * @en Current best partial path (optional)\n */\n readonly partialPath?: readonly IPoint[];\n}\n\n/**\n * @zh 增量寻路结果(扩展自 IPathResult)\n * @en Incremental pathfinding result (extends IPathResult)\n */\nexport interface IIncrementalPathResult extends IPathResult {\n /**\n * @zh 关联的请求 ID\n * @en Associated request ID\n */\n readonly requestId: number;\n\n /**\n * @zh 完成搜索所用的帧数\n * @en Number of frames used to complete search\n */\n readonly framesUsed: number;\n\n /**\n * @zh 是否为部分路径(未到达终点)\n * @en Whether this is a partial path (not reaching goal)\n */\n readonly isPartial: boolean;\n}\n\n// =============================================================================\n// 增量寻路器接口 | Incremental Pathfinder Interface\n// =============================================================================\n\n/**\n * @zh 增量寻路请求选项\n * @en Incremental pathfinding request options\n */\nexport interface IIncrementalPathfindingOptions extends IPathfindingOptions {\n /**\n * @zh 优先级(数值越小优先级越高,默认 50)\n * @en Priority (lower = higher, default 50)\n */\n priority?: number;\n}\n\n/**\n * @zh 增量寻路器接口\n * @en Incremental pathfinder interface\n *\n * @zh 支持时间切片的寻路器,可跨多帧执行搜索\n * @en Pathfinder with time slicing support, can execute search across multiple frames\n */\nexport interface IIncrementalPathfinder {\n /**\n * @zh 请求寻路(非阻塞)\n * @en Request pathfinding (non-blocking)\n *\n * @param startX - @zh 起点 X 坐标 @en Start X coordinate\n * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate\n * @param endX - @zh 终点 X 坐标 @en End X coordinate\n * @param endY - @zh 终点 Y 坐标 @en End Y coordinate\n * @param options - @zh 寻路选项 @en Pathfinding options\n * @returns @zh 寻路请求对象 @en Path request object\n */\n requestPath(\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n options?: IIncrementalPathfindingOptions\n ): IPathRequest;\n\n /**\n * @zh 执行一步搜索\n * @en Execute one step of search\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @param maxIterations - @zh 本步最大迭代次数 @en Maximum iterations this step\n * @returns @zh 当前进度 @en Current progress\n */\n step(requestId: number, maxIterations: number): IPathProgress;\n\n /**\n * @zh 暂停寻路\n * @en Pause pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n pause(requestId: number): void;\n\n /**\n * @zh 恢复寻路\n * @en Resume pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n resume(requestId: number): void;\n\n /**\n * @zh 取消寻路\n * @en Cancel pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cancel(requestId: number): void;\n\n /**\n * @zh 获取寻路结果(仅当状态为 Completed 或 Failed 时可用)\n * @en Get pathfinding result (only available when state is Completed or Failed)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 寻路结果或 null @en Path result or null\n */\n getResult(requestId: number): IIncrementalPathResult | null;\n\n /**\n * @zh 获取当前进度\n * @en Get current progress\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 当前进度或 null @en Current progress or null\n */\n getProgress(requestId: number): IPathProgress | null;\n\n /**\n * @zh 清理已完成的请求(释放内存)\n * @en Clean up completed request (release memory)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cleanup(requestId: number): void;\n\n /**\n * @zh 通知障碍物变化(用于动态重规划)\n * @en Notify obstacle change (for dynamic replanning)\n *\n * @param minX - @zh 变化区域最小 X @en Changed area min X\n * @param minY - @zh 变化区域最小 Y @en Changed area min Y\n * @param maxX - @zh 变化区域最大 X @en Changed area max X\n * @param maxY - @zh 变化区域最大 Y @en Changed area max Y\n */\n notifyObstacleChange(\n minX: number,\n minY: number,\n maxX: number,\n maxY: number\n ): void;\n\n /**\n * @zh 清理所有请求\n * @en Clear all requests\n */\n clear(): void;\n}\n\n// =============================================================================\n// 路径验证接口 | Path Validation Interface\n// =============================================================================\n\n/**\n * @zh 路径验证结果\n * @en Path validation result\n */\nexport interface IPathValidationResult {\n /**\n * @zh 路径是否有效\n * @en Whether the path is valid\n */\n readonly valid: boolean;\n\n /**\n * @zh 第一个无效点的索引(-1 表示全部有效)\n * @en Index of first invalid point (-1 if all valid)\n */\n readonly invalidIndex: number;\n}\n\n/**\n * @zh 路径验证器接口\n * @en Path validator interface\n */\nexport interface IPathValidator {\n /**\n * @zh 验证路径段的有效性\n * @en Validate path segment validity\n *\n * @param path - @zh 要验证的路径 @en Path to validate\n * @param fromIndex - @zh 起始索引 @en Start index\n * @param toIndex - @zh 结束索引 @en End index\n * @param map - @zh 地图实例 @en Map instance\n * @returns @zh 验证结果 @en Validation result\n */\n validatePath(\n path: readonly IPoint[],\n fromIndex: number,\n toIndex: number,\n map: IPathfindingMap\n ): IPathValidationResult;\n}\n\n// =============================================================================\n// 动态重规划配置 | Dynamic Replanning Configuration\n// =============================================================================\n\n/**\n * @zh 动态重规划配置\n * @en Dynamic replanning configuration\n */\nexport interface IReplanningConfig {\n /**\n * @zh 是否启用动态重规划\n * @en Whether dynamic replanning is enabled\n */\n enabled: boolean;\n\n /**\n * @zh 路径检查间隔(帧数)\n * @en Path check interval (in frames)\n */\n checkInterval: number;\n\n /**\n * @zh 触发重规划的距离阈值\n * @en Distance threshold to trigger replanning\n */\n distanceThreshold: number;\n\n /**\n * @zh 向前探测的距离(路径点数)\n * @en Lookahead distance (in path points)\n */\n lookaheadDistance: number;\n}\n\n/**\n * @zh 默认重规划配置\n * @en Default replanning configuration\n */\nexport const DEFAULT_REPLANNING_CONFIG: IReplanningConfig = {\n enabled: true,\n checkInterval: 10,\n distanceThreshold: 2,\n lookaheadDistance: 5\n};\n\n// =============================================================================\n// 空进度常量 | Empty Progress Constant\n// =============================================================================\n\n/**\n * @zh 空进度(用于无效请求)\n * @en Empty progress (for invalid requests)\n */\nexport const EMPTY_PROGRESS: IPathProgress = {\n state: PathfindingState.Idle,\n nodesSearched: 0,\n openListSize: 0,\n estimatedProgress: 0\n};\n"],"mappings":";AAeO,IAAKA,mBAAAA,0BAAAA,mBAAAA;AACsC,EAAAA,kBAAA,MAAA,IAAA;AAET,EAAAA,kBAAA,YAAA,IAAA;AAEd,EAAAA,kBAAA,QAAA,IAAA;AAEqB,EAAAA,kBAAA,WAAA,IAAA;AAEE,EAAAA,kBAAA,QAAA,IAAA;AAEpB,EAAAA,kBAAA,WAAA,IAAA;SAXlBA;;AAsVL,IAAMC,4BAA+C;EACxDC,SAAS;EACTC,eAAe;EACfC,mBAAmB;EACnBC,mBAAmB;AACvB;AAUO,IAAMC,iBAAgC;EACzCC,OAAK;EACLC,eAAe;EACfC,cAAc;EACdC,mBAAmB;AACvB;","names":["PathfindingState","DEFAULT_REPLANNING_CONFIG","enabled","checkInterval","distanceThreshold","lookaheadDistance","EMPTY_PROGRESS","state","nodesSearched","openListSize","estimatedProgress"]}
package/dist/ecs.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Component, EntitySystem, Entity } from '@esengine/ecs-framework';
2
2
  import { P as PathfindingState, e as IPoint, a as IPathfindingMap, f as IIncrementalPathfinder, m as IPathSmoother } from './IIncrementalPathfinding-3qs7e_pO.js';
3
+ import { O as ORCASolver, K as KDTree, b as IObstacle, c as IORCASolverConfig } from './KDTree-2rs2EXvm.js';
4
+ import '@esengine/ecs-framework-math';
3
5
 
4
6
  /**
5
7
  * @zh 寻路代理组件
@@ -500,4 +502,383 @@ declare class PathfindingSystem extends EntitySystem {
500
502
  private validatePaths;
501
503
  }
502
504
 
503
- export { PathfindingAgentComponent, PathfindingMapComponent, type PathfindingMapType, PathfindingSystem };
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 {
536
+ /**
537
+ * @zh 代理半径
538
+ * @en Agent radius
539
+ *
540
+ * @zh 用于碰撞检测和避让计算
541
+ * @en Used for collision detection and avoidance computation
542
+ */
543
+ radius: number;
544
+ /**
545
+ * @zh 最大速度
546
+ * @en Maximum speed
547
+ */
548
+ maxSpeed: number;
549
+ /**
550
+ * @zh 邻居检测距离
551
+ * @en Neighbor detection distance
552
+ *
553
+ * @zh 只考虑此范围内的其他代理
554
+ * @en Only considers other agents within this range
555
+ */
556
+ neighborDist: number;
557
+ /**
558
+ * @zh 最大邻居数量
559
+ * @en Maximum number of neighbors to consider
560
+ *
561
+ * @zh 限制计算量,优先考虑最近的邻居
562
+ * @en Limits computation, prioritizes closest neighbors
563
+ */
564
+ maxNeighbors: number;
565
+ /**
566
+ * @zh 代理避让时间视野(秒)
567
+ * @en Time horizon for agent avoidance (seconds)
568
+ *
569
+ * @zh 更大的值会让代理更早开始避让,但可能导致过于保守
570
+ * @en Larger values make agents start avoiding earlier, but may be too conservative
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
581
+ *
582
+ * @zh 如果实体有 Transform 组件,系统会自动同步
583
+ * @en If entity has Transform component, system will sync automatically
584
+ */
585
+ positionX: number;
586
+ /**
587
+ * @zh 当前位置 Y
588
+ * @en Current position Y
589
+ */
590
+ positionY: number;
591
+ /**
592
+ * @zh 当前速度 X
593
+ * @en Current velocity X
594
+ */
595
+ velocityX: number;
596
+ /**
597
+ * @zh 当前速度 Y
598
+ * @en Current velocity Y
599
+ */
600
+ velocityY: number;
601
+ /**
602
+ * @zh 首选速度 X(通常指向目标方向)
603
+ * @en Preferred velocity X (usually towards target)
604
+ */
605
+ preferredVelocityX: number;
606
+ /**
607
+ * @zh 首选速度 Y
608
+ * @en Preferred velocity Y
609
+ */
610
+ preferredVelocityY: number;
611
+ /**
612
+ * @zh ORCA 计算的新速度 X
613
+ * @en New velocity X computed by ORCA
614
+ */
615
+ newVelocityX: number;
616
+ /**
617
+ * @zh ORCA 计算的新速度 Y
618
+ * @en New velocity Y computed by ORCA
619
+ */
620
+ newVelocityY: number;
621
+ /**
622
+ * @zh 是否启用避让
623
+ * @en Whether avoidance is enabled
624
+ */
625
+ enabled: boolean;
626
+ /**
627
+ * @zh 是否自动应用新速度
628
+ * @en Whether to automatically apply new velocity
629
+ *
630
+ * @zh 如果为 true,系统会在计算后自动将 newVelocity 赋值给 velocity
631
+ * @en If true, system will automatically assign newVelocity to velocity after computation
632
+ */
633
+ autoApplyVelocity: boolean;
634
+ /**
635
+ * @zh 设置位置
636
+ * @en Set position
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
652
+ *
653
+ * @param targetX - @zh 目标 X @en Target X
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
687
+ */
688
+ onRemovedFromEntity(): void;
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;
727
+ /**
728
+ * @zh 默认时间视野(障碍物)
729
+ * @en Default time horizon for obstacles
730
+ */
731
+ defaultTimeHorizonObst: number;
732
+ /**
733
+ * @zh 时间步长
734
+ * @en Time step
735
+ */
736
+ timeStep: number;
737
+ /**
738
+ * @zh ORCA 求解器实例
739
+ * @en ORCA solver instance
740
+ */
741
+ solver: ORCASolver | null;
742
+ /**
743
+ * @zh KD-Tree 实例
744
+ * @en KD-Tree instance
745
+ */
746
+ kdTree: KDTree | null;
747
+ /**
748
+ * @zh 静态障碍物列表
749
+ * @en List of static obstacles
750
+ */
751
+ obstacles: IObstacle[];
752
+ /**
753
+ * @zh 是否已初始化
754
+ * @en Whether initialized
755
+ */
756
+ initialized: boolean;
757
+ /**
758
+ * @zh 当前代理数量
759
+ * @en Current agent count
760
+ */
761
+ agentCount: number;
762
+ /**
763
+ * @zh 本帧处理的代理数
764
+ * @en Agents processed this frame
765
+ */
766
+ agentsProcessedThisFrame: number;
767
+ /**
768
+ * @zh 本帧 ORCA 计算耗时(毫秒)
769
+ * @en ORCA computation time this frame (ms)
770
+ */
771
+ computeTimeMs: number;
772
+ /**
773
+ * @zh 获取 ORCA 配置
774
+ * @en Get ORCA configuration
775
+ */
776
+ getConfig(): IORCASolverConfig;
777
+ /**
778
+ * @zh 添加静态障碍物
779
+ * @en Add static obstacle
780
+ *
781
+ * @param obstacle - @zh 障碍物(顶点列表,逆时针顺序)@en Obstacle (vertex list, counter-clockwise)
782
+ */
783
+ addObstacle(obstacle: IObstacle): void;
784
+ /**
785
+ * @zh 添加矩形障碍物
786
+ * @en Add rectangular obstacle
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
792
+ */
793
+ addRectObstacle(x: number, y: number, width: number, height: number): void;
794
+ /**
795
+ * @zh 移除所有障碍物
796
+ * @en Remove all obstacles
797
+ */
798
+ clearObstacles(): void;
799
+ /**
800
+ * @zh 重置统计信息
801
+ * @en Reset statistics
802
+ */
803
+ resetStats(): void;
804
+ /**
805
+ * @zh 组件从实体移除时调用
806
+ * @en Called when component is removed from entity
807
+ */
808
+ onRemovedFromEntity(): void;
809
+ }
810
+
811
+ /**
812
+ * @zh 局部避让系统
813
+ * @en Local Avoidance System
814
+ */
815
+
816
+ /**
817
+ * @zh 局部避让系统
818
+ * @en Local Avoidance System
819
+ *
820
+ * @zh 使用 ORCA 算法计算代理的避让速度
821
+ * @en Uses ORCA algorithm to compute avoidance velocities for agents
822
+ *
823
+ * @example
824
+ * ```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());
838
+ *
839
+ * // 每帧设置首选速度(朝向目标)
840
+ * avoidance.setPreferredVelocityTowards(targetX, targetY);
841
+ *
842
+ * // 系统计算后,newVelocity 会被更新
843
+ * // 如果 autoApplyVelocity = true,velocity 也会自动更新
844
+ * ```
845
+ */
846
+ declare class LocalAvoidanceSystem extends EntitySystem {
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;
862
+ /**
863
+ * @zh 处理实体
864
+ * @en Process entities
865
+ */
866
+ protected process(entities: readonly Entity[]): void;
867
+ /**
868
+ * @zh 查找世界实体
869
+ * @en Find world entity
870
+ */
871
+ private findWorldEntity;
872
+ /**
873
+ * @zh 初始化求解器
874
+ * @en Initialize solver
875
+ */
876
+ private initializeSolver;
877
+ /**
878
+ * @zh 收集代理数据
879
+ * @en Collect agent data
880
+ */
881
+ private collectAgentData;
882
+ }
883
+
884
+ export { AvoidanceAgentComponent, AvoidanceWorldComponent, LocalAvoidanceSystem, PathfindingAgentComponent, PathfindingMapComponent, type PathfindingMapType, PathfindingSystem };