feat(particle): 添加粒子与 Rapier2D 物理碰撞集成 (#295)
* feat(particle): 添加粒子与 Rapier2D 物理碰撞集成 - 新增 Physics2DCollisionModule 模块,支持粒子与场景碰撞体交互 - 支持圆形重叠检测和射线检测两种模式 - 支持 Kill/Bounce/Stop 三种碰撞行为 - 修复 module.update() 参数顺序 bug - 物理模块自动通过 context 注入,用户只需添加模块即可 * chore: update pnpm-lock.yaml for particle physics dependency Update lockfile to include @esengine/physics-rapier2d as optional peer dependency.
This commit is contained in:
@@ -21,6 +21,34 @@ import { Physics2DService } from './services/Physics2DService';
|
||||
// 注册 Rapier2D 加载器
|
||||
import './loaders';
|
||||
|
||||
/**
|
||||
* 2D 物理查询接口
|
||||
* 2D Physics query interface
|
||||
*
|
||||
* 用于粒子系统等模块查询物理世界
|
||||
* Used by particle system and other modules to query physics world
|
||||
*/
|
||||
export interface IPhysics2DQuery {
|
||||
overlapCircle(
|
||||
center: { x: number; y: number },
|
||||
radius: number,
|
||||
collisionMask?: number
|
||||
): { entityIds: number[]; colliderHandles: number[] };
|
||||
|
||||
raycast(
|
||||
origin: { x: number; y: number },
|
||||
direction: { x: number; y: number },
|
||||
maxDistance: number,
|
||||
collisionMask?: number
|
||||
): {
|
||||
entityId: number;
|
||||
point: { x: number; y: number };
|
||||
normal: { x: number; y: number };
|
||||
distance: number;
|
||||
colliderHandle: number;
|
||||
} | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理系统上下文扩展
|
||||
*/
|
||||
@@ -39,6 +67,18 @@ export interface PhysicsSystemContext extends SystemContext {
|
||||
* 物理配置
|
||||
*/
|
||||
physicsConfig?: any;
|
||||
|
||||
/**
|
||||
* 2D 物理查询接口
|
||||
* 2D Physics query interface
|
||||
*
|
||||
* 供粒子系统等模块使用,用于检测粒子与物理碰撞体的碰撞。
|
||||
* 实际上是 Physics2DSystem 的引用,因为它实现了 IPhysics2DQuery 接口。
|
||||
*
|
||||
* For particle system and other modules to detect collision with physics colliders.
|
||||
* Actually a reference to Physics2DSystem which implements IPhysics2DQuery interface.
|
||||
*/
|
||||
physics2DQuery?: IPhysics2DQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,6 +183,9 @@ class PhysicsRuntimeModule implements IRuntimeModule {
|
||||
|
||||
physicsContext.physicsSystem = physicsSystem;
|
||||
physicsContext.physics2DWorld = physicsSystem.world;
|
||||
// 同时暴露 physics2DQuery,供粒子系统等模块使用
|
||||
// Also expose physics2DQuery for particle system and other modules
|
||||
physicsContext.physics2DQuery = physicsSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,3 +27,6 @@ export { Physics2DPlugin } from './PhysicsEditorPlugin';
|
||||
|
||||
// Runtime plugin (for game builds)
|
||||
export { PhysicsPlugin } from './PhysicsRuntimeModule';
|
||||
|
||||
// Physics query interface (for particle system integration)
|
||||
export type { IPhysics2DQuery, PhysicsSystemContext } from './PhysicsRuntimeModule';
|
||||
|
||||
Reference in New Issue
Block a user