@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/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as IPathfinder, a as IPathfindingMap, b as IPathfindingOptions, c as IPathResult, H as HeuristicFunction, d as IPathNode, e as IPoint, f as
|
|
2
|
-
export { D as DEFAULT_PATHFINDING_OPTIONS,
|
|
3
|
-
export {
|
|
4
|
-
export { s as solveORCALinearProgram } from './
|
|
1
|
+
import { I as IPathfinder, a as IPathfindingMap, b as IPathfindingOptions, c as IPathResult, H as HeuristicFunction, d as IPathNode, e as IPoint, f as IPathValidator, g as IPathValidationResult, h as IPathSmoother } from './FlowController-Dc3nuLq5.js';
|
|
2
|
+
export { ap as CollisionResolverAdapter, ab as DEFAULT_FLOW_CONTROLLER_CONFIG, p as DEFAULT_HPA_CONFIG, ao as DEFAULT_ORCA_PARAMS, D as DEFAULT_PATHFINDING_OPTIONS, r as DEFAULT_PATH_CACHE_CONFIG, C as DEFAULT_REPLANNING_CONFIG, a9 as EMPTY_COLLISION_RESULT, E as EMPTY_PATH_RESULT, a8 as EMPTY_PLAN_RESULT, F as EMPTY_PROGRESS, ar as FlowController, ag as GridPathfinderAdapter, l as HPAPathfinder, Z as IAvoidanceAgentData, $ as IAvoidanceResult, a2 as ICollisionResolver, a3 as ICongestionZone, N as IDynamicObstacle, a4 as IFlowAgentData, a5 as IFlowControlResult, a7 as IFlowController, a6 as IFlowControllerConfig, au as IGridPathfinderAdapterConfig, t as IHPAConfig, av as IIncrementalGridPathPlannerConfig, W as IIncrementalPathPlanner, X as IIncrementalPathRequest, w as IIncrementalPathResult, x as IIncrementalPathfinder, z as IIncrementalPathfinderConfig, y as IIncrementalPathfindingOptions, a0 as ILocalAvoidance, a1 as INavCollisionResult, Y as INavPathProgress, K as INavPolygon, S as INavVector2, at as IORCAParams, _ as IObstacleData, s as IPathCacheConfig, U as IPathPlanOptions, T as IPathPlanResult, V as IPathPlanner, v as IPathProgress, u as IPathRequest, M as IPortal, A as IReplanningConfig, G as IncrementalAStarPathfinder, ak as IncrementalGridPathPlannerAdapter, L as LineOfSightCheck, Q as NavMesh, ae as NavMeshPathPlannerAdapter, am as ORCALocalAvoidanceAdapter, O as ObstacleType, aa as PassPermission, P as PathCache, ac as PathPlanState, B as PathfindingState, k as chebyshevDistance, ah as createAStarPlanner, aq as createDefaultCollisionResolver, as as createFlowController, n as createHPAPathfinder, aj as createHPAPlanner, J as createIncrementalAStarPathfinder, al as createIncrementalAStarPlanner, ai as createJPSPlanner, R as createNavMesh, af as createNavMeshPathPlanner, an as createORCAAvoidance, q as createPathCache, i as createPoint, j as euclideanDistance, ad as isIncrementalPlanner, m as manhattanDistance, o as octileDistance } from './FlowController-Dc3nuLq5.js';
|
|
3
|
+
export { C as CollisionResolver, j as DEFAULT_AGENT_PARAMS, k as DEFAULT_COLLISION_CONFIG, D as DEFAULT_ORCA_CONFIG, E as EMPTY_COLLISION, a as IAvoidanceAgent, i as ICollisionResolverConfig, h as ICollisionResult, f as INeighborResult, I as IORCALine, d as IORCAResult, e as IORCASolver, c as IORCASolverConfig, b as IObstacle, g as ISpatialIndex, l as createCollisionResolver } from './CollisionResolver-CSgWsegP.js';
|
|
4
|
+
export { K as KDTree, O as ORCASolver, a as createKDTree, c as createORCASolver, s as solveORCALinearProgram } from './KDTree-BRpn7O8K.js';
|
|
5
5
|
export { IVector2 } from '@esengine/ecs-framework-math';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -456,322 +456,6 @@ declare class GridPathfinder implements IPathfinder {
|
|
|
456
456
|
*/
|
|
457
457
|
declare function createGridPathfinder(map: GridMap, config?: IGridPathfinderConfig): GridPathfinder;
|
|
458
458
|
|
|
459
|
-
/**
|
|
460
|
-
* @zh 路径缓存模块
|
|
461
|
-
* @en Path Cache Module
|
|
462
|
-
*
|
|
463
|
-
* @zh 缓存已计算的路径,避免重复计算相同起点终点的路径
|
|
464
|
-
* @en Cache computed paths to avoid recalculating paths with the same start and end points
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* @zh 缓存配置
|
|
469
|
-
* @en Cache configuration
|
|
470
|
-
*/
|
|
471
|
-
interface IPathCacheConfig {
|
|
472
|
-
/**
|
|
473
|
-
* @zh 最大缓存条目数
|
|
474
|
-
* @en Maximum number of cache entries
|
|
475
|
-
*/
|
|
476
|
-
maxEntries: number;
|
|
477
|
-
/**
|
|
478
|
-
* @zh 缓存过期时间(毫秒),0 表示不过期
|
|
479
|
-
* @en Cache expiration time in milliseconds, 0 means no expiration
|
|
480
|
-
*/
|
|
481
|
-
ttlMs: number;
|
|
482
|
-
/**
|
|
483
|
-
* @zh 是否启用近似匹配(在一定范围内的起点/终点视为相同)
|
|
484
|
-
* @en Whether to enable approximate matching (start/end within range considered same)
|
|
485
|
-
*/
|
|
486
|
-
enableApproximateMatch: boolean;
|
|
487
|
-
/**
|
|
488
|
-
* @zh 近似匹配范围
|
|
489
|
-
* @en Approximate matching range
|
|
490
|
-
*/
|
|
491
|
-
approximateRange: number;
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* @zh 默认缓存配置
|
|
495
|
-
* @en Default cache configuration
|
|
496
|
-
*/
|
|
497
|
-
declare const DEFAULT_PATH_CACHE_CONFIG: IPathCacheConfig;
|
|
498
|
-
/**
|
|
499
|
-
* @zh 路径缓存
|
|
500
|
-
* @en Path Cache
|
|
501
|
-
*
|
|
502
|
-
* @zh 缓存已计算的路径,支持 LRU 淘汰策略和 TTL 过期
|
|
503
|
-
* @en Cache computed paths with LRU eviction and TTL expiration
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```typescript
|
|
507
|
-
* const cache = new PathCache({ maxEntries: 500 });
|
|
508
|
-
* const cached = cache.get(0, 0, 10, 10, mapVersion);
|
|
509
|
-
* if (!cached) {
|
|
510
|
-
* const result = pathfinder.findPath(0, 0, 10, 10);
|
|
511
|
-
* cache.set(0, 0, 10, 10, result, mapVersion);
|
|
512
|
-
* }
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
declare class PathCache {
|
|
516
|
-
private readonly config;
|
|
517
|
-
private readonly cache;
|
|
518
|
-
private readonly accessOrder;
|
|
519
|
-
constructor(config?: Partial<IPathCacheConfig>);
|
|
520
|
-
/**
|
|
521
|
-
* @zh 获取缓存的路径
|
|
522
|
-
* @en Get cached path
|
|
523
|
-
*
|
|
524
|
-
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
525
|
-
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
526
|
-
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
527
|
-
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
528
|
-
* @param mapVersion - @zh 地图版本号 @en Map version number
|
|
529
|
-
* @returns @zh 缓存的路径结果或 null @en Cached path result or null
|
|
530
|
-
*/
|
|
531
|
-
get(startX: number, startY: number, endX: number, endY: number, mapVersion: number): IPathResult | null;
|
|
532
|
-
/**
|
|
533
|
-
* @zh 设置缓存路径
|
|
534
|
-
* @en Set cached path
|
|
535
|
-
*
|
|
536
|
-
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
537
|
-
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
538
|
-
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
539
|
-
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
540
|
-
* @param result - @zh 路径结果 @en Path result
|
|
541
|
-
* @param mapVersion - @zh 地图版本号 @en Map version number
|
|
542
|
-
*/
|
|
543
|
-
set(startX: number, startY: number, endX: number, endY: number, result: IPathResult, mapVersion: number): void;
|
|
544
|
-
/**
|
|
545
|
-
* @zh 使所有缓存失效
|
|
546
|
-
* @en Invalidate all cache
|
|
547
|
-
*/
|
|
548
|
-
invalidateAll(): void;
|
|
549
|
-
/**
|
|
550
|
-
* @zh 使指定区域的缓存失效
|
|
551
|
-
* @en Invalidate cache for specified region
|
|
552
|
-
*
|
|
553
|
-
* @param minX - @zh 最小 X 坐标 @en Minimum X coordinate
|
|
554
|
-
* @param minY - @zh 最小 Y 坐标 @en Minimum Y coordinate
|
|
555
|
-
* @param maxX - @zh 最大 X 坐标 @en Maximum X coordinate
|
|
556
|
-
* @param maxY - @zh 最大 Y 坐标 @en Maximum Y coordinate
|
|
557
|
-
*/
|
|
558
|
-
invalidateRegion(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
559
|
-
/**
|
|
560
|
-
* @zh 获取缓存统计信息
|
|
561
|
-
* @en Get cache statistics
|
|
562
|
-
*/
|
|
563
|
-
getStats(): {
|
|
564
|
-
size: number;
|
|
565
|
-
maxSize: number;
|
|
566
|
-
hitRate?: number;
|
|
567
|
-
};
|
|
568
|
-
/**
|
|
569
|
-
* @zh 清理过期条目
|
|
570
|
-
* @en Clean up expired entries
|
|
571
|
-
*/
|
|
572
|
-
cleanup(): void;
|
|
573
|
-
private generateKey;
|
|
574
|
-
private isValid;
|
|
575
|
-
private getApproximate;
|
|
576
|
-
private adjustPathForApproximate;
|
|
577
|
-
private updateAccessOrder;
|
|
578
|
-
private removeFromAccessOrder;
|
|
579
|
-
private evictLRU;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* @zh 创建路径缓存
|
|
583
|
-
* @en Create path cache
|
|
584
|
-
*
|
|
585
|
-
* @param config - @zh 缓存配置 @en Cache configuration
|
|
586
|
-
* @returns @zh 路径缓存实例 @en Path cache instance
|
|
587
|
-
*/
|
|
588
|
-
declare function createPathCache(config?: Partial<IPathCacheConfig>): PathCache;
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* @zh 增量 A* 寻路算法实现
|
|
592
|
-
* @en Incremental A* Pathfinding Algorithm Implementation
|
|
593
|
-
*/
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* @zh 增量寻路器配置
|
|
597
|
-
* @en Incremental pathfinder configuration
|
|
598
|
-
*/
|
|
599
|
-
interface IIncrementalPathfinderConfig {
|
|
600
|
-
/**
|
|
601
|
-
* @zh 是否启用路径缓存
|
|
602
|
-
* @en Whether to enable path caching
|
|
603
|
-
*/
|
|
604
|
-
enableCache?: boolean;
|
|
605
|
-
/**
|
|
606
|
-
* @zh 缓存配置
|
|
607
|
-
* @en Cache configuration
|
|
608
|
-
*/
|
|
609
|
-
cacheConfig?: Partial<IPathCacheConfig>;
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* @zh 增量 A* 寻路器
|
|
613
|
-
* @en Incremental A* Pathfinder
|
|
614
|
-
*
|
|
615
|
-
* @zh 支持时间切片的 A* 算法实现,可跨多帧执行搜索
|
|
616
|
-
* @en A* algorithm implementation with time slicing, can execute search across multiple frames
|
|
617
|
-
*
|
|
618
|
-
* @example
|
|
619
|
-
* ```typescript
|
|
620
|
-
* const map = createGridMap(100, 100);
|
|
621
|
-
* const pathfinder = createIncrementalAStarPathfinder(map);
|
|
622
|
-
*
|
|
623
|
-
* // Request path (non-blocking)
|
|
624
|
-
* const request = pathfinder.requestPath(0, 0, 99, 99);
|
|
625
|
-
*
|
|
626
|
-
* // Process over multiple frames
|
|
627
|
-
* function gameLoop() {
|
|
628
|
-
* const progress = pathfinder.step(request.id, 100);
|
|
629
|
-
*
|
|
630
|
-
* if (progress.state === PathfindingState.Completed) {
|
|
631
|
-
* const result = pathfinder.getResult(request.id);
|
|
632
|
-
* console.log('Path found:', result?.path);
|
|
633
|
-
* } else if (progress.state === PathfindingState.InProgress) {
|
|
634
|
-
* requestAnimationFrame(gameLoop);
|
|
635
|
-
* }
|
|
636
|
-
* }
|
|
637
|
-
* gameLoop();
|
|
638
|
-
* ```
|
|
639
|
-
*/
|
|
640
|
-
declare class IncrementalAStarPathfinder implements IIncrementalPathfinder {
|
|
641
|
-
private readonly map;
|
|
642
|
-
private readonly sessions;
|
|
643
|
-
private nextRequestId;
|
|
644
|
-
private readonly affectedRegions;
|
|
645
|
-
private readonly maxRegionAge;
|
|
646
|
-
private readonly cache;
|
|
647
|
-
private readonly enableCache;
|
|
648
|
-
private mapVersion;
|
|
649
|
-
private cacheHits;
|
|
650
|
-
private cacheMisses;
|
|
651
|
-
/**
|
|
652
|
-
* @zh 创建增量 A* 寻路器
|
|
653
|
-
* @en Create incremental A* pathfinder
|
|
654
|
-
*
|
|
655
|
-
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
656
|
-
* @param config - @zh 配置选项 @en Configuration options
|
|
657
|
-
*/
|
|
658
|
-
constructor(map: IPathfindingMap, config?: IIncrementalPathfinderConfig);
|
|
659
|
-
/**
|
|
660
|
-
* @zh 请求寻路(非阻塞)
|
|
661
|
-
* @en Request pathfinding (non-blocking)
|
|
662
|
-
*/
|
|
663
|
-
requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
|
|
664
|
-
/**
|
|
665
|
-
* @zh 执行一步搜索
|
|
666
|
-
* @en Execute one step of search
|
|
667
|
-
*/
|
|
668
|
-
step(requestId: number, maxIterations: number): IPathProgress;
|
|
669
|
-
/**
|
|
670
|
-
* @zh 暂停寻路
|
|
671
|
-
* @en Pause pathfinding
|
|
672
|
-
*/
|
|
673
|
-
pause(requestId: number): void;
|
|
674
|
-
/**
|
|
675
|
-
* @zh 恢复寻路
|
|
676
|
-
* @en Resume pathfinding
|
|
677
|
-
*/
|
|
678
|
-
resume(requestId: number): void;
|
|
679
|
-
/**
|
|
680
|
-
* @zh 取消寻路
|
|
681
|
-
* @en Cancel pathfinding
|
|
682
|
-
*/
|
|
683
|
-
cancel(requestId: number): void;
|
|
684
|
-
/**
|
|
685
|
-
* @zh 获取寻路结果
|
|
686
|
-
* @en Get pathfinding result
|
|
687
|
-
*/
|
|
688
|
-
getResult(requestId: number): IIncrementalPathResult | null;
|
|
689
|
-
/**
|
|
690
|
-
* @zh 获取当前进度
|
|
691
|
-
* @en Get current progress
|
|
692
|
-
*/
|
|
693
|
-
getProgress(requestId: number): IPathProgress | null;
|
|
694
|
-
/**
|
|
695
|
-
* @zh 清理已完成的请求
|
|
696
|
-
* @en Clean up completed request
|
|
697
|
-
*/
|
|
698
|
-
cleanup(requestId: number): void;
|
|
699
|
-
/**
|
|
700
|
-
* @zh 通知障碍物变化
|
|
701
|
-
* @en Notify obstacle change
|
|
702
|
-
*/
|
|
703
|
-
notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
704
|
-
/**
|
|
705
|
-
* @zh 清理所有请求
|
|
706
|
-
* @en Clear all requests
|
|
707
|
-
*/
|
|
708
|
-
clear(): void;
|
|
709
|
-
/**
|
|
710
|
-
* @zh 清空路径缓存
|
|
711
|
-
* @en Clear path cache
|
|
712
|
-
*/
|
|
713
|
-
clearCache(): void;
|
|
714
|
-
/**
|
|
715
|
-
* @zh 获取缓存统计信息
|
|
716
|
-
* @en Get cache statistics
|
|
717
|
-
*/
|
|
718
|
-
getCacheStats(): {
|
|
719
|
-
enabled: boolean;
|
|
720
|
-
hits: number;
|
|
721
|
-
misses: number;
|
|
722
|
-
hitRate: number;
|
|
723
|
-
size: number;
|
|
724
|
-
};
|
|
725
|
-
/**
|
|
726
|
-
* @zh 检查会话是否被障碍物变化影响
|
|
727
|
-
* @en Check if session is affected by obstacle change
|
|
728
|
-
*/
|
|
729
|
-
isAffectedByChange(requestId: number): boolean;
|
|
730
|
-
/**
|
|
731
|
-
* @zh 清除会话的变化标记
|
|
732
|
-
* @en Clear session's change flag
|
|
733
|
-
*/
|
|
734
|
-
clearChangeFlag(requestId: number): void;
|
|
735
|
-
/**
|
|
736
|
-
* @zh 展开邻居节点
|
|
737
|
-
* @en Expand neighbor nodes
|
|
738
|
-
*/
|
|
739
|
-
private expandNeighbors;
|
|
740
|
-
/**
|
|
741
|
-
* @zh 创建进度对象
|
|
742
|
-
* @en Create progress object
|
|
743
|
-
*/
|
|
744
|
-
private createProgress;
|
|
745
|
-
/**
|
|
746
|
-
* @zh 构建路径结果
|
|
747
|
-
* @en Build path result
|
|
748
|
-
*/
|
|
749
|
-
private buildResult;
|
|
750
|
-
/**
|
|
751
|
-
* @zh 创建空结果
|
|
752
|
-
* @en Create empty result
|
|
753
|
-
*/
|
|
754
|
-
private createEmptyResult;
|
|
755
|
-
/**
|
|
756
|
-
* @zh 检查会话是否被区域影响
|
|
757
|
-
* @en Check if session is affected by region
|
|
758
|
-
*/
|
|
759
|
-
private sessionAffectedByRegion;
|
|
760
|
-
/**
|
|
761
|
-
* @zh 清理过期的变化区域
|
|
762
|
-
* @en Clean up expired change regions
|
|
763
|
-
*/
|
|
764
|
-
private cleanupOldRegions;
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* @zh 创建增量 A* 寻路器
|
|
768
|
-
* @en Create incremental A* pathfinder
|
|
769
|
-
*
|
|
770
|
-
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
771
|
-
* @returns @zh 增量 A* 寻路器实例 @en Incremental A* pathfinder instance
|
|
772
|
-
*/
|
|
773
|
-
declare function createIncrementalAStarPathfinder(map: IPathfindingMap): IncrementalAStarPathfinder;
|
|
774
|
-
|
|
775
459
|
/**
|
|
776
460
|
* @zh 路径验证器
|
|
777
461
|
* @en Path Validator
|
|
@@ -1069,296 +753,6 @@ declare class JPSPathfinder implements IPathfinder {
|
|
|
1069
753
|
*/
|
|
1070
754
|
declare function createJPSPathfinder(map: IPathfindingMap): JPSPathfinder;
|
|
1071
755
|
|
|
1072
|
-
/**
|
|
1073
|
-
* @zh HPA* (Hierarchical Pathfinding A*) 寻路算法实现
|
|
1074
|
-
* @en HPA* (Hierarchical Pathfinding A*) Pathfinding Algorithm Implementation
|
|
1075
|
-
*
|
|
1076
|
-
* @zh HPA* 是一种分层寻路算法,适用于超大地图 (1000x1000+)
|
|
1077
|
-
* @en HPA* is a hierarchical pathfinding algorithm suitable for very large maps (1000x1000+)
|
|
1078
|
-
*
|
|
1079
|
-
* @zh 工作原理:
|
|
1080
|
-
* 1. 将地图划分为集群 (clusters)
|
|
1081
|
-
* 2. 在集群边界检测入口点 (entrances)
|
|
1082
|
-
* 3. 构建抽象图 (abstract graph) 连接入口点
|
|
1083
|
-
* 4. 先在抽象图上寻路,再细化为详细路径
|
|
1084
|
-
*
|
|
1085
|
-
* @en How it works:
|
|
1086
|
-
* 1. Divide map into clusters
|
|
1087
|
-
* 2. Detect entrances at cluster boundaries
|
|
1088
|
-
* 3. Build abstract graph connecting entrances
|
|
1089
|
-
* 4. First find path on abstract graph, then refine to detailed path
|
|
1090
|
-
*/
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* @zh HPA* 配置
|
|
1094
|
-
* @en HPA* Configuration
|
|
1095
|
-
*/
|
|
1096
|
-
interface IHPAConfig {
|
|
1097
|
-
/**
|
|
1098
|
-
* @zh 集群大小(边长)
|
|
1099
|
-
* @en Cluster size (side length)
|
|
1100
|
-
*/
|
|
1101
|
-
clusterSize: number;
|
|
1102
|
-
/**
|
|
1103
|
-
* @zh 最大入口宽度(超过此宽度会拆分为多个入口)
|
|
1104
|
-
* @en Maximum entrance width (entrances wider than this will be split)
|
|
1105
|
-
*/
|
|
1106
|
-
maxEntranceWidth: number;
|
|
1107
|
-
/**
|
|
1108
|
-
* @zh 是否启用内部路径缓存
|
|
1109
|
-
* @en Whether to enable internal path caching
|
|
1110
|
-
*/
|
|
1111
|
-
cacheInternalPaths: boolean;
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* @zh 默认 HPA* 配置
|
|
1115
|
-
* @en Default HPA* configuration
|
|
1116
|
-
*/
|
|
1117
|
-
declare const DEFAULT_HPA_CONFIG: IHPAConfig;
|
|
1118
|
-
/**
|
|
1119
|
-
* @zh HPA* 寻路器
|
|
1120
|
-
* @en HPA* Pathfinder
|
|
1121
|
-
*
|
|
1122
|
-
* @zh 适用于超大地图的分层寻路算法
|
|
1123
|
-
* @en Hierarchical pathfinding algorithm for very large maps
|
|
1124
|
-
*
|
|
1125
|
-
* @example
|
|
1126
|
-
* ```typescript
|
|
1127
|
-
* const map = createGridMap(1000, 1000);
|
|
1128
|
-
* const pathfinder = new HPAPathfinder(map, { clusterSize: 20 });
|
|
1129
|
-
*
|
|
1130
|
-
* // Preprocess (do once after map changes)
|
|
1131
|
-
* pathfinder.preprocess();
|
|
1132
|
-
*
|
|
1133
|
-
* // Find path
|
|
1134
|
-
* const result = pathfinder.findPath(0, 0, 999, 999);
|
|
1135
|
-
* ```
|
|
1136
|
-
*/
|
|
1137
|
-
declare class HPAPathfinder implements IPathfinder {
|
|
1138
|
-
private readonly map;
|
|
1139
|
-
private readonly config;
|
|
1140
|
-
private readonly width;
|
|
1141
|
-
private readonly height;
|
|
1142
|
-
private clusters;
|
|
1143
|
-
private entrances;
|
|
1144
|
-
private abstractNodes;
|
|
1145
|
-
private clusterGrid;
|
|
1146
|
-
private nextEntranceId;
|
|
1147
|
-
private nextNodeId;
|
|
1148
|
-
private internalPathCache;
|
|
1149
|
-
private localPathfinder;
|
|
1150
|
-
private preprocessed;
|
|
1151
|
-
constructor(map: IPathfindingMap, config?: Partial<IHPAConfig>);
|
|
1152
|
-
/**
|
|
1153
|
-
* @zh 预处理地图(构建抽象图)
|
|
1154
|
-
* @en Preprocess map (build abstract graph)
|
|
1155
|
-
*
|
|
1156
|
-
* @zh 在地图变化后需要重新调用
|
|
1157
|
-
* @en Need to call again after map changes
|
|
1158
|
-
*/
|
|
1159
|
-
preprocess(): void;
|
|
1160
|
-
/**
|
|
1161
|
-
* @zh 寻找路径
|
|
1162
|
-
* @en Find path
|
|
1163
|
-
*/
|
|
1164
|
-
findPath(startX: number, startY: number, endX: number, endY: number, options?: Partial<IPathfindingOptions>): IPathResult;
|
|
1165
|
-
/**
|
|
1166
|
-
* @zh 清理状态
|
|
1167
|
-
* @en Clear state
|
|
1168
|
-
*/
|
|
1169
|
-
clear(): void;
|
|
1170
|
-
/**
|
|
1171
|
-
* @zh 通知地图区域变化
|
|
1172
|
-
* @en Notify map region change
|
|
1173
|
-
*/
|
|
1174
|
-
notifyRegionChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
1175
|
-
/**
|
|
1176
|
-
* @zh 获取预处理统计信息
|
|
1177
|
-
* @en Get preprocessing statistics
|
|
1178
|
-
*/
|
|
1179
|
-
getStats(): {
|
|
1180
|
-
clusters: number;
|
|
1181
|
-
entrances: number;
|
|
1182
|
-
abstractNodes: number;
|
|
1183
|
-
cacheSize: number;
|
|
1184
|
-
};
|
|
1185
|
-
private getMapBounds;
|
|
1186
|
-
private buildClusters;
|
|
1187
|
-
private findEntrances;
|
|
1188
|
-
private findEntrancesBetween;
|
|
1189
|
-
private createEntrance;
|
|
1190
|
-
private buildAbstractGraph;
|
|
1191
|
-
private createAbstractNode;
|
|
1192
|
-
private connectIntraClusterNodes;
|
|
1193
|
-
private getClusterAt;
|
|
1194
|
-
private insertTemporaryNode;
|
|
1195
|
-
private removeTemporaryNodes;
|
|
1196
|
-
private searchAbstractGraph;
|
|
1197
|
-
private reconstructAbstractPath;
|
|
1198
|
-
private refinePath;
|
|
1199
|
-
private findLocalPath;
|
|
1200
|
-
private findInternalPath;
|
|
1201
|
-
private calculatePathCost;
|
|
1202
|
-
private heuristic;
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* @zh 创建 HPA* 寻路器
|
|
1206
|
-
* @en Create HPA* pathfinder
|
|
1207
|
-
*
|
|
1208
|
-
* @param map - @zh 寻路地图实例 @en Pathfinding map instance
|
|
1209
|
-
* @param config - @zh HPA* 配置 @en HPA* configuration
|
|
1210
|
-
* @returns @zh HPA* 寻路器实例 @en HPA* pathfinder instance
|
|
1211
|
-
*/
|
|
1212
|
-
declare function createHPAPathfinder(map: IPathfindingMap, config?: Partial<IHPAConfig>): HPAPathfinder;
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* @zh 导航网格实现
|
|
1216
|
-
* @en NavMesh Implementation
|
|
1217
|
-
*/
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* @zh 导航多边形
|
|
1221
|
-
* @en Navigation polygon
|
|
1222
|
-
*/
|
|
1223
|
-
interface INavPolygon {
|
|
1224
|
-
/** @zh 多边形ID @en Polygon ID */
|
|
1225
|
-
readonly id: number;
|
|
1226
|
-
/** @zh 顶点列表 @en Vertex list */
|
|
1227
|
-
readonly vertices: readonly IPoint[];
|
|
1228
|
-
/** @zh 中心点 @en Center point */
|
|
1229
|
-
readonly center: IPoint;
|
|
1230
|
-
/** @zh 邻居多边形ID @en Neighbor polygon IDs */
|
|
1231
|
-
readonly neighbors: readonly number[];
|
|
1232
|
-
/** @zh 到邻居的共享边 @en Shared edges to neighbors */
|
|
1233
|
-
readonly portals: ReadonlyMap<number, IPortal>;
|
|
1234
|
-
}
|
|
1235
|
-
/**
|
|
1236
|
-
* @zh 入口(两个多边形之间的共享边)
|
|
1237
|
-
* @en Portal (shared edge between two polygons)
|
|
1238
|
-
*/
|
|
1239
|
-
interface IPortal {
|
|
1240
|
-
/** @zh 边的左端点 @en Left endpoint of edge */
|
|
1241
|
-
readonly left: IPoint;
|
|
1242
|
-
/** @zh 边的右端点 @en Right endpoint of edge */
|
|
1243
|
-
readonly right: IPoint;
|
|
1244
|
-
}
|
|
1245
|
-
/**
|
|
1246
|
-
* @zh 导航网格
|
|
1247
|
-
* @en Navigation Mesh
|
|
1248
|
-
*
|
|
1249
|
-
* @zh 使用凸多边形网格进行高效寻路,适合复杂地形
|
|
1250
|
-
* @en Uses convex polygon mesh for efficient pathfinding, suitable for complex terrain
|
|
1251
|
-
*
|
|
1252
|
-
* @example
|
|
1253
|
-
* ```typescript
|
|
1254
|
-
* const navmesh = new NavMesh();
|
|
1255
|
-
*
|
|
1256
|
-
* // Add polygons
|
|
1257
|
-
* navmesh.addPolygon([
|
|
1258
|
-
* { x: 0, y: 0 }, { x: 10, y: 0 },
|
|
1259
|
-
* { x: 10, y: 10 }, { x: 0, y: 10 }
|
|
1260
|
-
* ]);
|
|
1261
|
-
*
|
|
1262
|
-
* // Build connections
|
|
1263
|
-
* navmesh.build();
|
|
1264
|
-
*
|
|
1265
|
-
* // Find path
|
|
1266
|
-
* const result = navmesh.findPath(1, 1, 8, 8);
|
|
1267
|
-
* ```
|
|
1268
|
-
*/
|
|
1269
|
-
declare class NavMesh implements IPathfindingMap {
|
|
1270
|
-
private polygons;
|
|
1271
|
-
private nodes;
|
|
1272
|
-
private nextId;
|
|
1273
|
-
/**
|
|
1274
|
-
* @zh 添加导航多边形
|
|
1275
|
-
* @en Add navigation polygon
|
|
1276
|
-
*
|
|
1277
|
-
* @returns @zh 多边形ID @en Polygon ID
|
|
1278
|
-
*/
|
|
1279
|
-
addPolygon(vertices: IPoint[], neighbors?: number[]): number;
|
|
1280
|
-
/**
|
|
1281
|
-
* @zh 设置两个多边形之间的连接
|
|
1282
|
-
* @en Set connection between two polygons
|
|
1283
|
-
*/
|
|
1284
|
-
setConnection(polyA: number, polyB: number, portal: IPortal): void;
|
|
1285
|
-
/**
|
|
1286
|
-
* @zh 自动检测并建立相邻多边形的连接
|
|
1287
|
-
* @en Auto-detect and build connections between adjacent polygons
|
|
1288
|
-
*/
|
|
1289
|
-
build(): void;
|
|
1290
|
-
/**
|
|
1291
|
-
* @zh 查找两个多边形的共享边
|
|
1292
|
-
* @en Find shared edge between two polygons
|
|
1293
|
-
*/
|
|
1294
|
-
private findSharedEdge;
|
|
1295
|
-
/**
|
|
1296
|
-
* @zh 计算多边形中心
|
|
1297
|
-
* @en Calculate polygon center
|
|
1298
|
-
*/
|
|
1299
|
-
private calculateCenter;
|
|
1300
|
-
/**
|
|
1301
|
-
* @zh 查找包含点的多边形
|
|
1302
|
-
* @en Find polygon containing point
|
|
1303
|
-
*/
|
|
1304
|
-
findPolygonAt(x: number, y: number): INavPolygon | null;
|
|
1305
|
-
/**
|
|
1306
|
-
* @zh 检查点是否在多边形内
|
|
1307
|
-
* @en Check if point is inside polygon
|
|
1308
|
-
*/
|
|
1309
|
-
private isPointInPolygon;
|
|
1310
|
-
getNodeAt(x: number, y: number): IPathNode | null;
|
|
1311
|
-
getNeighbors(node: IPathNode): IPathNode[];
|
|
1312
|
-
heuristic(a: IPoint, b: IPoint): number;
|
|
1313
|
-
getMovementCost(from: IPathNode, to: IPathNode): number;
|
|
1314
|
-
isWalkable(x: number, y: number): boolean;
|
|
1315
|
-
/**
|
|
1316
|
-
* @zh 在导航网格上寻路
|
|
1317
|
-
* @en Find path on navigation mesh
|
|
1318
|
-
*/
|
|
1319
|
-
findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
|
|
1320
|
-
/**
|
|
1321
|
-
* @zh 在多边形图上寻路
|
|
1322
|
-
* @en Find path on polygon graph
|
|
1323
|
-
*/
|
|
1324
|
-
private findPolygonPath;
|
|
1325
|
-
/**
|
|
1326
|
-
* @zh 使用漏斗算法优化路径
|
|
1327
|
-
* @en Optimize path using funnel algorithm
|
|
1328
|
-
*/
|
|
1329
|
-
private funnelPath;
|
|
1330
|
-
/**
|
|
1331
|
-
* @zh 计算三角形面积的两倍(用于判断点的相对位置)
|
|
1332
|
-
* @en Calculate twice the triangle area (for point relative position)
|
|
1333
|
-
*/
|
|
1334
|
-
private triArea2;
|
|
1335
|
-
/**
|
|
1336
|
-
* @zh 计算路径总长度
|
|
1337
|
-
* @en Calculate total path length
|
|
1338
|
-
*/
|
|
1339
|
-
private calculatePathLength;
|
|
1340
|
-
/**
|
|
1341
|
-
* @zh 清空导航网格
|
|
1342
|
-
* @en Clear navigation mesh
|
|
1343
|
-
*/
|
|
1344
|
-
clear(): void;
|
|
1345
|
-
/**
|
|
1346
|
-
* @zh 获取所有多边形
|
|
1347
|
-
* @en Get all polygons
|
|
1348
|
-
*/
|
|
1349
|
-
getPolygons(): INavPolygon[];
|
|
1350
|
-
/**
|
|
1351
|
-
* @zh 获取多边形数量
|
|
1352
|
-
* @en Get polygon count
|
|
1353
|
-
*/
|
|
1354
|
-
get polygonCount(): number;
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* @zh 创建导航网格
|
|
1358
|
-
* @en Create navigation mesh
|
|
1359
|
-
*/
|
|
1360
|
-
declare function createNavMesh(): NavMesh;
|
|
1361
|
-
|
|
1362
756
|
/**
|
|
1363
757
|
* @zh 路径平滑算法
|
|
1364
758
|
* @en Path Smoothing Algorithms
|
|
@@ -1434,4 +828,152 @@ declare function createCatmullRomSmoother(segments?: number, tension?: number):
|
|
|
1434
828
|
*/
|
|
1435
829
|
declare function createCombinedSmoother(curveSegments?: number, tension?: number): CombinedSmoother;
|
|
1436
830
|
|
|
1437
|
-
|
|
831
|
+
/**
|
|
832
|
+
* @zh 半径感知路径平滑器
|
|
833
|
+
* @en Radius-Aware Path Smoother
|
|
834
|
+
*
|
|
835
|
+
* @zh 通用的路径后处理器,确保路径与障碍物保持安全距离
|
|
836
|
+
* @en Generic path post-processor that ensures paths maintain safe distance from obstacles
|
|
837
|
+
*/
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* @zh 半径感知平滑器配置
|
|
841
|
+
* @en Radius-aware smoother configuration
|
|
842
|
+
*/
|
|
843
|
+
interface IRadiusAwareSmootherConfig {
|
|
844
|
+
/**
|
|
845
|
+
* @zh 代理半径
|
|
846
|
+
* @en Agent radius
|
|
847
|
+
*/
|
|
848
|
+
agentRadius: number;
|
|
849
|
+
/**
|
|
850
|
+
* @zh 额外安全边距
|
|
851
|
+
* @en Extra safety margin
|
|
852
|
+
* @default 0.1
|
|
853
|
+
*/
|
|
854
|
+
safetyMargin?: number;
|
|
855
|
+
/**
|
|
856
|
+
* @zh 采样方向数量(用于检测周围障碍物)
|
|
857
|
+
* @en Number of sample directions (for detecting nearby obstacles)
|
|
858
|
+
* @default 8
|
|
859
|
+
*/
|
|
860
|
+
sampleDirections?: number;
|
|
861
|
+
/**
|
|
862
|
+
* @zh 最大偏移尝试次数
|
|
863
|
+
* @en Maximum offset attempts
|
|
864
|
+
* @default 8
|
|
865
|
+
*/
|
|
866
|
+
maxOffsetAttempts?: number;
|
|
867
|
+
/**
|
|
868
|
+
* @zh 是否处理拐点(角落)
|
|
869
|
+
* @en Whether to process turning points (corners)
|
|
870
|
+
* @default true
|
|
871
|
+
*/
|
|
872
|
+
processCorners?: boolean;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* @zh 半径感知路径平滑器
|
|
876
|
+
* @en Radius-Aware Path Smoother
|
|
877
|
+
*
|
|
878
|
+
* @zh 对任意寻路算法输出的路径进行后处理,确保路径点与障碍物保持足够距离
|
|
879
|
+
* @en Post-processes paths from any pathfinding algorithm to ensure path points maintain sufficient distance from obstacles
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```typescript
|
|
883
|
+
* // 创建平滑器
|
|
884
|
+
* const smoother = new RadiusAwarePathSmoother({ agentRadius: 0.5 });
|
|
885
|
+
*
|
|
886
|
+
* // 处理路径
|
|
887
|
+
* const safePath = smoother.smooth(rawPath, map);
|
|
888
|
+
*
|
|
889
|
+
* // 与其他平滑器组合使用
|
|
890
|
+
* const combined = new CombinedRadiusAwareSmoother(
|
|
891
|
+
* new LineOfSightSmoother(),
|
|
892
|
+
* { agentRadius: 0.5 }
|
|
893
|
+
* );
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
declare class RadiusAwarePathSmoother implements IPathSmoother {
|
|
897
|
+
private readonly config;
|
|
898
|
+
private readonly sampleAngles;
|
|
899
|
+
constructor(config: IRadiusAwareSmootherConfig);
|
|
900
|
+
/**
|
|
901
|
+
* @zh 平滑路径,确保与障碍物保持安全距离
|
|
902
|
+
* @en Smooth path, ensuring safe distance from obstacles
|
|
903
|
+
*
|
|
904
|
+
* @param path - @zh 原始路径 @en Original path
|
|
905
|
+
* @param map - @zh 地图 @en Map
|
|
906
|
+
* @returns @zh 处理后的安全路径 @en Processed safe path
|
|
907
|
+
*/
|
|
908
|
+
smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
|
|
909
|
+
/**
|
|
910
|
+
* @zh 将点从障碍物偏移
|
|
911
|
+
* @en Offset point away from obstacles
|
|
912
|
+
*/
|
|
913
|
+
private offsetPointFromObstacles;
|
|
914
|
+
/**
|
|
915
|
+
* @zh 偏移拐点(角落)
|
|
916
|
+
* @en Offset corner point
|
|
917
|
+
*/
|
|
918
|
+
private offsetCornerPoint;
|
|
919
|
+
/**
|
|
920
|
+
* @zh 检测附近的障碍物方向
|
|
921
|
+
* @en Detect nearby obstacle directions
|
|
922
|
+
*/
|
|
923
|
+
private detectNearbyObstacles;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* @zh 组合半径感知平滑器
|
|
927
|
+
* @en Combined radius-aware smoother
|
|
928
|
+
*
|
|
929
|
+
* @zh 先使用其他平滑器(如 LOS、Catmull-Rom),再应用半径感知处理
|
|
930
|
+
* @en First applies other smoother (like LOS, Catmull-Rom), then applies radius-aware processing
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```typescript
|
|
934
|
+
* const smoother = new CombinedRadiusAwareSmoother(
|
|
935
|
+
* new LineOfSightSmoother(),
|
|
936
|
+
* { agentRadius: 0.5 }
|
|
937
|
+
* );
|
|
938
|
+
* const path = smoother.smooth(rawPath, map);
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
declare class CombinedRadiusAwareSmoother implements IPathSmoother {
|
|
942
|
+
private readonly baseSmoother;
|
|
943
|
+
private readonly radiusAwareSmoother;
|
|
944
|
+
constructor(baseSmoother: IPathSmoother, config: IRadiusAwareSmootherConfig);
|
|
945
|
+
smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* @zh 创建半径感知平滑器
|
|
949
|
+
* @en Create radius-aware smoother
|
|
950
|
+
*
|
|
951
|
+
* @param agentRadius - @zh 代理半径 @en Agent radius
|
|
952
|
+
* @param options - @zh 额外配置 @en Additional options
|
|
953
|
+
*
|
|
954
|
+
* @example
|
|
955
|
+
* ```typescript
|
|
956
|
+
* const smoother = createRadiusAwareSmoother(0.5);
|
|
957
|
+
* const safePath = smoother.smooth(path, map);
|
|
958
|
+
* ```
|
|
959
|
+
*/
|
|
960
|
+
declare function createRadiusAwareSmoother(agentRadius: number, options?: Omit<IRadiusAwareSmootherConfig, 'agentRadius'>): RadiusAwarePathSmoother;
|
|
961
|
+
/**
|
|
962
|
+
* @zh 创建组合半径感知平滑器
|
|
963
|
+
* @en Create combined radius-aware smoother
|
|
964
|
+
*
|
|
965
|
+
* @param baseSmoother - @zh 基础平滑器 @en Base smoother
|
|
966
|
+
* @param agentRadius - @zh 代理半径 @en Agent radius
|
|
967
|
+
* @param options - @zh 额外配置 @en Additional options
|
|
968
|
+
*
|
|
969
|
+
* @example
|
|
970
|
+
* ```typescript
|
|
971
|
+
* const smoother = createCombinedRadiusAwareSmoother(
|
|
972
|
+
* new LineOfSightSmoother(),
|
|
973
|
+
* 0.5
|
|
974
|
+
* );
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
977
|
+
declare function createCombinedRadiusAwareSmoother(baseSmoother: IPathSmoother, agentRadius: number, options?: Omit<IRadiusAwareSmootherConfig, 'agentRadius'>): CombinedRadiusAwareSmoother;
|
|
978
|
+
|
|
979
|
+
export { AStarPathfinder, BinaryHeap, CatmullRomSmoother, CombinedRadiusAwareSmoother, CombinedSmoother, DEFAULT_GRID_OPTIONS, DIRECTIONS_4, DIRECTIONS_8, GridMap, GridNode, GridPathfinder, type GridPathfinderMode, HeuristicFunction, type IChangeRegion, type IGridMapOptions, type IGridPathfinderConfig, type IHeapIndexable, type IObstacleChange, IPathNode, IPathResult, IPathSmoother, IPathValidationResult, IPathValidator, IPathfinder, IPathfindingMap, IPathfindingOptions, IPoint, type IRadiusAwareSmootherConfig, IndexedBinaryHeap, JPSPathfinder, LineOfSightSmoother, ObstacleChangeManager, PathValidator, RadiusAwarePathSmoother, bresenhamLineOfSight, createAStarPathfinder, createCatmullRomSmoother, createCombinedRadiusAwareSmoother, createCombinedSmoother, createGridMap, createGridPathfinder, createJPSPathfinder, createLineOfSightSmoother, createObstacleChangeManager, createPathValidator, createRadiusAwareSmoother, raycastLineOfSight };
|