ecspresso 0.14.2 → 0.14.4

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.
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/plugins/physics/physics2D.ts", "../src/utils/narrowphase.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Physics 2D Plugin for ECSpresso\n *\n * Provides ECS-native arcade physics: gravity, forces, drag, semi-implicit Euler\n * integration, and impulse-based collision response with friction.\n *\n * Reuses collider types from the collision plugin for shape definitions.\n * Has its own collision detection in fixedUpdate for physics response;\n * the existing collision plugin can still run in postUpdate for game logic events.\n */\n\nimport { definePlugin } from 'ecspresso';\nimport type { SystemPhase } from 'ecspresso';\nimport type { TransformComponentTypes, TransformWorldConfig } from '../spatial/transform';\nimport type { CollisionComponentTypes, LayerFactories } from './collision';\nimport type { Vector2D } from 'ecspresso';\nimport { fillBaseColliderInfo, detectCollisions, AABB_SHAPE, type Contact, type BaseColliderInfo } from '../../utils/narrowphase';\nimport type { SpatialIndex } from '../../utils/spatial-hash';\n\n// ==================== Component Types ====================\n\n/**\n * Rigid body types for physics simulation.\n * - 'dynamic': Fully simulated (gravity, forces, collisions)\n * - 'kinematic': Moves via velocity only (ignores gravity/forces, immovable in collisions)\n * - 'static': Immovable (ignores gravity, forces, and velocity)\n */\nexport type BodyType = 'dynamic' | 'kinematic' | 'static';\n\n/**\n * Rigid body component controlling physics behavior.\n */\nexport interface RigidBody {\n\ttype: BodyType;\n\t/** Mass in arbitrary units. Affects force→acceleration. Infinity = immovable. */\n\tmass: number;\n\t/** Linear velocity damping coefficient (units/sec, 0 = none) */\n\tdrag: number;\n\t/** Bounciness 0–1 (0 = no bounce, 1 = perfectly elastic) */\n\trestitution: number;\n\t/** Surface friction coefficient 0–1 */\n\tfriction: number;\n\t/** Per-entity gravity multiplier (0 = no gravity) */\n\tgravityScale: number;\n}\n\n/**\n * Component types directly provided by the physics plugin.\n */\nexport interface Physics2DOwnComponentTypes {\n\trigidBody: RigidBody;\n\tvelocity: Vector2D;\n\tforce: Vector2D;\n}\n\n/**\n * Full component types available when using the physics plugin\n * (own components + transform + collision dependencies).\n * Convenience alias for consumer code.\n */\nexport interface Physics2DComponentTypes<L extends string = never> extends TransformComponentTypes, CollisionComponentTypes<L>, Physics2DOwnComponentTypes {}\n\n// ==================== Resource Types ====================\n\n/**\n * Physics configuration resource.\n */\nexport interface Physics2DConfig {\n\tgravity: Vector2D;\n}\n\nexport interface Physics2DResourceTypes {\n\tphysicsConfig: Physics2DConfig;\n}\n\n// ==================== Event Types ====================\n\n/**\n * Event emitted for each physics collision pair.\n *\n * Normal components are flattened (`normalX`/`normalY`) rather than nested\n * in a `Vector2D` to avoid a per-event allocation in the physics hot path.\n */\nexport interface Physics2DCollisionEvent {\n\tentityA: number;\n\tentityB: number;\n\t/** Unit normal X, pointing from A toward B */\n\tnormalX: number;\n\t/** Unit normal Y, pointing from A toward B */\n\tnormalY: number;\n\t/** Penetration depth (positive) */\n\tdepth: number;\n}\n\nexport interface Physics2DEventTypes {\n\tphysicsCollision: Physics2DCollisionEvent;\n}\n\n// ==================== Plugin Options ====================\n\nexport interface Physics2DPluginOptions<G extends string = 'physics2D', CG extends string = never> {\n\t/** World gravity vector (default: {x: 0, y: 0}) */\n\tgravity?: Vector2D;\n\t/** System group name (default: 'physics2D') */\n\tsystemGroup?: G;\n\t/** Additional group for the collision system only (default: none).\n\t * When set, the collision system belongs to both `systemGroup` and this group,\n\t * allowing independent enable/disable of collision detection. */\n\tcollisionSystemGroup?: CG;\n\t/** Priority for integration system (default: 1000) */\n\tintegrationPriority?: number;\n\t/** Priority for collision system (default: 900) */\n\tcollisionPriority?: number;\n\t/** Execution phase (default: 'fixedUpdate') */\n\tphase?: SystemPhase;\n}\n\n// ==================== Helper Functions ====================\n\nexport interface RigidBodyOptions {\n\tmass?: number;\n\tdrag?: number;\n\trestitution?: number;\n\tfriction?: number;\n\tgravityScale?: number;\n}\n\n/**\n * Create a rigid body + force component pair.\n * Static bodies automatically get mass=Infinity.\n */\nexport function createRigidBody(\n\ttype: BodyType,\n\toptions?: RigidBodyOptions,\n): { rigidBody: RigidBody; force: Vector2D } {\n\treturn {\n\t\trigidBody: {\n\t\t\ttype,\n\t\t\tmass: type === 'static' ? Infinity : (options?.mass ?? 1),\n\t\t\tdrag: options?.drag ?? 0,\n\t\t\trestitution: options?.restitution ?? 0,\n\t\t\tfriction: options?.friction ?? 0,\n\t\t\tgravityScale: options?.gravityScale ?? 1,\n\t\t},\n\t\tforce: { x: 0, y: 0 },\n\t};\n}\n\n/**\n * Create a force component with initial values.\n */\nexport function createForce(x: number, y: number): { force: Vector2D } {\n\treturn { force: { x, y } };\n}\n\n/**\n * Accumulate a force onto an entity's force component.\n */\nexport function applyForce(\n\tecs: { getComponent(id: number, name: 'force'): Vector2D | undefined },\n\tentityId: number,\n\tfx: number,\n\tfy: number,\n): void {\n\tconst force = ecs.getComponent(entityId, 'force');\n\tif (!force) return;\n\tforce.x += fx;\n\tforce.y += fy;\n}\n\n/**\n * Apply an instantaneous impulse: velocity += impulse / mass.\n */\nexport function applyImpulse(\n\tecs: {\n\t\tgetComponent(id: number, name: 'velocity'): Vector2D | undefined;\n\t\tgetComponent(id: number, name: 'rigidBody'): RigidBody | undefined;\n\t},\n\tentityId: number,\n\tix: number,\n\tiy: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity');\n\tconst rigidBody = ecs.getComponent(entityId, 'rigidBody');\n\tif (!velocity || !rigidBody) return;\n\tif (rigidBody.mass === Infinity || rigidBody.mass === 0) return;\n\tvelocity.x += ix / rigidBody.mass;\n\tvelocity.y += iy / rigidBody.mass;\n}\n\n/**\n * Directly set an entity's velocity.\n */\nexport function setVelocity(\n\tecs: { getComponent(id: number, name: 'velocity'): Vector2D | undefined },\n\tentityId: number,\n\tvx: number,\n\tvy: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity');\n\tif (!velocity) return;\n\tvelocity.x = vx;\n\tvelocity.y = vy;\n}\n\n// ==================== Internal: Collider Info ====================\n\ninterface Physics2DColliderInfo<L extends string = string> extends BaseColliderInfo<L> {\n\trigidBody: RigidBody;\n\tvelocity: Vector2D;\n}\n\n// ==================== Collision Response ====================\n\n/**\n * Module-level reusable physics collision event. Subscribers must consume\n * synchronously — same contract as the shared narrowphase Contact.\n */\nconst _physicsCollisionEvent: Physics2DCollisionEvent = {\n\tentityA: 0, entityB: 0, normalX: 0, normalY: 0, depth: 0,\n};\n\ninterface PhysicsEcsLike {\n\tgetComponent(id: number, name: 'localTransform'): { x: number; y: number } | undefined;\n\teventBus: { publish(event: 'physicsCollision', data: Physics2DCollisionEvent): void };\n\tmarkChanged(entityId: number, componentName: 'localTransform' | 'velocity'): void;\n}\n\n/**\n * Resolve a physics collision pair: position correction, impulse response, event.\n */\nfunction resolvePhysicsContact(\n\ta: Physics2DColliderInfo,\n\tb: Physics2DColliderInfo,\n\tcontact: Contact,\n\tecs: PhysicsEcsLike,\n): void {\n\tconst invMassA = (a.rigidBody.type === 'dynamic' && a.rigidBody.mass > 0 && a.rigidBody.mass !== Infinity)\n\t\t? 1 / a.rigidBody.mass\n\t\t: 0;\n\tconst invMassB = (b.rigidBody.type === 'dynamic' && b.rigidBody.mass > 0 && b.rigidBody.mass !== Infinity)\n\t\t? 1 / b.rigidBody.mass\n\t\t: 0;\n\tconst totalInvMass = invMassA + invMassB;\n\n\t// Position correction\n\tif (totalInvMass > 0) {\n\t\tconst correctionScale = contact.depth / totalInvMass;\n\n\t\tif (invMassA > 0) {\n\t\t\tconst ltA = ecs.getComponent(a.entityId, 'localTransform');\n\t\t\tif (!ltA) return;\n\t\t\tltA.x -= correctionScale * invMassA * contact.normalX;\n\t\t\tltA.y -= correctionScale * invMassA * contact.normalY;\n\t\t\t// Update cached position for subsequent pairs (collider offset already baked in)\n\t\t\ta.x = ltA.x;\n\t\t\tecs.markChanged(a.entityId, 'localTransform');\n\t\t}\n\n\t\tif (invMassB > 0) {\n\t\t\tconst ltB = ecs.getComponent(b.entityId, 'localTransform');\n\t\t\tif (!ltB) return;\n\t\t\tltB.x += correctionScale * invMassB * contact.normalX;\n\t\t\tltB.y += correctionScale * invMassB * contact.normalY;\n\t\t\tecs.markChanged(b.entityId, 'localTransform');\n\t\t}\n\n\t\t// Velocity response (impulse-based)\n\t\tconst relVelX = b.velocity.x - a.velocity.x;\n\t\tconst relVelY = b.velocity.y - a.velocity.y;\n\t\tconst velAlongNormal = relVelX * contact.normalX + relVelY * contact.normalY;\n\n\t\tif (velAlongNormal < 0) {\n\t\t\tconst restitution = Math.min(a.rigidBody.restitution, b.rigidBody.restitution);\n\t\t\tconst normalImpulse = -(1 + restitution) * velAlongNormal / totalInvMass;\n\n\t\t\ta.velocity.x -= normalImpulse * invMassA * contact.normalX;\n\t\t\ta.velocity.y -= normalImpulse * invMassA * contact.normalY;\n\t\t\tb.velocity.x += normalImpulse * invMassB * contact.normalX;\n\t\t\tb.velocity.y += normalImpulse * invMassB * contact.normalY;\n\n\t\t\t// Friction (tangential impulse)\n\t\t\tconst tangentX = relVelX - velAlongNormal * contact.normalX;\n\t\t\tconst tangentY = relVelY - velAlongNormal * contact.normalY;\n\t\t\tconst tangentSpeed = Math.sqrt(tangentX * tangentX + tangentY * tangentY);\n\n\t\t\tif (tangentSpeed > 1e-6) {\n\t\t\t\tconst tangentNX = tangentX / tangentSpeed;\n\t\t\t\tconst tangentNY = tangentY / tangentSpeed;\n\t\t\t\tconst friction = Math.sqrt(a.rigidBody.friction * b.rigidBody.friction);\n\t\t\t\tconst maxFrictionImpulse = friction * Math.abs(normalImpulse);\n\t\t\t\tconst tangentImpulse = Math.min(tangentSpeed / totalInvMass, maxFrictionImpulse);\n\n\t\t\t\ta.velocity.x += tangentImpulse * invMassA * tangentNX;\n\t\t\t\ta.velocity.y += tangentImpulse * invMassA * tangentNY;\n\t\t\t\tb.velocity.x -= tangentImpulse * invMassB * tangentNX;\n\t\t\t\tb.velocity.y -= tangentImpulse * invMassB * tangentNY;\n\t\t\t}\n\t\t}\n\n\t\tecs.markChanged(a.entityId, 'velocity');\n\t\tecs.markChanged(b.entityId, 'velocity');\n\t}\n\n\t_physicsCollisionEvent.entityA = a.entityId;\n\t_physicsCollisionEvent.entityB = b.entityId;\n\t_physicsCollisionEvent.normalX = contact.normalX;\n\t_physicsCollisionEvent.normalY = contact.normalY;\n\t_physicsCollisionEvent.depth = contact.depth;\n\tecs.eventBus.publish('physicsCollision', _physicsCollisionEvent);\n}\n\n// ==================== Plugin Factory ====================\n\n/**\n * Create a 2D physics plugin for ECSpresso.\n *\n * Provides:\n * - Semi-implicit Euler integration (gravity, forces, drag → velocity → position)\n * - Impulse-based collision response with restitution and friction\n * - physicsCollision events with contact normal and depth\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTransformPlugin())\n * .withPlugin(createPhysics2DPlugin({ gravity: { x: 0, y: 980 } }))\n * .withFixedTimestep(1/60)\n * .build();\n *\n * ecs.spawn({\n * ...createTransform(100, 200),\n * ...createRigidBody('dynamic', { mass: 1, restitution: 0.5 }),\n * velocity: { x: 0, y: 0 },\n * ...createAABBCollider(32, 32),\n * ...createCollisionLayer('player', ['ground']),\n * });\n * ```\n */\n\ntype Physics2DProvides<L extends string = never> = Physics2DOwnComponentTypes & CollisionComponentTypes<L>;\n\nexport function createPhysics2DPlugin<L extends string = never, G extends string = 'physics2D', CG extends string = never>(\n\toptions?: Physics2DPluginOptions<G, CG> & { layers?: LayerFactories<Record<L, readonly string[]>> },\n) {\n\tconst {\n\t\tgravity = { x: 0, y: 0 },\n\t\tsystemGroup = 'physics2D',\n\t\tcollisionSystemGroup,\n\t\tintegrationPriority = 1000,\n\t\tcollisionPriority = 900,\n\t\tphase = 'fixedUpdate',\n\t} = options ?? {};\n\n\treturn definePlugin('physics2D')\n\t\t.withComponentTypes<Physics2DProvides<L>>()\n\t\t.withEventTypes<Physics2DEventTypes>()\n\t\t.withResourceTypes<Physics2DResourceTypes>()\n\t\t.withLabels<'physics2D-integration' | 'physics2D-collision'>()\n\t\t.withGroups<G | CG>()\n\t\t.requires<TransformWorldConfig>()\n\t\t.install((world) => {\n\t\t\t// rigidBody requires velocity and force — auto-add with zero defaults\n\t\t\tworld.registerRequired('rigidBody', 'velocity', () => ({ x: 0, y: 0 }));\n\t\t\tworld.registerRequired('rigidBody', 'force', () => ({ x: 0, y: 0 }));\n\n\t\t\tworld.addResource('physicsConfig', { gravity: { x: gravity.x, y: gravity.y } });\n\n\t\t\t// ==================== Integration System ====================\n\n\t\t\tworld\n\t\t\t\t.addSystem('physics2D-integration')\n\t\t\t\t.setPriority(integrationPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup)\n\t\t\t\t.addQuery('bodies', {\n\t\t\t\t\twith: ['localTransform', 'velocity', 'rigidBody', 'force'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, dt, ecs }) => {\n\t\t\t\t\tconst { gravity: g } = ecs.getResource('physicsConfig');\n\t\t\t\t\tconst gx = g.x;\n\t\t\t\t\tconst gy = g.y;\n\n\t\t\t\t\tfor (const entity of queries.bodies) {\n\t\t\t\t\t\tconst { localTransform, velocity, rigidBody, force } = entity.components;\n\n\t\t\t\t\t\t// Static bodies: skip entirely\n\t\t\t\t\t\tif (rigidBody.type === 'static') continue;\n\n\t\t\t\t\t\t// Dynamic bodies: apply gravity, forces, drag\n\t\t\t\t\t\tif (rigidBody.type === 'dynamic') {\n\t\t\t\t\t\t\t// 1. Gravity\n\t\t\t\t\t\t\tvelocity.x += gx * rigidBody.gravityScale * dt;\n\t\t\t\t\t\t\tvelocity.y += gy * rigidBody.gravityScale * dt;\n\n\t\t\t\t\t\t\t// 2. Forces (F = ma → a = F/m)\n\t\t\t\t\t\t\tif (rigidBody.mass > 0 && rigidBody.mass !== Infinity) {\n\t\t\t\t\t\t\t\tvelocity.x += (force.x / rigidBody.mass) * dt;\n\t\t\t\t\t\t\t\tvelocity.y += (force.y / rigidBody.mass) * dt;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// 3. Drag\n\t\t\t\t\t\t\tif (rigidBody.drag > 0) {\n\t\t\t\t\t\t\t\tconst damping = Math.max(0, 1 - rigidBody.drag * dt);\n\t\t\t\t\t\t\t\tvelocity.x *= damping;\n\t\t\t\t\t\t\t\tvelocity.y *= damping;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Both dynamic and kinematic: integrate position\n\t\t\t\t\t\tlocalTransform.x += velocity.x * dt;\n\t\t\t\t\t\tlocalTransform.y += velocity.y * dt;\n\n\t\t\t\t\t\t// Clear accumulated forces\n\t\t\t\t\t\tforce.x = 0;\n\t\t\t\t\t\tforce.y = 0;\n\n\t\t\t\t\t\tecs.markChanged(entity.id, 'localTransform');\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t// ==================== Collision System ====================\n\n\t\t\tconst collisionSystem = world\n\t\t\t\t.addSystem('physics2D-collision')\n\t\t\t\t.setPriority(collisionPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup);\n\n\t\t\tif (collisionSystemGroup) {\n\t\t\t\tcollisionSystem.inGroup(collisionSystemGroup);\n\t\t\t}\n\n\t\t\t// Grow-only pool of Physics2DColliderInfo slots reused across frames.\n\t\t\t// Steady-state: zero allocations per frame once the pool is warm.\n\t\t\tconst colliderPool: Physics2DColliderInfo<L>[] = [];\n\t\t\t// Reusable entityId → collider lookup for the broadphase path.\n\t\t\tconst broadphaseMap = new Map<number, Physics2DColliderInfo<L>>();\n\t\t\t// Cached spatial index reference (resolved once on first frame).\n\t\t\tlet cachedSI: SpatialIndex | undefined;\n\t\t\tlet siResolved = false;\n\n\t\t\tcollisionSystem\n\t\t\t\t.addQuery('collidables', {\n\t\t\t\t\twith: ['localTransform', 'rigidBody', 'velocity', 'collisionLayer'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, ecs }) => {\n\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\tfor (const entity of queries.collidables) {\n\t\t\t\t\t\tconst { localTransform, rigidBody, velocity, collisionLayer } = entity.components;\n\t\t\t\t\t\tconst aabb = ecs.getComponent(entity.id, 'aabbCollider');\n\t\t\t\t\t\tconst circle = aabb ? undefined : ecs.getComponent(entity.id, 'circleCollider');\n\t\t\t\t\t\tif (!aabb && !circle) continue;\n\n\t\t\t\t\t\tlet slot = colliderPool[count];\n\t\t\t\t\t\tif (!slot) {\n\t\t\t\t\t\t\tslot = {\n\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\tx: localTransform.x,\n\t\t\t\t\t\t\t\ty: localTransform.y,\n\t\t\t\t\t\t\t\tlayer: collisionLayer.layer,\n\t\t\t\t\t\t\t\tcollidesWith: collisionLayer.collidesWith,\n\t\t\t\t\t\t\t\tshape: AABB_SHAPE,\n\t\t\t\t\t\t\t\thalfWidth: 0,\n\t\t\t\t\t\t\t\thalfHeight: 0,\n\t\t\t\t\t\t\t\tradius: 0,\n\t\t\t\t\t\t\t\trigidBody,\n\t\t\t\t\t\t\t\tvelocity,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tcolliderPool[count] = slot;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tslot.rigidBody = rigidBody;\n\t\t\t\t\t\t\tslot.velocity = velocity;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!fillBaseColliderInfo(\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tentity.id, localTransform.x, localTransform.y,\n\t\t\t\t\t\t\tcollisionLayer.layer, collisionLayer.collidesWith,\n\t\t\t\t\t\t\taabb, circle,\n\t\t\t\t\t\t)) continue;\n\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!siResolved) {\n\t\t\t\t\t\tcachedSI = ecs.tryGetResource<SpatialIndex>('spatialIndex');\n\t\t\t\t\t\tsiResolved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdetectCollisions(colliderPool, count, broadphaseMap, cachedSI, resolvePhysicsContact, ecs);\n\t\t\t\t});\n\t\t});\n}\n",
6
- "/**\n * Shared Narrowphase Module\n *\n * Provides contact-computing narrowphase tests and a generic collision\n * iteration pipeline used by both the collision plugin (event-only) and\n * the physics2D plugin (impulse response).\n */\n\nimport type { SpatialIndex } from './spatial-hash';\n\n// ==================== Contact ====================\n\n/**\n * Contact result from a narrowphase test. Normal points from A toward B.\n *\n * Narrowphase functions use this as an out-parameter: the caller owns the\n * struct, the function writes fields in place and returns `true` on hit.\n * The `onContact` callback in `detectCollisions` receives a shared module-\n * level instance — **subscribers must consume it synchronously and must not\n * retain the reference across frames**.\n */\nexport interface Contact {\n\tnormalX: number;\n\tnormalY: number;\n\t/** Penetration depth (positive = overlapping) */\n\tdepth: number;\n}\n\n/**\n * Module-level reusable Contact passed down from `detectCollisions` into\n * narrowphase tests and forwarded to the `onContact` callback. Reused across\n * every pair in every frame — zero allocation in the narrowphase hot path.\n */\nconst _sharedContact: Contact = { normalX: 0, normalY: 0, depth: 0 };\n\n// ==================== BaseColliderInfo ====================\n\n/** Collider shape discriminator for the flattened BaseColliderInfo layout. */\nexport const AABB_SHAPE = 0;\nexport const CIRCLE_SHAPE = 1;\nexport type ColliderShape = typeof AABB_SHAPE | typeof CIRCLE_SHAPE;\n\n/**\n * Minimum collider data shared by collision and physics bundles.\n *\n * Flat layout (no nested `aabb` / `circle` sub-objects): the `shape`\n * discriminator tells you whether to read `halfWidth`/`halfHeight`\n * (AABB) or `radius` (Circle). Unused fields are set to 0.\n *\n * This shape is pool-friendly — all fields are assigned in place each\n * frame without allocating nested objects.\n */\nexport interface BaseColliderInfo<L extends string = string> {\n\tentityId: number;\n\tx: number;\n\ty: number;\n\tlayer: L;\n\tcollidesWith: readonly L[];\n\tshape: ColliderShape;\n\thalfWidth: number;\n\thalfHeight: number;\n\tradius: number;\n}\n\n// ==================== Collider Construction ====================\n\n/**\n * Populate a `BaseColliderInfo` slot in place from raw component data.\n * Returns `true` if the slot was filled, `false` if the entity has no\n * collider (caller should skip it).\n *\n * If an entity has both AABB and circle colliders, AABB wins and only\n * the AABB offset is applied. This matches the dispatch precedence in\n * `computeContact`; the previous implementation stacked both offsets,\n * which was a bug.\n */\nexport function fillBaseColliderInfo<L extends string>(\n\tinfo: BaseColliderInfo<L>,\n\tentityId: number,\n\tx: number,\n\ty: number,\n\tlayer: L,\n\tcollidesWith: readonly L[],\n\taabb: { width: number; height: number; offsetX?: number; offsetY?: number } | undefined,\n\tcircle: { radius: number; offsetX?: number; offsetY?: number } | undefined,\n): boolean {\n\tinfo.entityId = entityId;\n\tinfo.layer = layer;\n\tinfo.collidesWith = collidesWith;\n\n\tif (aabb) {\n\t\tinfo.x = x + (aabb.offsetX ?? 0);\n\t\tinfo.y = y + (aabb.offsetY ?? 0);\n\t\tinfo.shape = AABB_SHAPE;\n\t\tinfo.halfWidth = aabb.width / 2;\n\t\tinfo.halfHeight = aabb.height / 2;\n\t\tinfo.radius = 0;\n\t\treturn true;\n\t}\n\n\tif (circle) {\n\t\tinfo.x = x + (circle.offsetX ?? 0);\n\t\tinfo.y = y + (circle.offsetY ?? 0);\n\t\tinfo.shape = CIRCLE_SHAPE;\n\t\tinfo.halfWidth = 0;\n\t\tinfo.halfHeight = 0;\n\t\tinfo.radius = circle.radius;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// ==================== Spatial Index Lookup ====================\n\n/**\n * Retrieve the optional spatialIndex resource, returning undefined when absent.\n * Centralizes the cross-plugin typed lookup so individual plugins don't each\n * need to import SpatialIndex or repeat the tryGetResource pattern.\n */\nexport function tryGetSpatialIndex(\n\ttryGetResource: <T>(key: string) => T | undefined,\n): SpatialIndex | undefined {\n\treturn tryGetResource<SpatialIndex>('spatialIndex');\n}\n\n// ==================== Narrowphase Tests ====================\n\n/**\n * Write an AABB-AABB contact into `out`. Returns `true` if the shapes\n * overlap (out was filled), `false` otherwise.\n */\nexport function computeAABBvsAABB(\n\tax: number, ay: number, ahw: number, ahh: number,\n\tbx: number, by: number, bhw: number, bhh: number,\n\tout: Contact,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst overlapX = (ahw + bhw) - Math.abs(dx);\n\tconst overlapY = (ahh + bhh) - Math.abs(dy);\n\n\tif (overlapX <= 0 || overlapY <= 0) return false;\n\n\tif (overlapX < overlapY) {\n\t\tout.normalX = dx >= 0 ? 1 : -1;\n\t\tout.normalY = 0;\n\t\tout.depth = overlapX;\n\t\treturn true;\n\t}\n\tout.normalX = 0;\n\tout.normalY = dy >= 0 ? 1 : -1;\n\tout.depth = overlapY;\n\treturn true;\n}\n\nexport function computeCircleVsCircle(\n\tax: number, ay: number, ar: number,\n\tbx: number, by: number, br: number,\n\tout: Contact,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst distSq = dx * dx + dy * dy;\n\tconst radiusSum = ar + br;\n\n\tif (distSq >= radiusSum * radiusSum) return false;\n\n\tconst dist = Math.sqrt(distSq);\n\tif (dist === 0) {\n\t\tout.normalX = 1;\n\t\tout.normalY = 0;\n\t\tout.depth = radiusSum;\n\t\treturn true;\n\t}\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.depth = radiusSum - dist;\n\treturn true;\n}\n\nexport function computeAABBvsCircle(\n\taabbX: number, aabbY: number, ahw: number, ahh: number,\n\tcircleX: number, circleY: number, radius: number,\n\tout: Contact,\n): boolean {\n\tconst closestX = Math.max(aabbX - ahw, Math.min(circleX, aabbX + ahw));\n\tconst closestY = Math.max(aabbY - ahh, Math.min(circleY, aabbY + ahh));\n\n\tconst dx = circleX - closestX;\n\tconst dy = circleY - closestY;\n\tconst distSq = dx * dx + dy * dy;\n\n\tif (distSq >= radius * radius) return false;\n\n\t// Circle center inside AABB\n\tif (distSq === 0) {\n\t\tconst pushLeft = (circleX - (aabbX - ahw));\n\t\tconst pushRight = ((aabbX + ahw) - circleX);\n\t\tconst pushUp = (circleY - (aabbY - ahh));\n\t\tconst pushDown = ((aabbY + ahh) - circleY);\n\t\tconst minPush = Math.min(pushLeft, pushRight, pushUp, pushDown);\n\n\t\tif (minPush === pushRight) {\n\t\t\tout.normalX = 1; out.normalY = 0; out.depth = pushRight + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushLeft) {\n\t\t\tout.normalX = -1; out.normalY = 0; out.depth = pushLeft + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushDown) {\n\t\t\tout.normalX = 0; out.normalY = 1; out.depth = pushDown + radius;\n\t\t\treturn true;\n\t\t}\n\t\tout.normalX = 0; out.normalY = -1; out.depth = pushUp + radius;\n\t\treturn true;\n\t}\n\n\tconst dist = Math.sqrt(distSq);\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.depth = radius - dist;\n\treturn true;\n}\n\n// ==================== Contact Dispatcher ====================\n\n/**\n * Dispatch to the correct narrowphase function for the given pair and\n * write the contact into `out`. Returns `true` if the pair overlaps.\n */\nexport function computeContact(a: BaseColliderInfo, b: BaseColliderInfo, out: Contact): boolean {\n\tif (a.shape === AABB_SHAPE && b.shape === AABB_SHAPE) {\n\t\treturn computeAABBvsAABB(\n\t\t\ta.x, a.y, a.halfWidth, a.halfHeight,\n\t\t\tb.x, b.y, b.halfWidth, b.halfHeight,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === CIRCLE_SHAPE && b.shape === CIRCLE_SHAPE) {\n\t\treturn computeCircleVsCircle(\n\t\t\ta.x, a.y, a.radius,\n\t\t\tb.x, b.y, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === AABB_SHAPE && b.shape === CIRCLE_SHAPE) {\n\t\treturn computeAABBvsCircle(\n\t\t\ta.x, a.y, a.halfWidth, a.halfHeight,\n\t\t\tb.x, b.y, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\t// a is Circle, b is AABB — compute as AABB-vs-Circle, then flip normal in place\n\tif (!computeAABBvsCircle(\n\t\tb.x, b.y, b.halfWidth, b.halfHeight,\n\t\ta.x, a.y, a.radius,\n\t\tout,\n\t)) return false;\n\tout.normalX = -out.normalX;\n\tout.normalY = -out.normalY;\n\treturn true;\n}\n\n// ==================== Collision Iteration ====================\n\n/** Module-level reusable set for broadphase candidates. */\nconst _broadphaseCandidates = new Set<number>();\n\nlet _bruteForceWarned = false;\nconst BRUTE_FORCE_WARN_THRESHOLD = 50;\n\n/**\n * Generic collision detection pipeline: brute-force or broadphase,\n * with layer filtering and contact computation.\n *\n * `count` is the number of live entries at the front of `colliders`.\n * The array itself may be a grow-only pool — only indices `[0, count)`\n * are iterated, so trailing pool slots are ignored.\n *\n * `workingMap` is a caller-owned `Map<number, I>` used by the broadphase\n * path as an entityId → collider lookup. It is cleared and repopulated on\n * each call; callers should allocate it once and pass the same instance\n * every frame. Unused by the brute-force path but still required so that\n * typed reuse is the default, not an opt-in.\n *\n * Uses a context parameter forwarded to the callback to avoid\n * per-frame closure allocation.\n */\nexport function detectCollisions<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tworkingMap: Map<number, I>,\n\tspatialIndex: SpatialIndex | undefined,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tif (spatialIndex) {\n\t\tbroadphaseDetect(colliders, count, workingMap, spatialIndex, onContact, context);\n\t} else {\n\t\tbruteForceDetect(colliders, count, onContact, context);\n\t}\n}\n\nfunction bruteForceDetect<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tif (!_bruteForceWarned && count >= BRUTE_FORCE_WARN_THRESHOLD) {\n\t\t_bruteForceWarned = true;\n\t\tconsole.warn(\n\t\t\t`[ecspresso] Collision detection is using O(n²) brute force with ${count} colliders. ` +\n\t\t\t`For better performance, install createSpatialIndexPlugin() alongside your collision or physics2D plugin.`,\n\t\t);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tfor (let j = i + 1; j < count; j++) {\n\t\t\tconst b = colliders[j];\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n\nfunction broadphaseDetect<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tcolliderMap: Map<number, I>,\n\tspatialIndex: SpatialIndex,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tcolliderMap.clear();\n\tfor (let i = 0; i < count; i++) {\n\t\tconst c = colliders[i];\n\t\tif (!c) continue;\n\t\tcolliderMap.set(c.entityId, c);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tconst aHalfW = a.shape === AABB_SHAPE ? a.halfWidth : a.radius;\n\t\tconst aHalfH = a.shape === AABB_SHAPE ? a.halfHeight : a.radius;\n\n\t\t_broadphaseCandidates.clear();\n\t\tspatialIndex.queryRectInto(\n\t\t\ta.x - aHalfW, a.y - aHalfH,\n\t\t\ta.x + aHalfW, a.y + aHalfH,\n\t\t\t_broadphaseCandidates,\n\t\t);\n\n\t\tfor (const bId of _broadphaseCandidates) {\n\t\t\tif (bId <= a.entityId) continue;\n\n\t\t\tconst b = colliderMap.get(bId);\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n"
5
+ "/**\n * Physics 2D Plugin for ECSpresso\n *\n * Provides ECS-native arcade physics: gravity, forces, drag, semi-implicit Euler\n * integration, and impulse-based collision response with friction.\n *\n * Reuses collider types from the collision plugin for shape definitions.\n * Has its own collision detection in fixedUpdate for physics response;\n * the existing collision plugin can still run in postUpdate for game logic events.\n */\n\nimport { definePlugin } from 'ecspresso';\nimport type { SystemPhase } from 'ecspresso';\nimport type { TransformComponentTypes, TransformWorldConfig } from '../spatial/transform';\nimport type { CollisionComponentTypes, LayerFactories } from './collision';\nimport type { Vector2D } from 'ecspresso';\nimport { fillBaseColliderInfo, detectCollisions, AABB_SHAPE, type Contact, type BaseColliderInfo } from '../../utils/narrowphase';\nimport type { SpatialIndex } from '../../utils/spatial-hash';\n\n// ==================== Component Types ====================\n\n/**\n * Rigid body types for physics simulation.\n * - 'dynamic': Fully simulated (gravity, forces, collisions)\n * - 'kinematic': Moves via velocity only (ignores gravity/forces, immovable in collisions)\n * - 'static': Immovable (ignores gravity, forces, and velocity)\n */\nexport type BodyType = 'dynamic' | 'kinematic' | 'static';\n\n/**\n * Rigid body component controlling physics behavior.\n */\nexport interface RigidBody {\n\ttype: BodyType;\n\t/** Mass in arbitrary units. Affects force→acceleration. Infinity = immovable. */\n\tmass: number;\n\t/** Linear velocity damping coefficient (units/sec, 0 = none) */\n\tdrag: number;\n\t/** Bounciness 0–1 (0 = no bounce, 1 = perfectly elastic) */\n\trestitution: number;\n\t/** Surface friction coefficient 0–1 */\n\tfriction: number;\n\t/** Per-entity gravity multiplier (0 = no gravity) */\n\tgravityScale: number;\n}\n\n/**\n * Component types directly provided by the physics plugin.\n */\nexport interface Physics2DOwnComponentTypes {\n\trigidBody: RigidBody;\n\tvelocity: Vector2D;\n\tforce: Vector2D;\n}\n\n/**\n * Full component types available when using the physics plugin\n * (own components + transform + collision dependencies).\n * Convenience alias for consumer code.\n */\nexport interface Physics2DComponentTypes<L extends string = never> extends TransformComponentTypes, CollisionComponentTypes<L>, Physics2DOwnComponentTypes {}\n\n// ==================== Resource Types ====================\n\n/**\n * Physics configuration resource.\n */\nexport interface Physics2DConfig {\n\tgravity: Vector2D;\n}\n\nexport interface Physics2DResourceTypes {\n\tphysicsConfig: Physics2DConfig;\n}\n\n// ==================== Event Types ====================\n\n/**\n * Event emitted for each physics collision pair.\n *\n * Normal components are flattened (`normalX`/`normalY`) rather than nested\n * in a `Vector2D` to avoid a per-event allocation in the physics hot path.\n */\nexport interface Physics2DCollisionEvent {\n\tentityA: number;\n\tentityB: number;\n\t/** Unit normal X, pointing from A toward B */\n\tnormalX: number;\n\t/** Unit normal Y, pointing from A toward B */\n\tnormalY: number;\n\t/** Penetration depth (positive) */\n\tdepth: number;\n}\n\nexport interface Physics2DEventTypes {\n\tphysicsCollision: Physics2DCollisionEvent;\n}\n\n// ==================== Plugin Options ====================\n\nexport interface Physics2DPluginOptions<G extends string = 'physics2D', CG extends string = never> {\n\t/** World gravity vector (default: {x: 0, y: 0}) */\n\tgravity?: Vector2D;\n\t/** System group name (default: 'physics2D') */\n\tsystemGroup?: G;\n\t/** Additional group for the collision system only (default: none).\n\t * When set, the collision system belongs to both `systemGroup` and this group,\n\t * allowing independent enable/disable of collision detection. */\n\tcollisionSystemGroup?: CG;\n\t/** Priority for integration system (default: 1000) */\n\tintegrationPriority?: number;\n\t/** Priority for collision system (default: 900) */\n\tcollisionPriority?: number;\n\t/** Execution phase (default: 'fixedUpdate') */\n\tphase?: SystemPhase;\n}\n\n// ==================== Helper Functions ====================\n\nexport interface RigidBodyOptions {\n\tmass?: number;\n\tdrag?: number;\n\trestitution?: number;\n\tfriction?: number;\n\tgravityScale?: number;\n}\n\n/**\n * Create a rigid body + force component pair.\n * Static bodies automatically get mass=Infinity.\n */\nexport function createRigidBody(\n\ttype: BodyType,\n\toptions?: RigidBodyOptions,\n): { rigidBody: RigidBody; force: Vector2D } {\n\treturn {\n\t\trigidBody: {\n\t\t\ttype,\n\t\t\tmass: type === 'static' ? Infinity : (options?.mass ?? 1),\n\t\t\tdrag: options?.drag ?? 0,\n\t\t\trestitution: options?.restitution ?? 0,\n\t\t\tfriction: options?.friction ?? 0,\n\t\t\tgravityScale: options?.gravityScale ?? 1,\n\t\t},\n\t\tforce: { x: 0, y: 0 },\n\t};\n}\n\n/**\n * Create a force component with initial values.\n */\nexport function createForce(x: number, y: number): { force: Vector2D } {\n\treturn { force: { x, y } };\n}\n\n/**\n * Accumulate a force onto an entity's force component.\n */\nexport function applyForce(\n\tecs: { getComponent(id: number, name: 'force'): Vector2D | undefined },\n\tentityId: number,\n\tfx: number,\n\tfy: number,\n): void {\n\tconst force = ecs.getComponent(entityId, 'force');\n\tif (!force) return;\n\tforce.x += fx;\n\tforce.y += fy;\n}\n\n/**\n * Apply an instantaneous impulse: velocity += impulse / mass.\n */\nexport function applyImpulse(\n\tecs: {\n\t\tgetComponent(id: number, name: 'velocity'): Vector2D | undefined;\n\t\tgetComponent(id: number, name: 'rigidBody'): RigidBody | undefined;\n\t},\n\tentityId: number,\n\tix: number,\n\tiy: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity');\n\tconst rigidBody = ecs.getComponent(entityId, 'rigidBody');\n\tif (!velocity || !rigidBody) return;\n\tif (rigidBody.mass === Infinity || rigidBody.mass === 0) return;\n\tvelocity.x += ix / rigidBody.mass;\n\tvelocity.y += iy / rigidBody.mass;\n}\n\n/**\n * Directly set an entity's velocity.\n */\nexport function setVelocity(\n\tecs: { getComponent(id: number, name: 'velocity'): Vector2D | undefined },\n\tentityId: number,\n\tvx: number,\n\tvy: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity');\n\tif (!velocity) return;\n\tvelocity.x = vx;\n\tvelocity.y = vy;\n}\n\n// ==================== Internal: Collider Info ====================\n\ninterface Physics2DColliderInfo<L extends string = string> extends BaseColliderInfo<L> {\n\trigidBody: RigidBody;\n\tvelocity: Vector2D;\n}\n\n// ==================== Collision Response ====================\n\n/**\n * Module-level reusable physics collision event. Subscribers must consume\n * synchronously — same contract as the shared narrowphase Contact.\n */\nconst _physicsCollisionEvent: Physics2DCollisionEvent = {\n\tentityA: 0, entityB: 0, normalX: 0, normalY: 0, depth: 0,\n};\n\ninterface PhysicsEcsLike {\n\tgetComponent(id: number, name: 'localTransform'): { x: number; y: number } | undefined;\n\teventBus: { publish(event: 'physicsCollision', data: Physics2DCollisionEvent): void };\n\tmarkChanged(entityId: number, componentName: 'localTransform' | 'velocity'): void;\n}\n\n/**\n * Resolve a physics collision pair: position correction, impulse response, event.\n */\nfunction resolvePhysicsContact(\n\ta: Physics2DColliderInfo,\n\tb: Physics2DColliderInfo,\n\tcontact: Contact,\n\tecs: PhysicsEcsLike,\n): void {\n\tconst invMassA = (a.rigidBody.type === 'dynamic' && a.rigidBody.mass > 0 && a.rigidBody.mass !== Infinity)\n\t\t? 1 / a.rigidBody.mass\n\t\t: 0;\n\tconst invMassB = (b.rigidBody.type === 'dynamic' && b.rigidBody.mass > 0 && b.rigidBody.mass !== Infinity)\n\t\t? 1 / b.rigidBody.mass\n\t\t: 0;\n\tconst totalInvMass = invMassA + invMassB;\n\n\t// Position correction\n\tif (totalInvMass > 0) {\n\t\tconst correctionScale = contact.depth / totalInvMass;\n\n\t\tif (invMassA > 0) {\n\t\t\tconst ltA = ecs.getComponent(a.entityId, 'localTransform');\n\t\t\tif (!ltA) return;\n\t\t\tconst corrA = correctionScale * invMassA;\n\t\t\tltA.x -= corrA * contact.normalX;\n\t\t\tltA.y -= corrA * contact.normalY;\n\t\t\t// Sync cached position so subsequent pairs in this frame use corrected values\n\t\t\ta.x = ltA.x;\n\t\t\ta.y = ltA.y;\n\t\t\tecs.markChanged(a.entityId, 'localTransform');\n\t\t}\n\n\t\tif (invMassB > 0) {\n\t\t\tconst ltB = ecs.getComponent(b.entityId, 'localTransform');\n\t\t\tif (!ltB) return;\n\t\t\tconst corrB = correctionScale * invMassB;\n\t\t\tltB.x += corrB * contact.normalX;\n\t\t\tltB.y += corrB * contact.normalY;\n\t\t\tb.x = ltB.x;\n\t\t\tb.y = ltB.y;\n\t\t\tecs.markChanged(b.entityId, 'localTransform');\n\t\t}\n\n\t\t// Velocity response (impulse-based)\n\t\tconst relVelX = b.velocity.x - a.velocity.x;\n\t\tconst relVelY = b.velocity.y - a.velocity.y;\n\t\tconst velAlongNormal = relVelX * contact.normalX + relVelY * contact.normalY;\n\n\t\tif (velAlongNormal < 0) {\n\t\t\tconst restitution = Math.min(a.rigidBody.restitution, b.rigidBody.restitution);\n\t\t\tconst normalImpulse = -(1 + restitution) * velAlongNormal / totalInvMass;\n\n\t\t\ta.velocity.x -= normalImpulse * invMassA * contact.normalX;\n\t\t\ta.velocity.y -= normalImpulse * invMassA * contact.normalY;\n\t\t\tb.velocity.x += normalImpulse * invMassB * contact.normalX;\n\t\t\tb.velocity.y += normalImpulse * invMassB * contact.normalY;\n\n\t\t\t// Friction (tangential impulse)\n\t\t\tconst tangentX = relVelX - velAlongNormal * contact.normalX;\n\t\t\tconst tangentY = relVelY - velAlongNormal * contact.normalY;\n\t\t\tconst tangentSpeed = Math.sqrt(tangentX * tangentX + tangentY * tangentY);\n\n\t\t\tif (tangentSpeed > 1e-6) {\n\t\t\t\tconst tangentNX = tangentX / tangentSpeed;\n\t\t\t\tconst tangentNY = tangentY / tangentSpeed;\n\t\t\t\tconst friction = Math.sqrt(a.rigidBody.friction * b.rigidBody.friction);\n\t\t\t\tconst maxFrictionImpulse = friction * Math.abs(normalImpulse);\n\t\t\t\tconst tangentImpulse = Math.min(tangentSpeed / totalInvMass, maxFrictionImpulse);\n\n\t\t\t\ta.velocity.x += tangentImpulse * invMassA * tangentNX;\n\t\t\t\ta.velocity.y += tangentImpulse * invMassA * tangentNY;\n\t\t\t\tb.velocity.x -= tangentImpulse * invMassB * tangentNX;\n\t\t\t\tb.velocity.y -= tangentImpulse * invMassB * tangentNY;\n\t\t\t}\n\t\t}\n\n\t\tecs.markChanged(a.entityId, 'velocity');\n\t\tecs.markChanged(b.entityId, 'velocity');\n\t}\n\n\t_physicsCollisionEvent.entityA = a.entityId;\n\t_physicsCollisionEvent.entityB = b.entityId;\n\t_physicsCollisionEvent.normalX = contact.normalX;\n\t_physicsCollisionEvent.normalY = contact.normalY;\n\t_physicsCollisionEvent.depth = contact.depth;\n\tecs.eventBus.publish('physicsCollision', _physicsCollisionEvent);\n}\n\n// ==================== Plugin Factory ====================\n\n/**\n * Create a 2D physics plugin for ECSpresso.\n *\n * Provides:\n * - Semi-implicit Euler integration (gravity, forces, drag → velocity → position)\n * - Impulse-based collision response with restitution and friction\n * - physicsCollision events with contact normal and depth\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTransformPlugin())\n * .withPlugin(createPhysics2DPlugin({ gravity: { x: 0, y: 980 } }))\n * .withFixedTimestep(1/60)\n * .build();\n *\n * ecs.spawn({\n * ...createTransform(100, 200),\n * ...createRigidBody('dynamic', { mass: 1, restitution: 0.5 }),\n * velocity: { x: 0, y: 0 },\n * ...createAABBCollider(32, 32),\n * ...createCollisionLayer('player', ['ground']),\n * });\n * ```\n */\n\ntype Physics2DProvides<L extends string = never> = Physics2DOwnComponentTypes & CollisionComponentTypes<L>;\n\nexport function createPhysics2DPlugin<L extends string = never, G extends string = 'physics2D', CG extends string = never>(\n\toptions?: Physics2DPluginOptions<G, CG> & { layers?: LayerFactories<Record<L, readonly string[]>> },\n) {\n\tconst {\n\t\tgravity = { x: 0, y: 0 },\n\t\tsystemGroup = 'physics2D',\n\t\tcollisionSystemGroup,\n\t\tintegrationPriority = 1000,\n\t\tcollisionPriority = 900,\n\t\tphase = 'fixedUpdate',\n\t} = options ?? {};\n\n\treturn definePlugin('physics2D')\n\t\t.withComponentTypes<Physics2DProvides<L>>()\n\t\t.withEventTypes<Physics2DEventTypes>()\n\t\t.withResourceTypes<Physics2DResourceTypes>()\n\t\t.withLabels<'physics2D-integration' | 'physics2D-collision'>()\n\t\t.withGroups<G | CG>()\n\t\t.requires<TransformWorldConfig>()\n\t\t.install((world) => {\n\t\t\t// rigidBody requires velocity and force — auto-add with zero defaults\n\t\t\tworld.registerRequired('rigidBody', 'velocity', () => ({ x: 0, y: 0 }));\n\t\t\tworld.registerRequired('rigidBody', 'force', () => ({ x: 0, y: 0 }));\n\n\t\t\tworld.addResource('physicsConfig', { gravity: { x: gravity.x, y: gravity.y } });\n\n\t\t\t// ==================== Integration System ====================\n\n\t\t\tworld\n\t\t\t\t.addSystem('physics2D-integration')\n\t\t\t\t.setPriority(integrationPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup)\n\t\t\t\t.addQuery('bodies', {\n\t\t\t\t\twith: ['localTransform', 'velocity', 'rigidBody', 'force'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, dt, ecs }) => {\n\t\t\t\t\tconst { gravity: g } = ecs.getResource('physicsConfig');\n\t\t\t\t\tconst gx = g.x;\n\t\t\t\t\tconst gy = g.y;\n\n\t\t\t\t\t// TODO(perf): no early-out for \"sleeping\" dynamic bodies — a packed\n\t\t\t\t\t// pile of resting entities still runs gravity/drag/force-clear/\n\t\t\t\t\t// markChanged every step. A sleep flag on RigidBody that latches\n\t\t\t\t\t// after N frames of near-zero velocity (and clears on impulse or\n\t\t\t\t\t// applied force) would let most of a stabilized scene skip the\n\t\t\t\t\t// full per-entity body of this loop. Keep in sync with physics3D.\n\t\t\t\t\tfor (const entity of queries.bodies) {\n\t\t\t\t\t\tconst { localTransform, velocity, rigidBody, force } = entity.components;\n\n\t\t\t\t\t\t// Static bodies: skip entirely\n\t\t\t\t\t\tif (rigidBody.type === 'static') continue;\n\n\t\t\t\t\t\t// Dynamic bodies: apply gravity, forces, drag\n\t\t\t\t\t\tif (rigidBody.type === 'dynamic') {\n\t\t\t\t\t\t\t// 1. Gravity\n\t\t\t\t\t\t\tconst gsdt = rigidBody.gravityScale * dt;\n\t\t\t\t\t\t\tvelocity.x += gx * gsdt;\n\t\t\t\t\t\t\tvelocity.y += gy * gsdt;\n\n\t\t\t\t\t\t\t// 2. Forces (F = ma → a = F/m)\n\t\t\t\t\t\t\tconst mass = rigidBody.mass;\n\t\t\t\t\t\t\tif (mass > 0 && mass !== Infinity) {\n\t\t\t\t\t\t\t\tconst invMassDt = dt / mass;\n\t\t\t\t\t\t\t\tvelocity.x += force.x * invMassDt;\n\t\t\t\t\t\t\t\tvelocity.y += force.y * invMassDt;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// 3. Drag\n\t\t\t\t\t\t\tif (rigidBody.drag > 0) {\n\t\t\t\t\t\t\t\tconst damping = Math.max(0, 1 - rigidBody.drag * dt);\n\t\t\t\t\t\t\t\tvelocity.x *= damping;\n\t\t\t\t\t\t\t\tvelocity.y *= damping;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Both dynamic and kinematic: integrate position\n\t\t\t\t\t\tlocalTransform.x += velocity.x * dt;\n\t\t\t\t\t\tlocalTransform.y += velocity.y * dt;\n\n\t\t\t\t\t\t// Clear accumulated forces\n\t\t\t\t\t\tforce.x = 0;\n\t\t\t\t\t\tforce.y = 0;\n\n\t\t\t\t\t\tecs.markChanged(entity.id, 'localTransform');\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t// ==================== Collision System ====================\n\n\t\t\tconst collisionSystem = world\n\t\t\t\t.addSystem('physics2D-collision')\n\t\t\t\t.setPriority(collisionPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup);\n\n\t\t\tif (collisionSystemGroup) {\n\t\t\t\tcollisionSystem.inGroup(collisionSystemGroup);\n\t\t\t}\n\n\t\t\t// Grow-only pool of Physics2DColliderInfo slots reused across frames.\n\t\t\t// Steady-state: zero allocations per frame once the pool is warm.\n\t\t\tconst colliderPool: Physics2DColliderInfo<L>[] = [];\n\t\t\t// Reusable entityId → collider lookup for the broadphase path.\n\t\t\tconst broadphaseMap = new Map<number, Physics2DColliderInfo<L>>();\n\t\t\t// Cached spatial index reference (resolved once on first frame).\n\t\t\tlet cachedSI: SpatialIndex | undefined;\n\t\t\tlet siResolved = false;\n\n\t\t\tcollisionSystem\n\t\t\t\t.addQuery('collidables', {\n\t\t\t\t\twith: ['localTransform', 'rigidBody', 'velocity', 'collisionLayer'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, ecs }) => {\n\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\t// TODO(perf): collider shape is discovered via two ecs.getComponent\n\t\t\t\t\t// calls per entity per frame because the query can't express\n\t\t\t\t\t// \"aabbCollider OR circleCollider\". Splitting into two queries\n\t\t\t\t\t// (aabb-bearing, circle-bearing) would eliminate these lookups at\n\t\t\t\t\t// the cost of two pool-fill passes. Keep in sync with physics3D.\n\t\t\t\t\tfor (const entity of queries.collidables) {\n\t\t\t\t\t\tconst { localTransform, rigidBody, velocity, collisionLayer } = entity.components;\n\t\t\t\t\t\tconst aabb = ecs.getComponent(entity.id, 'aabbCollider');\n\t\t\t\t\t\tconst circle = aabb ? undefined : ecs.getComponent(entity.id, 'circleCollider');\n\t\t\t\t\t\tif (!aabb && !circle) continue;\n\n\t\t\t\t\t\tlet slot = colliderPool[count];\n\t\t\t\t\t\tif (!slot) {\n\t\t\t\t\t\t\tslot = {\n\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\tx: localTransform.x,\n\t\t\t\t\t\t\t\ty: localTransform.y,\n\t\t\t\t\t\t\t\tlayer: collisionLayer.layer,\n\t\t\t\t\t\t\t\tcollidesWith: collisionLayer.collidesWith,\n\t\t\t\t\t\t\t\tshape: AABB_SHAPE,\n\t\t\t\t\t\t\t\thalfWidth: 0,\n\t\t\t\t\t\t\t\thalfHeight: 0,\n\t\t\t\t\t\t\t\tradius: 0,\n\t\t\t\t\t\t\t\trigidBody,\n\t\t\t\t\t\t\t\tvelocity,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tcolliderPool[count] = slot;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tslot.rigidBody = rigidBody;\n\t\t\t\t\t\t\tslot.velocity = velocity;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!fillBaseColliderInfo(\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tentity.id, localTransform.x, localTransform.y,\n\t\t\t\t\t\t\tcollisionLayer.layer, collisionLayer.collidesWith,\n\t\t\t\t\t\t\taabb, circle,\n\t\t\t\t\t\t)) continue;\n\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!siResolved) {\n\t\t\t\t\t\tcachedSI = ecs.tryGetResource<SpatialIndex>('spatialIndex');\n\t\t\t\t\t\tsiResolved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdetectCollisions(colliderPool, count, broadphaseMap, cachedSI, resolvePhysicsContact, ecs);\n\t\t\t\t});\n\t\t});\n}\n",
6
+ "/**\n * Shared Narrowphase Module\n *\n * Provides contact-computing narrowphase tests and a generic collision\n * iteration pipeline used by both the collision plugin (event-only) and\n * the physics2D plugin (impulse response).\n */\n\nimport type { SpatialIndex } from './spatial-hash';\n\n// ==================== Contact ====================\n\n/**\n * Contact result from a narrowphase test. Normal points from A toward B.\n *\n * Narrowphase functions use this as an out-parameter: the caller owns the\n * struct, the function writes fields in place and returns `true` on hit.\n * The `onContact` callback in `detectCollisions` receives a shared module-\n * level instance — **subscribers must consume it synchronously and must not\n * retain the reference across frames**.\n */\nexport interface Contact {\n\tnormalX: number;\n\tnormalY: number;\n\t/** Penetration depth (positive = overlapping) */\n\tdepth: number;\n}\n\n/**\n * Module-level reusable Contact passed down from `detectCollisions` into\n * narrowphase tests and forwarded to the `onContact` callback. Reused across\n * every pair in every frame — zero allocation in the narrowphase hot path.\n */\nconst _sharedContact: Contact = { normalX: 0, normalY: 0, depth: 0 };\n\n// ==================== BaseColliderInfo ====================\n\n/** Collider shape discriminator for the flattened BaseColliderInfo layout. */\nexport const AABB_SHAPE = 0;\nexport const CIRCLE_SHAPE = 1;\nexport type ColliderShape = typeof AABB_SHAPE | typeof CIRCLE_SHAPE;\n\n/**\n * Minimum collider data shared by collision and physics bundles.\n *\n * Flat layout (no nested `aabb` / `circle` sub-objects): the `shape`\n * discriminator tells you whether to read `halfWidth`/`halfHeight`\n * (AABB) or `radius` (Circle). Unused fields are set to 0.\n *\n * This shape is pool-friendly — all fields are assigned in place each\n * frame without allocating nested objects.\n */\nexport interface BaseColliderInfo<L extends string = string> {\n\tentityId: number;\n\tx: number;\n\ty: number;\n\tlayer: L;\n\tcollidesWith: readonly L[];\n\tshape: ColliderShape;\n\thalfWidth: number;\n\thalfHeight: number;\n\tradius: number;\n}\n\n// ==================== Collider Construction ====================\n\n/**\n * Populate a `BaseColliderInfo` slot in place from raw component data.\n * Returns `true` if the slot was filled, `false` if the entity has no\n * collider (caller should skip it).\n *\n * If an entity has both AABB and circle colliders, AABB wins and only\n * the AABB offset is applied. This matches the dispatch precedence in\n * `computeContact`; the previous implementation stacked both offsets,\n * which was a bug.\n */\nexport function fillBaseColliderInfo<L extends string>(\n\tinfo: BaseColliderInfo<L>,\n\tentityId: number,\n\tx: number,\n\ty: number,\n\tlayer: L,\n\tcollidesWith: readonly L[],\n\taabb: { width: number; height: number; offsetX?: number; offsetY?: number } | undefined,\n\tcircle: { radius: number; offsetX?: number; offsetY?: number } | undefined,\n): boolean {\n\tinfo.entityId = entityId;\n\tinfo.layer = layer;\n\tinfo.collidesWith = collidesWith;\n\n\tif (aabb) {\n\t\tinfo.x = x + (aabb.offsetX ?? 0);\n\t\tinfo.y = y + (aabb.offsetY ?? 0);\n\t\tinfo.shape = AABB_SHAPE;\n\t\tinfo.halfWidth = aabb.width / 2;\n\t\tinfo.halfHeight = aabb.height / 2;\n\t\tinfo.radius = 0;\n\t\treturn true;\n\t}\n\n\tif (circle) {\n\t\tinfo.x = x + (circle.offsetX ?? 0);\n\t\tinfo.y = y + (circle.offsetY ?? 0);\n\t\tinfo.shape = CIRCLE_SHAPE;\n\t\tinfo.halfWidth = 0;\n\t\tinfo.halfHeight = 0;\n\t\tinfo.radius = circle.radius;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// ==================== Spatial Index Lookup ====================\n\n/**\n * Retrieve the optional spatialIndex resource, returning undefined when absent.\n * Centralizes the cross-plugin typed lookup so individual plugins don't each\n * need to import SpatialIndex or repeat the tryGetResource pattern.\n */\nexport function tryGetSpatialIndex(\n\ttryGetResource: <T>(key: string) => T | undefined,\n): SpatialIndex | undefined {\n\treturn tryGetResource<SpatialIndex>('spatialIndex');\n}\n\n// ==================== Narrowphase Tests ====================\n\n/**\n * Write an AABB-AABB contact into `out`. Returns `true` if the shapes\n * overlap (out was filled), `false` otherwise.\n */\nexport function computeAABBvsAABB(\n\tax: number, ay: number, ahw: number, ahh: number,\n\tbx: number, by: number, bhw: number, bhh: number,\n\tout: Contact,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst overlapX = (ahw + bhw) - Math.abs(dx);\n\tconst overlapY = (ahh + bhh) - Math.abs(dy);\n\n\tif (overlapX <= 0 || overlapY <= 0) return false;\n\n\tif (overlapX < overlapY) {\n\t\tout.normalX = dx >= 0 ? 1 : -1;\n\t\tout.normalY = 0;\n\t\tout.depth = overlapX;\n\t\treturn true;\n\t}\n\tout.normalX = 0;\n\tout.normalY = dy >= 0 ? 1 : -1;\n\tout.depth = overlapY;\n\treturn true;\n}\n\nexport function computeCircleVsCircle(\n\tax: number, ay: number, ar: number,\n\tbx: number, by: number, br: number,\n\tout: Contact,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst distSq = dx * dx + dy * dy;\n\tconst radiusSum = ar + br;\n\n\tif (distSq >= radiusSum * radiusSum) return false;\n\n\tconst dist = Math.sqrt(distSq);\n\tif (dist === 0) {\n\t\tout.normalX = 1;\n\t\tout.normalY = 0;\n\t\tout.depth = radiusSum;\n\t\treturn true;\n\t}\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.depth = radiusSum - dist;\n\treturn true;\n}\n\nexport function computeAABBvsCircle(\n\taabbX: number, aabbY: number, ahw: number, ahh: number,\n\tcircleX: number, circleY: number, radius: number,\n\tout: Contact,\n): boolean {\n\tconst closestX = Math.max(aabbX - ahw, Math.min(circleX, aabbX + ahw));\n\tconst closestY = Math.max(aabbY - ahh, Math.min(circleY, aabbY + ahh));\n\n\tconst dx = circleX - closestX;\n\tconst dy = circleY - closestY;\n\tconst distSq = dx * dx + dy * dy;\n\n\tif (distSq >= radius * radius) return false;\n\n\t// Circle center inside AABB\n\tif (distSq === 0) {\n\t\tconst pushLeft = (circleX - (aabbX - ahw));\n\t\tconst pushRight = ((aabbX + ahw) - circleX);\n\t\tconst pushUp = (circleY - (aabbY - ahh));\n\t\tconst pushDown = ((aabbY + ahh) - circleY);\n\t\tconst minPush = Math.min(pushLeft, pushRight, pushUp, pushDown);\n\n\t\tif (minPush === pushRight) {\n\t\t\tout.normalX = 1; out.normalY = 0; out.depth = pushRight + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushLeft) {\n\t\t\tout.normalX = -1; out.normalY = 0; out.depth = pushLeft + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushDown) {\n\t\t\tout.normalX = 0; out.normalY = 1; out.depth = pushDown + radius;\n\t\t\treturn true;\n\t\t}\n\t\tout.normalX = 0; out.normalY = -1; out.depth = pushUp + radius;\n\t\treturn true;\n\t}\n\n\tconst dist = Math.sqrt(distSq);\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.depth = radius - dist;\n\treturn true;\n}\n\n// ==================== Contact Dispatcher ====================\n\n/**\n * Dispatch to the correct narrowphase function for the given pair and\n * write the contact into `out`. Returns `true` if the pair overlaps.\n */\nexport function computeContact(a: BaseColliderInfo, b: BaseColliderInfo, out: Contact): boolean {\n\tif (a.shape === AABB_SHAPE && b.shape === AABB_SHAPE) {\n\t\treturn computeAABBvsAABB(\n\t\t\ta.x, a.y, a.halfWidth, a.halfHeight,\n\t\t\tb.x, b.y, b.halfWidth, b.halfHeight,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === CIRCLE_SHAPE && b.shape === CIRCLE_SHAPE) {\n\t\treturn computeCircleVsCircle(\n\t\t\ta.x, a.y, a.radius,\n\t\t\tb.x, b.y, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === AABB_SHAPE && b.shape === CIRCLE_SHAPE) {\n\t\treturn computeAABBvsCircle(\n\t\t\ta.x, a.y, a.halfWidth, a.halfHeight,\n\t\t\tb.x, b.y, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\t// a is Circle, b is AABB — compute as AABB-vs-Circle, then flip normal in place\n\tif (!computeAABBvsCircle(\n\t\tb.x, b.y, b.halfWidth, b.halfHeight,\n\t\ta.x, a.y, a.radius,\n\t\tout,\n\t)) return false;\n\tout.normalX = -out.normalX;\n\tout.normalY = -out.normalY;\n\treturn true;\n}\n\n// ==================== Collision Iteration ====================\n\n/** Module-level reusable set for broadphase candidates. */\nconst _broadphaseCandidates = new Set<number>();\n\nlet _bruteForceWarned = false;\nconst BRUTE_FORCE_WARN_THRESHOLD = 50;\n\n/**\n * Generic collision detection pipeline: brute-force or broadphase,\n * with layer filtering and contact computation.\n *\n * `count` is the number of live entries at the front of `colliders`.\n * The array itself may be a grow-only pool — only indices `[0, count)`\n * are iterated, so trailing pool slots are ignored.\n *\n * `workingMap` is a caller-owned `Map<number, I>` used by the broadphase\n * path as an entityId → collider lookup. It is cleared and repopulated on\n * each call; callers should allocate it once and pass the same instance\n * every frame. Unused by the brute-force path but still required so that\n * typed reuse is the default, not an opt-in.\n *\n * Uses a context parameter forwarded to the callback to avoid\n * per-frame closure allocation.\n */\nexport function detectCollisions<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tworkingMap: Map<number, I>,\n\tspatialIndex: SpatialIndex | undefined,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tif (spatialIndex) {\n\t\tbroadphaseDetect(colliders, count, workingMap, spatialIndex, onContact, context);\n\t} else {\n\t\tbruteForceDetect(colliders, count, onContact, context);\n\t}\n}\n\nfunction bruteForceDetect<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tif (!_bruteForceWarned && count >= BRUTE_FORCE_WARN_THRESHOLD) {\n\t\t_bruteForceWarned = true;\n\t\tconsole.warn(\n\t\t\t`[ecspresso] Collision detection is using O(n²) brute force with ${count} colliders. ` +\n\t\t\t`For better performance, install createSpatialIndexPlugin() alongside your collision or physics2D plugin.`,\n\t\t);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tfor (let j = i + 1; j < count; j++) {\n\t\t\tconst b = colliders[j];\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n\nfunction broadphaseDetect<I extends BaseColliderInfo, C>(\n\tcolliders: I[],\n\tcount: number,\n\tcolliderMap: Map<number, I>,\n\tspatialIndex: SpatialIndex,\n\tonContact: (a: I, b: I, contact: Contact, context: C) => void,\n\tcontext: C,\n): void {\n\tcolliderMap.clear();\n\tfor (let i = 0; i < count; i++) {\n\t\tconst c = colliders[i];\n\t\tif (!c) continue;\n\t\tcolliderMap.set(c.entityId, c);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tconst aHalfW = a.shape === AABB_SHAPE ? a.halfWidth : a.radius;\n\t\tconst aHalfH = a.shape === AABB_SHAPE ? a.halfHeight : a.radius;\n\n\t\t_broadphaseCandidates.clear();\n\t\tspatialIndex.queryRectInto(\n\t\t\ta.x - aHalfW, a.y - aHalfH,\n\t\t\ta.x + aHalfW, a.y + aHalfH,\n\t\t\t_broadphaseCandidates,\n\t\t);\n\n\t\t// TODO(perf): mirrors narrowphase3D — dense grids add every candidate\n\t\t// (including `a` itself and lower-ID entities) to the set before the\n\t\t// filter below discards ~half of them. Emitting only pairs with larger\n\t\t// IDs at query time would remove the post-hoc filter. Keep in sync with\n\t\t// whatever fix lands in narrowphase3D.\n\t\tfor (const bId of _broadphaseCandidates) {\n\t\t\tif (bId <= a.entityId) continue;\n\n\t\t\tconst b = colliderMap.get(bId);\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n"
7
7
  ],
8
- "mappings": "4cAWA,uBAAS,kBCsBT,IAAM,EAA0B,CAAE,QAAS,EAAG,QAAS,EAAG,MAAO,CAAE,EAKtD,EAAa,EAsCnB,SAAS,CAAsC,CACrD,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACU,CAKV,GAJA,EAAK,SAAW,EAChB,EAAK,MAAQ,EACb,EAAK,aAAe,EAEhB,EAOH,OANA,EAAK,EAAI,GAAK,EAAK,SAAW,GAC9B,EAAK,EAAI,GAAK,EAAK,SAAW,GAC9B,EAAK,MAvDmB,EAwDxB,EAAK,UAAY,EAAK,MAAQ,EAC9B,EAAK,WAAa,EAAK,OAAS,EAChC,EAAK,OAAS,EACP,GAGR,GAAI,EAOH,OANA,EAAK,EAAI,GAAK,EAAO,SAAW,GAChC,EAAK,EAAI,GAAK,EAAO,SAAW,GAChC,EAAK,MAhEqB,EAiE1B,EAAK,UAAY,EACjB,EAAK,WAAa,EAClB,EAAK,OAAS,EAAO,OACd,GAGR,MAAO,GAsBD,SAAS,CAAiB,CAChC,EAAY,EAAY,EAAa,EACrC,EAAY,EAAY,EAAa,EACrC,EACU,CACV,IAAM,EAAK,EAAK,EACV,EAAK,EAAK,EACV,EAAY,EAAM,EAAO,KAAK,IAAI,CAAE,EACpC,EAAY,EAAM,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F,IAAM,EAAkB,EACtB,UAAU,qBAAqB,EAC/B,YAAY,CAAiB,EAC7B,QAAQ,CAAK,EACb,QAAQ,CAAW,EAErB,GAAI,EACH,EAAgB,QAAQ,CAAoB,EAK7C,IAAM,EAA2C,CAAC,EAE5C,EAAgB,IAAI,IAEtB,EACA,EAAa,GAEjB,EACE,SAAS,cAAe,CACxB,KAAM,CAAC,iBAAkB,YAAa,WAAY,gBAAgB,CACnE,CAAC,EACA,WAAW,EAAG,UAAS,SAAU,CACjC,IAAI,EAAQ,EAOZ,QAAW,KAAU,EAAQ,YAAa,CACzC,IAAQ,iBAAgB,YAAW,WAAU,kBAAmB,EAAO,WACjE,EAAO,EAAI,aAAa,EAAO,GAAI,cAAc,EACjD,EAAS,EAAO,OAAY,EAAI,aAAa,EAAO,GAAI,gBAAgB,EAC9E,GAAI,CAAC,GAAQ,CAAC,EAAQ,SAEtB,IAAI,EAAO,EAAa,GACxB,GAAI,CAAC,EACJ,EAAO,CACN,SAAU,EAAO,GACjB,EAAG,EAAe,EAClB,EAAG,EAAe,EAClB,MAAO,EAAe,MACtB,aAAc,EAAe,aAC7B,MAAO,EACP,UAAW,EACX,WAAY,EACZ,OAAQ,EACR,YACA,UACD,EACA,EAAa,GAAS,EAEtB,OAAK,UAAY,EACjB,EAAK,SAAW,EAGjB,GAAI,CAAC,EACJ,EACA,EAAO,GAAI,EAAe,EAAG,EAAe,EAC5C,EAAe,MAAO,EAAe,aACrC,EAAM,CACP,EAAG,SAEH,IAGD,GAAI,CAAC,EACJ,EAAW,EAAI,eAA6B,cAAc,EAC1D,EAAa,GAEd,EAAiB,EAAc,EAAO,EAAe,EAAU,EAAuB,CAAG,EACzF,EACF",
9
+ "debugId": "E520CE282EB80E4364756E2164756E21",
10
10
  "names": []
11
11
  }
@@ -1,4 +1,4 @@
1
- var f=Object.defineProperty;var y=(J)=>J;function h(J,K){this[J]=y.bind(null,K)}var s=(J,K)=>{for(var Q in K)f(J,Q,{get:K[Q],enumerable:!0,configurable:!0,set:h.bind(K,Q)})};var n=(J,K)=>()=>(J&&(K=J(J=0)),K);var i=((J)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(J,{get:(K,Q)=>(typeof require<"u"?require:K)[Q]}):J)(function(J){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+J+'" is not supported')});import{definePlugin as r}from"ecspresso";var C={normalX:0,normalY:0,normalZ:0,depth:0},m=0;function g(J,K,Q,G,V,O,F,$,k){if(J.entityId=K,J.layer=O,J.collidesWith=F,$)return J.x=Q+($.offsetX??0),J.y=G+($.offsetY??0),J.z=V+($.offsetZ??0),J.shape=0,J.halfWidth=$.width/2,J.halfHeight=$.height/2,J.halfDepth=$.depth/2,J.radius=0,!0;if(k)return J.x=Q+(k.offsetX??0),J.y=G+(k.offsetY??0),J.z=V+(k.offsetZ??0),J.shape=1,J.halfWidth=0,J.halfHeight=0,J.halfDepth=0,J.radius=k.radius,!0;return!1}function p(J,K,Q,G,V,O,F,$,k,L,U,T,j){let q=F-J,W=$-K,P=k-Q,H=G+L-Math.abs(q),N=V+U-Math.abs(W),_=O+T-Math.abs(P);if(H<=0||N<=0||_<=0)return!1;if(H<=N&&H<=_)return j.normalX=q>=0?1:-1,j.normalY=0,j.normalZ=0,j.depth=H,!0;if(N<=_)return j.normalX=0,j.normalY=W>=0?1:-1,j.normalZ=0,j.depth=N,!0;return j.normalX=0,j.normalY=0,j.normalZ=P>=0?1:-1,j.depth=_,!0}function b(J,K,Q,G,V,O,F,$,k){let L=V-J,U=O-K,T=F-Q,j=L*L+U*U+T*T,q=G+$;if(j>=q*q)return!1;let W=Math.sqrt(j);if(W===0)return k.normalX=1,k.normalY=0,k.normalZ=0,k.depth=q,!0;return k.normalX=L/W,k.normalY=U/W,k.normalZ=T/W,k.depth=q-W,!0}function x(J,K,Q,G,V,O,F,$,k,L,U){let T=Math.max(J-G,Math.min(F,J+G)),j=Math.max(K-V,Math.min($,K+V)),q=Math.max(Q-O,Math.min(k,Q+O)),W=F-T,P=$-j,H=k-q,N=W*W+P*P+H*H;if(N>=L*L)return!1;if(N===0){let M=F-(J-G),S=J+G-F,X=$-(K-V),R=K+V-$,E=k-(Q-O),Y=Q+O-k,Z=Math.min(M,S,X,R,E,Y);if(Z===S)return U.normalX=1,U.normalY=0,U.normalZ=0,U.depth=S+L,!0;if(Z===M)return U.normalX=-1,U.normalY=0,U.normalZ=0,U.depth=M+L,!0;if(Z===R)return U.normalX=0,U.normalY=1,U.normalZ=0,U.depth=R+L,!0;if(Z===X)return U.normalX=0,U.normalY=-1,U.normalZ=0,U.depth=X+L,!0;if(Z===Y)return U.normalX=0,U.normalY=0,U.normalZ=1,U.depth=Y+L,!0;return U.normalX=0,U.normalY=0,U.normalZ=-1,U.depth=E+L,!0}let _=Math.sqrt(N);return U.normalX=W/_,U.normalY=P/_,U.normalZ=H/_,U.depth=L-_,!0}function D(J,K,Q){if(J.shape===0&&K.shape===0)return p(J.x,J.y,J.z,J.halfWidth,J.halfHeight,J.halfDepth,K.x,K.y,K.z,K.halfWidth,K.halfHeight,K.halfDepth,Q);if(J.shape===1&&K.shape===1)return b(J.x,J.y,J.z,J.radius,K.x,K.y,K.z,K.radius,Q);if(J.shape===0&&K.shape===1)return x(J.x,J.y,J.z,J.halfWidth,J.halfHeight,J.halfDepth,K.x,K.y,K.z,K.radius,Q);if(!x(K.x,K.y,K.z,K.halfWidth,K.halfHeight,K.halfDepth,J.x,J.y,J.z,J.radius,Q))return!1;return Q.normalX=-Q.normalX,Q.normalY=-Q.normalY,Q.normalZ=-Q.normalZ,!0}var A=new Set,B=!1,u=50;function v(J,K,Q,G,V,O){if(G)l(J,K,Q,G,V,O);else d(J,K,V,O)}function d(J,K,Q,G){if(!B&&K>=u)B=!0,console.warn(`[ecspresso] 3D collision detection is using O(n²) brute force with ${K} colliders. For better performance, install createSpatialIndex3DPlugin() alongside your collision or physics3D plugin.`);for(let V=0;V<K;V++){let O=J[V];if(!O)continue;for(let F=V+1;F<K;F++){let $=J[F];if(!$)continue;if(!O.collidesWith.includes($.layer)&&!$.collidesWith.includes(O.layer))continue;if(!D(O,$,C))continue;Q(O,$,C,G)}}}function l(J,K,Q,G,V,O){Q.clear();for(let F=0;F<K;F++){let $=J[F];if(!$)continue;Q.set($.entityId,$)}for(let F=0;F<K;F++){let $=J[F];if(!$)continue;let k=$.shape===0?$.halfWidth:$.radius,L=$.shape===0?$.halfHeight:$.radius,U=$.shape===0?$.halfDepth:$.radius;A.clear(),G.queryBoxInto($.x-k,$.y-L,$.z-U,$.x+k,$.y+L,$.z+U,A);for(let T of A){if(T<=$.entityId)continue;let j=Q.get(T);if(!j)continue;if(!$.collidesWith.includes(j.layer)&&!j.collidesWith.includes($.layer))continue;if(!D($,j,C))continue;V($,j,C,O)}}}function JJ(J,K){return{rigidBody3D:{type:J,mass:J==="static"?1/0:K?.mass??1,drag:K?.drag??0,restitution:K?.restitution??0,friction:K?.friction??0,gravityScale:K?.gravityScale??1},force3D:{x:0,y:0,z:0}}}function KJ(J,K,Q){return{force3D:{x:J,y:K,z:Q}}}function QJ(J,K,Q,G,V){let O=J.getComponent(K,"force3D");if(!O)return;O.x+=Q,O.y+=G,O.z+=V}function $J(J,K,Q,G,V){let O=J.getComponent(K,"velocity3D"),F=J.getComponent(K,"rigidBody3D");if(!O||!F)return;if(F.mass===1/0||F.mass===0)return;O.x+=Q/F.mass,O.y+=G/F.mass,O.z+=V/F.mass}function OJ(J,K,Q,G,V){let O=J.getComponent(K,"velocity3D");if(!O)return;O.x=Q,O.y=G,O.z=V}var z={entityA:0,entityB:0,normalX:0,normalY:0,normalZ:0,depth:0};function c(J,K,Q,G){let V=J.rigidBody.type==="dynamic"&&J.rigidBody.mass>0&&J.rigidBody.mass!==1/0?1/J.rigidBody.mass:0,O=K.rigidBody.type==="dynamic"&&K.rigidBody.mass>0&&K.rigidBody.mass!==1/0?1/K.rigidBody.mass:0,F=V+O;if(F>0){let $=Q.depth/F;if(V>0){let j=G.getComponent(J.entityId,"localTransform3D");if(!j)return;let q=$*V;j.x-=q*Q.normalX,j.y-=q*Q.normalY,j.z-=q*Q.normalZ,J.x=j.x,J.y=j.y,J.z=j.z,G.markChanged(J.entityId,"localTransform3D")}if(O>0){let j=G.getComponent(K.entityId,"localTransform3D");if(!j)return;let q=$*O;j.x+=q*Q.normalX,j.y+=q*Q.normalY,j.z+=q*Q.normalZ,K.x=j.x,K.y=j.y,K.z=j.z,G.markChanged(K.entityId,"localTransform3D")}let k=K.velocity.x-J.velocity.x,L=K.velocity.y-J.velocity.y,U=K.velocity.z-J.velocity.z,T=k*Q.normalX+L*Q.normalY+U*Q.normalZ;if(T<0){let q=-(1+Math.min(J.rigidBody.restitution,K.rigidBody.restitution))*T/F,W=q*V,P=q*O;J.velocity.x-=W*Q.normalX,J.velocity.y-=W*Q.normalY,J.velocity.z-=W*Q.normalZ,K.velocity.x+=P*Q.normalX,K.velocity.y+=P*Q.normalY,K.velocity.z+=P*Q.normalZ;let H=k-T*Q.normalX,N=L-T*Q.normalY,_=U-T*Q.normalZ,M=Math.sqrt(H*H+N*N+_*_);if(M>0.000001){let S=H/M,X=N/M,R=_/M,Y=Math.sqrt(J.rigidBody.friction*K.rigidBody.friction)*Math.abs(q),Z=Math.min(M/F,Y),w=Z*V,I=Z*O;J.velocity.x+=w*S,J.velocity.y+=w*X,J.velocity.z+=w*R,K.velocity.x-=I*S,K.velocity.y-=I*X,K.velocity.z-=I*R}}G.markChanged(J.entityId,"velocity3D"),G.markChanged(K.entityId,"velocity3D")}z.entityA=J.entityId,z.entityB=K.entityId,z.normalX=Q.normalX,z.normalY=Q.normalY,z.normalZ=Q.normalZ,z.depth=Q.depth,G.eventBus.publish("physics3DCollision",z)}function jJ(J){let{gravity:K={x:0,y:0,z:0},systemGroup:Q="physics3D",collisionSystemGroup:G,integrationPriority:V=1000,collisionPriority:O=900,phase:F="fixedUpdate"}=J??{};return r("physics3D").withComponentTypes().withEventTypes().withResourceTypes().withLabels().withGroups().requires().install(($)=>{$.registerRequired("rigidBody3D","velocity3D",()=>({x:0,y:0,z:0})),$.registerRequired("rigidBody3D","force3D",()=>({x:0,y:0,z:0})),$.addResource("physics3DConfig",{gravity:{x:K.x,y:K.y,z:K.z}}),$.addSystem("physics3D-integration").setPriority(V).inPhase(F).inGroup(Q).addQuery("bodies",{with:["localTransform3D","velocity3D","rigidBody3D","force3D"]}).setProcess(({queries:q,dt:W,ecs:P})=>{let{gravity:H}=P.getResource("physics3DConfig"),N=H.x,_=H.y,M=H.z;for(let S of q.bodies){let{localTransform3D:X,velocity3D:R,rigidBody3D:E,force3D:Y}=S.components;if(E.type==="static")continue;if(E.type==="dynamic"){if(R.x+=N*E.gravityScale*W,R.y+=_*E.gravityScale*W,R.z+=M*E.gravityScale*W,E.mass>0&&E.mass!==1/0)R.x+=Y.x/E.mass*W,R.y+=Y.y/E.mass*W,R.z+=Y.z/E.mass*W;if(E.drag>0){let Z=Math.max(0,1-E.drag*W);R.x*=Z,R.y*=Z,R.z*=Z}}X.x+=R.x*W,X.y+=R.y*W,X.z+=R.z*W,Y.x=0,Y.y=0,Y.z=0,P.markChanged(S.id,"localTransform3D")}});let k=$.addSystem("physics3D-collision").setPriority(O).inPhase(F).inGroup(Q);if(G)k.inGroup(G);let L=[],U=new Map,T,j=!1;k.addQuery("collidables",{with:["localTransform3D","rigidBody3D","velocity3D","collisionLayer"]}).setProcess(({queries:q,ecs:W})=>{let P=0;for(let H of q.collidables){let{localTransform3D:N,rigidBody3D:_,velocity3D:M,collisionLayer:S}=H.components,X=W.getComponent(H.id,"aabb3DCollider"),R=X?void 0:W.getComponent(H.id,"sphereCollider");if(!X&&!R)continue;let E=L[P];if(!E)E={entityId:H.id,x:N.x,y:N.y,z:N.z,layer:S.layer,collidesWith:S.collidesWith,shape:m,halfWidth:0,halfHeight:0,halfDepth:0,radius:0,rigidBody:_,velocity:M},L[P]=E;else E.rigidBody=_,E.velocity=M;if(!g(E,H.id,N.x,N.y,N.z,S.layer,S.collidesWith,X,R))continue;P++}if(!j)T=W.tryGetResource("spatialIndex3D"),j=!0;v(L,P,U,T,c,W)})})}export{OJ as setVelocity3D,JJ as createRigidBody3D,jJ as createPhysics3DPlugin,KJ as createForce3D,$J as applyImpulse3D,QJ as applyForce3D};
1
+ var v=Object.defineProperty;var y=(J)=>J;function h(J,K){this[J]=y.bind(null,K)}var i=(J,K)=>{for(var Q in K)v(J,Q,{get:K[Q],enumerable:!0,configurable:!0,set:h.bind(K,Q)})};var n=(J,K)=>()=>(J&&(K=J(J=0)),K);var s=((J)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(J,{get:(K,Q)=>(typeof require<"u"?require:K)[Q]}):J)(function(J){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+J+'" is not supported')});import{definePlugin as r}from"ecspresso";var I={normalX:0,normalY:0,normalZ:0,depth:0},m=0;function g(J,K,Q,G,F,j,k,$,V){if(J.entityId=K,J.layer=j,J.collidesWith=k,$)return J.x=Q+($.offsetX??0),J.y=G+($.offsetY??0),J.z=F+($.offsetZ??0),J.shape=0,J.halfWidth=$.width/2,J.halfHeight=$.height/2,J.halfDepth=$.depth/2,J.radius=0,!0;if(V)return J.x=Q+(V.offsetX??0),J.y=G+(V.offsetY??0),J.z=F+(V.offsetZ??0),J.shape=1,J.halfWidth=0,J.halfHeight=0,J.halfDepth=0,J.radius=V.radius,!0;return!1}function p(J,K,Q,G,F,j,k,$,V,L,U,T,O){let q=k-J,W=$-K,N=V-Q,E=G+L-Math.abs(q),R=F+U-Math.abs(W),P=j+T-Math.abs(N);if(E<=0||R<=0||P<=0)return!1;if(E<=R&&E<=P)return O.normalX=q>=0?1:-1,O.normalY=0,O.normalZ=0,O.depth=E,!0;if(R<=P)return O.normalX=0,O.normalY=W>=0?1:-1,O.normalZ=0,O.depth=R,!0;return O.normalX=0,O.normalY=0,O.normalZ=N>=0?1:-1,O.depth=P,!0}function d(J,K,Q,G,F,j,k,$,V){let L=F-J,U=j-K,T=k-Q,O=L*L+U*U+T*T,q=G+$;if(O>=q*q)return!1;let W=Math.sqrt(O);if(W===0)return V.normalX=1,V.normalY=0,V.normalZ=0,V.depth=q,!0;return V.normalX=L/W,V.normalY=U/W,V.normalZ=T/W,V.depth=q-W,!0}function x(J,K,Q,G,F,j,k,$,V,L,U){let T=Math.max(J-G,Math.min(k,J+G)),O=Math.max(K-F,Math.min($,K+F)),q=Math.max(Q-j,Math.min(V,Q+j)),W=k-T,N=$-O,E=V-q,R=W*W+N*N+E*E;if(R>=L*L)return!1;if(R===0){let M=k-(J-G),w=J+G-k,C=$-(K-F),H=K+F-$,_=V-(Q-j),X=Q+j-V,Y=Math.min(M,w,C,H,_,X);if(Y===w)return U.normalX=1,U.normalY=0,U.normalZ=0,U.depth=w+L,!0;if(Y===M)return U.normalX=-1,U.normalY=0,U.normalZ=0,U.depth=M+L,!0;if(Y===H)return U.normalX=0,U.normalY=1,U.normalZ=0,U.depth=H+L,!0;if(Y===C)return U.normalX=0,U.normalY=-1,U.normalZ=0,U.depth=C+L,!0;if(Y===X)return U.normalX=0,U.normalY=0,U.normalZ=1,U.depth=X+L,!0;return U.normalX=0,U.normalY=0,U.normalZ=-1,U.depth=_+L,!0}let P=Math.sqrt(R);return U.normalX=W/P,U.normalY=N/P,U.normalZ=E/P,U.depth=L-P,!0}function D(J,K,Q){if(J.shape===0&&K.shape===0)return p(J.x,J.y,J.z,J.halfWidth,J.halfHeight,J.halfDepth,K.x,K.y,K.z,K.halfWidth,K.halfHeight,K.halfDepth,Q);if(J.shape===1&&K.shape===1)return d(J.x,J.y,J.z,J.radius,K.x,K.y,K.z,K.radius,Q);if(J.shape===0&&K.shape===1)return x(J.x,J.y,J.z,J.halfWidth,J.halfHeight,J.halfDepth,K.x,K.y,K.z,K.radius,Q);if(!x(K.x,K.y,K.z,K.halfWidth,K.halfHeight,K.halfDepth,J.x,J.y,J.z,J.radius,Q))return!1;return Q.normalX=-Q.normalX,Q.normalY=-Q.normalY,Q.normalZ=-Q.normalZ,!0}var A=new Set,B=!1,b=50;function f(J,K,Q,G,F,j){if(G)l(J,K,Q,G,F,j);else u(J,K,F,j)}function u(J,K,Q,G){if(!B&&K>=b)B=!0,console.warn(`[ecspresso] 3D collision detection is using O(n²) brute force with ${K} colliders. For better performance, install createSpatialIndex3DPlugin() alongside your collision or physics3D plugin.`);for(let F=0;F<K;F++){let j=J[F];if(!j)continue;for(let k=F+1;k<K;k++){let $=J[k];if(!$)continue;if(!j.collidesWith.includes($.layer)&&!$.collidesWith.includes(j.layer))continue;if(!D(j,$,I))continue;Q(j,$,I,G)}}}function l(J,K,Q,G,F,j){Q.clear();for(let k=0;k<K;k++){let $=J[k];if(!$)continue;Q.set($.entityId,$)}for(let k=0;k<K;k++){let $=J[k];if(!$)continue;let V=$.shape===0?$.halfWidth:$.radius,L=$.shape===0?$.halfHeight:$.radius,U=$.shape===0?$.halfDepth:$.radius;A.clear(),G.queryBoxInto($.x-V,$.y-L,$.z-U,$.x+V,$.y+L,$.z+U,A);for(let T of A){if(T<=$.entityId)continue;let O=Q.get(T);if(!O)continue;if(!$.collidesWith.includes(O.layer)&&!O.collidesWith.includes($.layer))continue;if(!D($,O,I))continue;F($,O,I,j)}}}function JJ(J,K){return{rigidBody3D:{type:J,mass:J==="static"?1/0:K?.mass??1,drag:K?.drag??0,restitution:K?.restitution??0,friction:K?.friction??0,gravityScale:K?.gravityScale??1},force3D:{x:0,y:0,z:0}}}function KJ(J,K,Q){return{force3D:{x:J,y:K,z:Q}}}function QJ(J,K,Q,G,F){let j=J.getComponent(K,"force3D");if(!j)return;j.x+=Q,j.y+=G,j.z+=F}function $J(J,K,Q,G,F){let j=J.getComponent(K,"velocity3D"),k=J.getComponent(K,"rigidBody3D");if(!j||!k)return;if(k.mass===1/0||k.mass===0)return;j.x+=Q/k.mass,j.y+=G/k.mass,j.z+=F/k.mass}function jJ(J,K,Q,G,F){let j=J.getComponent(K,"velocity3D");if(!j)return;j.x=Q,j.y=G,j.z=F}var S={entityA:0,entityB:0,normalX:0,normalY:0,normalZ:0,depth:0};function c(J,K,Q,G){let F=J.rigidBody.type==="dynamic"&&J.rigidBody.mass>0&&J.rigidBody.mass!==1/0?1/J.rigidBody.mass:0,j=K.rigidBody.type==="dynamic"&&K.rigidBody.mass>0&&K.rigidBody.mass!==1/0?1/K.rigidBody.mass:0,k=F+j;if(k>0){let $=Q.depth/k;if(F>0){let O=G.getComponent(J.entityId,"localTransform3D");if(!O)return;let q=$*F;O.x-=q*Q.normalX,O.y-=q*Q.normalY,O.z-=q*Q.normalZ,J.x=O.x,J.y=O.y,J.z=O.z,G.markChanged(J.entityId,"localTransform3D")}if(j>0){let O=G.getComponent(K.entityId,"localTransform3D");if(!O)return;let q=$*j;O.x+=q*Q.normalX,O.y+=q*Q.normalY,O.z+=q*Q.normalZ,K.x=O.x,K.y=O.y,K.z=O.z,G.markChanged(K.entityId,"localTransform3D")}let V=K.velocity.x-J.velocity.x,L=K.velocity.y-J.velocity.y,U=K.velocity.z-J.velocity.z,T=V*Q.normalX+L*Q.normalY+U*Q.normalZ;if(T<0){let q=-(1+Math.min(J.rigidBody.restitution,K.rigidBody.restitution))*T/k,W=q*F,N=q*j;J.velocity.x-=W*Q.normalX,J.velocity.y-=W*Q.normalY,J.velocity.z-=W*Q.normalZ,K.velocity.x+=N*Q.normalX,K.velocity.y+=N*Q.normalY,K.velocity.z+=N*Q.normalZ;let E=V-T*Q.normalX,R=L-T*Q.normalY,P=U-T*Q.normalZ,M=Math.sqrt(E*E+R*R+P*P);if(M>0.000001){let w=E/M,C=R/M,H=P/M,X=Math.sqrt(J.rigidBody.friction*K.rigidBody.friction)*Math.abs(q),Y=Math.min(M/k,X),z=Y*F,Z=Y*j;J.velocity.x+=z*w,J.velocity.y+=z*C,J.velocity.z+=z*H,K.velocity.x-=Z*w,K.velocity.y-=Z*C,K.velocity.z-=Z*H}}G.markChanged(J.entityId,"velocity3D"),G.markChanged(K.entityId,"velocity3D")}S.entityA=J.entityId,S.entityB=K.entityId,S.normalX=Q.normalX,S.normalY=Q.normalY,S.normalZ=Q.normalZ,S.depth=Q.depth,G.eventBus.publish("physics3DCollision",S)}function OJ(J){let{gravity:K={x:0,y:0,z:0},systemGroup:Q="physics3D",collisionSystemGroup:G,integrationPriority:F=1000,collisionPriority:j=900,phase:k="fixedUpdate"}=J??{};return r("physics3D").withComponentTypes().withEventTypes().withResourceTypes().withLabels().withGroups().requires().install(($)=>{$.registerRequired("rigidBody3D","velocity3D",()=>({x:0,y:0,z:0})),$.registerRequired("rigidBody3D","force3D",()=>({x:0,y:0,z:0})),$.addResource("physics3DConfig",{gravity:{x:K.x,y:K.y,z:K.z}}),$.addSystem("physics3D-integration").setPriority(F).inPhase(k).inGroup(Q).addQuery("bodies",{with:["localTransform3D","velocity3D","rigidBody3D","force3D"]}).setProcess(({queries:q,dt:W,ecs:N})=>{let{gravity:E}=N.getResource("physics3DConfig"),R=E.x,P=E.y,M=E.z;for(let w of q.bodies){let{localTransform3D:C,velocity3D:H,rigidBody3D:_,force3D:X}=w.components;if(_.type==="static")continue;if(_.type==="dynamic"){let Y=_.gravityScale*W;H.x+=R*Y,H.y+=P*Y,H.z+=M*Y;let z=_.mass;if(z>0&&z!==1/0){let Z=W/z;H.x+=X.x*Z,H.y+=X.y*Z,H.z+=X.z*Z}if(_.drag>0){let Z=Math.max(0,1-_.drag*W);H.x*=Z,H.y*=Z,H.z*=Z}}C.x+=H.x*W,C.y+=H.y*W,C.z+=H.z*W,X.x=0,X.y=0,X.z=0,N.markChanged(w.id,"localTransform3D")}});let V=$.addSystem("physics3D-collision").setPriority(j).inPhase(k).inGroup(Q);if(G)V.inGroup(G);let L=[],U=new Map,T,O=!1;V.addQuery("collidables",{with:["localTransform3D","rigidBody3D","velocity3D","collisionLayer"]}).setProcess(({queries:q,ecs:W})=>{let N=0;for(let E of q.collidables){let{localTransform3D:R,rigidBody3D:P,velocity3D:M,collisionLayer:w}=E.components,C=W.getComponent(E.id,"aabb3DCollider"),H=C?void 0:W.getComponent(E.id,"sphereCollider");if(!C&&!H)continue;let _=L[N];if(!_)_={entityId:E.id,x:R.x,y:R.y,z:R.z,layer:w.layer,collidesWith:w.collidesWith,shape:m,halfWidth:0,halfHeight:0,halfDepth:0,radius:0,rigidBody:P,velocity:M},L[N]=_;else _.rigidBody=P,_.velocity=M;if(!g(_,E.id,R.x,R.y,R.z,w.layer,w.collidesWith,C,H))continue;N++}if(!O)T=W.tryGetResource("spatialIndex3D"),O=!0;f(L,N,U,T,c,W)})})}export{jJ as setVelocity3D,JJ as createRigidBody3D,OJ as createPhysics3DPlugin,KJ as createForce3D,$J as applyImpulse3D,QJ as applyForce3D};
2
2
 
3
- //# debugId=62C31FA369CDE2E864756E2164756E21
3
+ //# debugId=56EB52F40B9450C864756E2164756E21
4
4
  //# sourceMappingURL=physics3D.js.map
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/plugins/physics/physics3D.ts", "../src/utils/narrowphase3D.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Physics 3D Plugin for ECSpresso\n *\n * Provides ECS-native 3D arcade physics: gravity, forces, drag, semi-implicit Euler\n * integration, and impulse-based collision response with friction.\n *\n * Reuses RigidBody and collider types from the 2D physics/collision plugins for\n * shape definitions. Has its own collision detection in fixedUpdate for physics\n * response; the existing collision3D plugin can still run in postUpdate for game\n * logic events.\n */\n\nimport { definePlugin } from 'ecspresso';\nimport type { SystemPhase } from 'ecspresso';\nimport type { Vector3D } from 'ecspresso';\nimport type { Transform3DWorldConfig } from '../spatial/transform3D';\nimport type { Collision3DComponentTypes, LayerFactories } from './collision3D';\nimport type { RigidBody, BodyType, RigidBodyOptions } from './physics2D';\nimport { fillBaseColliderInfo3D, detectCollisions3D, AABB3D_SHAPE, type Contact3D, type BaseColliderInfo3D } from '../../utils/narrowphase3D';\nimport type { SpatialIndex3D } from '../../utils/spatial-hash3D';\n\n// Re-export so consumers can type rigid bodies without importing physics2D\nexport type { RigidBody, BodyType, RigidBodyOptions };\n\n// ==================== Component Types ====================\n\n/**\n * Component types directly provided by the physics3D plugin.\n */\nexport interface Physics3DOwnComponentTypes {\n\trigidBody3D: RigidBody;\n\tvelocity3D: Vector3D;\n\tforce3D: Vector3D;\n}\n\n/**\n * Full component types available when using the physics3D plugin\n * (own components + transform + collision dependencies).\n * Convenience alias for consumer code.\n */\nexport interface Physics3DComponentTypes<L extends string = never> extends Collision3DComponentTypes<L>, Physics3DOwnComponentTypes {}\n\n// ==================== Resource Types ====================\n\n/**\n * Physics 3D configuration resource.\n */\nexport interface Physics3DConfig {\n\tgravity: Vector3D;\n}\n\nexport interface Physics3DResourceTypes {\n\tphysics3DConfig: Physics3DConfig;\n}\n\n// ==================== Event Types ====================\n\n/**\n * Event emitted for each physics 3D collision pair.\n *\n * Normal components are flattened (`normalX`/`normalY`/`normalZ`) rather than\n * nested in a `Vector3D` to avoid a per-event allocation in the physics hot path.\n */\nexport interface Physics3DCollisionEvent {\n\tentityA: number;\n\tentityB: number;\n\t/** Unit normal X, pointing from A toward B */\n\tnormalX: number;\n\t/** Unit normal Y, pointing from A toward B */\n\tnormalY: number;\n\t/** Unit normal Z, pointing from A toward B */\n\tnormalZ: number;\n\t/** Penetration depth (positive) */\n\tdepth: number;\n}\n\nexport interface Physics3DEventTypes {\n\tphysics3DCollision: Physics3DCollisionEvent;\n}\n\n// ==================== Plugin Options ====================\n\nexport interface Physics3DPluginOptions<G extends string = 'physics3D', CG extends string = never> {\n\t/** World gravity vector (default: {x: 0, y: 0, z: 0}) */\n\tgravity?: Vector3D;\n\t/** System group name (default: 'physics3D') */\n\tsystemGroup?: G;\n\t/** Additional group for the collision system only (default: none).\n\t * When set, the collision system belongs to both `systemGroup` and this group,\n\t * allowing independent enable/disable of collision detection. */\n\tcollisionSystemGroup?: CG;\n\t/** Priority for integration system (default: 1000) */\n\tintegrationPriority?: number;\n\t/** Priority for collision system (default: 900) */\n\tcollisionPriority?: number;\n\t/** Execution phase (default: 'fixedUpdate') */\n\tphase?: SystemPhase;\n}\n\n// ==================== Helper Functions ====================\n\n/**\n * Create a rigidBody3D + force3D component pair.\n * Static bodies automatically get mass=Infinity.\n */\nexport function createRigidBody3D(\n\ttype: BodyType,\n\toptions?: RigidBodyOptions,\n): { rigidBody3D: RigidBody; force3D: Vector3D } {\n\treturn {\n\t\trigidBody3D: {\n\t\t\ttype,\n\t\t\tmass: type === 'static' ? Infinity : (options?.mass ?? 1),\n\t\t\tdrag: options?.drag ?? 0,\n\t\t\trestitution: options?.restitution ?? 0,\n\t\t\tfriction: options?.friction ?? 0,\n\t\t\tgravityScale: options?.gravityScale ?? 1,\n\t\t},\n\t\tforce3D: { x: 0, y: 0, z: 0 },\n\t};\n}\n\n/**\n * Create a force3D component with initial values.\n */\nexport function createForce3D(x: number, y: number, z: number): { force3D: Vector3D } {\n\treturn { force3D: { x, y, z } };\n}\n\n/**\n * Accumulate a force onto an entity's force3D component.\n */\nexport function applyForce3D(\n\tecs: { getComponent(id: number, name: 'force3D'): Vector3D | undefined },\n\tentityId: number,\n\tfx: number,\n\tfy: number,\n\tfz: number,\n): void {\n\tconst force = ecs.getComponent(entityId, 'force3D');\n\tif (!force) return;\n\tforce.x += fx;\n\tforce.y += fy;\n\tforce.z += fz;\n}\n\n/**\n * Apply an instantaneous impulse: velocity3D += impulse / mass.\n */\nexport function applyImpulse3D(\n\tecs: {\n\t\tgetComponent(id: number, name: 'velocity3D'): Vector3D | undefined;\n\t\tgetComponent(id: number, name: 'rigidBody3D'): RigidBody | undefined;\n\t},\n\tentityId: number,\n\tix: number,\n\tiy: number,\n\tiz: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity3D');\n\tconst rigidBody = ecs.getComponent(entityId, 'rigidBody3D');\n\tif (!velocity || !rigidBody) return;\n\tif (rigidBody.mass === Infinity || rigidBody.mass === 0) return;\n\tvelocity.x += ix / rigidBody.mass;\n\tvelocity.y += iy / rigidBody.mass;\n\tvelocity.z += iz / rigidBody.mass;\n}\n\n/**\n * Directly set an entity's velocity3D.\n */\nexport function setVelocity3D(\n\tecs: { getComponent(id: number, name: 'velocity3D'): Vector3D | undefined },\n\tentityId: number,\n\tvx: number,\n\tvy: number,\n\tvz: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity3D');\n\tif (!velocity) return;\n\tvelocity.x = vx;\n\tvelocity.y = vy;\n\tvelocity.z = vz;\n}\n\n// ==================== Internal: Collider Info ====================\n\ninterface Physics3DColliderInfo<L extends string = string> extends BaseColliderInfo3D<L> {\n\trigidBody: RigidBody;\n\tvelocity: Vector3D;\n}\n\n// ==================== Collision Response ====================\n\n/**\n * Module-level reusable physics3D collision event. Subscribers must consume\n * synchronously — same contract as the shared narrowphase Contact3D.\n */\nconst _physicsCollisionEvent: Physics3DCollisionEvent = {\n\tentityA: 0, entityB: 0, normalX: 0, normalY: 0, normalZ: 0, depth: 0,\n};\n\ninterface PhysicsEcs3DLike {\n\tgetComponent(id: number, name: 'localTransform3D'): { x: number; y: number; z: number } | undefined;\n\teventBus: { publish(event: 'physics3DCollision', data: Physics3DCollisionEvent): void };\n\tmarkChanged(entityId: number, componentName: 'localTransform3D' | 'velocity3D'): void;\n}\n\n/**\n * Resolve a 3D physics collision pair: position correction, impulse response, event.\n *\n * Friction uses a tangent plane projection: the tangential velocity is the\n * component of relative velocity perpendicular to the contact normal. This\n * generalizes the 2D tangent-line approach to 3D — mathematically the same\n * operation with an added Z component.\n */\nfunction resolvePhysicsContact3D(\n\ta: Physics3DColliderInfo,\n\tb: Physics3DColliderInfo,\n\tcontact: Contact3D,\n\tecs: PhysicsEcs3DLike,\n): void {\n\tconst invMassA = (a.rigidBody.type === 'dynamic' && a.rigidBody.mass > 0 && a.rigidBody.mass !== Infinity)\n\t\t? 1 / a.rigidBody.mass\n\t\t: 0;\n\tconst invMassB = (b.rigidBody.type === 'dynamic' && b.rigidBody.mass > 0 && b.rigidBody.mass !== Infinity)\n\t\t? 1 / b.rigidBody.mass\n\t\t: 0;\n\tconst totalInvMass = invMassA + invMassB;\n\n\t// Position correction\n\tif (totalInvMass > 0) {\n\t\tconst correctionScale = contact.depth / totalInvMass;\n\n\t\tif (invMassA > 0) {\n\t\t\tconst ltA = ecs.getComponent(a.entityId, 'localTransform3D');\n\t\t\tif (!ltA) return;\n\t\t\tconst corrA = correctionScale * invMassA;\n\t\t\tltA.x -= corrA * contact.normalX;\n\t\t\tltA.y -= corrA * contact.normalY;\n\t\t\tltA.z -= corrA * contact.normalZ;\n\t\t\t// Sync cached position so subsequent pairs in this frame use corrected values\n\t\t\ta.x = ltA.x;\n\t\t\ta.y = ltA.y;\n\t\t\ta.z = ltA.z;\n\t\t\tecs.markChanged(a.entityId, 'localTransform3D');\n\t\t}\n\n\t\tif (invMassB > 0) {\n\t\t\tconst ltB = ecs.getComponent(b.entityId, 'localTransform3D');\n\t\t\tif (!ltB) return;\n\t\t\tconst corrB = correctionScale * invMassB;\n\t\t\tltB.x += corrB * contact.normalX;\n\t\t\tltB.y += corrB * contact.normalY;\n\t\t\tltB.z += corrB * contact.normalZ;\n\t\t\tb.x = ltB.x;\n\t\t\tb.y = ltB.y;\n\t\t\tb.z = ltB.z;\n\t\t\tecs.markChanged(b.entityId, 'localTransform3D');\n\t\t}\n\n\t\t// Velocity response (impulse-based)\n\t\tconst relVelX = b.velocity.x - a.velocity.x;\n\t\tconst relVelY = b.velocity.y - a.velocity.y;\n\t\tconst relVelZ = b.velocity.z - a.velocity.z;\n\t\tconst velAlongNormal = relVelX * contact.normalX + relVelY * contact.normalY + relVelZ * contact.normalZ;\n\n\t\tif (velAlongNormal < 0) {\n\t\t\tconst restitution = Math.min(a.rigidBody.restitution, b.rigidBody.restitution);\n\t\t\tconst normalImpulse = -(1 + restitution) * velAlongNormal / totalInvMass;\n\t\t\tconst impA = normalImpulse * invMassA;\n\t\t\tconst impB = normalImpulse * invMassB;\n\n\t\t\ta.velocity.x -= impA * contact.normalX;\n\t\t\ta.velocity.y -= impA * contact.normalY;\n\t\t\ta.velocity.z -= impA * contact.normalZ;\n\t\t\tb.velocity.x += impB * contact.normalX;\n\t\t\tb.velocity.y += impB * contact.normalY;\n\t\t\tb.velocity.z += impB * contact.normalZ;\n\n\t\t\t// Friction (tangential impulse — project relative velocity onto tangent plane)\n\t\t\tconst tangentX = relVelX - velAlongNormal * contact.normalX;\n\t\t\tconst tangentY = relVelY - velAlongNormal * contact.normalY;\n\t\t\tconst tangentZ = relVelZ - velAlongNormal * contact.normalZ;\n\t\t\tconst tangentSpeed = Math.sqrt(tangentX * tangentX + tangentY * tangentY + tangentZ * tangentZ);\n\n\t\t\tif (tangentSpeed > 1e-6) {\n\t\t\t\tconst tangentNX = tangentX / tangentSpeed;\n\t\t\t\tconst tangentNY = tangentY / tangentSpeed;\n\t\t\t\tconst tangentNZ = tangentZ / tangentSpeed;\n\t\t\t\tconst friction = Math.sqrt(a.rigidBody.friction * b.rigidBody.friction);\n\t\t\t\tconst maxFrictionImpulse = friction * Math.abs(normalImpulse);\n\t\t\t\tconst tangentImpulse = Math.min(tangentSpeed / totalInvMass, maxFrictionImpulse);\n\t\t\t\tconst tanA = tangentImpulse * invMassA;\n\t\t\t\tconst tanB = tangentImpulse * invMassB;\n\n\t\t\t\ta.velocity.x += tanA * tangentNX;\n\t\t\t\ta.velocity.y += tanA * tangentNY;\n\t\t\t\ta.velocity.z += tanA * tangentNZ;\n\t\t\t\tb.velocity.x -= tanB * tangentNX;\n\t\t\t\tb.velocity.y -= tanB * tangentNY;\n\t\t\t\tb.velocity.z -= tanB * tangentNZ;\n\t\t\t}\n\t\t}\n\n\t\tecs.markChanged(a.entityId, 'velocity3D');\n\t\tecs.markChanged(b.entityId, 'velocity3D');\n\t}\n\n\t_physicsCollisionEvent.entityA = a.entityId;\n\t_physicsCollisionEvent.entityB = b.entityId;\n\t_physicsCollisionEvent.normalX = contact.normalX;\n\t_physicsCollisionEvent.normalY = contact.normalY;\n\t_physicsCollisionEvent.normalZ = contact.normalZ;\n\t_physicsCollisionEvent.depth = contact.depth;\n\tecs.eventBus.publish('physics3DCollision', _physicsCollisionEvent);\n}\n\n// ==================== Plugin Factory ====================\n\n/**\n * Create a 3D physics plugin for ECSpresso.\n *\n * Provides:\n * - Semi-implicit Euler integration (gravity, forces, drag → velocity3D → position)\n * - Impulse-based collision response with restitution and friction\n * - physics3DCollision events with contact normal and depth\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTransform3DPlugin())\n * .withPlugin(createPhysics3DPlugin({ gravity: { x: 0, y: -9.81, z: 0 } }))\n * .withFixedTimestep(1/60)\n * .build();\n *\n * ecs.spawn({\n * ...createTransform3D(0, 10, 0),\n * ...createRigidBody3D('dynamic', { mass: 1, restitution: 0.5 }),\n * velocity3D: { x: 0, y: 0, z: 0 },\n * ...createAABB3DCollider(1, 1, 1),\n * ...createCollisionLayer('player', ['ground']),\n * });\n * ```\n */\n\ntype Physics3DProvides<L extends string = never> = Physics3DOwnComponentTypes & Collision3DComponentTypes<L>;\n\nexport function createPhysics3DPlugin<L extends string = never, G extends string = 'physics3D', CG extends string = never>(\n\toptions?: Physics3DPluginOptions<G, CG> & { layers?: LayerFactories<Record<L, readonly string[]>> },\n) {\n\tconst {\n\t\tgravity = { x: 0, y: 0, z: 0 },\n\t\tsystemGroup = 'physics3D',\n\t\tcollisionSystemGroup,\n\t\tintegrationPriority = 1000,\n\t\tcollisionPriority = 900,\n\t\tphase = 'fixedUpdate',\n\t} = options ?? {};\n\n\treturn definePlugin('physics3D')\n\t\t.withComponentTypes<Physics3DProvides<L>>()\n\t\t.withEventTypes<Physics3DEventTypes>()\n\t\t.withResourceTypes<Physics3DResourceTypes>()\n\t\t.withLabels<'physics3D-integration' | 'physics3D-collision'>()\n\t\t.withGroups<G | CG>()\n\t\t.requires<Transform3DWorldConfig>()\n\t\t.install((world) => {\n\t\t\t// rigidBody3D requires velocity3D and force3D — auto-add with zero defaults\n\t\t\tworld.registerRequired('rigidBody3D', 'velocity3D', () => ({ x: 0, y: 0, z: 0 }));\n\t\t\tworld.registerRequired('rigidBody3D', 'force3D', () => ({ x: 0, y: 0, z: 0 }));\n\n\t\t\tworld.addResource('physics3DConfig', { gravity: { x: gravity.x, y: gravity.y, z: gravity.z } });\n\n\t\t\t// ==================== Integration System ====================\n\n\t\t\tworld\n\t\t\t\t.addSystem('physics3D-integration')\n\t\t\t\t.setPriority(integrationPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup)\n\t\t\t\t.addQuery('bodies', {\n\t\t\t\t\twith: ['localTransform3D', 'velocity3D', 'rigidBody3D', 'force3D'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, dt, ecs }) => {\n\t\t\t\t\tconst { gravity: g } = ecs.getResource('physics3DConfig');\n\t\t\t\t\tconst gx = g.x;\n\t\t\t\t\tconst gy = g.y;\n\t\t\t\t\tconst gz = g.z;\n\n\t\t\t\t\tfor (const entity of queries.bodies) {\n\t\t\t\t\t\tconst { localTransform3D, velocity3D, rigidBody3D, force3D } = entity.components;\n\n\t\t\t\t\t\t// Static bodies: skip entirely\n\t\t\t\t\t\tif (rigidBody3D.type === 'static') continue;\n\n\t\t\t\t\t\t// Dynamic bodies: apply gravity, forces, drag\n\t\t\t\t\t\tif (rigidBody3D.type === 'dynamic') {\n\t\t\t\t\t\t\t// 1. Gravity\n\t\t\t\t\t\t\tvelocity3D.x += gx * rigidBody3D.gravityScale * dt;\n\t\t\t\t\t\t\tvelocity3D.y += gy * rigidBody3D.gravityScale * dt;\n\t\t\t\t\t\t\tvelocity3D.z += gz * rigidBody3D.gravityScale * dt;\n\n\t\t\t\t\t\t\t// 2. Forces (F = ma → a = F/m)\n\t\t\t\t\t\t\tif (rigidBody3D.mass > 0 && rigidBody3D.mass !== Infinity) {\n\t\t\t\t\t\t\t\tvelocity3D.x += (force3D.x / rigidBody3D.mass) * dt;\n\t\t\t\t\t\t\t\tvelocity3D.y += (force3D.y / rigidBody3D.mass) * dt;\n\t\t\t\t\t\t\t\tvelocity3D.z += (force3D.z / rigidBody3D.mass) * dt;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// 3. Drag\n\t\t\t\t\t\t\tif (rigidBody3D.drag > 0) {\n\t\t\t\t\t\t\t\tconst damping = Math.max(0, 1 - rigidBody3D.drag * dt);\n\t\t\t\t\t\t\t\tvelocity3D.x *= damping;\n\t\t\t\t\t\t\t\tvelocity3D.y *= damping;\n\t\t\t\t\t\t\t\tvelocity3D.z *= damping;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Both dynamic and kinematic: integrate position\n\t\t\t\t\t\tlocalTransform3D.x += velocity3D.x * dt;\n\t\t\t\t\t\tlocalTransform3D.y += velocity3D.y * dt;\n\t\t\t\t\t\tlocalTransform3D.z += velocity3D.z * dt;\n\n\t\t\t\t\t\t// Clear accumulated forces\n\t\t\t\t\t\tforce3D.x = 0;\n\t\t\t\t\t\tforce3D.y = 0;\n\t\t\t\t\t\tforce3D.z = 0;\n\n\t\t\t\t\t\tecs.markChanged(entity.id, 'localTransform3D');\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t// ==================== Collision System ====================\n\n\t\t\tconst collisionSystem = world\n\t\t\t\t.addSystem('physics3D-collision')\n\t\t\t\t.setPriority(collisionPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup);\n\n\t\t\tif (collisionSystemGroup) {\n\t\t\t\tcollisionSystem.inGroup(collisionSystemGroup);\n\t\t\t}\n\n\t\t\t// Grow-only pool of Physics3DColliderInfo slots reused across frames.\n\t\t\t// Steady-state: zero allocations per frame once the pool is warm.\n\t\t\tconst colliderPool: Physics3DColliderInfo<L>[] = [];\n\t\t\t// Reusable entityId → collider lookup for the broadphase path.\n\t\t\tconst broadphaseMap = new Map<number, Physics3DColliderInfo<L>>();\n\t\t\t// Cached spatial index reference (resolved once on first frame).\n\t\t\tlet cachedSI: SpatialIndex3D | undefined;\n\t\t\tlet siResolved = false;\n\n\t\t\tcollisionSystem\n\t\t\t\t.addQuery('collidables', {\n\t\t\t\t\twith: ['localTransform3D', 'rigidBody3D', 'velocity3D', 'collisionLayer'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, ecs }) => {\n\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\tfor (const entity of queries.collidables) {\n\t\t\t\t\t\tconst { localTransform3D, rigidBody3D, velocity3D, collisionLayer } = entity.components;\n\t\t\t\t\t\tconst aabb = ecs.getComponent(entity.id, 'aabb3DCollider');\n\t\t\t\t\t\tconst sphere = aabb ? undefined : ecs.getComponent(entity.id, 'sphereCollider');\n\t\t\t\t\t\tif (!aabb && !sphere) continue;\n\n\t\t\t\t\t\tlet slot = colliderPool[count];\n\t\t\t\t\t\tif (!slot) {\n\t\t\t\t\t\t\tslot = {\n\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\tx: localTransform3D.x,\n\t\t\t\t\t\t\t\ty: localTransform3D.y,\n\t\t\t\t\t\t\t\tz: localTransform3D.z,\n\t\t\t\t\t\t\t\tlayer: collisionLayer.layer,\n\t\t\t\t\t\t\t\tcollidesWith: collisionLayer.collidesWith,\n\t\t\t\t\t\t\t\tshape: AABB3D_SHAPE,\n\t\t\t\t\t\t\t\thalfWidth: 0,\n\t\t\t\t\t\t\t\thalfHeight: 0,\n\t\t\t\t\t\t\t\thalfDepth: 0,\n\t\t\t\t\t\t\t\tradius: 0,\n\t\t\t\t\t\t\t\trigidBody: rigidBody3D,\n\t\t\t\t\t\t\t\tvelocity: velocity3D,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tcolliderPool[count] = slot;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tslot.rigidBody = rigidBody3D;\n\t\t\t\t\t\t\tslot.velocity = velocity3D;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!fillBaseColliderInfo3D(\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tentity.id, localTransform3D.x, localTransform3D.y, localTransform3D.z,\n\t\t\t\t\t\t\tcollisionLayer.layer, collisionLayer.collidesWith,\n\t\t\t\t\t\t\taabb, sphere,\n\t\t\t\t\t\t)) continue;\n\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!siResolved) {\n\t\t\t\t\t\tcachedSI = ecs.tryGetResource<SpatialIndex3D>('spatialIndex3D');\n\t\t\t\t\t\tsiResolved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdetectCollisions3D(colliderPool, count, broadphaseMap, cachedSI, resolvePhysicsContact3D, ecs);\n\t\t\t\t});\n\t\t});\n}\n",
6
- "/**\n * Shared Narrowphase Module — 3D\n *\n * Provides contact-computing narrowphase tests and a generic collision\n * iteration pipeline for 3D collider pairs (AABB3D + Sphere).\n *\n * Mirrors the 2D narrowphase (`narrowphase.ts`) with an added Z axis.\n */\n\nimport type { SpatialIndex3D } from './spatial-hash3D';\n\n// ==================== Contact3D ====================\n\n/**\n * Contact result from a 3D narrowphase test. Normal points from A toward B.\n *\n * Narrowphase functions use this as an out-parameter: the caller owns the\n * struct, the function writes fields in place and returns `true` on hit.\n * The `onContact` callback in `detectCollisions3D` receives a shared module-\n * level instance — **subscribers must consume it synchronously and must not\n * retain the reference across frames**.\n */\nexport interface Contact3D {\n\tnormalX: number;\n\tnormalY: number;\n\tnormalZ: number;\n\t/** Penetration depth (positive = overlapping) */\n\tdepth: number;\n}\n\n/**\n * Module-level reusable Contact3D passed down from `detectCollisions3D` into\n * narrowphase tests and forwarded to the `onContact` callback. Reused across\n * every pair in every frame — zero allocation in the narrowphase hot path.\n */\nconst _sharedContact: Contact3D = { normalX: 0, normalY: 0, normalZ: 0, depth: 0 };\n\n// ==================== BaseColliderInfo3D ====================\n\n/** Collider shape discriminator for the flattened BaseColliderInfo3D layout. */\nexport const AABB3D_SHAPE = 0;\nexport const SPHERE_SHAPE = 1;\nexport type ColliderShape3D = typeof AABB3D_SHAPE | typeof SPHERE_SHAPE;\n\n/**\n * Minimum collider data shared by 3D collision and physics bundles.\n *\n * Flat layout (no nested sub-objects): the `shape` discriminator tells you\n * whether to read `halfWidth`/`halfHeight`/`halfDepth` (AABB3D) or `radius`\n * (Sphere). Unused fields are set to 0.\n *\n * Pool-friendly — all fields are assigned in place each frame.\n */\nexport interface BaseColliderInfo3D<L extends string = string> {\n\tentityId: number;\n\tx: number;\n\ty: number;\n\tz: number;\n\tlayer: L;\n\tcollidesWith: readonly L[];\n\tshape: ColliderShape3D;\n\thalfWidth: number;\n\thalfHeight: number;\n\thalfDepth: number;\n\tradius: number;\n}\n\n// ==================== Collider Construction ====================\n\n/**\n * Populate a `BaseColliderInfo3D` slot in place from raw component data.\n * Returns `true` if the slot was filled, `false` if the entity has no\n * collider (caller should skip it).\n *\n * If an entity has both AABB3D and sphere colliders, AABB3D wins and only\n * the AABB3D offset is applied.\n */\nexport function fillBaseColliderInfo3D<L extends string>(\n\tinfo: BaseColliderInfo3D<L>,\n\tentityId: number,\n\tx: number,\n\ty: number,\n\tz: number,\n\tlayer: L,\n\tcollidesWith: readonly L[],\n\taabb3D: { width: number; height: number; depth: number; offsetX?: number; offsetY?: number; offsetZ?: number } | undefined,\n\tsphere: { radius: number; offsetX?: number; offsetY?: number; offsetZ?: number } | undefined,\n): boolean {\n\tinfo.entityId = entityId;\n\tinfo.layer = layer;\n\tinfo.collidesWith = collidesWith;\n\n\tif (aabb3D) {\n\t\tinfo.x = x + (aabb3D.offsetX ?? 0);\n\t\tinfo.y = y + (aabb3D.offsetY ?? 0);\n\t\tinfo.z = z + (aabb3D.offsetZ ?? 0);\n\t\tinfo.shape = AABB3D_SHAPE;\n\t\tinfo.halfWidth = aabb3D.width / 2;\n\t\tinfo.halfHeight = aabb3D.height / 2;\n\t\tinfo.halfDepth = aabb3D.depth / 2;\n\t\tinfo.radius = 0;\n\t\treturn true;\n\t}\n\n\tif (sphere) {\n\t\tinfo.x = x + (sphere.offsetX ?? 0);\n\t\tinfo.y = y + (sphere.offsetY ?? 0);\n\t\tinfo.z = z + (sphere.offsetZ ?? 0);\n\t\tinfo.shape = SPHERE_SHAPE;\n\t\tinfo.halfWidth = 0;\n\t\tinfo.halfHeight = 0;\n\t\tinfo.halfDepth = 0;\n\t\tinfo.radius = sphere.radius;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// ==================== Spatial Index Lookup ====================\n\n/**\n * Retrieve the optional spatialIndex3D resource, returning undefined when absent.\n * Centralizes the cross-plugin typed lookup so individual plugins don't each\n * need to import SpatialIndex3D or repeat the tryGetResource pattern.\n */\nexport function tryGetSpatialIndex3D(\n\ttryGetResource: <T>(key: string) => T | undefined,\n): SpatialIndex3D | undefined {\n\treturn tryGetResource<SpatialIndex3D>('spatialIndex3D');\n}\n\n// ==================== Narrowphase Tests ====================\n\n/**\n * Write an AABB3D-vs-AABB3D contact into `out`. Returns `true` if the\n * shapes overlap (out was filled), `false` otherwise.\n *\n * Resolves along the axis with minimum penetration depth.\n */\nexport function computeAABB3DvsAABB3D(\n\tax: number, ay: number, az: number, ahw: number, ahh: number, ahd: number,\n\tbx: number, by: number, bz: number, bhw: number, bhh: number, bhd: number,\n\tout: Contact3D,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst dz = bz - az;\n\tconst overlapX = (ahw + bhw) - Math.abs(dx);\n\tconst overlapY = (ahh + bhh) - Math.abs(dy);\n\tconst overlapZ = (ahd + bhd) - Math.abs(dz);\n\n\tif (overlapX <= 0 || overlapY <= 0 || overlapZ <= 0) return false;\n\n\tif (overlapX <= overlapY && overlapX <= overlapZ) {\n\t\tout.normalX = dx >= 0 ? 1 : -1;\n\t\tout.normalY = 0;\n\t\tout.normalZ = 0;\n\t\tout.depth = overlapX;\n\t\treturn true;\n\t}\n\n\tif (overlapY <= overlapZ) {\n\t\tout.normalX = 0;\n\t\tout.normalY = dy >= 0 ? 1 : -1;\n\t\tout.normalZ = 0;\n\t\tout.depth = overlapY;\n\t\treturn true;\n\t}\n\n\tout.normalX = 0;\n\tout.normalY = 0;\n\tout.normalZ = dz >= 0 ? 1 : -1;\n\tout.depth = overlapZ;\n\treturn true;\n}\n\n/**\n * Write a sphere-vs-sphere contact into `out`. Returns `true` if the\n * spheres overlap.\n */\nexport function computeSphereVsSphere(\n\tax: number, ay: number, az: number, ar: number,\n\tbx: number, by: number, bz: number, br: number,\n\tout: Contact3D,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst dz = bz - az;\n\tconst distSq = dx * dx + dy * dy + dz * dz;\n\tconst radiusSum = ar + br;\n\n\tif (distSq >= radiusSum * radiusSum) return false;\n\n\tconst dist = Math.sqrt(distSq);\n\tif (dist === 0) {\n\t\tout.normalX = 1;\n\t\tout.normalY = 0;\n\t\tout.normalZ = 0;\n\t\tout.depth = radiusSum;\n\t\treturn true;\n\t}\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.normalZ = dz / dist;\n\tout.depth = radiusSum - dist;\n\treturn true;\n}\n\n/**\n * Write an AABB3D-vs-sphere contact into `out`. Returns `true` if the\n * shapes overlap.\n *\n * Uses closest-point-on-AABB to sphere center. When the sphere center\n * is inside the AABB, resolves along the axis with minimum push distance.\n */\nexport function computeAABB3DvsSphere(\n\taabbX: number, aabbY: number, aabbZ: number, ahw: number, ahh: number, ahd: number,\n\tsphereX: number, sphereY: number, sphereZ: number, radius: number,\n\tout: Contact3D,\n): boolean {\n\tconst closestX = Math.max(aabbX - ahw, Math.min(sphereX, aabbX + ahw));\n\tconst closestY = Math.max(aabbY - ahh, Math.min(sphereY, aabbY + ahh));\n\tconst closestZ = Math.max(aabbZ - ahd, Math.min(sphereZ, aabbZ + ahd));\n\n\tconst dx = sphereX - closestX;\n\tconst dy = sphereY - closestY;\n\tconst dz = sphereZ - closestZ;\n\tconst distSq = dx * dx + dy * dy + dz * dz;\n\n\tif (distSq >= radius * radius) return false;\n\n\t// Sphere center inside AABB — resolve along minimum push axis\n\tif (distSq === 0) {\n\t\tconst pushLeft = (sphereX - (aabbX - ahw));\n\t\tconst pushRight = ((aabbX + ahw) - sphereX);\n\t\tconst pushUp = (sphereY - (aabbY - ahh));\n\t\tconst pushDown = ((aabbY + ahh) - sphereY);\n\t\tconst pushFront = (sphereZ - (aabbZ - ahd));\n\t\tconst pushBack = ((aabbZ + ahd) - sphereZ);\n\t\tconst minPush = Math.min(pushLeft, pushRight, pushUp, pushDown, pushFront, pushBack);\n\n\t\tif (minPush === pushRight) {\n\t\t\tout.normalX = 1; out.normalY = 0; out.normalZ = 0; out.depth = pushRight + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushLeft) {\n\t\t\tout.normalX = -1; out.normalY = 0; out.normalZ = 0; out.depth = pushLeft + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushDown) {\n\t\t\tout.normalX = 0; out.normalY = 1; out.normalZ = 0; out.depth = pushDown + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushUp) {\n\t\t\tout.normalX = 0; out.normalY = -1; out.normalZ = 0; out.depth = pushUp + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushBack) {\n\t\t\tout.normalX = 0; out.normalY = 0; out.normalZ = 1; out.depth = pushBack + radius;\n\t\t\treturn true;\n\t\t}\n\t\tout.normalX = 0; out.normalY = 0; out.normalZ = -1; out.depth = pushFront + radius;\n\t\treturn true;\n\t}\n\n\tconst dist = Math.sqrt(distSq);\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.normalZ = dz / dist;\n\tout.depth = radius - dist;\n\treturn true;\n}\n\n// ==================== Contact Dispatcher ====================\n\n/**\n * Dispatch to the correct narrowphase function for the given pair and\n * write the contact into `out`. Returns `true` if the pair overlaps.\n */\nexport function computeContact3D(a: BaseColliderInfo3D, b: BaseColliderInfo3D, out: Contact3D): boolean {\n\tif (a.shape === AABB3D_SHAPE && b.shape === AABB3D_SHAPE) {\n\t\treturn computeAABB3DvsAABB3D(\n\t\t\ta.x, a.y, a.z, a.halfWidth, a.halfHeight, a.halfDepth,\n\t\t\tb.x, b.y, b.z, b.halfWidth, b.halfHeight, b.halfDepth,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === SPHERE_SHAPE && b.shape === SPHERE_SHAPE) {\n\t\treturn computeSphereVsSphere(\n\t\t\ta.x, a.y, a.z, a.radius,\n\t\t\tb.x, b.y, b.z, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === AABB3D_SHAPE && b.shape === SPHERE_SHAPE) {\n\t\treturn computeAABB3DvsSphere(\n\t\t\ta.x, a.y, a.z, a.halfWidth, a.halfHeight, a.halfDepth,\n\t\t\tb.x, b.y, b.z, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\t// a is Sphere, b is AABB3D — compute as AABB3D-vs-Sphere, then flip normal\n\tif (!computeAABB3DvsSphere(\n\t\tb.x, b.y, b.z, b.halfWidth, b.halfHeight, b.halfDepth,\n\t\ta.x, a.y, a.z, a.radius,\n\t\tout,\n\t)) return false;\n\tout.normalX = -out.normalX;\n\tout.normalY = -out.normalY;\n\tout.normalZ = -out.normalZ;\n\treturn true;\n}\n\n// ==================== Collision Iteration ====================\n\n/** Module-level reusable set for broadphase candidates. */\nconst _broadphaseCandidates = new Set<number>();\n\nlet _bruteForceWarned = false;\nconst BRUTE_FORCE_WARN_THRESHOLD = 50;\n\n/**\n * Generic 3D collision detection pipeline: brute-force or broadphase,\n * with layer filtering and contact computation.\n *\n * `count` is the number of live entries at the front of `colliders`.\n * The array itself may be a grow-only pool — only indices `[0, count)`\n * are iterated, so trailing pool slots are ignored.\n *\n * `workingMap` is a caller-owned `Map<number, I>` used by the broadphase\n * path as an entityId → collider lookup. It is cleared and repopulated on\n * each call; callers should allocate it once and pass the same instance\n * every frame.\n *\n * Uses a context parameter forwarded to the callback to avoid\n * per-frame closure allocation.\n */\nexport function detectCollisions3D<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tworkingMap: Map<number, I>,\n\tspatialIndex: SpatialIndex3D | undefined,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tif (spatialIndex) {\n\t\tbroadphaseDetect(colliders, count, workingMap, spatialIndex, onContact, context);\n\t} else {\n\t\tbruteForceDetect(colliders, count, onContact, context);\n\t}\n}\n\nfunction bruteForceDetect<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tif (!_bruteForceWarned && count >= BRUTE_FORCE_WARN_THRESHOLD) {\n\t\t_bruteForceWarned = true;\n\t\tconsole.warn(\n\t\t\t`[ecspresso] 3D collision detection is using O(n²) brute force with ${count} colliders. ` +\n\t\t\t`For better performance, install createSpatialIndex3DPlugin() alongside your collision or physics3D plugin.`,\n\t\t);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tfor (let j = i + 1; j < count; j++) {\n\t\t\tconst b = colliders[j];\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact3D(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n\nfunction broadphaseDetect<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tcolliderMap: Map<number, I>,\n\tspatialIndex: SpatialIndex3D,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tcolliderMap.clear();\n\tfor (let i = 0; i < count; i++) {\n\t\tconst c = colliders[i];\n\t\tif (!c) continue;\n\t\tcolliderMap.set(c.entityId, c);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tconst aHalfW = a.shape === AABB3D_SHAPE ? a.halfWidth : a.radius;\n\t\tconst aHalfH = a.shape === AABB3D_SHAPE ? a.halfHeight : a.radius;\n\t\tconst aHalfD = a.shape === AABB3D_SHAPE ? a.halfDepth : a.radius;\n\n\t\t_broadphaseCandidates.clear();\n\t\tspatialIndex.queryBoxInto(\n\t\t\ta.x - aHalfW, a.y - aHalfH, a.z - aHalfD,\n\t\t\ta.x + aHalfW, a.y + aHalfH, a.z + aHalfD,\n\t\t\t_broadphaseCandidates,\n\t\t);\n\n\t\tfor (const bId of _broadphaseCandidates) {\n\t\t\tif (bId <= a.entityId) continue;\n\n\t\t\tconst b = colliderMap.get(bId);\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact3D(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n"
5
+ "/**\n * Physics 3D Plugin for ECSpresso\n *\n * Provides ECS-native 3D arcade physics: gravity, forces, drag, semi-implicit Euler\n * integration, and impulse-based collision response with friction.\n *\n * Reuses RigidBody and collider types from the 2D physics/collision plugins for\n * shape definitions. Has its own collision detection in fixedUpdate for physics\n * response; the existing collision3D plugin can still run in postUpdate for game\n * logic events.\n */\n\nimport { definePlugin } from 'ecspresso';\nimport type { SystemPhase } from 'ecspresso';\nimport type { Vector3D } from 'ecspresso';\nimport type { Transform3DWorldConfig } from '../spatial/transform3D';\nimport type { Collision3DComponentTypes, LayerFactories } from './collision3D';\nimport type { RigidBody, BodyType, RigidBodyOptions } from './physics2D';\nimport { fillBaseColliderInfo3D, detectCollisions3D, AABB3D_SHAPE, type Contact3D, type BaseColliderInfo3D } from '../../utils/narrowphase3D';\nimport type { SpatialIndex3D } from '../../utils/spatial-hash3D';\n\n// Re-export so consumers can type rigid bodies without importing physics2D\nexport type { RigidBody, BodyType, RigidBodyOptions };\n\n// ==================== Component Types ====================\n\n/**\n * Component types directly provided by the physics3D plugin.\n */\nexport interface Physics3DOwnComponentTypes {\n\trigidBody3D: RigidBody;\n\tvelocity3D: Vector3D;\n\tforce3D: Vector3D;\n}\n\n/**\n * Full component types available when using the physics3D plugin\n * (own components + transform + collision dependencies).\n * Convenience alias for consumer code.\n */\nexport interface Physics3DComponentTypes<L extends string = never> extends Collision3DComponentTypes<L>, Physics3DOwnComponentTypes {}\n\n// ==================== Resource Types ====================\n\n/**\n * Physics 3D configuration resource.\n */\nexport interface Physics3DConfig {\n\tgravity: Vector3D;\n}\n\nexport interface Physics3DResourceTypes {\n\tphysics3DConfig: Physics3DConfig;\n}\n\n// ==================== Event Types ====================\n\n/**\n * Event emitted for each physics 3D collision pair.\n *\n * Normal components are flattened (`normalX`/`normalY`/`normalZ`) rather than\n * nested in a `Vector3D` to avoid a per-event allocation in the physics hot path.\n */\nexport interface Physics3DCollisionEvent {\n\tentityA: number;\n\tentityB: number;\n\t/** Unit normal X, pointing from A toward B */\n\tnormalX: number;\n\t/** Unit normal Y, pointing from A toward B */\n\tnormalY: number;\n\t/** Unit normal Z, pointing from A toward B */\n\tnormalZ: number;\n\t/** Penetration depth (positive) */\n\tdepth: number;\n}\n\nexport interface Physics3DEventTypes {\n\tphysics3DCollision: Physics3DCollisionEvent;\n}\n\n// ==================== Plugin Options ====================\n\nexport interface Physics3DPluginOptions<G extends string = 'physics3D', CG extends string = never> {\n\t/** World gravity vector (default: {x: 0, y: 0, z: 0}) */\n\tgravity?: Vector3D;\n\t/** System group name (default: 'physics3D') */\n\tsystemGroup?: G;\n\t/** Additional group for the collision system only (default: none).\n\t * When set, the collision system belongs to both `systemGroup` and this group,\n\t * allowing independent enable/disable of collision detection. */\n\tcollisionSystemGroup?: CG;\n\t/** Priority for integration system (default: 1000) */\n\tintegrationPriority?: number;\n\t/** Priority for collision system (default: 900) */\n\tcollisionPriority?: number;\n\t/** Execution phase (default: 'fixedUpdate') */\n\tphase?: SystemPhase;\n}\n\n// ==================== Helper Functions ====================\n\n/**\n * Create a rigidBody3D + force3D component pair.\n * Static bodies automatically get mass=Infinity.\n */\nexport function createRigidBody3D(\n\ttype: BodyType,\n\toptions?: RigidBodyOptions,\n): { rigidBody3D: RigidBody; force3D: Vector3D } {\n\treturn {\n\t\trigidBody3D: {\n\t\t\ttype,\n\t\t\tmass: type === 'static' ? Infinity : (options?.mass ?? 1),\n\t\t\tdrag: options?.drag ?? 0,\n\t\t\trestitution: options?.restitution ?? 0,\n\t\t\tfriction: options?.friction ?? 0,\n\t\t\tgravityScale: options?.gravityScale ?? 1,\n\t\t},\n\t\tforce3D: { x: 0, y: 0, z: 0 },\n\t};\n}\n\n/**\n * Create a force3D component with initial values.\n */\nexport function createForce3D(x: number, y: number, z: number): { force3D: Vector3D } {\n\treturn { force3D: { x, y, z } };\n}\n\n/**\n * Accumulate a force onto an entity's force3D component.\n */\nexport function applyForce3D(\n\tecs: { getComponent(id: number, name: 'force3D'): Vector3D | undefined },\n\tentityId: number,\n\tfx: number,\n\tfy: number,\n\tfz: number,\n): void {\n\tconst force = ecs.getComponent(entityId, 'force3D');\n\tif (!force) return;\n\tforce.x += fx;\n\tforce.y += fy;\n\tforce.z += fz;\n}\n\n/**\n * Apply an instantaneous impulse: velocity3D += impulse / mass.\n */\nexport function applyImpulse3D(\n\tecs: {\n\t\tgetComponent(id: number, name: 'velocity3D'): Vector3D | undefined;\n\t\tgetComponent(id: number, name: 'rigidBody3D'): RigidBody | undefined;\n\t},\n\tentityId: number,\n\tix: number,\n\tiy: number,\n\tiz: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity3D');\n\tconst rigidBody = ecs.getComponent(entityId, 'rigidBody3D');\n\tif (!velocity || !rigidBody) return;\n\tif (rigidBody.mass === Infinity || rigidBody.mass === 0) return;\n\tvelocity.x += ix / rigidBody.mass;\n\tvelocity.y += iy / rigidBody.mass;\n\tvelocity.z += iz / rigidBody.mass;\n}\n\n/**\n * Directly set an entity's velocity3D.\n */\nexport function setVelocity3D(\n\tecs: { getComponent(id: number, name: 'velocity3D'): Vector3D | undefined },\n\tentityId: number,\n\tvx: number,\n\tvy: number,\n\tvz: number,\n): void {\n\tconst velocity = ecs.getComponent(entityId, 'velocity3D');\n\tif (!velocity) return;\n\tvelocity.x = vx;\n\tvelocity.y = vy;\n\tvelocity.z = vz;\n}\n\n// ==================== Internal: Collider Info ====================\n\ninterface Physics3DColliderInfo<L extends string = string> extends BaseColliderInfo3D<L> {\n\trigidBody: RigidBody;\n\tvelocity: Vector3D;\n}\n\n// ==================== Collision Response ====================\n\n/**\n * Module-level reusable physics3D collision event. Subscribers must consume\n * synchronously — same contract as the shared narrowphase Contact3D.\n */\nconst _physicsCollisionEvent: Physics3DCollisionEvent = {\n\tentityA: 0, entityB: 0, normalX: 0, normalY: 0, normalZ: 0, depth: 0,\n};\n\ninterface PhysicsEcs3DLike {\n\tgetComponent(id: number, name: 'localTransform3D'): { x: number; y: number; z: number } | undefined;\n\teventBus: { publish(event: 'physics3DCollision', data: Physics3DCollisionEvent): void };\n\tmarkChanged(entityId: number, componentName: 'localTransform3D' | 'velocity3D'): void;\n}\n\n/**\n * Resolve a 3D physics collision pair: position correction, impulse response, event.\n *\n * Friction uses a tangent plane projection: the tangential velocity is the\n * component of relative velocity perpendicular to the contact normal. This\n * generalizes the 2D tangent-line approach to 3D — mathematically the same\n * operation with an added Z component.\n */\nfunction resolvePhysicsContact3D(\n\ta: Physics3DColliderInfo,\n\tb: Physics3DColliderInfo,\n\tcontact: Contact3D,\n\tecs: PhysicsEcs3DLike,\n): void {\n\tconst invMassA = (a.rigidBody.type === 'dynamic' && a.rigidBody.mass > 0 && a.rigidBody.mass !== Infinity)\n\t\t? 1 / a.rigidBody.mass\n\t\t: 0;\n\tconst invMassB = (b.rigidBody.type === 'dynamic' && b.rigidBody.mass > 0 && b.rigidBody.mass !== Infinity)\n\t\t? 1 / b.rigidBody.mass\n\t\t: 0;\n\tconst totalInvMass = invMassA + invMassB;\n\n\t// Position correction\n\tif (totalInvMass > 0) {\n\t\tconst correctionScale = contact.depth / totalInvMass;\n\n\t\tif (invMassA > 0) {\n\t\t\tconst ltA = ecs.getComponent(a.entityId, 'localTransform3D');\n\t\t\tif (!ltA) return;\n\t\t\tconst corrA = correctionScale * invMassA;\n\t\t\tltA.x -= corrA * contact.normalX;\n\t\t\tltA.y -= corrA * contact.normalY;\n\t\t\tltA.z -= corrA * contact.normalZ;\n\t\t\t// Sync cached position so subsequent pairs in this frame use corrected values\n\t\t\ta.x = ltA.x;\n\t\t\ta.y = ltA.y;\n\t\t\ta.z = ltA.z;\n\t\t\tecs.markChanged(a.entityId, 'localTransform3D');\n\t\t}\n\n\t\tif (invMassB > 0) {\n\t\t\tconst ltB = ecs.getComponent(b.entityId, 'localTransform3D');\n\t\t\tif (!ltB) return;\n\t\t\tconst corrB = correctionScale * invMassB;\n\t\t\tltB.x += corrB * contact.normalX;\n\t\t\tltB.y += corrB * contact.normalY;\n\t\t\tltB.z += corrB * contact.normalZ;\n\t\t\tb.x = ltB.x;\n\t\t\tb.y = ltB.y;\n\t\t\tb.z = ltB.z;\n\t\t\tecs.markChanged(b.entityId, 'localTransform3D');\n\t\t}\n\n\t\t// Velocity response (impulse-based)\n\t\tconst relVelX = b.velocity.x - a.velocity.x;\n\t\tconst relVelY = b.velocity.y - a.velocity.y;\n\t\tconst relVelZ = b.velocity.z - a.velocity.z;\n\t\tconst velAlongNormal = relVelX * contact.normalX + relVelY * contact.normalY + relVelZ * contact.normalZ;\n\n\t\tif (velAlongNormal < 0) {\n\t\t\tconst restitution = Math.min(a.rigidBody.restitution, b.rigidBody.restitution);\n\t\t\tconst normalImpulse = -(1 + restitution) * velAlongNormal / totalInvMass;\n\t\t\tconst impA = normalImpulse * invMassA;\n\t\t\tconst impB = normalImpulse * invMassB;\n\n\t\t\ta.velocity.x -= impA * contact.normalX;\n\t\t\ta.velocity.y -= impA * contact.normalY;\n\t\t\ta.velocity.z -= impA * contact.normalZ;\n\t\t\tb.velocity.x += impB * contact.normalX;\n\t\t\tb.velocity.y += impB * contact.normalY;\n\t\t\tb.velocity.z += impB * contact.normalZ;\n\n\t\t\t// Friction (tangential impulse — project relative velocity onto tangent plane)\n\t\t\tconst tangentX = relVelX - velAlongNormal * contact.normalX;\n\t\t\tconst tangentY = relVelY - velAlongNormal * contact.normalY;\n\t\t\tconst tangentZ = relVelZ - velAlongNormal * contact.normalZ;\n\t\t\tconst tangentSpeed = Math.sqrt(tangentX * tangentX + tangentY * tangentY + tangentZ * tangentZ);\n\n\t\t\tif (tangentSpeed > 1e-6) {\n\t\t\t\tconst tangentNX = tangentX / tangentSpeed;\n\t\t\t\tconst tangentNY = tangentY / tangentSpeed;\n\t\t\t\tconst tangentNZ = tangentZ / tangentSpeed;\n\t\t\t\tconst friction = Math.sqrt(a.rigidBody.friction * b.rigidBody.friction);\n\t\t\t\tconst maxFrictionImpulse = friction * Math.abs(normalImpulse);\n\t\t\t\tconst tangentImpulse = Math.min(tangentSpeed / totalInvMass, maxFrictionImpulse);\n\t\t\t\tconst tanA = tangentImpulse * invMassA;\n\t\t\t\tconst tanB = tangentImpulse * invMassB;\n\n\t\t\t\ta.velocity.x += tanA * tangentNX;\n\t\t\t\ta.velocity.y += tanA * tangentNY;\n\t\t\t\ta.velocity.z += tanA * tangentNZ;\n\t\t\t\tb.velocity.x -= tanB * tangentNX;\n\t\t\t\tb.velocity.y -= tanB * tangentNY;\n\t\t\t\tb.velocity.z -= tanB * tangentNZ;\n\t\t\t}\n\t\t}\n\n\t\tecs.markChanged(a.entityId, 'velocity3D');\n\t\tecs.markChanged(b.entityId, 'velocity3D');\n\t}\n\n\t_physicsCollisionEvent.entityA = a.entityId;\n\t_physicsCollisionEvent.entityB = b.entityId;\n\t_physicsCollisionEvent.normalX = contact.normalX;\n\t_physicsCollisionEvent.normalY = contact.normalY;\n\t_physicsCollisionEvent.normalZ = contact.normalZ;\n\t_physicsCollisionEvent.depth = contact.depth;\n\tecs.eventBus.publish('physics3DCollision', _physicsCollisionEvent);\n}\n\n// ==================== Plugin Factory ====================\n\n/**\n * Create a 3D physics plugin for ECSpresso.\n *\n * Provides:\n * - Semi-implicit Euler integration (gravity, forces, drag → velocity3D → position)\n * - Impulse-based collision response with restitution and friction\n * - physics3DCollision events with contact normal and depth\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTransform3DPlugin())\n * .withPlugin(createPhysics3DPlugin({ gravity: { x: 0, y: -9.81, z: 0 } }))\n * .withFixedTimestep(1/60)\n * .build();\n *\n * ecs.spawn({\n * ...createTransform3D(0, 10, 0),\n * ...createRigidBody3D('dynamic', { mass: 1, restitution: 0.5 }),\n * velocity3D: { x: 0, y: 0, z: 0 },\n * ...createAABB3DCollider(1, 1, 1),\n * ...createCollisionLayer('player', ['ground']),\n * });\n * ```\n */\n\ntype Physics3DProvides<L extends string = never> = Physics3DOwnComponentTypes & Collision3DComponentTypes<L>;\n\nexport function createPhysics3DPlugin<L extends string = never, G extends string = 'physics3D', CG extends string = never>(\n\toptions?: Physics3DPluginOptions<G, CG> & { layers?: LayerFactories<Record<L, readonly string[]>> },\n) {\n\tconst {\n\t\tgravity = { x: 0, y: 0, z: 0 },\n\t\tsystemGroup = 'physics3D',\n\t\tcollisionSystemGroup,\n\t\tintegrationPriority = 1000,\n\t\tcollisionPriority = 900,\n\t\tphase = 'fixedUpdate',\n\t} = options ?? {};\n\n\treturn definePlugin('physics3D')\n\t\t.withComponentTypes<Physics3DProvides<L>>()\n\t\t.withEventTypes<Physics3DEventTypes>()\n\t\t.withResourceTypes<Physics3DResourceTypes>()\n\t\t.withLabels<'physics3D-integration' | 'physics3D-collision'>()\n\t\t.withGroups<G | CG>()\n\t\t.requires<Transform3DWorldConfig>()\n\t\t.install((world) => {\n\t\t\t// rigidBody3D requires velocity3D and force3D — auto-add with zero defaults\n\t\t\tworld.registerRequired('rigidBody3D', 'velocity3D', () => ({ x: 0, y: 0, z: 0 }));\n\t\t\tworld.registerRequired('rigidBody3D', 'force3D', () => ({ x: 0, y: 0, z: 0 }));\n\n\t\t\tworld.addResource('physics3DConfig', { gravity: { x: gravity.x, y: gravity.y, z: gravity.z } });\n\n\t\t\t// ==================== Integration System ====================\n\n\t\t\tworld\n\t\t\t\t.addSystem('physics3D-integration')\n\t\t\t\t.setPriority(integrationPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup)\n\t\t\t\t.addQuery('bodies', {\n\t\t\t\t\twith: ['localTransform3D', 'velocity3D', 'rigidBody3D', 'force3D'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, dt, ecs }) => {\n\t\t\t\t\tconst { gravity: g } = ecs.getResource('physics3DConfig');\n\t\t\t\t\tconst gx = g.x;\n\t\t\t\t\tconst gy = g.y;\n\t\t\t\t\tconst gz = g.z;\n\n\t\t\t\t\t// TODO(perf): no early-out for \"sleeping\" dynamic bodies — a packed\n\t\t\t\t\t// pile of resting entities still runs gravity/drag/force-clear/\n\t\t\t\t\t// markChanged every step. A sleep flag on RigidBody that latches\n\t\t\t\t\t// after N frames of near-zero velocity (and clears on impulse or\n\t\t\t\t\t// applied force) would let most of a stabilized scene skip the\n\t\t\t\t\t// full per-entity body of this loop. Needs collision response to\n\t\t\t\t\t// wake sleepers back up; keep in sync with physics2D when landed.\n\t\t\t\t\tfor (const entity of queries.bodies) {\n\t\t\t\t\t\tconst { localTransform3D, velocity3D, rigidBody3D, force3D } = entity.components;\n\n\t\t\t\t\t\t// Static bodies: skip entirely\n\t\t\t\t\t\tif (rigidBody3D.type === 'static') continue;\n\n\t\t\t\t\t\t// Dynamic bodies: apply gravity, forces, drag\n\t\t\t\t\t\tif (rigidBody3D.type === 'dynamic') {\n\t\t\t\t\t\t\t// 1. Gravity\n\t\t\t\t\t\t\tconst gsdt = rigidBody3D.gravityScale * dt;\n\t\t\t\t\t\t\tvelocity3D.x += gx * gsdt;\n\t\t\t\t\t\t\tvelocity3D.y += gy * gsdt;\n\t\t\t\t\t\t\tvelocity3D.z += gz * gsdt;\n\n\t\t\t\t\t\t\t// 2. Forces (F = ma → a = F/m)\n\t\t\t\t\t\t\tconst mass = rigidBody3D.mass;\n\t\t\t\t\t\t\tif (mass > 0 && mass !== Infinity) {\n\t\t\t\t\t\t\t\tconst invMassDt = dt / mass;\n\t\t\t\t\t\t\t\tvelocity3D.x += force3D.x * invMassDt;\n\t\t\t\t\t\t\t\tvelocity3D.y += force3D.y * invMassDt;\n\t\t\t\t\t\t\t\tvelocity3D.z += force3D.z * invMassDt;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// 3. Drag\n\t\t\t\t\t\t\tif (rigidBody3D.drag > 0) {\n\t\t\t\t\t\t\t\tconst damping = Math.max(0, 1 - rigidBody3D.drag * dt);\n\t\t\t\t\t\t\t\tvelocity3D.x *= damping;\n\t\t\t\t\t\t\t\tvelocity3D.y *= damping;\n\t\t\t\t\t\t\t\tvelocity3D.z *= damping;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Both dynamic and kinematic: integrate position\n\t\t\t\t\t\tlocalTransform3D.x += velocity3D.x * dt;\n\t\t\t\t\t\tlocalTransform3D.y += velocity3D.y * dt;\n\t\t\t\t\t\tlocalTransform3D.z += velocity3D.z * dt;\n\n\t\t\t\t\t\t// Clear accumulated forces\n\t\t\t\t\t\tforce3D.x = 0;\n\t\t\t\t\t\tforce3D.y = 0;\n\t\t\t\t\t\tforce3D.z = 0;\n\n\t\t\t\t\t\tecs.markChanged(entity.id, 'localTransform3D');\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t// ==================== Collision System ====================\n\n\t\t\tconst collisionSystem = world\n\t\t\t\t.addSystem('physics3D-collision')\n\t\t\t\t.setPriority(collisionPriority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup);\n\n\t\t\tif (collisionSystemGroup) {\n\t\t\t\tcollisionSystem.inGroup(collisionSystemGroup);\n\t\t\t}\n\n\t\t\t// Grow-only pool of Physics3DColliderInfo slots reused across frames.\n\t\t\t// Steady-state: zero allocations per frame once the pool is warm.\n\t\t\tconst colliderPool: Physics3DColliderInfo<L>[] = [];\n\t\t\t// Reusable entityId → collider lookup for the broadphase path.\n\t\t\tconst broadphaseMap = new Map<number, Physics3DColliderInfo<L>>();\n\t\t\t// Cached spatial index reference (resolved once on first frame).\n\t\t\tlet cachedSI: SpatialIndex3D | undefined;\n\t\t\tlet siResolved = false;\n\n\t\t\tcollisionSystem\n\t\t\t\t.addQuery('collidables', {\n\t\t\t\t\twith: ['localTransform3D', 'rigidBody3D', 'velocity3D', 'collisionLayer'],\n\t\t\t\t})\n\t\t\t\t.setProcess(({ queries, ecs }) => {\n\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\t// TODO(perf): collider shape is discovered via two ecs.getComponent\n\t\t\t\t\t// calls per entity per frame because the query can't express\n\t\t\t\t\t// \"aabb3DCollider OR sphereCollider\". Splitting into two queries\n\t\t\t\t\t// (aabb-bearing, sphere-bearing) would eliminate these lookups at\n\t\t\t\t\t// the cost of two pool-fill passes. Revisit once the query API\n\t\t\t\t\t// gains `anyOf`-style predicates.\n\t\t\t\t\tfor (const entity of queries.collidables) {\n\t\t\t\t\t\tconst { localTransform3D, rigidBody3D, velocity3D, collisionLayer } = entity.components;\n\t\t\t\t\t\tconst aabb = ecs.getComponent(entity.id, 'aabb3DCollider');\n\t\t\t\t\t\tconst sphere = aabb ? undefined : ecs.getComponent(entity.id, 'sphereCollider');\n\t\t\t\t\t\tif (!aabb && !sphere) continue;\n\n\t\t\t\t\t\tlet slot = colliderPool[count];\n\t\t\t\t\t\tif (!slot) {\n\t\t\t\t\t\t\tslot = {\n\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\tx: localTransform3D.x,\n\t\t\t\t\t\t\t\ty: localTransform3D.y,\n\t\t\t\t\t\t\t\tz: localTransform3D.z,\n\t\t\t\t\t\t\t\tlayer: collisionLayer.layer,\n\t\t\t\t\t\t\t\tcollidesWith: collisionLayer.collidesWith,\n\t\t\t\t\t\t\t\tshape: AABB3D_SHAPE,\n\t\t\t\t\t\t\t\thalfWidth: 0,\n\t\t\t\t\t\t\t\thalfHeight: 0,\n\t\t\t\t\t\t\t\thalfDepth: 0,\n\t\t\t\t\t\t\t\tradius: 0,\n\t\t\t\t\t\t\t\trigidBody: rigidBody3D,\n\t\t\t\t\t\t\t\tvelocity: velocity3D,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tcolliderPool[count] = slot;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tslot.rigidBody = rigidBody3D;\n\t\t\t\t\t\t\tslot.velocity = velocity3D;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!fillBaseColliderInfo3D(\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tentity.id, localTransform3D.x, localTransform3D.y, localTransform3D.z,\n\t\t\t\t\t\t\tcollisionLayer.layer, collisionLayer.collidesWith,\n\t\t\t\t\t\t\taabb, sphere,\n\t\t\t\t\t\t)) continue;\n\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!siResolved) {\n\t\t\t\t\t\tcachedSI = ecs.tryGetResource<SpatialIndex3D>('spatialIndex3D');\n\t\t\t\t\t\tsiResolved = true;\n\t\t\t\t\t}\n\t\t\t\t\tdetectCollisions3D(colliderPool, count, broadphaseMap, cachedSI, resolvePhysicsContact3D, ecs);\n\t\t\t\t});\n\t\t});\n}\n",
6
+ "/**\n * Shared Narrowphase Module — 3D\n *\n * Provides contact-computing narrowphase tests and a generic collision\n * iteration pipeline for 3D collider pairs (AABB3D + Sphere).\n *\n * Mirrors the 2D narrowphase (`narrowphase.ts`) with an added Z axis.\n */\n\nimport type { SpatialIndex3D } from './spatial-hash3D';\n\n// ==================== Contact3D ====================\n\n/**\n * Contact result from a 3D narrowphase test. Normal points from A toward B.\n *\n * Narrowphase functions use this as an out-parameter: the caller owns the\n * struct, the function writes fields in place and returns `true` on hit.\n * The `onContact` callback in `detectCollisions3D` receives a shared module-\n * level instance — **subscribers must consume it synchronously and must not\n * retain the reference across frames**.\n */\nexport interface Contact3D {\n\tnormalX: number;\n\tnormalY: number;\n\tnormalZ: number;\n\t/** Penetration depth (positive = overlapping) */\n\tdepth: number;\n}\n\n/**\n * Module-level reusable Contact3D passed down from `detectCollisions3D` into\n * narrowphase tests and forwarded to the `onContact` callback. Reused across\n * every pair in every frame — zero allocation in the narrowphase hot path.\n */\nconst _sharedContact: Contact3D = { normalX: 0, normalY: 0, normalZ: 0, depth: 0 };\n\n// ==================== BaseColliderInfo3D ====================\n\n/** Collider shape discriminator for the flattened BaseColliderInfo3D layout. */\nexport const AABB3D_SHAPE = 0;\nexport const SPHERE_SHAPE = 1;\nexport type ColliderShape3D = typeof AABB3D_SHAPE | typeof SPHERE_SHAPE;\n\n/**\n * Minimum collider data shared by 3D collision and physics bundles.\n *\n * Flat layout (no nested sub-objects): the `shape` discriminator tells you\n * whether to read `halfWidth`/`halfHeight`/`halfDepth` (AABB3D) or `radius`\n * (Sphere). Unused fields are set to 0.\n *\n * Pool-friendly — all fields are assigned in place each frame.\n */\nexport interface BaseColliderInfo3D<L extends string = string> {\n\tentityId: number;\n\tx: number;\n\ty: number;\n\tz: number;\n\tlayer: L;\n\tcollidesWith: readonly L[];\n\tshape: ColliderShape3D;\n\thalfWidth: number;\n\thalfHeight: number;\n\thalfDepth: number;\n\tradius: number;\n}\n\n// ==================== Collider Construction ====================\n\n/**\n * Populate a `BaseColliderInfo3D` slot in place from raw component data.\n * Returns `true` if the slot was filled, `false` if the entity has no\n * collider (caller should skip it).\n *\n * If an entity has both AABB3D and sphere colliders, AABB3D wins and only\n * the AABB3D offset is applied.\n */\nexport function fillBaseColliderInfo3D<L extends string>(\n\tinfo: BaseColliderInfo3D<L>,\n\tentityId: number,\n\tx: number,\n\ty: number,\n\tz: number,\n\tlayer: L,\n\tcollidesWith: readonly L[],\n\taabb3D: { width: number; height: number; depth: number; offsetX?: number; offsetY?: number; offsetZ?: number } | undefined,\n\tsphere: { radius: number; offsetX?: number; offsetY?: number; offsetZ?: number } | undefined,\n): boolean {\n\tinfo.entityId = entityId;\n\tinfo.layer = layer;\n\tinfo.collidesWith = collidesWith;\n\n\tif (aabb3D) {\n\t\tinfo.x = x + (aabb3D.offsetX ?? 0);\n\t\tinfo.y = y + (aabb3D.offsetY ?? 0);\n\t\tinfo.z = z + (aabb3D.offsetZ ?? 0);\n\t\tinfo.shape = AABB3D_SHAPE;\n\t\tinfo.halfWidth = aabb3D.width / 2;\n\t\tinfo.halfHeight = aabb3D.height / 2;\n\t\tinfo.halfDepth = aabb3D.depth / 2;\n\t\tinfo.radius = 0;\n\t\treturn true;\n\t}\n\n\tif (sphere) {\n\t\tinfo.x = x + (sphere.offsetX ?? 0);\n\t\tinfo.y = y + (sphere.offsetY ?? 0);\n\t\tinfo.z = z + (sphere.offsetZ ?? 0);\n\t\tinfo.shape = SPHERE_SHAPE;\n\t\tinfo.halfWidth = 0;\n\t\tinfo.halfHeight = 0;\n\t\tinfo.halfDepth = 0;\n\t\tinfo.radius = sphere.radius;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// ==================== Spatial Index Lookup ====================\n\n/**\n * Retrieve the optional spatialIndex3D resource, returning undefined when absent.\n * Centralizes the cross-plugin typed lookup so individual plugins don't each\n * need to import SpatialIndex3D or repeat the tryGetResource pattern.\n */\nexport function tryGetSpatialIndex3D(\n\ttryGetResource: <T>(key: string) => T | undefined,\n): SpatialIndex3D | undefined {\n\treturn tryGetResource<SpatialIndex3D>('spatialIndex3D');\n}\n\n// ==================== Narrowphase Tests ====================\n\n/**\n * Write an AABB3D-vs-AABB3D contact into `out`. Returns `true` if the\n * shapes overlap (out was filled), `false` otherwise.\n *\n * Resolves along the axis with minimum penetration depth.\n */\nexport function computeAABB3DvsAABB3D(\n\tax: number, ay: number, az: number, ahw: number, ahh: number, ahd: number,\n\tbx: number, by: number, bz: number, bhw: number, bhh: number, bhd: number,\n\tout: Contact3D,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst dz = bz - az;\n\tconst overlapX = (ahw + bhw) - Math.abs(dx);\n\tconst overlapY = (ahh + bhh) - Math.abs(dy);\n\tconst overlapZ = (ahd + bhd) - Math.abs(dz);\n\n\tif (overlapX <= 0 || overlapY <= 0 || overlapZ <= 0) return false;\n\n\tif (overlapX <= overlapY && overlapX <= overlapZ) {\n\t\tout.normalX = dx >= 0 ? 1 : -1;\n\t\tout.normalY = 0;\n\t\tout.normalZ = 0;\n\t\tout.depth = overlapX;\n\t\treturn true;\n\t}\n\n\tif (overlapY <= overlapZ) {\n\t\tout.normalX = 0;\n\t\tout.normalY = dy >= 0 ? 1 : -1;\n\t\tout.normalZ = 0;\n\t\tout.depth = overlapY;\n\t\treturn true;\n\t}\n\n\tout.normalX = 0;\n\tout.normalY = 0;\n\tout.normalZ = dz >= 0 ? 1 : -1;\n\tout.depth = overlapZ;\n\treturn true;\n}\n\n/**\n * Write a sphere-vs-sphere contact into `out`. Returns `true` if the\n * spheres overlap.\n */\nexport function computeSphereVsSphere(\n\tax: number, ay: number, az: number, ar: number,\n\tbx: number, by: number, bz: number, br: number,\n\tout: Contact3D,\n): boolean {\n\tconst dx = bx - ax;\n\tconst dy = by - ay;\n\tconst dz = bz - az;\n\tconst distSq = dx * dx + dy * dy + dz * dz;\n\tconst radiusSum = ar + br;\n\n\tif (distSq >= radiusSum * radiusSum) return false;\n\n\tconst dist = Math.sqrt(distSq);\n\tif (dist === 0) {\n\t\tout.normalX = 1;\n\t\tout.normalY = 0;\n\t\tout.normalZ = 0;\n\t\tout.depth = radiusSum;\n\t\treturn true;\n\t}\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.normalZ = dz / dist;\n\tout.depth = radiusSum - dist;\n\treturn true;\n}\n\n/**\n * Write an AABB3D-vs-sphere contact into `out`. Returns `true` if the\n * shapes overlap.\n *\n * Uses closest-point-on-AABB to sphere center. When the sphere center\n * is inside the AABB, resolves along the axis with minimum push distance.\n */\nexport function computeAABB3DvsSphere(\n\taabbX: number, aabbY: number, aabbZ: number, ahw: number, ahh: number, ahd: number,\n\tsphereX: number, sphereY: number, sphereZ: number, radius: number,\n\tout: Contact3D,\n): boolean {\n\tconst closestX = Math.max(aabbX - ahw, Math.min(sphereX, aabbX + ahw));\n\tconst closestY = Math.max(aabbY - ahh, Math.min(sphereY, aabbY + ahh));\n\tconst closestZ = Math.max(aabbZ - ahd, Math.min(sphereZ, aabbZ + ahd));\n\n\tconst dx = sphereX - closestX;\n\tconst dy = sphereY - closestY;\n\tconst dz = sphereZ - closestZ;\n\tconst distSq = dx * dx + dy * dy + dz * dz;\n\n\tif (distSq >= radius * radius) return false;\n\n\t// Sphere center inside AABB — resolve along minimum push axis\n\tif (distSq === 0) {\n\t\tconst pushLeft = (sphereX - (aabbX - ahw));\n\t\tconst pushRight = ((aabbX + ahw) - sphereX);\n\t\tconst pushUp = (sphereY - (aabbY - ahh));\n\t\tconst pushDown = ((aabbY + ahh) - sphereY);\n\t\tconst pushFront = (sphereZ - (aabbZ - ahd));\n\t\tconst pushBack = ((aabbZ + ahd) - sphereZ);\n\t\tconst minPush = Math.min(pushLeft, pushRight, pushUp, pushDown, pushFront, pushBack);\n\n\t\tif (minPush === pushRight) {\n\t\t\tout.normalX = 1; out.normalY = 0; out.normalZ = 0; out.depth = pushRight + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushLeft) {\n\t\t\tout.normalX = -1; out.normalY = 0; out.normalZ = 0; out.depth = pushLeft + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushDown) {\n\t\t\tout.normalX = 0; out.normalY = 1; out.normalZ = 0; out.depth = pushDown + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushUp) {\n\t\t\tout.normalX = 0; out.normalY = -1; out.normalZ = 0; out.depth = pushUp + radius;\n\t\t\treturn true;\n\t\t}\n\t\tif (minPush === pushBack) {\n\t\t\tout.normalX = 0; out.normalY = 0; out.normalZ = 1; out.depth = pushBack + radius;\n\t\t\treturn true;\n\t\t}\n\t\tout.normalX = 0; out.normalY = 0; out.normalZ = -1; out.depth = pushFront + radius;\n\t\treturn true;\n\t}\n\n\tconst dist = Math.sqrt(distSq);\n\tout.normalX = dx / dist;\n\tout.normalY = dy / dist;\n\tout.normalZ = dz / dist;\n\tout.depth = radius - dist;\n\treturn true;\n}\n\n// ==================== Contact Dispatcher ====================\n\n/**\n * Dispatch to the correct narrowphase function for the given pair and\n * write the contact into `out`. Returns `true` if the pair overlaps.\n */\nexport function computeContact3D(a: BaseColliderInfo3D, b: BaseColliderInfo3D, out: Contact3D): boolean {\n\tif (a.shape === AABB3D_SHAPE && b.shape === AABB3D_SHAPE) {\n\t\treturn computeAABB3DvsAABB3D(\n\t\t\ta.x, a.y, a.z, a.halfWidth, a.halfHeight, a.halfDepth,\n\t\t\tb.x, b.y, b.z, b.halfWidth, b.halfHeight, b.halfDepth,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === SPHERE_SHAPE && b.shape === SPHERE_SHAPE) {\n\t\treturn computeSphereVsSphere(\n\t\t\ta.x, a.y, a.z, a.radius,\n\t\t\tb.x, b.y, b.z, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\tif (a.shape === AABB3D_SHAPE && b.shape === SPHERE_SHAPE) {\n\t\treturn computeAABB3DvsSphere(\n\t\t\ta.x, a.y, a.z, a.halfWidth, a.halfHeight, a.halfDepth,\n\t\t\tb.x, b.y, b.z, b.radius,\n\t\t\tout,\n\t\t);\n\t}\n\n\t// a is Sphere, b is AABB3D — compute as AABB3D-vs-Sphere, then flip normal\n\tif (!computeAABB3DvsSphere(\n\t\tb.x, b.y, b.z, b.halfWidth, b.halfHeight, b.halfDepth,\n\t\ta.x, a.y, a.z, a.radius,\n\t\tout,\n\t)) return false;\n\tout.normalX = -out.normalX;\n\tout.normalY = -out.normalY;\n\tout.normalZ = -out.normalZ;\n\treturn true;\n}\n\n// ==================== Collision Iteration ====================\n\n/** Module-level reusable set for broadphase candidates. */\nconst _broadphaseCandidates = new Set<number>();\n\nlet _bruteForceWarned = false;\nconst BRUTE_FORCE_WARN_THRESHOLD = 50;\n\n/**\n * Generic 3D collision detection pipeline: brute-force or broadphase,\n * with layer filtering and contact computation.\n *\n * `count` is the number of live entries at the front of `colliders`.\n * The array itself may be a grow-only pool — only indices `[0, count)`\n * are iterated, so trailing pool slots are ignored.\n *\n * `workingMap` is a caller-owned `Map<number, I>` used by the broadphase\n * path as an entityId → collider lookup. It is cleared and repopulated on\n * each call; callers should allocate it once and pass the same instance\n * every frame.\n *\n * Uses a context parameter forwarded to the callback to avoid\n * per-frame closure allocation.\n */\nexport function detectCollisions3D<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tworkingMap: Map<number, I>,\n\tspatialIndex: SpatialIndex3D | undefined,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tif (spatialIndex) {\n\t\tbroadphaseDetect(colliders, count, workingMap, spatialIndex, onContact, context);\n\t} else {\n\t\tbruteForceDetect(colliders, count, onContact, context);\n\t}\n}\n\nfunction bruteForceDetect<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tif (!_bruteForceWarned && count >= BRUTE_FORCE_WARN_THRESHOLD) {\n\t\t_bruteForceWarned = true;\n\t\tconsole.warn(\n\t\t\t`[ecspresso] 3D collision detection is using O(n²) brute force with ${count} colliders. ` +\n\t\t\t`For better performance, install createSpatialIndex3DPlugin() alongside your collision or physics3D plugin.`,\n\t\t);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tfor (let j = i + 1; j < count; j++) {\n\t\t\tconst b = colliders[j];\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact3D(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _sharedContact, context);\n\t\t}\n\t}\n}\n\nfunction broadphaseDetect<I extends BaseColliderInfo3D, C>(\n\tcolliders: I[],\n\tcount: number,\n\tcolliderMap: Map<number, I>,\n\tspatialIndex: SpatialIndex3D,\n\tonContact: (a: I, b: I, contact: Contact3D, context: C) => void,\n\tcontext: C,\n): void {\n\tcolliderMap.clear();\n\tfor (let i = 0; i < count; i++) {\n\t\tconst c = colliders[i];\n\t\tif (!c) continue;\n\t\tcolliderMap.set(c.entityId, c);\n\t}\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst a = colliders[i];\n\t\tif (!a) continue;\n\n\t\tconst aHalfW = a.shape === AABB3D_SHAPE ? a.halfWidth : a.radius;\n\t\tconst aHalfH = a.shape === AABB3D_SHAPE ? a.halfHeight : a.radius;\n\t\tconst aHalfD = a.shape === AABB3D_SHAPE ? a.halfDepth : a.radius;\n\n\t\t_broadphaseCandidates.clear();\n\t\tspatialIndex.queryBoxInto(\n\t\t\ta.x - aHalfW, a.y - aHalfH, a.z - aHalfD,\n\t\t\ta.x + aHalfW, a.y + aHalfH, a.z + aHalfD,\n\t\t\t_broadphaseCandidates,\n\t\t);\n\n\t\t// TODO(perf): dense grids add every candidate (including `a` itself and\n\t\t// all lower-ID entities) to the set before the filter below discards ~half\n\t\t// of them. Emitting only pairs with larger IDs at query time — e.g. cells\n\t\t// as sorted arrays, or inserting entries in id-ascending order and having\n\t\t// the grid skip entries with id <= query-entity-id — would remove the\n\t\t// post-hoc filter and halve the Set churn for dense scenes.\n\t\tfor (const bId of _broadphaseCandidates) {\n\t\t\tif (bId <= a.entityId) continue;\n\n\t\t\tconst b = colliderMap.get(bId);\n\t\t\tif (!b) continue;\n\n\t\t\tif (!a.collidesWith.includes(b.layer) && !b.collidesWith.includes(a.layer)) continue;\n\n\t\t\tif (!computeContact3D(a, b, _sharedContact)) continue;\n\n\t\t\tonContact(a, b, _s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