@esengine/pathfinding 12.1.2 → 13.0.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/{IIncrementalPathfinding-3qs7e_pO.d.ts → KDTree-Bw4Faf2O.d.ts} +371 -1
- package/dist/{chunk-TPT7Q3E3.js → chunk-OA7ZZQMH.js} +906 -2
- package/dist/chunk-OA7ZZQMH.js.map +1 -0
- package/dist/ecs.d.ts +382 -2
- package/dist/ecs.js +687 -2
- package/dist/ecs.js.map +1 -1
- package/dist/index.d.ts +28 -3
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-TPT7Q3E3.js.map +0 -1
package/dist/ecs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, EntitySystem, Entity } from '@esengine/ecs-framework';
|
|
2
|
-
import { P as PathfindingState, e as IPoint, a as IPathfindingMap, f as IIncrementalPathfinder, m as IPathSmoother } from './
|
|
2
|
+
import { P as PathfindingState, e as IPoint, a as IPathfindingMap, f as IIncrementalPathfinder, m as IPathSmoother, O as ORCASolver, K as KDTree, x as IObstacle, y as IORCASolverConfig } from './KDTree-Bw4Faf2O.js';
|
|
3
|
+
import '@esengine/ecs-framework-math';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @zh 寻路代理组件
|
|
@@ -500,4 +501,383 @@ declare class PathfindingSystem extends EntitySystem {
|
|
|
500
501
|
private validatePaths;
|
|
501
502
|
}
|
|
502
503
|
|
|
503
|
-
|
|
504
|
+
/**
|
|
505
|
+
* @zh 避让代理组件
|
|
506
|
+
* @en Avoidance Agent Component
|
|
507
|
+
*/
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* @zh 避让代理组件
|
|
511
|
+
* @en Avoidance Agent Component
|
|
512
|
+
*
|
|
513
|
+
* @zh 附加到需要局部避让的实体上,与 ORCA 系统配合使用
|
|
514
|
+
* @en Attach to entities that need local avoidance, works with ORCA system
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const entity = scene.createEntity('Monster');
|
|
519
|
+
*
|
|
520
|
+
* // 添加避让代理
|
|
521
|
+
* const avoidance = entity.addComponent(new AvoidanceAgentComponent());
|
|
522
|
+
* avoidance.radius = 0.5;
|
|
523
|
+
* avoidance.maxSpeed = 5.0;
|
|
524
|
+
*
|
|
525
|
+
* // 设置首选速度(朝向目标)
|
|
526
|
+
* avoidance.setPreferredVelocityTowards(targetX, targetY, currentX, currentY);
|
|
527
|
+
*
|
|
528
|
+
* // 系统计算后,使用新速度更新位置
|
|
529
|
+
* // After system computes, use new velocity to update position
|
|
530
|
+
* x += avoidance.newVelocityX * deltaTime;
|
|
531
|
+
* y += avoidance.newVelocityY * deltaTime;
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare class AvoidanceAgentComponent extends Component {
|
|
535
|
+
/**
|
|
536
|
+
* @zh 代理半径
|
|
537
|
+
* @en Agent radius
|
|
538
|
+
*
|
|
539
|
+
* @zh 用于碰撞检测和避让计算
|
|
540
|
+
* @en Used for collision detection and avoidance computation
|
|
541
|
+
*/
|
|
542
|
+
radius: number;
|
|
543
|
+
/**
|
|
544
|
+
* @zh 最大速度
|
|
545
|
+
* @en Maximum speed
|
|
546
|
+
*/
|
|
547
|
+
maxSpeed: number;
|
|
548
|
+
/**
|
|
549
|
+
* @zh 邻居检测距离
|
|
550
|
+
* @en Neighbor detection distance
|
|
551
|
+
*
|
|
552
|
+
* @zh 只考虑此范围内的其他代理
|
|
553
|
+
* @en Only considers other agents within this range
|
|
554
|
+
*/
|
|
555
|
+
neighborDist: number;
|
|
556
|
+
/**
|
|
557
|
+
* @zh 最大邻居数量
|
|
558
|
+
* @en Maximum number of neighbors to consider
|
|
559
|
+
*
|
|
560
|
+
* @zh 限制计算量,优先考虑最近的邻居
|
|
561
|
+
* @en Limits computation, prioritizes closest neighbors
|
|
562
|
+
*/
|
|
563
|
+
maxNeighbors: number;
|
|
564
|
+
/**
|
|
565
|
+
* @zh 代理避让时间视野(秒)
|
|
566
|
+
* @en Time horizon for agent avoidance (seconds)
|
|
567
|
+
*
|
|
568
|
+
* @zh 更大的值会让代理更早开始避让,但可能导致过于保守
|
|
569
|
+
* @en Larger values make agents start avoiding earlier, but may be too conservative
|
|
570
|
+
*/
|
|
571
|
+
timeHorizon: number;
|
|
572
|
+
/**
|
|
573
|
+
* @zh 障碍物避让时间视野(秒)
|
|
574
|
+
* @en Time horizon for obstacle avoidance (seconds)
|
|
575
|
+
*/
|
|
576
|
+
timeHorizonObst: number;
|
|
577
|
+
/**
|
|
578
|
+
* @zh 当前位置 X
|
|
579
|
+
* @en Current position X
|
|
580
|
+
*
|
|
581
|
+
* @zh 如果实体有 Transform 组件,系统会自动同步
|
|
582
|
+
* @en If entity has Transform component, system will sync automatically
|
|
583
|
+
*/
|
|
584
|
+
positionX: number;
|
|
585
|
+
/**
|
|
586
|
+
* @zh 当前位置 Y
|
|
587
|
+
* @en Current position Y
|
|
588
|
+
*/
|
|
589
|
+
positionY: number;
|
|
590
|
+
/**
|
|
591
|
+
* @zh 当前速度 X
|
|
592
|
+
* @en Current velocity X
|
|
593
|
+
*/
|
|
594
|
+
velocityX: number;
|
|
595
|
+
/**
|
|
596
|
+
* @zh 当前速度 Y
|
|
597
|
+
* @en Current velocity Y
|
|
598
|
+
*/
|
|
599
|
+
velocityY: number;
|
|
600
|
+
/**
|
|
601
|
+
* @zh 首选速度 X(通常指向目标方向)
|
|
602
|
+
* @en Preferred velocity X (usually towards target)
|
|
603
|
+
*/
|
|
604
|
+
preferredVelocityX: number;
|
|
605
|
+
/**
|
|
606
|
+
* @zh 首选速度 Y
|
|
607
|
+
* @en Preferred velocity Y
|
|
608
|
+
*/
|
|
609
|
+
preferredVelocityY: number;
|
|
610
|
+
/**
|
|
611
|
+
* @zh ORCA 计算的新速度 X
|
|
612
|
+
* @en New velocity X computed by ORCA
|
|
613
|
+
*/
|
|
614
|
+
newVelocityX: number;
|
|
615
|
+
/**
|
|
616
|
+
* @zh ORCA 计算的新速度 Y
|
|
617
|
+
* @en New velocity Y computed by ORCA
|
|
618
|
+
*/
|
|
619
|
+
newVelocityY: number;
|
|
620
|
+
/**
|
|
621
|
+
* @zh 是否启用避让
|
|
622
|
+
* @en Whether avoidance is enabled
|
|
623
|
+
*/
|
|
624
|
+
enabled: boolean;
|
|
625
|
+
/**
|
|
626
|
+
* @zh 是否自动应用新速度
|
|
627
|
+
* @en Whether to automatically apply new velocity
|
|
628
|
+
*
|
|
629
|
+
* @zh 如果为 true,系统会在计算后自动将 newVelocity 赋值给 velocity
|
|
630
|
+
* @en If true, system will automatically assign newVelocity to velocity after computation
|
|
631
|
+
*/
|
|
632
|
+
autoApplyVelocity: boolean;
|
|
633
|
+
/**
|
|
634
|
+
* @zh 设置位置
|
|
635
|
+
* @en Set position
|
|
636
|
+
*/
|
|
637
|
+
setPosition(x: number, y: number): void;
|
|
638
|
+
/**
|
|
639
|
+
* @zh 设置当前速度
|
|
640
|
+
* @en Set current velocity
|
|
641
|
+
*/
|
|
642
|
+
setVelocity(x: number, y: number): void;
|
|
643
|
+
/**
|
|
644
|
+
* @zh 设置首选速度
|
|
645
|
+
* @en Set preferred velocity
|
|
646
|
+
*/
|
|
647
|
+
setPreferredVelocity(x: number, y: number): void;
|
|
648
|
+
/**
|
|
649
|
+
* @zh 设置首选速度朝向目标
|
|
650
|
+
* @en Set preferred velocity towards target
|
|
651
|
+
*
|
|
652
|
+
* @param targetX - @zh 目标 X @en Target X
|
|
653
|
+
* @param targetY - @zh 目标 Y @en Target Y
|
|
654
|
+
* @param currentX - @zh 当前 X(可选,默认使用 positionX)@en Current X (optional, defaults to positionX)
|
|
655
|
+
* @param currentY - @zh 当前 Y(可选,默认使用 positionY)@en Current Y (optional, defaults to positionY)
|
|
656
|
+
*/
|
|
657
|
+
setPreferredVelocityTowards(targetX: number, targetY: number, currentX?: number, currentY?: number): void;
|
|
658
|
+
/**
|
|
659
|
+
* @zh 应用 ORCA 计算的新速度
|
|
660
|
+
* @en Apply new velocity computed by ORCA
|
|
661
|
+
*/
|
|
662
|
+
applyNewVelocity(): void;
|
|
663
|
+
/**
|
|
664
|
+
* @zh 获取新速度的长度
|
|
665
|
+
* @en Get length of new velocity
|
|
666
|
+
*/
|
|
667
|
+
getNewSpeed(): number;
|
|
668
|
+
/**
|
|
669
|
+
* @zh 获取当前速度的长度
|
|
670
|
+
* @en Get length of current velocity
|
|
671
|
+
*/
|
|
672
|
+
getCurrentSpeed(): number;
|
|
673
|
+
/**
|
|
674
|
+
* @zh 停止代理
|
|
675
|
+
* @en Stop the agent
|
|
676
|
+
*/
|
|
677
|
+
stop(): void;
|
|
678
|
+
/**
|
|
679
|
+
* @zh 重置组件状态
|
|
680
|
+
* @en Reset component state
|
|
681
|
+
*/
|
|
682
|
+
reset(): void;
|
|
683
|
+
/**
|
|
684
|
+
* @zh 组件从实体移除时调用
|
|
685
|
+
* @en Called when component is removed from entity
|
|
686
|
+
*/
|
|
687
|
+
onRemovedFromEntity(): void;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* @zh 避让世界组件
|
|
692
|
+
* @en Avoidance World Component
|
|
693
|
+
*/
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* @zh 避让世界组件
|
|
697
|
+
* @en Avoidance World Component
|
|
698
|
+
*
|
|
699
|
+
* @zh 挂载在场景实体上,持有 ORCA 求解器和静态障碍物
|
|
700
|
+
* @en Attached to scene entity, holds ORCA solver and static obstacles
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* const worldEntity = scene.createEntity('AvoidanceWorld');
|
|
705
|
+
* const world = worldEntity.addComponent(new AvoidanceWorldComponent());
|
|
706
|
+
*
|
|
707
|
+
* // 添加静态障碍物(墙壁)
|
|
708
|
+
* world.addObstacle({
|
|
709
|
+
* vertices: [
|
|
710
|
+
* { x: 0, y: 0 },
|
|
711
|
+
* { x: 10, y: 0 },
|
|
712
|
+
* { x: 10, y: 1 },
|
|
713
|
+
* { x: 0, y: 1 }
|
|
714
|
+
* ]
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* // LocalAvoidanceSystem 会自动使用此组件
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
declare class AvoidanceWorldComponent extends Component {
|
|
721
|
+
/**
|
|
722
|
+
* @zh 默认时间视野(代理)
|
|
723
|
+
* @en Default time horizon for agents
|
|
724
|
+
*/
|
|
725
|
+
defaultTimeHorizon: number;
|
|
726
|
+
/**
|
|
727
|
+
* @zh 默认时间视野(障碍物)
|
|
728
|
+
* @en Default time horizon for obstacles
|
|
729
|
+
*/
|
|
730
|
+
defaultTimeHorizonObst: number;
|
|
731
|
+
/**
|
|
732
|
+
* @zh 时间步长
|
|
733
|
+
* @en Time step
|
|
734
|
+
*/
|
|
735
|
+
timeStep: number;
|
|
736
|
+
/**
|
|
737
|
+
* @zh ORCA 求解器实例
|
|
738
|
+
* @en ORCA solver instance
|
|
739
|
+
*/
|
|
740
|
+
solver: ORCASolver | null;
|
|
741
|
+
/**
|
|
742
|
+
* @zh KD-Tree 实例
|
|
743
|
+
* @en KD-Tree instance
|
|
744
|
+
*/
|
|
745
|
+
kdTree: KDTree | null;
|
|
746
|
+
/**
|
|
747
|
+
* @zh 静态障碍物列表
|
|
748
|
+
* @en List of static obstacles
|
|
749
|
+
*/
|
|
750
|
+
obstacles: IObstacle[];
|
|
751
|
+
/**
|
|
752
|
+
* @zh 是否已初始化
|
|
753
|
+
* @en Whether initialized
|
|
754
|
+
*/
|
|
755
|
+
initialized: boolean;
|
|
756
|
+
/**
|
|
757
|
+
* @zh 当前代理数量
|
|
758
|
+
* @en Current agent count
|
|
759
|
+
*/
|
|
760
|
+
agentCount: number;
|
|
761
|
+
/**
|
|
762
|
+
* @zh 本帧处理的代理数
|
|
763
|
+
* @en Agents processed this frame
|
|
764
|
+
*/
|
|
765
|
+
agentsProcessedThisFrame: number;
|
|
766
|
+
/**
|
|
767
|
+
* @zh 本帧 ORCA 计算耗时(毫秒)
|
|
768
|
+
* @en ORCA computation time this frame (ms)
|
|
769
|
+
*/
|
|
770
|
+
computeTimeMs: number;
|
|
771
|
+
/**
|
|
772
|
+
* @zh 获取 ORCA 配置
|
|
773
|
+
* @en Get ORCA configuration
|
|
774
|
+
*/
|
|
775
|
+
getConfig(): IORCASolverConfig;
|
|
776
|
+
/**
|
|
777
|
+
* @zh 添加静态障碍物
|
|
778
|
+
* @en Add static obstacle
|
|
779
|
+
*
|
|
780
|
+
* @param obstacle - @zh 障碍物(顶点列表,逆时针顺序)@en Obstacle (vertex list, counter-clockwise)
|
|
781
|
+
*/
|
|
782
|
+
addObstacle(obstacle: IObstacle): void;
|
|
783
|
+
/**
|
|
784
|
+
* @zh 添加矩形障碍物
|
|
785
|
+
* @en Add rectangular obstacle
|
|
786
|
+
*
|
|
787
|
+
* @param x - @zh 左下角 X @en Bottom-left X
|
|
788
|
+
* @param y - @zh 左下角 Y @en Bottom-left Y
|
|
789
|
+
* @param width - @zh 宽度 @en Width
|
|
790
|
+
* @param height - @zh 高度 @en Height
|
|
791
|
+
*/
|
|
792
|
+
addRectObstacle(x: number, y: number, width: number, height: number): void;
|
|
793
|
+
/**
|
|
794
|
+
* @zh 移除所有障碍物
|
|
795
|
+
* @en Remove all obstacles
|
|
796
|
+
*/
|
|
797
|
+
clearObstacles(): void;
|
|
798
|
+
/**
|
|
799
|
+
* @zh 重置统计信息
|
|
800
|
+
* @en Reset statistics
|
|
801
|
+
*/
|
|
802
|
+
resetStats(): void;
|
|
803
|
+
/**
|
|
804
|
+
* @zh 组件从实体移除时调用
|
|
805
|
+
* @en Called when component is removed from entity
|
|
806
|
+
*/
|
|
807
|
+
onRemovedFromEntity(): void;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* @zh 局部避让系统
|
|
812
|
+
* @en Local Avoidance System
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* @zh 局部避让系统
|
|
817
|
+
* @en Local Avoidance System
|
|
818
|
+
*
|
|
819
|
+
* @zh 使用 ORCA 算法计算代理的避让速度
|
|
820
|
+
* @en Uses ORCA algorithm to compute avoidance velocities for agents
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```typescript
|
|
824
|
+
* // 添加系统到场景
|
|
825
|
+
* scene.addSystem(new LocalAvoidanceSystem());
|
|
826
|
+
*
|
|
827
|
+
* // 创建避让世界(可选,用于静态障碍物)
|
|
828
|
+
* const worldEntity = scene.createEntity('AvoidanceWorld');
|
|
829
|
+
* worldEntity.addComponent(new AvoidanceWorldComponent());
|
|
830
|
+
*
|
|
831
|
+
* // 创建代理
|
|
832
|
+
* const agent = scene.createEntity('Agent');
|
|
833
|
+
* const avoidance = agent.addComponent(new AvoidanceAgentComponent());
|
|
834
|
+
*
|
|
835
|
+
* // 可选:同时添加寻路代理,系统会自动同步位置
|
|
836
|
+
* agent.addComponent(new PathfindingAgentComponent());
|
|
837
|
+
*
|
|
838
|
+
* // 每帧设置首选速度(朝向目标)
|
|
839
|
+
* avoidance.setPreferredVelocityTowards(targetX, targetY);
|
|
840
|
+
*
|
|
841
|
+
* // 系统计算后,newVelocity 会被更新
|
|
842
|
+
* // 如果 autoApplyVelocity = true,velocity 也会自动更新
|
|
843
|
+
* ```
|
|
844
|
+
*/
|
|
845
|
+
declare class LocalAvoidanceSystem extends EntitySystem {
|
|
846
|
+
private worldEntity;
|
|
847
|
+
private worldComponent;
|
|
848
|
+
private solver;
|
|
849
|
+
private kdTree;
|
|
850
|
+
constructor();
|
|
851
|
+
/**
|
|
852
|
+
* @zh 系统初始化
|
|
853
|
+
* @en System initialization
|
|
854
|
+
*/
|
|
855
|
+
protected onInitialize(): void;
|
|
856
|
+
/**
|
|
857
|
+
* @zh 系统激活时调用
|
|
858
|
+
* @en Called when system is enabled
|
|
859
|
+
*/
|
|
860
|
+
protected onEnable(): void;
|
|
861
|
+
/**
|
|
862
|
+
* @zh 处理实体
|
|
863
|
+
* @en Process entities
|
|
864
|
+
*/
|
|
865
|
+
protected process(entities: readonly Entity[]): void;
|
|
866
|
+
/**
|
|
867
|
+
* @zh 查找世界实体
|
|
868
|
+
* @en Find world entity
|
|
869
|
+
*/
|
|
870
|
+
private findWorldEntity;
|
|
871
|
+
/**
|
|
872
|
+
* @zh 初始化求解器
|
|
873
|
+
* @en Initialize solver
|
|
874
|
+
*/
|
|
875
|
+
private initializeSolver;
|
|
876
|
+
/**
|
|
877
|
+
* @zh 收集代理数据
|
|
878
|
+
* @en Collect agent data
|
|
879
|
+
*/
|
|
880
|
+
private collectAgentData;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export { AvoidanceAgentComponent, AvoidanceWorldComponent, LocalAvoidanceSystem, PathfindingAgentComponent, PathfindingMapComponent, type PathfindingMapType, PathfindingSystem };
|