ecspresso 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command-buffer.d.ts +1 -5
- package/dist/ecspresso-builder.d.ts +15 -7
- package/dist/ecspresso.d.ts +4 -5
- package/dist/entity-manager.d.ts +47 -3
- package/dist/event-bus.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +9 -9
- package/dist/plugins/ai/flocking.js +2 -2
- package/dist/plugins/ai/flocking.js.map +3 -3
- package/dist/plugins/physics/collision.js +2 -2
- package/dist/plugins/physics/collision.js.map +3 -3
- package/dist/plugins/physics/collision3D.js +2 -2
- package/dist/plugins/physics/collision3D.js.map +4 -4
- package/dist/plugins/physics/physics2D.js +2 -2
- package/dist/plugins/physics/physics2D.js.map +3 -3
- package/dist/plugins/physics/physics3D.js +2 -2
- package/dist/plugins/physics/physics3D.js.map +3 -3
- package/dist/plugins/scripting/timers.d.ts +36 -11
- package/dist/plugins/scripting/timers.js +2 -2
- package/dist/plugins/scripting/timers.js.map +3 -3
- package/dist/plugins/spatial/spatial-index.d.ts +19 -1
- package/dist/plugins/spatial/spatial-index.js +2 -2
- package/dist/plugins/spatial/spatial-index.js.map +4 -4
- package/dist/plugins/spatial/spatial-index3D.d.ts +19 -1
- package/dist/plugins/spatial/spatial-index3D.js +2 -2
- package/dist/plugins/spatial/spatial-index3D.js.map +4 -4
- package/dist/types.d.ts +9 -1
- package/dist/utils/spatial-hash.d.ts +20 -8
- package/dist/utils/spatial-hash3D.d.ts +20 -8
- package/package.json +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=((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 s}from"ecspresso";function v(J){let K=new Map,Q=new WeakMap,G=1;function V(j){let $=K.get(j);if($!==void 0)return $;if(G===0)throw Error(`[ecspresso] ${J} layer bitmask overflow: more than 32 distinct layers registered`);let N=G;return K.set(j,N),G<<=1,N}function O(j){let $=Q.get(j);if($!==void 0)return $;let N=0;for(let k=0;k<j.length;k++)N|=V(j[k]);return Q.set(j,N),N}return{getLayerBit:V,getCollidesWithMask:O}}var m={normalX:0,normalY:0,normalZ:0,depth:0},w=0,A=1,y=v("3D collision"),b=y.getLayerBit,u=y.getCollidesWithMask;function B(J,K,Q,G,V,O,j,$,N){if(J.entityId=K,J.layer=O,J.collidesWith=j,J.layerBit=b(O),J.collidesWithMask=u(j),$)return J.x=Q+($.offsetX??0),J.y=G+($.offsetY??0),J.z=V+($.offsetZ??0),J.shape=w,J.halfWidth=$.width/2,J.halfHeight=$.height/2,J.halfDepth=$.depth/2,J.radius=0,!0;if(N)return J.x=Q+(N.offsetX??0),J.y=G+(N.offsetY??0),J.z=V+(N.offsetZ??0),J.shape=A,J.halfWidth=0,J.halfHeight=0,J.halfDepth=0,J.radius=N.radius,!0;return!1}function d(J,K,Q,G,V,O,j,$,N,k,F,z,U){let R=j-J,L=$-K,P=N-Q,W=G+k-Math.abs(R),q=V+F-Math.abs(L),T=O+z-Math.abs(P);if(W<=0||q<=0||T<=0)return!1;if(W<=q&&W<=T)return U.normalX=R>=0?1:-1,U.normalY=0,U.normalZ=0,U.depth=W,!0;if(q<=T)return U.normalX=0,U.normalY=L>=0?1:-1,U.normalZ=0,U.depth=q,!0;return U.normalX=0,U.normalY=0,U.normalZ=P>=0?1:-1,U.depth=T,!0}function r(J,K,Q,G,V,O,j,$,N){let k=V-J,F=O-K,z=j-Q,U=k*k+F*F+z*z,R=G+$;if(U>=R*R)return!1;let L=Math.sqrt(U);if(L===0)return N.normalX=1,N.normalY=0,N.normalZ=0,N.depth=R,!0;return N.normalX=k/L,N.normalY=F/L,N.normalZ=z/L,N.depth=R-L,!0}function D(J,K,Q,G,V,O,j,$,N,k,F){let z=Math.max(J-G,Math.min(j,J+G)),U=Math.max(K-V,Math.min($,K+V)),R=Math.max(Q-O,Math.min(N,Q+O)),L=j-z,P=$-U,W=N-R,q=L*L+P*P+W*W;if(q>=k*k)return!1;if(q===0){let Z=j-(J-G),Y=J+G-j,H=$-(K-V),E=K+V-$,X=N-(Q-O),_=Q+O-N,M=Math.min(Z,Y,H,E,X,_);if(M===Y)return F.normalX=1,F.normalY=0,F.normalZ=0,F.depth=Y+k,!0;if(M===Z)return F.normalX=-1,F.normalY=0,F.normalZ=0,F.depth=Z+k,!0;if(M===E)return F.normalX=0,F.normalY=1,F.normalZ=0,F.depth=E+k,!0;if(M===H)return F.normalX=0,F.normalY=-1,F.normalZ=0,F.depth=H+k,!0;if(M===_)return F.normalX=0,F.normalY=0,F.normalZ=1,F.depth=_+k,!0;return F.normalX=0,F.normalY=0,F.normalZ=-1,F.depth=X+k,!0}let T=Math.sqrt(q);return F.normalX=L/T,F.normalY=P/T,F.normalZ=W/T,F.depth=k-T,!0}function p(J,K,Q){if(J.shape===w&&K.shape===w)return d(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===A&&K.shape===A)return r(J.x,J.y,J.z,J.radius,K.x,K.y,K.z,K.radius,Q);if(J.shape===w&&K.shape===A)return D(J.x,J.y,J.z,J.halfWidth,J.halfHeight,J.halfDepth,K.x,K.y,K.z,K.radius,Q);if(!D(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 g=[],f=!1,c=50;function h(J,K,Q,G,V,O){if(G)n(J,K,Q,G,V,O);else l(J,K,V,O)}function l(J,K,Q,G){if(!f&&K>=c)f=!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 j=V+1;j<K;j++){let $=J[j];if(!$)continue;if((O.collidesWithMask&$.layerBit|$.collidesWithMask&O.layerBit)===0)continue;if(!p(O,$,m))continue;Q(O,$,m,G)}}}function n(J,K,Q,G,V,O){Q.clear();for(let j=0;j<K;j++){let $=J[j];if(!$)continue;Q.set($.entityId,$)}for(let j=0;j<K;j++){let $=J[j];if(!$)continue;let N=$.shape===w?$.halfWidth:$.radius,k=$.shape===w?$.halfHeight:$.radius,F=$.shape===w?$.halfDepth:$.radius;g.length=0,G.queryBoxInto($.x-N,$.y-k,$.z-F,$.x+N,$.y+k,$.z+F,g,$.entityId);for(let z of g){let U=Q.get(z);if(!U)continue;if(($.collidesWithMask&U.layerBit|U.collidesWithMask&$.layerBit)===0)continue;if(!p($,U,m))continue;V($,U,m,O)}}}function $J(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 OJ(J,K,Q){return{force3D:{x:J,y:K,z:Q}}}function jJ(J,K,Q,G,V){let O=J.getComponent(K,"force3D");if(!O)return;O.x+=Q,O.y+=G,O.z+=V}function UJ(J,K,Q,G,V){let O=J.getComponent(K,"velocity3D"),j=J.getComponent(K,"rigidBody3D");if(!O||!j)return;if(j.mass===1/0||j.mass===0)return;O.x+=Q/j.mass,O.y+=G/j.mass,O.z+=V/j.mass}function FJ(J,K,Q,G,V){let O=J.getComponent(K,"velocity3D");if(!O)return;O.x=Q,O.y=G,O.z=V}var x={entityA:0,entityB:0,normalX:0,normalY:0,normalZ:0,depth:0};function i(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,j=V+O;if(j>0){let $=Q.depth/j;if(V>0){let U=G.getComponent(J.entityId,"localTransform3D");if(!U)return;let R=$*V;U.x-=R*Q.normalX,U.y-=R*Q.normalY,U.z-=R*Q.normalZ,J.x=U.x,J.y=U.y,J.z=U.z,G.markChanged(J.entityId,"localTransform3D")}if(O>0){let U=G.getComponent(K.entityId,"localTransform3D");if(!U)return;let R=$*O;U.x+=R*Q.normalX,U.y+=R*Q.normalY,U.z+=R*Q.normalZ,K.x=U.x,K.y=U.y,K.z=U.z,G.markChanged(K.entityId,"localTransform3D")}let N=K.velocity.x-J.velocity.x,k=K.velocity.y-J.velocity.y,F=K.velocity.z-J.velocity.z,z=N*Q.normalX+k*Q.normalY+F*Q.normalZ;if(z<0){let R=-(1+Math.min(J.rigidBody.restitution,K.rigidBody.restitution))*z/j,L=R*V,P=R*O;J.velocity.x-=L*Q.normalX,J.velocity.y-=L*Q.normalY,J.velocity.z-=L*Q.normalZ,K.velocity.x+=P*Q.normalX,K.velocity.y+=P*Q.normalY,K.velocity.z+=P*Q.normalZ;let W=N-z*Q.normalX,q=k-z*Q.normalY,T=F-z*Q.normalZ,Z=Math.sqrt(W*W+q*q+T*T);if(Z>0.000001){let Y=W/Z,H=q/Z,E=T/Z,_=Math.sqrt(J.rigidBody.friction*K.rigidBody.friction)*Math.abs(R),M=Math.min(Z/j,_),I=M*V,C=M*O;J.velocity.x+=I*Y,J.velocity.y+=I*H,J.velocity.z+=I*E,K.velocity.x-=C*Y,K.velocity.y-=C*H,K.velocity.z-=C*E}}G.markChanged(J.entityId,"velocity3D"),G.markChanged(K.entityId,"velocity3D")}x.entityA=J.entityId,x.entityB=K.entityId,x.normalX=Q.normalX,x.normalY=Q.normalY,x.normalZ=Q.normalZ,x.depth=Q.depth,G.eventBus.publish("physics3DCollision",x)}function GJ(J){let{gravity:K={x:0,y:0,z:0},systemGroup:Q="physics3D",collisionSystemGroup:G,integrationPriority:V=1000,collisionPriority:O=900,phase:j="fixedUpdate"}=J??{};return s("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(j).inGroup(Q).addQuery("bodies",{with:["localTransform3D","velocity3D","rigidBody3D","force3D"]}).setProcess(({queries:L,dt:P,ecs:W})=>{let{gravity:q}=W.getResource("physics3DConfig"),T=q.x,Z=q.y,Y=q.z;for(let H of L.bodies){let{localTransform3D:E,velocity3D:X,rigidBody3D:_,force3D:M}=H.components;if(_.type==="static")continue;if(_.type==="dynamic"){let I=_.gravityScale*P;X.x+=T*I,X.y+=Z*I,X.z+=Y*I;let C=_.mass;if(C>0&&C!==1/0){let S=P/C;X.x+=M.x*S,X.y+=M.y*S,X.z+=M.z*S}if(_.drag>0){let S=Math.max(0,1-_.drag*P);X.x*=S,X.y*=S,X.z*=S}}E.x+=X.x*P,E.y+=X.y*P,E.z+=X.z*P,M.x=0,M.y=0,M.z=0,W.markChanged(H.id,"localTransform3D")}});let N=$.addSystem("physics3D-collision").setPriority(O).inPhase(j).inGroup(Q);if(G)N.inGroup(G);let k=[],F=new Map,z,U=!1,R=(L,P,W,q,T,Z)=>{let Y=k[L];if(!Y)Y={entityId:P,x:0,y:0,z:0,layer:W,collidesWith:q,layerBit:0,collidesWithMask:0,shape:w,halfWidth:0,halfHeight:0,halfDepth:0,radius:0,rigidBody:T,velocity:Z},k[L]=Y;else Y.rigidBody=T,Y.velocity=Z;return Y};N.addQuery("aabbOnly",{with:["localTransform3D","rigidBody3D","velocity3D","collisionLayer","aabb3DCollider"],without:["sphereCollider"]}).addQuery("sphereOnly",{with:["localTransform3D","rigidBody3D","velocity3D","collisionLayer","sphereCollider"],without:["aabb3DCollider"]}).addQuery("both",{with:["localTransform3D","rigidBody3D","velocity3D","collisionLayer","aabb3DCollider","sphereCollider"]}).setProcess(({queries:L,ecs:P})=>{let W=0;for(let q of L.aabbOnly){let{localTransform3D:T,rigidBody3D:Z,velocity3D:Y,collisionLayer:H,aabb3DCollider:E}=q.components,X=R(W,q.id,H.layer,H.collidesWith,Z,Y);if(!B(X,q.id,T.x,T.y,T.z,H.layer,H.collidesWith,E,void 0))continue;W++}for(let q of L.sphereOnly){let{localTransform3D:T,rigidBody3D:Z,velocity3D:Y,collisionLayer:H,sphereCollider:E}=q.components,X=R(W,q.id,H.layer,H.collidesWith,Z,Y);if(!B(X,q.id,T.x,T.y,T.z,H.layer,H.collidesWith,void 0,E))continue;W++}for(let q of L.both){let{localTransform3D:T,rigidBody3D:Z,velocity3D:Y,collisionLayer:H,aabb3DCollider:E,sphereCollider:X}=q.components,_=R(W,q.id,H.layer,H.collidesWith,Z,Y);if(!B(_,q.id,T.x,T.y,T.z,H.layer,H.collidesWith,E,X))continue;W++}if(!U)z=P.tryGetResource("spatialIndex3D"),U=!0;h(k,W,F,z,i,P)})})}export{FJ as setVelocity3D,$J as createRigidBody3D,GJ as createPhysics3DPlugin,OJ as createForce3D,UJ as applyImpulse3D,jJ as applyForce3D};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=FABAD286A305821E64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=physics3D.js.map
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/plugins/physics/physics3D.ts", "../src/utils/layer-bit-registry.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\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\tlayerBit: 0,\n\t\t\t\t\t\t\t\tcollidesWithMask: 0,\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",
|
|
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\tconst ensureSlot = (idx: number, entityId: number, layer: L, collidesWith: readonly L[], rigidBody: RigidBody, velocity: Vector3D): Physics3DColliderInfo<L> => {\n\t\t\t\tlet slot = colliderPool[idx];\n\t\t\t\tif (!slot) {\n\t\t\t\t\tslot = {\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tx: 0,\n\t\t\t\t\t\ty: 0,\n\t\t\t\t\t\tz: 0,\n\t\t\t\t\t\tlayer,\n\t\t\t\t\t\tcollidesWith,\n\t\t\t\t\t\tlayerBit: 0,\n\t\t\t\t\t\tcollidesWithMask: 0,\n\t\t\t\t\t\tshape: AABB3D_SHAPE,\n\t\t\t\t\t\thalfWidth: 0,\n\t\t\t\t\t\thalfHeight: 0,\n\t\t\t\t\t\thalfDepth: 0,\n\t\t\t\t\t\tradius: 0,\n\t\t\t\t\t\trigidBody,\n\t\t\t\t\t\tvelocity,\n\t\t\t\t\t};\n\t\t\t\t\tcolliderPool[idx] = slot;\n\t\t\t\t} else {\n\t\t\t\t\tslot.rigidBody = rigidBody;\n\t\t\t\t\tslot.velocity = velocity;\n\t\t\t\t}\n\t\t\t\treturn slot;\n\t\t\t};\n\n\t\t\tcollisionSystem\n\t\t\t\t.addQuery('aabbOnly', {\n\t\t\t\t\twith: ['localTransform3D', 'rigidBody3D', 'velocity3D', 'collisionLayer', 'aabb3DCollider'],\n\t\t\t\t\twithout: ['sphereCollider'],\n\t\t\t\t})\n\t\t\t\t.addQuery('sphereOnly', {\n\t\t\t\t\twith: ['localTransform3D', 'rigidBody3D', 'velocity3D', 'collisionLayer', 'sphereCollider'],\n\t\t\t\t\twithout: ['aabb3DCollider'],\n\t\t\t\t})\n\t\t\t\t.addQuery('both', {\n\t\t\t\t\twith: ['localTransform3D', 'rigidBody3D', 'velocity3D', 'collisionLayer', 'aabb3DCollider', 'sphereCollider'],\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.aabbOnly) {\n\t\t\t\t\t\tconst { localTransform3D, rigidBody3D, velocity3D, collisionLayer, aabb3DCollider } = entity.components;\n\t\t\t\t\t\tconst slot = ensureSlot(count, entity.id, collisionLayer.layer, collisionLayer.collidesWith, rigidBody3D, velocity3D);\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\taabb3DCollider, undefined,\n\t\t\t\t\t\t)) continue;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const entity of queries.sphereOnly) {\n\t\t\t\t\t\tconst { localTransform3D, rigidBody3D, velocity3D, collisionLayer, sphereCollider } = entity.components;\n\t\t\t\t\t\tconst slot = ensureSlot(count, entity.id, collisionLayer.layer, collisionLayer.collidesWith, rigidBody3D, velocity3D);\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\tundefined, sphereCollider,\n\t\t\t\t\t\t)) continue;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\n\t\t\t\t\t// fillBaseColliderInfo3D picks aabb when both present — preserves prior precedence.\n\t\t\t\t\tfor (const entity of queries.both) {\n\t\t\t\t\t\tconst { localTransform3D, rigidBody3D, velocity3D, collisionLayer, aabb3DCollider, sphereCollider } = entity.components;\n\t\t\t\t\t\tconst slot = ensureSlot(count, entity.id, collisionLayer.layer, collisionLayer.collidesWith, rigidBody3D, velocity3D);\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\taabb3DCollider, sphereCollider,\n\t\t\t\t\t\t)) continue;\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
6
|
"/**\n * Lazy monotonic registry mapping layer name → unique bit. Lets pair\n * filtering use a single `(a.collidesWithMask & b.layerBit)` check\n * instead of `Array.includes` on every collision pair.\n *\n * One registry per dimension (2D and 3D) — user-defined layer namespaces\n * are independent, so bits should not be shared across systems.\n *\n * Maximum 32 layers per registry (one per bit in a 32-bit signed int).\n * Crossing the limit throws on the next `getLayerBit` call.\n */\nexport interface LayerBitRegistry {\n\tgetLayerBit(layer: string): number;\n\t/** OR of `getLayerBit` for every entry. Cached by array reference. */\n\tgetCollidesWithMask(collidesWith: readonly string[]): number;\n}\n\nexport function createLayerBitRegistry(label: string): LayerBitRegistry {\n\tconst layerBits = new Map<string, number>();\n\tconst maskCache = new WeakMap<readonly string[], number>();\n\tlet nextBit = 1;\n\n\tfunction getLayerBit(layer: string): number {\n\t\tconst existing = layerBits.get(layer);\n\t\tif (existing !== undefined) return existing;\n\t\tif (nextBit === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`[ecspresso] ${label} layer bitmask overflow: more than 32 distinct layers registered`,\n\t\t\t);\n\t\t}\n\t\tconst bit = nextBit;\n\t\tlayerBits.set(layer, bit);\n\t\t// `<<= 1` rolls 1<<31 to 0, which is detected on the next call.\n\t\tnextBit <<= 1;\n\t\treturn bit;\n\t}\n\n\tfunction getCollidesWithMask(collidesWith: readonly string[]): number {\n\t\tconst cached = maskCache.get(collidesWith);\n\t\tif (cached !== undefined) return cached;\n\t\tlet mask = 0;\n\t\tfor (let i = 0; i < collidesWith.length; i++) {\n\t\t\tmask |= getLayerBit(collidesWith[i]!);\n\t\t}\n\t\tmaskCache.set(collidesWith, mask);\n\t\treturn mask;\n\t}\n\n\treturn { getLayerBit, getCollidesWithMask };\n}\n",
|
|
7
7
|
"/**\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';\nimport { createLayerBitRegistry } from './layer-bit-registry';\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\t/**\n\t * Bit assigned to `layer` from the lazy layer registry. Populated by\n\t * `fillBaseColliderInfo3D`. Used together with `collidesWithMask` to\n\t * replace per-pair `Array.includes` layer checks with a single AND.\n\t */\n\tlayerBit: number;\n\t/** OR of `getLayerBit3D` for every entry in `collidesWith`. */\n\tcollidesWithMask: number;\n\tshape: ColliderShape3D;\n\thalfWidth: number;\n\thalfHeight: number;\n\thalfDepth: number;\n\tradius: number;\n}\n\n// ==================== Layer Bit Registry ====================\n\n// Independent from the 2D registry: 2D and 3D layer namespaces are\n// defined separately by user code, so bits should not collide.\nconst _layerRegistry = createLayerBitRegistry('3D collision');\nexport const getLayerBit3D = _layerRegistry.getLayerBit;\nexport const getCollidesWithMask3D = _layerRegistry.getCollidesWithMask;\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\tinfo.layerBit = getLayerBit3D(layer);\n\tinfo.collidesWithMask = getCollidesWithMask3D(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 array for broadphase candidates. */\nconst _broadphaseCandidates: 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.collidesWithMask & b.layerBit) | (b.collidesWithMask & a.layerBit)) === 0) 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.length = 0;\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\ta.entityId,\n\t\t);\n\n\t\tfor (const bId of _broadphaseCandidates) {\n\t\t\tconst b = colliderMap.get(bId);\n\t\t\tif (!b) continue;\n\n\t\t\tif (((a.collidesWithMask & b.layerBit) | (b.collidesWithMask & a.layerBit)) === 0) 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"
|
|
8
8
|
],
|
|
9
|
-
"mappings": "2PAYA,uBAAS,kBCKF,SAAS,CAAsB,CAAC,EAAiC,CACvE,IAAM,EAAY,IAAI,IAChB,EAAY,IAAI,QAClB,EAAU,EAEd,SAAS,CAAW,CAAC,EAAuB,CAC3C,IAAM,EAAW,EAAU,IAAI,CAAK,EACpC,GAAI,IAAa,OAAW,OAAO,EACnC,GAAI,IAAY,EACf,MAAU,MACT,eAAe,mEAChB,EAED,IAAM,EAAM,EAIZ,OAHA,EAAU,IAAI,EAAO,CAAG,EAExB,IAAY,EACL,EAGR,SAAS,CAAmB,CAAC,EAAyC,CACrE,IAAM,EAAS,EAAU,IAAI,CAAY,EACzC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EAAe,MAAO,EAAe,aAAc,EAAa,CAAU,EACpH,GAAI,CAAC,EACJ,EACA,EAAO,GAAI,EAAiB,EAAG,EAAiB,EAAG,EAAiB,EACpE,EAAe,MAAO,EAAe,aACrC,EAAgB,CACjB,EAAG,SACH,IAGD,GAAI,CAAC,EACJ,EAAW,EAAI,eAA+B,gBAAgB,EAC9D,EAAa,GAEd,EAAmB,EAAc,EAAO,EAAe,EAAU,EAAyB,CAAG,EAC7F,EACF",
|
|
10
|
+
"debugId": "FABAD286A305821E64756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -22,11 +22,11 @@ import { type BasePluginOptions } from 'ecspresso';
|
|
|
22
22
|
* }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export interface TimerEventData {
|
|
25
|
+
export interface TimerEventData<Slots extends string = string> {
|
|
26
26
|
/** The entity ID that owns the timer slot */
|
|
27
27
|
entityId: number;
|
|
28
28
|
/** The slot name within the entity's `timers` map */
|
|
29
|
-
slot:
|
|
29
|
+
slot: Slots;
|
|
30
30
|
/** The slot's configured duration in seconds */
|
|
31
31
|
duration: number;
|
|
32
32
|
/** The actual elapsed time (may exceed duration slightly) */
|
|
@@ -36,7 +36,7 @@ export interface TimerEventData {
|
|
|
36
36
|
* A single timer's data. Multiple of these can live on one entity, keyed by slot name.
|
|
37
37
|
* Use `justFinished` to detect completion in your systems.
|
|
38
38
|
*/
|
|
39
|
-
export interface Timer {
|
|
39
|
+
export interface Timer<Slots extends string = string> {
|
|
40
40
|
/** Time accumulated so far (seconds) */
|
|
41
41
|
elapsed: number;
|
|
42
42
|
/** Target duration (seconds) */
|
|
@@ -48,7 +48,7 @@ export interface Timer {
|
|
|
48
48
|
/** True for one frame after the timer completes */
|
|
49
49
|
justFinished: boolean;
|
|
50
50
|
/** Optional callback invoked when the timer completes */
|
|
51
|
-
onComplete?: (data: TimerEventData) => void;
|
|
51
|
+
onComplete?: (data: TimerEventData<Slots>) => void;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Component types provided by the timer plugin.
|
|
@@ -71,14 +71,14 @@ export interface Timer {
|
|
|
71
71
|
* });
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
export interface TimerComponentTypes {
|
|
75
|
-
timers: Record<
|
|
74
|
+
export interface TimerComponentTypes<Slots extends string = string> {
|
|
75
|
+
timers: Partial<Record<Slots, Timer<Slots>>>;
|
|
76
76
|
}
|
|
77
77
|
export interface TimerPluginOptions<G extends string = 'timers'> extends BasePluginOptions<G> {
|
|
78
78
|
}
|
|
79
|
-
export interface TimerOptions {
|
|
79
|
+
export interface TimerOptions<Slots extends string = string> {
|
|
80
80
|
/** Callback invoked when the timer completes */
|
|
81
|
-
onComplete?: (data: TimerEventData) => void;
|
|
81
|
+
onComplete?: (data: TimerEventData<Slots>) => void;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Create a one-shot `Timer` to drop into a `timers` slot.
|
|
@@ -105,7 +105,7 @@ export interface TimerOptions {
|
|
|
105
105
|
* });
|
|
106
106
|
* ```
|
|
107
107
|
*/
|
|
108
|
-
export declare function createTimer(duration: number, options?: TimerOptions): Timer
|
|
108
|
+
export declare function createTimer<Slots extends string = string>(duration: number, options?: TimerOptions<Slots>): Timer<Slots>;
|
|
109
109
|
/**
|
|
110
110
|
* Create a repeating `Timer` to drop into a `timers` slot. Fires
|
|
111
111
|
* `justFinished` once per cycle and continues running.
|
|
@@ -118,7 +118,7 @@ export declare function createTimer(duration: number, options?: TimerOptions): T
|
|
|
118
118
|
* });
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
|
-
export declare function createRepeatingTimer(duration: number, options?: TimerOptions): Timer
|
|
121
|
+
export declare function createRepeatingTimer<Slots extends string = string>(duration: number, options?: TimerOptions<Slots>): Timer<Slots>;
|
|
122
122
|
/**
|
|
123
123
|
* Create a timer plugin for ECSpresso.
|
|
124
124
|
*
|
|
@@ -148,5 +148,30 @@ export declare function createRepeatingTimer(duration: number, options?: TimerOp
|
|
|
148
148
|
* }
|
|
149
149
|
* });
|
|
150
150
|
* ```
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* Typed slot names — pass a string-union generic to lock the set of legal
|
|
154
|
+
* slot names. Spawn sites reject typos, autocomplete works on slot access,
|
|
155
|
+
* and `slot` is narrowed in `onComplete` callbacks. Defaults to `string`
|
|
156
|
+
* (any slot name) when omitted.
|
|
157
|
+
*
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const ecs = ECSpresso.create()
|
|
160
|
+
* .withPlugin(createTimerPlugin<'launch' | 'hangarCycle'>())
|
|
161
|
+
* .build();
|
|
162
|
+
*
|
|
163
|
+
* ecs.spawn({ timers: { launch: createTimer(2.0) } }); // ok
|
|
164
|
+
* ecs.spawn({ timers: { typo: createTimer(2.0) } }); // type error
|
|
165
|
+
*
|
|
166
|
+
* createTimer<'launch' | 'hangarCycle'>(1.0, {
|
|
167
|
+
* onComplete: ({ slot }) => {
|
|
168
|
+
* // slot is 'launch' | 'hangarCycle', not string
|
|
169
|
+
* },
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* Only one timer plugin can be installed per world. Feature plugins should
|
|
174
|
+
* re-export their slot union as a type so the app can assemble them:
|
|
175
|
+
* `createTimerPlugin<FighterSlots | CarrierSlots>()`.
|
|
151
176
|
*/
|
|
152
|
-
export declare function createTimerPlugin<G extends string = 'timers'>(options?: TimerPluginOptions<G>): import("ecspresso").Plugin<import("ecspresso").WithComponents<import("ecspresso").EmptyConfig, TimerComponentTypes
|
|
177
|
+
export declare function createTimerPlugin<Slots extends string = string, G extends string = 'timers'>(options?: TimerPluginOptions<G>): import("ecspresso").Plugin<import("ecspresso").WithComponents<import("ecspresso").EmptyConfig, TimerComponentTypes<Slots>>, import("ecspresso").EmptyConfig, "timer-update", G, never, never>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var X=((A)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(A,{get:(B,H)=>(typeof require<"u"?require:B)[H]}):A)(function(A){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+A+'" is not supported')});import{definePlugin as W}from"ecspresso";function _(A,B){return{elapsed:0,duration:A,repeat:!1,active:!0,justFinished:!1,onComplete:B?.onComplete}}function $(A,B){return{elapsed:0,duration:A,repeat:!0,active:!0,justFinished:!1,onComplete:B?.onComplete}}function D(A){let{systemGroup:B="timers",priority:H=0,phase:M="preUpdate"}=A??{};return W("timers").withComponentTypes().withLabels().withGroups().install((N)=>{N.addSystem("timer-update").setPriority(H).inPhase(M).inGroup(B).addQuery("timers",{with:["timers"]}).setProcess(({queries:U,dt:V})=>{for(let J of U.timers){let L=J.components.timers;for(let K in L){let z=L[K];if(!z)continue;if(z.justFinished=!1,!z.active)continue;if(z.elapsed+=V,z.elapsed<z.duration)continue;if(z.repeat)while(z.elapsed>=z.duration)z.justFinished=!0,z.onComplete?.({entityId:J.id,slot:K,duration:z.duration,elapsed:z.elapsed}),z.elapsed-=z.duration;else z.justFinished=!0,z.onComplete?.({entityId:J.id,slot:K,duration:z.duration,elapsed:z.elapsed}),z.active=!1}}})})}export{D as createTimerPlugin,_ as createTimer,$ as createRepeatingTimer};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=5793392D19F4504664756E2164756E21
|
|
4
4
|
//# sourceMappingURL=timers.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/plugins/scripting/timers.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Timer Plugin for ECSpresso\n *\n * ECS-native timers as pure data. An entity may carry multiple named timer\n * slots; the plugin's update system ticks every slot each frame and exposes\n * `justFinished` for the frame a slot crosses its duration. The plugin never\n * touches entity lifecycle — callers despawn (or do anything else) themselves\n * by reacting to `justFinished` or in the slot's `onComplete` callback.\n */\n\nimport { definePlugin, type BasePluginOptions } from 'ecspresso';\n\n// ==================== Event Types ====================\n\n/**\n * Data passed to a slot's `onComplete` callback when its timer completes.\n *\n * @example\n * ```typescript\n * timers: {\n * launch: createTimer(1.5, {\n * onComplete: ({ entityId, slot, elapsed }) => {\n * console.log(`Slot ${slot} on entity ${entityId} finished after ${elapsed}s`);\n * },\n * }),\n * }\n * ```\n */\nexport interface TimerEventData {\n\t/** The entity ID that owns the timer slot */\n\tentityId: number;\n\t/** The slot name within the entity's `timers` map */\n\tslot:
|
|
5
|
+
"/**\n * Timer Plugin for ECSpresso\n *\n * ECS-native timers as pure data. An entity may carry multiple named timer\n * slots; the plugin's update system ticks every slot each frame and exposes\n * `justFinished` for the frame a slot crosses its duration. The plugin never\n * touches entity lifecycle — callers despawn (or do anything else) themselves\n * by reacting to `justFinished` or in the slot's `onComplete` callback.\n */\n\nimport { definePlugin, type BasePluginOptions } from 'ecspresso';\n\n// ==================== Event Types ====================\n\n/**\n * Data passed to a slot's `onComplete` callback when its timer completes.\n *\n * @example\n * ```typescript\n * timers: {\n * launch: createTimer(1.5, {\n * onComplete: ({ entityId, slot, elapsed }) => {\n * console.log(`Slot ${slot} on entity ${entityId} finished after ${elapsed}s`);\n * },\n * }),\n * }\n * ```\n */\nexport interface TimerEventData<Slots extends string = string> {\n\t/** The entity ID that owns the timer slot */\n\tentityId: number;\n\t/** The slot name within the entity's `timers` map */\n\tslot: Slots;\n\t/** The slot's configured duration in seconds */\n\tduration: number;\n\t/** The actual elapsed time (may exceed duration slightly) */\n\telapsed: number;\n}\n\n// ==================== Component Types ====================\n\n/**\n * A single timer's data. Multiple of these can live on one entity, keyed by slot name.\n * Use `justFinished` to detect completion in your systems.\n */\nexport interface Timer<Slots extends string = string> {\n\t/** Time accumulated so far (seconds) */\n\telapsed: number;\n\t/** Target duration (seconds) */\n\tduration: number;\n\t/** Whether the timer repeats after completion */\n\trepeat: boolean;\n\t/** Whether the timer is currently running */\n\tactive: boolean;\n\t/** True for one frame after the timer completes */\n\tjustFinished: boolean;\n\t/** Optional callback invoked when the timer completes */\n\tonComplete?: (data: TimerEventData<Slots>) => void;\n}\n\n/**\n * Component types provided by the timer plugin.\n *\n * Each entity carries a single `timers` component whose value is a map of\n * named slots. This lets one entity host independent phase clocks\n * (e.g. `{ launch: ..., shieldDepletion: ..., hangarCycle: ... }`) without\n * one timer's lifecycle constraining another.\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTimerPlugin())\n * .withComponentTypes<{ fighter: true }>()\n * .build();\n *\n * ecs.spawn({\n * fighter: true,\n * timers: { launch: createTimer(2.0) },\n * });\n * ```\n */\nexport interface TimerComponentTypes<Slots extends string = string> {\n\ttimers: Partial<Record<Slots, Timer<Slots>>>;\n}\n\n// ==================== Plugin Options ====================\n\nexport interface TimerPluginOptions<G extends string = 'timers'> extends BasePluginOptions<G> {}\n\n// ==================== Helper Functions ====================\n\nexport interface TimerOptions<Slots extends string = string> {\n\t/** Callback invoked when the timer completes */\n\tonComplete?: (data: TimerEventData<Slots>) => void;\n}\n\n/**\n * Create a one-shot `Timer` to drop into a `timers` slot.\n *\n * The timer fires `justFinished` for one frame on completion and then idles\n * (`active = false`). The entity is left alone — if the slot's lifetime\n * coincides with the entity's lifetime (vfx, blasts, summon-anim), despawn\n * the host yourself in `onComplete` or in a system that watches `justFinished`.\n *\n * @example\n * ```typescript\n * ecs.spawn({\n * fighter: true,\n * timers: { launch: createTimer(2.0) },\n * });\n *\n * // Self-destructing vfx — caller owns the despawn:\n * ecs.spawn({\n * timers: {\n * fade: createTimer(1.0, {\n * onComplete: ({ entityId }) => ecs.commands.removeEntity(entityId),\n * }),\n * },\n * });\n * ```\n */\nexport function createTimer<Slots extends string = string>(duration: number, options?: TimerOptions<Slots>): Timer<Slots> {\n\treturn {\n\t\telapsed: 0,\n\t\tduration,\n\t\trepeat: false,\n\t\tactive: true,\n\t\tjustFinished: false,\n\t\tonComplete: options?.onComplete,\n\t};\n}\n\n/**\n * Create a repeating `Timer` to drop into a `timers` slot. Fires\n * `justFinished` once per cycle and continues running.\n *\n * @example\n * ```typescript\n * ecs.spawn({\n * carrier: true,\n * timers: { hangarCycle: createRepeatingTimer(5.0) },\n * });\n * ```\n */\nexport function createRepeatingTimer<Slots extends string = string>(duration: number, options?: TimerOptions<Slots>): Timer<Slots> {\n\treturn {\n\t\telapsed: 0,\n\t\tduration,\n\t\trepeat: true,\n\t\tactive: true,\n\t\tjustFinished: false,\n\t\tonComplete: options?.onComplete,\n\t};\n}\n\n// ==================== Plugin Factory ====================\n\n/**\n * Create a timer plugin for ECSpresso.\n *\n * The plugin installs one update system that ticks every slot of every\n * `timers` component each frame. It does not touch entity lifecycle —\n * react to `justFinished` (or use `onComplete`) and despawn yourself if needed.\n *\n * @example\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTimerPlugin())\n * .withComponentTypes<{ spawner: true }>()\n * .build();\n *\n * ecs.spawn({\n * spawner: true,\n * timers: { wave: createRepeatingTimer(5.0) },\n * });\n *\n * ecs.addSystem('spawn-on-timer')\n * .addQuery('spawners', { with: ['timers', 'spawner'] })\n * .setProcess(({ queries, ecs }) => {\n * for (const { components } of queries.spawners) {\n * if (components.timers.wave?.justFinished) {\n * ecs.spawn({ enemy: true });\n * }\n * }\n * });\n * ```\n *\n * @example\n * Typed slot names — pass a string-union generic to lock the set of legal\n * slot names. Spawn sites reject typos, autocomplete works on slot access,\n * and `slot` is narrowed in `onComplete` callbacks. Defaults to `string`\n * (any slot name) when omitted.\n *\n * ```typescript\n * const ecs = ECSpresso.create()\n * .withPlugin(createTimerPlugin<'launch' | 'hangarCycle'>())\n * .build();\n *\n * ecs.spawn({ timers: { launch: createTimer(2.0) } }); // ok\n * ecs.spawn({ timers: { typo: createTimer(2.0) } }); // type error\n *\n * createTimer<'launch' | 'hangarCycle'>(1.0, {\n * onComplete: ({ slot }) => {\n * // slot is 'launch' | 'hangarCycle', not string\n * },\n * });\n * ```\n *\n * Only one timer plugin can be installed per world. Feature plugins should\n * re-export their slot union as a type so the app can assemble them:\n * `createTimerPlugin<FighterSlots | CarrierSlots>()`.\n */\nexport function createTimerPlugin<\n\tSlots extends string = string,\n\tG extends string = 'timers',\n>(\n\toptions?: TimerPluginOptions<G>\n) {\n\tconst {\n\t\tsystemGroup = 'timers',\n\t\tpriority = 0,\n\t\tphase = 'preUpdate',\n\t} = options ?? {};\n\n\treturn definePlugin('timers')\n\t\t.withComponentTypes<TimerComponentTypes<Slots>>()\n\t\t.withLabels<'timer-update'>()\n\t\t.withGroups<G>()\n\t\t.install((world) => {\n\t\t\tworld\n\t\t\t\t.addSystem('timer-update')\n\t\t\t\t.setPriority(priority)\n\t\t\t\t.inPhase(phase)\n\t\t\t\t.inGroup(systemGroup)\n\t\t\t\t.addQuery('timers', { with: ['timers'] })\n\t\t\t\t.setProcess(({ queries, dt }) => {\n\t\t\t\t\tfor (const entity of queries.timers) {\n\t\t\t\t\t\tconst slots = entity.components.timers;\n\t\t\t\t\t\tfor (const slot in slots) {\n\t\t\t\t\t\t\tconst timer = slots[slot];\n\t\t\t\t\t\t\tif (!timer) continue;\n\n\t\t\t\t\t\t\ttimer.justFinished = false;\n\t\t\t\t\t\t\tif (!timer.active) continue;\n\n\t\t\t\t\t\t\ttimer.elapsed += dt;\n\t\t\t\t\t\t\tif (timer.elapsed < timer.duration) continue;\n\n\t\t\t\t\t\t\tif (timer.repeat) {\n\t\t\t\t\t\t\t\twhile (timer.elapsed >= timer.duration) {\n\t\t\t\t\t\t\t\t\ttimer.justFinished = true;\n\t\t\t\t\t\t\t\t\ttimer.onComplete?.({\n\t\t\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\t\t\t\tduration: timer.duration,\n\t\t\t\t\t\t\t\t\t\telapsed: timer.elapsed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\ttimer.elapsed -= timer.duration;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\ttimer.justFinished = true;\n\t\t\t\t\t\t\t\ttimer.onComplete?.({\n\t\t\t\t\t\t\t\t\tentityId: entity.id,\n\t\t\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\t\t\tduration: timer.duration,\n\t\t\t\t\t\t\t\t\telapsed: timer.elapsed,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\ttimer.active = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t});\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "2PAUA,uBAAS,kBA+GF,SAAS,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "2PAUA,uBAAS,kBA+GF,SAAS,CAA0C,CAAC,EAAkB,EAA6C,CACzH,MAAO,CACN,QAAS,EACT,WACA,OAAQ,GACR,OAAQ,GACR,aAAc,GACd,WAAY,GAAS,UACtB,EAeM,SAAS,CAAmD,CAAC,EAAkB,EAA6C,CAClI,MAAO,CACN,QAAS,EACT,WACA,OAAQ,GACR,OAAQ,GACR,aAAc,GACd,WAAY,GAAS,UACtB,EA4DM,SAAS,CAGf,CACA,EACC,CACD,IACC,cAAc,SACd,WAAW,EACX,QAAQ,aACL,GAAW,CAAC,EAEhB,OAAO,EAAa,QAAQ,EAC1B,mBAA+C,EAC/C,WAA2B,EAC3B,WAAc,EACd,QAAQ,CAAC,IAAU,CACnB,EACE,UAAU,cAAc,EACxB,YAAY,CAAQ,EACpB,QAAQ,CAAK,EACb,QAAQ,CAAW,EACnB,SAAS,SAAU,CAAE,KAAM,CAAC,QAAQ,CAAE,CAAC,EACvC,WAAW,EAAG,UAAS,QAAS,CAChC,QAAW,KAAU,EAAQ,OAAQ,CACpC,IAAM,EAAQ,EAAO,WAAW,OAChC,QAAW,KAAQ,EAAO,CACzB,IAAM,EAAQ,EAAM,GACpB,GAAI,CAAC,EAAO,SAGZ,GADA,EAAM,aAAe,GACjB,CAAC,EAAM,OAAQ,SAGnB,GADA,EAAM,SAAW,EACb,EAAM,QAAU,EAAM,SAAU,SAEpC,GAAI,EAAM,OACT,MAAO,EAAM,SAAW,EAAM,SAC7B,EAAM,aAAe,GACrB,EAAM,aAAa,CAClB,SAAU,EAAO,GACjB,OACA,SAAU,EAAM,SAChB,QAAS,EAAM,OAChB,CAAC,EACD,EAAM,SAAW,EAAM,SAGxB,OAAM,aAAe,GACrB,EAAM,aAAa,CAClB,SAAU,EAAO,GACjB,OACA,SAAU,EAAM,SAChB,QAAS,EAAM,OAChB,CAAC,EACD,EAAM,OAAS,KAIlB,EACF",
|
|
8
|
+
"debugId": "5793392D19F4504664756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -24,7 +24,25 @@ export interface SpatialIndexPluginOptions<G extends string = 'spatialIndex'> {
|
|
|
24
24
|
systemGroup?: G;
|
|
25
25
|
/** Priority for rebuild systems (default: 2000, before collision) */
|
|
26
26
|
priority?: number;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Phases to register rebuild systems in (default: ['fixedUpdate', 'postUpdate']).
|
|
29
|
+
*
|
|
30
|
+
* When both phases are registered, the `postUpdate` rebuild is
|
|
31
|
+
* automatically skipped on cycles where:
|
|
32
|
+
* 1. The `fixedUpdate` rebuild already ran this cycle, AND
|
|
33
|
+
* 2. No entity hierarchy exists.
|
|
34
|
+
*
|
|
35
|
+
* In flat-hierarchy scenes `transform-propagation` copies
|
|
36
|
+
* `localTransform → worldTransform` unchanged, so the postUpdate
|
|
37
|
+
* grid would duplicate the fixedUpdate one. The skip is automatic
|
|
38
|
+
* and re-engages once any parent relationship is set, or whenever
|
|
39
|
+
* `fixedUpdate` doesn't run that cycle (sub-fixed-DT frames).
|
|
40
|
+
*
|
|
41
|
+
* Edge case: if you write to `worldTransform` directly between
|
|
42
|
+
* phases without using `transform-propagation` or entity hierarchy,
|
|
43
|
+
* the auto-skip will leave your writes unindexed. Set
|
|
44
|
+
* `phases: ['postUpdate']` explicitly to bypass the auto-skip.
|
|
45
|
+
*/
|
|
28
46
|
phases?: ReadonlyArray<SpatialIndexPhase>;
|
|
29
47
|
}
|
|
30
48
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var X=((j)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(j,{get:(B,D)=>(typeof require<"u"?require:B)[D]}):j)(function(j){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+j+'" is not supported')});import{definePlugin as I}from"ecspresso";function G(j,B){return j*73856093^B*19349663}function H(j){return{cellSize:j,invCellSize:1/j,cells:new Map,entries:[],_aliveGen:0,_queryGen:0}}function W(j){j._aliveGen++}function z(j,B,D,K,O,V){let _=j._aliveGen,Z=j.entries[B],$;if(Z)Z.x=D,Z.y=K,Z.halfW=O,Z.halfH=V,Z._aliveGen=_,$=Z;else $={entityId:B,x:D,y:K,halfW:O,halfH:V,_lastSeenGen:0,_aliveGen:_},j.entries[B]=$;let F=j.invCellSize,L=Math.floor((D-O)*F),T=Math.floor((D+O)*F),U=Math.floor((K-V)*F),w=Math.floor((K+V)*F);for(let J=L;J<=T;J++)for(let N=U;N<=w;N++){let A=G(J,N),M=j.cells.get(A);if(M&&M._gen===_)M.push($);else if(M)M.length=0,M._gen=_,M.push($);else{let P=[$];P._gen=_,j.cells.set(A,P)}}}function q(j,B,D,K,O,V,_=-1){let Z=j.invCellSize,$=Math.floor(B*Z),F=Math.floor(K*Z),L=Math.floor(D*Z),T=Math.floor(O*Z),U=++j._queryGen,w=j._aliveGen;for(let J=$;J<=F;J++)for(let N=L;N<=T;N++){let A=j.cells.get(G(J,N));if(!A||A._gen!==w)continue;for(let M of A){if(M.entityId<=_||M._lastSeenGen===U)continue;M._lastSeenGen=U,V.push(M.entityId)}}}function S(j,B,D,K,O){let V=K*K,_=j.invCellSize,Z=Math.floor((B-K)*_),$=Math.floor((B+K)*_),F=Math.floor((D-K)*_),L=Math.floor((D+K)*_),T=++j._queryGen,U=j._aliveGen;for(let w=Z;w<=$;w++)for(let J=F;J<=L;J++){let N=j.cells.get(G(w,J));if(!N||N._gen!==U)continue;for(let A of N){if(A._lastSeenGen===T)continue;A._lastSeenGen=T;let M=Math.max(A.x-A.halfW,Math.min(B,A.x+A.halfW)),P=Math.max(A.y-A.halfH,Math.min(D,A.y+A.halfH)),E=B-M,Q=D-P;if(E*E+Q*Q<=V)O.push(A.entityId)}}}function R(j,B){let D=j.entries[B];if(!D||D._aliveGen!==j._aliveGen)return;return D}function v(j){return{grid:j,queryRect(B,D,K,O){let V=[];return q(j,B,D,K,O,V),V},queryRectInto(B,D,K,O,V,_){q(j,B,D,K,O,V,_)},queryRadius(B,D,K){let O=[];return S(j,B,D,K,O),O},queryRadiusInto(B,D,K,O){S(j,B,D,K,O)},getEntry(B){return R(j,B)}}}function h(j){let{cellSize:B=64,systemGroup:D="spatialIndex",priority:K=2000,phases:O=["fixedUpdate","postUpdate"]}=j??{},V=H(B),_=v(V);return I("spatialIndex").withComponentTypes().withResourceTypes().withLabels().withGroups().install((Z)=>{Z.addResource("spatialIndex",_);let $=!1;for(let F of O){let L=F==="fixedUpdate"?"localTransform":"worldTransform",T=F==="postUpdate";Z.addSystem(`spatial-index-rebuild-${F}`).setPriority(K).inPhase(F).inGroup(D).addQuery("aabbOnly",{with:[L,"aabbCollider"],without:["circleCollider"]}).addQuery("circleOnly",{with:[L,"circleCollider"],without:["aabbCollider"]}).addQuery("both",{with:[L,"aabbCollider","circleCollider"]}).setProcess(({queries:U,ecs:w})=>{if(T){let J=$;if($=!1,J&&!w.entityManager.hasHierarchy)return}W(V);for(let J of U.aabbOnly){let N=J.components[L],{aabbCollider:A}=J.components,M=N.x+(A.offsetX??0),P=N.y+(A.offsetY??0);z(V,J.id,M,P,A.width/2,A.height/2)}for(let J of U.circleOnly){let N=J.components[L],{circleCollider:A}=J.components,M=N.x+(A.offsetX??0),P=N.y+(A.offsetY??0);z(V,J.id,M,P,A.radius,A.radius)}for(let J of U.both){let N=J.components[L],{aabbCollider:A,circleCollider:M}=J.components,P=N.x+(A.offsetX??0)+(M.offsetX??0),E=N.y+(A.offsetY??0)+(M.offsetY??0),Q=Math.max(A.width/2,M.radius),k=Math.max(A.height/2,M.radius);z(V,J.id,P,E,Q,k)}if(!T)$=!0})}})}export{h as createSpatialIndexPlugin};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=31D57D221FCA9D0D64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=spatial-index.js.map
|