@codexo/exojs-physics 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.
Files changed (63) hide show
  1. package/dist/esm/Collider.d.ts +0 -33
  2. package/dist/esm/Collider.d.ts.map +1 -1
  3. package/dist/esm/Collider.js +1 -1
  4. package/dist/esm/Collider.js.map +1 -1
  5. package/dist/esm/ContactGraph.d.ts +11 -14
  6. package/dist/esm/ContactGraph.d.ts.map +1 -1
  7. package/dist/esm/ContactGraph.js +20 -4
  8. package/dist/esm/ContactGraph.js.map +1 -1
  9. package/dist/esm/ContactModifier.d.ts +0 -23
  10. package/dist/esm/ContactModifier.d.ts.map +1 -1
  11. package/dist/esm/PhysicsBody.d.ts +0 -81
  12. package/dist/esm/PhysicsBody.d.ts.map +1 -1
  13. package/dist/esm/PhysicsBody.js +2 -2
  14. package/dist/esm/PhysicsBody.js.map +1 -1
  15. package/dist/esm/PhysicsWorld.d.ts +8 -37
  16. package/dist/esm/PhysicsWorld.d.ts.map +1 -1
  17. package/dist/esm/PhysicsWorld.js +39 -18
  18. package/dist/esm/PhysicsWorld.js.map +1 -1
  19. package/dist/esm/collision/chainAdjacency.d.ts +1 -28
  20. package/dist/esm/collision/chainAdjacency.d.ts.map +1 -1
  21. package/dist/esm/joints/DistanceJoint.d.ts +0 -3
  22. package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
  23. package/dist/esm/joints/DistanceJoint.js +3 -0
  24. package/dist/esm/joints/DistanceJoint.js.map +1 -1
  25. package/dist/esm/joints/Joint.d.ts +0 -6
  26. package/dist/esm/joints/Joint.d.ts.map +1 -1
  27. package/dist/esm/joints/MouseJoint.d.ts +0 -3
  28. package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
  29. package/dist/esm/joints/MouseJoint.js +3 -0
  30. package/dist/esm/joints/MouseJoint.js.map +1 -1
  31. package/dist/esm/joints/PrismaticJoint.d.ts +0 -3
  32. package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
  33. package/dist/esm/joints/PrismaticJoint.js +3 -0
  34. package/dist/esm/joints/PrismaticJoint.js.map +1 -1
  35. package/dist/esm/joints/RevoluteJoint.d.ts +0 -3
  36. package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
  37. package/dist/esm/joints/RevoluteJoint.js +3 -0
  38. package/dist/esm/joints/RevoluteJoint.js.map +1 -1
  39. package/dist/esm/joints/WeldJoint.d.ts +0 -3
  40. package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
  41. package/dist/esm/joints/WeldJoint.js +3 -0
  42. package/dist/esm/joints/WeldJoint.js.map +1 -1
  43. package/dist/esm/joints/WheelJoint.d.ts +0 -3
  44. package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
  45. package/dist/esm/joints/WheelJoint.js +3 -0
  46. package/dist/esm/joints/WheelJoint.js.map +1 -1
  47. package/dist/esm/physicsBuildInfo.js +2 -2
  48. package/dist/esm/shapes/ChainEdgeShape.d.ts +1 -29
  49. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -1
  50. package/dist/esm/shapes/ChainShape.d.ts +0 -6
  51. package/dist/esm/shapes/ChainShape.d.ts.map +1 -1
  52. package/dist/esm/shapes/decompose.d.ts +1 -23
  53. package/dist/esm/shapes/decompose.d.ts.map +1 -1
  54. package/dist/esm/solver/ContactSolver.d.ts.map +1 -1
  55. package/dist/esm/solver/ContactSolver.js +16 -3
  56. package/dist/esm/solver/ContactSolver.js.map +1 -1
  57. package/dist/esm/solver/tolerances.d.ts +1 -33
  58. package/dist/esm/solver/tolerances.d.ts.map +1 -1
  59. package/dist/esm/solver/tolerances.js +14 -16
  60. package/dist/esm/solver/tolerances.js.map +1 -1
  61. package/dist/esm/sort.d.ts +1 -17
  62. package/dist/esm/sort.d.ts.map +1 -1
  63. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"PhysicsBody.js","names":[],"sources":["../../src/PhysicsBody.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\nimport { Vector } from '@codexo/exojs';\n\nimport { Collider, type ColliderOptions } from './Collider';\nimport type { Transform } from './math';\nimport { applyTransform, createTransform, setTransform } from './math';\nimport type { ShapeMassProperties } from './shapes/Shape';\nimport type { BodyType } from './types';\n\n/** Construction options for a body. */\nexport interface BodyOptions {\n /** Simulation role. Default `'dynamic'`. */\n type?: BodyType;\n /** Initial world position. Default `(0, 0)`. */\n position?: Readonly<PointLike>;\n /** Initial rotation in radians. Default `0`. */\n angle?: number;\n /** Linear damping applied to the velocity each sub-step. Default `0`. */\n linearDamping?: number;\n /** Angular damping applied to the angular velocity each sub-step. Default `0`. */\n angularDamping?: number;\n /** Per-body multiplier on world gravity (e.g. `0` to ignore gravity). Default `1`. */\n gravityScale?: number;\n /** When `true`, the body never rotates under contacts (infinite rotational inertia). Default `false`. */\n fixedRotation?: boolean;\n /** When `true`, the body's colliders are shape-cast along each step's motion (CCD) so it cannot tunnel through thin geometry. Default `false`. */\n isBullet?: boolean;\n /** Colliders to attach up-front. Each may be a {@link Collider} instance or its {@link ColliderOptions}. */\n colliders?: Array<Collider | ColliderOptions>;\n}\n\n/**\n * Internal hook the world hands to each body so colliders can be id-allocated\n * and registered without the body importing the concrete world class.\n */\nexport interface BodyOwner {\n _allocateColliderId(): number;\n _registerCollider(collider: Collider): void;\n}\n\n/**\n * A rigid body: a world transform plus mass properties aggregated from its\n * colliders. Dynamic bodies integrate under gravity, accumulated forces/torque\n * and contact impulses each fixed sub-step; static bodies never move; kinematic\n * bodies move by their velocity only and stay immovable under contacts. Drive a\n * body with {@link applyForce}, {@link applyTorque} and {@link applyImpulse}, or\n * set {@link linearVelocityX}/{@link linearVelocityY}/{@link angularVelocity}\n * directly; reposition it (teleport, no velocity) with {@link setTransform}.\n */\nexport class PhysicsBody {\n public readonly type: BodyType;\n\n /** Linear damping applied to the velocity each sub-step. */\n public linearDamping: number;\n /** Angular damping applied to the angular velocity each sub-step. */\n public angularDamping: number;\n /** Per-body multiplier on world gravity (e.g. `0` to ignore gravity). */\n public gravityScale: number;\n /** When `true`, rotational inertia is treated as infinite. */\n public fixedRotation: boolean;\n /** When `true`, the body's colliders are shape-cast along each step's motion (CCD) so it cannot tunnel through thin geometry. */\n public isBullet: boolean;\n\n /** Total mass (0 for static/kinematic). */\n public mass = 0;\n /** Inverse mass (`0` = immovable). */\n public invMass = 0;\n /** Rotational inertia about the centre of mass (0 for static/kinematic or fixed rotation). */\n public inertia = 0;\n /** Inverse rotational inertia (`0` = no angular response). */\n public invInertia = 0;\n\n /** Linear velocity X in px/s. */\n public linearVelocityX = 0;\n /** Linear velocity Y in px/s. */\n public linearVelocityY = 0;\n /** Angular velocity in rad/s. */\n public angularVelocity = 0;\n\n /** When `false`, this body is never put to sleep. Default `true`. */\n public allowSleep = true;\n\n /** @internal - Delta position X accumulated across the frame's sub-steps by the TGS integrator; written into the transform once per frame by {@link _finalizePosition}. */\n public _deltaPosX = 0;\n /** @internal - Delta position Y accumulated across the frame's sub-steps by the TGS integrator. */\n public _deltaPosY = 0;\n /** @internal - Delta rotation (radians) accumulated across the frame's sub-steps by the TGS integrator. */\n public _deltaAngle = 0;\n /** @internal - `cos(_deltaAngle)`, cached so the solver can rotate the contact anchors by the live sub-step rotation without a per-contact trig call. */\n public _deltaCos = 1;\n /** @internal - `sin(_deltaAngle)`, cached alongside {@link _deltaCos}. */\n public _deltaSin = 0;\n\n private _forceX = 0;\n private _forceY = 0;\n private _torque = 0;\n\n /** @internal - seconds the body has stayed below the sleep thresholds (frozen while asleep). Read by the world's island pass. */\n public _sleepTime = 0;\n /** @internal - dense union-find index assigned by the world's island pass each step. */\n public _islandIndex = 0;\n /**\n * @internal - raised by {@link setTransform}, cleared once the fixed step that\n * saw it completes. A static/kinematic body driven by teleporting carries no\n * velocity, so this is the world's only signal that such a body moved and its\n * sleeping contact partners must be woken.\n */\n public _teleported = false;\n /** @internal - world-space centre of mass at the start of the current fixed step (CCD swept-test origin). */\n public _ccdPrevX = 0;\n /** @internal - see {@link _ccdPrevX}. */\n public _ccdPrevY = 0;\n\n private _sleeping = false;\n\n private _id = -1;\n private _owner: BodyOwner | null = null;\n private _attached = false;\n\n private readonly _transform: Transform;\n // Transform at the START of the most recent fixed step. Presentation only:\n // the solver never reads it, and it is captured before the step writes its\n // delta so a teleport can collapse it onto the current state.\n private _previousX: number;\n private _previousY: number;\n private _previousAngle: number;\n private readonly _colliders: Collider[] = [];\n private _comX = 0;\n private _comY = 0;\n private _massReady = false;\n private _destroyed = false;\n\n public constructor(options: BodyOptions = {}) {\n this.type = options.type ?? 'dynamic';\n this._transform = createTransform(options.position?.x ?? 0, options.position?.y ?? 0, options.angle ?? 0);\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n this.linearDamping = options.linearDamping ?? 0;\n this.angularDamping = options.angularDamping ?? 0;\n this.gravityScale = options.gravityScale ?? 1;\n this.fixedRotation = options.fixedRotation ?? false;\n this.isBullet = options.isBullet ?? false;\n\n // Build up-front colliders now (no id/world registration until the body\n // joins a world via `world.add()`). They sit in `_colliders` unsynchronised;\n // `_attachToWorld` assigns ids, registers them and computes the mass model.\n if (options.colliders) {\n for (const entry of options.colliders) {\n this._colliders.push(entry instanceof Collider ? entry : new Collider(entry));\n }\n }\n }\n\n /** Stable id, assigned when the body joins a world via `world.add()`; `-1` until then. */\n public get id(): number {\n return this._id;\n }\n\n /** `true` once the body has been added to a world (guards against double-add). */\n public get attached(): boolean {\n return this._attached;\n }\n\n /** World X. */\n public get x(): number {\n return this._transform.x;\n }\n\n /** World Y. */\n public get y(): number {\n return this._transform.y;\n }\n\n /** Rotation in radians. */\n public get angle(): number {\n return this._transform.angle;\n }\n\n /**\n * World X at the start of the most recent fixed step. With {@link x} it\n * brackets the last step, which is what an interpolating presentation blends\n * between; a teleport collapses it onto {@link x}. Never read by the solver.\n */\n public get previousX(): number {\n return this._previousX;\n }\n\n /** World Y at the start of the most recent fixed step; see {@link previousX}. */\n public get previousY(): number {\n return this._previousY;\n }\n\n /**\n * Rotation in radians at the start of the most recent fixed step; see\n * {@link previousX}. Body angles are continuous and unbounded, never wrapped\n * to a range, so this and {@link angle} can be blended with a plain lerp.\n */\n public get previousAngle(): number {\n return this._previousAngle;\n }\n\n /** A fresh `Vector` copy of the body's world position. */\n public get position(): Vector {\n return new Vector(this._transform.x, this._transform.y);\n }\n\n /** The body's world transform (read-only; mutate via {@link setTransform}). */\n public get transform(): Readonly<Transform> {\n return this._transform;\n }\n\n /** The body's colliders (read-only view). */\n public get colliders(): readonly Collider[] {\n return this._colliders;\n }\n\n /** Centre of mass in body-local space (relative to the body origin). */\n public get centerOfMassX(): number {\n return this._comX;\n }\n\n /** Centre of mass in body-local space (relative to the body origin). */\n public get centerOfMassY(): number {\n return this._comY;\n }\n\n /**\n * `true` when the body is ready to simulate. Static/kinematic bodies are\n * always ready (infinite-mass semantics); a dynamic body is ready only once\n * it has at least one positive-density collider.\n */\n public get isMassReady(): boolean {\n return this.type !== 'dynamic' || this._massReady;\n }\n\n /** `true` after the owning world has destroyed this body. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /** `true` when the body is asleep - skipped by the integrator and solver until woken. */\n public get isSleeping(): boolean {\n return this._sleeping;\n }\n\n /**\n * Attach a collider to this body. Accepts a {@link Collider} instance or its\n * {@link ColliderOptions} (a convenience that constructs the collider for you).\n * When the body is already in a world, the collider is id-allocated, registered,\n * the mass model is recomputed and the world geometry synchronised immediately;\n * on a free-standing body the collider is simply held until `world.add()`.\n * Returns the collider.\n */\n public addCollider(collider: Collider | ColliderOptions): Collider {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot add a collider to a destroyed body.');\n }\n\n // Collider imports PhysicsBody type-only (erased), so this value import is\n // one-directional - no runtime cycle.\n const instance = collider instanceof Collider ? collider : new Collider(collider);\n\n this._colliders.push(instance);\n\n // Before the body joins a world there is no owner to allocate ids / register\n // with; `_attachToWorld` does that (and the mass/sync pass) for every held\n // collider. Once attached, mirror the world's create order exactly.\n if (this._attached && this._owner) {\n attachWithChainEdges(instance, this, this._owner);\n this._recomputeMass();\n this._assertDynamicCarriesMass();\n instance.synchronize(this._transform);\n this._owner._registerCollider(instance);\n }\n\n return instance;\n }\n\n /**\n * Set the body's world transform. Resets the body's cached collider geometry\n * immediately so subsequent queries see the new placement. Returns `this`.\n */\n public setTransform(position: Readonly<PointLike>, angle: number = this._transform.angle): this {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot move a destroyed body.');\n }\n\n this.wake();\n\n this._teleported = true;\n\n setTransform(this._transform, position.x, position.y, angle);\n\n // A teleport is a discontinuity, not motion - collapsing the pair keeps an\n // interpolating presentation from sweeping the node across the jump.\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n\n return this;\n }\n\n /** Refresh every collider's world geometry from the current transform. */\n public synchronizeColliders(): void {\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n }\n\n /** World-space centre of mass X (body origin + rotated local centre of mass). */\n public get worldCenterOfMassX(): number {\n return this._transform.x + this._transform.cos * this._comX - this._transform.sin * this._comY;\n }\n\n /** World-space centre of mass Y. */\n public get worldCenterOfMassY(): number {\n return this._transform.y + this._transform.sin * this._comX + this._transform.cos * this._comY;\n }\n\n /**\n * Accumulate a world-space force at the centre of mass; integrated on the next\n * sub-step and then cleared. No-op on static/kinematic bodies. Returns `this`.\n */\n public applyForce(forceX: number, forceY: number): this {\n this.wake();\n this._forceX += forceX;\n this._forceY += forceY;\n\n return this;\n }\n\n /**\n * Accumulate a torque; integrated on the next sub-step and then cleared. No-op\n * on static/kinematic bodies (and fixed-rotation bodies). Returns `this`.\n */\n public applyTorque(torque: number): this {\n this.wake();\n this._torque += torque;\n\n return this;\n }\n\n /**\n * Apply an instantaneous world-space impulse at `(pointX, pointY)` (world space;\n * defaults to the centre of mass), changing velocity immediately. No-op on\n * static/kinematic bodies (infinite mass). Returns `this`.\n */\n public applyImpulse(impulseX: number, impulseY: number, pointX?: number, pointY?: number): this {\n if (this.invMass === 0) {\n return this;\n }\n\n this.wake();\n this.linearVelocityX += impulseX * this.invMass;\n this.linearVelocityY += impulseY * this.invMass;\n\n if (pointX !== undefined && pointY !== undefined && this.invInertia !== 0) {\n const rx = pointX - this.worldCenterOfMassX;\n const ry = pointY - this.worldCenterOfMassY;\n\n this.angularVelocity += (rx * impulseY - ry * impulseX) * this.invInertia;\n }\n\n return this;\n }\n\n /**\n * @internal - integrate velocity from gravity, accumulated forces/torque and\n * damping over the sub-step `h`. No-op for static/kinematic (infinite mass\n * keeps their velocity solver-driven only). Called once per TGS sub-step, so\n * gravity/forces are applied with `h` each sub-step (`N·h = dt`, same total\n * impulse, but the small-step position error scales with `h²`). The\n * force/torque accumulators are **not** cleared here - they are consumed by\n * every sub-step and cleared once per frame by {@link _finalizePosition}.\n */\n public _integrateVelocity(h: number, gravityX: number, gravityY: number): void {\n if (this.invMass === 0 || this._sleeping) {\n return;\n }\n\n this.linearVelocityX += (gravityX * this.gravityScale + this._forceX * this.invMass) * h;\n this.linearVelocityY += (gravityY * this.gravityScale + this._forceY * this.invMass) * h;\n this.angularVelocity += this._torque * this.invInertia * h;\n\n // Exponential damping (no-op when damping is 0).\n this.linearVelocityX /= 1 + h * this.linearDamping;\n this.linearVelocityY /= 1 + h * this.linearDamping;\n this.angularVelocity /= 1 + h * this.angularDamping;\n }\n\n /**\n * @internal - accumulate this sub-step's velocity into the per-frame delta\n * position/rotation (TGS sub-stepping). The transform itself is **not** moved\n * here; {@link _finalizePosition} writes the accumulated delta once per frame.\n * Tracking the delta (rather than moving the transform each sub-step) lets the\n * solver recompute contact separation from it without re-running detection or\n * re-syncing collider geometry per sub-step. Static bodies never move.\n */\n public _integratePosition(h: number): void {\n if (this.type === 'static' || this._sleeping) {\n return;\n }\n\n this._deltaPosX += this.linearVelocityX * h;\n this._deltaPosY += this.linearVelocityY * h;\n this._deltaAngle += this.angularVelocity * h;\n\n // Cache the rotation so the solver can rotate the contact anchors by the\n // live sub-step rotation (TGS): without it the anchors stay frozen at frame\n // start and a tilting tower's restoring torque is mis-computed, so the tilt\n // grows instead of being corrected. Only non-zero rotation pays the trig.\n if (this._deltaAngle !== 0) {\n this._deltaCos = Math.cos(this._deltaAngle);\n this._deltaSin = Math.sin(this._deltaAngle);\n }\n }\n\n /**\n * @internal - advance the sleep timer over one fixed step `dt`. A body below\n * both velocity thresholds accumulates time; a too-fast body, or one that opts\n * out via {@link allowSleep}, resets it. The sleep/wake decision is made per\n * island by the world (so a stack sleeps as a unit) from {@link _sleepTime}.\n */\n public _accumulateSleepTime(dt: number, linearThreshold: number, angularThreshold: number): void {\n const tooFast =\n this.linearVelocityX * this.linearVelocityX + this.linearVelocityY * this.linearVelocityY > linearThreshold * linearThreshold ||\n Math.abs(this.angularVelocity) > angularThreshold;\n\n this._sleepTime = !this.allowSleep || tooFast ? 0 : this._sleepTime + dt;\n }\n\n /** @internal - set the sleep state. Sleeping zeroes the velocity; waking resets the sleep timer. */\n public _setSleeping(sleeping: boolean): void {\n if (this._sleeping === sleeping) {\n return;\n }\n\n this._sleeping = sleeping;\n\n if (sleeping) {\n this.linearVelocityX = 0;\n this.linearVelocityY = 0;\n this.angularVelocity = 0;\n } else {\n this._sleepTime = 0;\n }\n }\n\n /**\n * Wake the body if it is asleep, resetting its sleep timer. The rest of its\n * island wakes with it on the next step (a contact to an awake body keeps the\n * whole island awake). Returns `this`.\n */\n public wake(): this {\n this._setSleeping(false);\n this._sleepTime = 0;\n\n return this;\n }\n\n /**\n * @internal - apply the frame's accumulated delta position/rotation to the\n * transform (rotating about the centre of mass), re-sync collider geometry and\n * clear the force/torque accumulators. Called once per frame after the\n * sub-step loop. Static bodies never move; the force clear still runs (forces\n * are a no-op on infinite mass but the accumulator is reset for consistency).\n */\n public _finalizePosition(): void {\n this._forceX = 0;\n this._forceY = 0;\n this._torque = 0;\n this._teleported = false;\n\n // Captured before the step's delta is applied, and before the no-motion\n // early return below - a body that did not move must report previous ===\n // current rather than a stale pair from the last step it did move in.\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n\n if (this.type === 'static' || (this._deltaPosX === 0 && this._deltaPosY === 0 && this._deltaAngle === 0)) {\n this._resetDelta();\n\n return;\n }\n\n const newComX = this.worldCenterOfMassX + this._deltaPosX;\n const newComY = this.worldCenterOfMassY + this._deltaPosY;\n const newAngle = this._transform.angle + this._deltaAngle;\n const cos = Math.cos(newAngle);\n const sin = Math.sin(newAngle);\n\n // origin = newCoM − R(newAngle)·comLocal (so rotation pivots about the CoM).\n setTransform(this._transform, newComX - (cos * this._comX - sin * this._comY), newComY - (sin * this._comX + cos * this._comY), newAngle);\n\n this._resetDelta();\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n }\n\n /** Clear the per-frame TGS delta accumulators (position, rotation and its cached cos/sin). */\n private _resetDelta(): void {\n this._deltaPosX = 0;\n this._deltaPosY = 0;\n this._deltaAngle = 0;\n this._deltaCos = 1;\n this._deltaSin = 0;\n }\n\n /** Internal: detach a collider (called by the world during destruction). */\n public _removeCollider(collider: Collider): void {\n const index = this._colliders.indexOf(collider);\n\n if (index !== -1) {\n this._colliders.splice(index, 1);\n this._recomputeMass();\n }\n }\n\n /**\n * @internal - join `owner`'s world with the allocated `id`. Allocates ids for\n * and registers every held collider, then aggregates the mass model and\n * synchronises world geometry. Called once by {@link PhysicsWorld.add}.\n *\n * Ordering matters and mirrors the per-collider create path exactly: ids and\n * the body link go on first, then a single mass recompute over the full\n * collider set (so the centre of mass / inertia aggregate is correct), then\n * `synchronize` over every collider (the cached world geometry the broad/narrow\n * phase reads), then world registration last. Recomputing mass before all\n * colliders are linked, or syncing before the mass model exists, would feed the\n * solver a stale CoM and produce subtle integration bugs.\n */\n public _attachToWorld(owner: BodyOwner, id: number): void {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot add a destroyed body to a world.');\n }\n\n // Validate before touching `_owner`/`_id`/`_attached`: the mass check only\n // reads the held colliders, so it can run before the body claims a world at\n // all. Throwing after that point would leave the body half-attached -\n // `attached === true` with nothing else done - and unrecoverable, since a\n // second `add()` then rejects it as already-added.\n this._recomputeMass();\n this._assertDynamicCarriesMass();\n\n this._owner = owner;\n this._id = id;\n this._attached = true;\n\n for (const collider of this._colliders) {\n attachWithChainEdges(collider, this, owner);\n }\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n\n for (const collider of this._colliders) {\n owner._registerCollider(collider);\n }\n }\n\n /** Internal: mark destroyed (called by the world). */\n public _markDestroyed(): void {\n this._destroyed = true;\n }\n\n /**\n * A dynamic body has to carry mass. Boundary geometry (a segment, a chain)\n * reports no mass properties, and a collider may also be given zero density,\n * so a dynamic body can end up with none at all - which the solver cannot tell\n * apart from a static body, since both have `invMass === 0`. Rejecting it is\n * the difference between a clear error and a body that silently stops moving.\n */\n private _assertDynamicCarriesMass(): void {\n if (this.type !== 'dynamic' || this._massReady || this._colliders.length === 0) {\n return;\n }\n\n throw new Error(\n 'PhysicsBody: a dynamic body must carry at least one collider with mass — every collider it holds is either boundary geometry (a segment or chain, which has no interior) or has zero density. Add a solid collider, or make the body static or kinematic.',\n );\n }\n\n /** Recompute mass, centre of mass and rotational inertia from the colliders. */\n private _recomputeMass(): void {\n if (this.type !== 'dynamic') {\n this.mass = 0;\n this.invMass = 0;\n this.inertia = 0;\n this.invInertia = 0;\n this._comX = 0;\n this._comY = 0;\n this._massReady = false;\n\n return;\n }\n\n let mass = 0;\n let cx = 0;\n let cy = 0;\n let inertiaOrigin = 0;\n const point = { x: 0, y: 0 };\n\n for (const collider of this._colliders) {\n // Boundary geometry (a segment, later a chain) has no interior and reports\n // no mass properties; it contributes collision only.\n const massProperties: ShapeMassProperties | null = collider.shape.massProperties;\n\n if (massProperties === null) {\n continue;\n }\n\n const m = collider.density * massProperties.area;\n\n if (m <= 0) {\n continue;\n }\n\n // Shape centroid expressed in body-local space (offset + local rotation).\n applyTransform(collider.localTransform, massProperties.centroidX, massProperties.centroidY, point);\n mass += m;\n cx += m * point.x;\n cy += m * point.y;\n // Parallel-axis to the body origin: I_origin += I_centroid + m·d².\n inertiaOrigin += collider.density * massProperties.unitInertia + m * (point.x * point.x + point.y * point.y);\n }\n\n if (mass > 0) {\n cx /= mass;\n cy /= mass;\n }\n\n this.mass = mass;\n this.invMass = mass > 0 ? 1 / mass : 0;\n this._comX = cx;\n this._comY = cy;\n // Shift inertia from the body origin to the centre of mass.\n const inertiaCom = inertiaOrigin - mass * (cx * cx + cy * cy);\n\n this.inertia = this.fixedRotation ? 0 : inertiaCom;\n this.invInertia = this.fixedRotation || inertiaCom <= 0 ? 0 : 1 / inertiaCom;\n this._massReady = mass > 0;\n }\n}\n\n/**\n * Give a collider its id, and a chain collider's edge proxies theirs. The\n * proxies are ids in the same space as authored colliders - the contact graph\n * keys pairs on them - but they never appear in `body.colliders`.\n */\nconst attachWithChainEdges = (collider: Collider, body: PhysicsBody, owner: BodyOwner): void => {\n collider._attach(body, owner._allocateColliderId());\n\n const edges = collider.chainEdges;\n\n if (edges === null) {\n return;\n }\n\n for (const edge of edges) {\n edge._attach(body, owner._allocateColliderId());\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAiDA,IAAa,cAAb,MAAyB;CACvB,AAAgB;;CAGhB,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAGP,AAAO,OAAO;;CAEd,AAAO,UAAU;;CAEjB,AAAO,UAAU;;CAEjB,AAAO,aAAa;;CAGpB,AAAO,kBAAkB;;CAEzB,AAAO,kBAAkB;;CAEzB,AAAO,kBAAkB;;CAGzB,AAAO,aAAa;;CAGpB,AAAO,aAAa;;CAEpB,AAAO,aAAa;;CAEpB,AAAO,cAAc;;CAErB,AAAO,YAAY;;CAEnB,AAAO,YAAY;CAEnB,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,UAAU;;CAGlB,AAAO,aAA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sourcesContent":["import type { PointLike } from '@codexo/exojs';\nimport { Vector } from '@codexo/exojs';\n\nimport { Collider, type ColliderOptions } from './Collider';\nimport type { Transform } from './math';\nimport { applyTransform, createTransform, setTransform } from './math';\nimport type { ShapeMassProperties } from './shapes/Shape';\nimport type { BodyType } from './types';\n\n/** Construction options for a body. */\nexport interface BodyOptions {\n /** Simulation role. Default `'dynamic'`. */\n type?: BodyType;\n /** Initial world position. Default `(0, 0)`. */\n position?: Readonly<PointLike>;\n /** Initial rotation in radians. Default `0`. */\n angle?: number;\n /** Linear damping applied to the velocity each sub-step. Default `0`. */\n linearDamping?: number;\n /** Angular damping applied to the angular velocity each sub-step. Default `0`. */\n angularDamping?: number;\n /** Per-body multiplier on world gravity (e.g. `0` to ignore gravity). Default `1`. */\n gravityScale?: number;\n /** When `true`, the body never rotates under contacts (infinite rotational inertia). Default `false`. */\n fixedRotation?: boolean;\n /** When `true`, the body's colliders are shape-cast along each step's motion (CCD) so it cannot tunnel through thin geometry. Default `false`. */\n isBullet?: boolean;\n /** Colliders to attach up-front. Each may be a {@link Collider} instance or its {@link ColliderOptions}. */\n colliders?: Array<Collider | ColliderOptions>;\n}\n\n/**\n * Internal hook the world hands to each body so colliders can be id-allocated\n * and registered without the body importing the concrete world class.\n */\nexport interface BodyOwner {\n /** @internal */\n _allocateColliderId(): number;\n /** @internal */\n _registerCollider(collider: Collider): void;\n}\n\n/**\n * A rigid body: a world transform plus mass properties aggregated from its\n * colliders. Dynamic bodies integrate under gravity, accumulated forces/torque\n * and contact impulses each fixed sub-step; static bodies never move; kinematic\n * bodies move by their velocity only and stay immovable under contacts. Drive a\n * body with {@link applyForce}, {@link applyTorque} and {@link applyImpulse}, or\n * set {@link linearVelocityX}/{@link linearVelocityY}/{@link angularVelocity}\n * directly; reposition it (teleport, no velocity) with {@link setTransform}.\n */\nexport class PhysicsBody {\n public readonly type: BodyType;\n\n /** Linear damping applied to the velocity each sub-step. */\n public linearDamping: number;\n /** Angular damping applied to the angular velocity each sub-step. */\n public angularDamping: number;\n /** Per-body multiplier on world gravity (e.g. `0` to ignore gravity). */\n public gravityScale: number;\n /** When `true`, rotational inertia is treated as infinite. */\n public fixedRotation: boolean;\n /** When `true`, the body's colliders are shape-cast along each step's motion (CCD) so it cannot tunnel through thin geometry. */\n public isBullet: boolean;\n\n /** Total mass (0 for static/kinematic). */\n public mass = 0;\n /** Inverse mass (`0` = immovable). */\n public invMass = 0;\n /** Rotational inertia about the centre of mass (0 for static/kinematic or fixed rotation). */\n public inertia = 0;\n /** Inverse rotational inertia (`0` = no angular response). */\n public invInertia = 0;\n\n /** Linear velocity X in px/s. */\n public linearVelocityX = 0;\n /** Linear velocity Y in px/s. */\n public linearVelocityY = 0;\n /** Angular velocity in rad/s. */\n public angularVelocity = 0;\n\n /** When `false`, this body is never put to sleep. Default `true`. */\n public allowSleep = true;\n\n /** @internal - Delta position X accumulated across the frame's sub-steps by the TGS integrator; written into the transform once per frame by {@link _finalizePosition}. */\n public _deltaPosX = 0;\n /** @internal - Delta position Y accumulated across the frame's sub-steps by the TGS integrator. */\n public _deltaPosY = 0;\n /** @internal - Delta rotation (radians) accumulated across the frame's sub-steps by the TGS integrator. */\n public _deltaAngle = 0;\n /** @internal - `cos(_deltaAngle)`, cached so the solver can rotate the contact anchors by the live sub-step rotation without a per-contact trig call. */\n public _deltaCos = 1;\n /** @internal - `sin(_deltaAngle)`, cached alongside {@link _deltaCos}. */\n public _deltaSin = 0;\n\n private _forceX = 0;\n private _forceY = 0;\n private _torque = 0;\n\n /** @internal - seconds the body has stayed below the sleep thresholds (frozen while asleep). Read by the world's island pass. */\n public _sleepTime = 0;\n /** @internal - dense union-find index assigned by the world's island pass each step. */\n public _islandIndex = 0;\n /**\n * @internal - raised by {@link setTransform}, cleared once the fixed step that\n * saw it completes. A static/kinematic body driven by teleporting carries no\n * velocity, so this is the world's only signal that such a body moved and its\n * sleeping contact partners must be woken.\n */\n public _teleported = false;\n /** @internal - world-space centre of mass at the start of the current fixed step (CCD swept-test origin). */\n public _ccdPrevX = 0;\n /** @internal - see {@link _ccdPrevX}. */\n public _ccdPrevY = 0;\n\n private _sleeping = false;\n\n private _id = -1;\n private _owner: BodyOwner | null = null;\n private _attached = false;\n\n private readonly _transform: Transform;\n // Transform at the START of the most recent fixed step. Presentation only:\n // the solver never reads it, and it is captured before the step writes its\n // delta so a teleport can collapse it onto the current state.\n private _previousX: number;\n private _previousY: number;\n private _previousAngle: number;\n private readonly _colliders: Collider[] = [];\n private _comX = 0;\n private _comY = 0;\n private _massReady = false;\n private _destroyed = false;\n\n public constructor(options: BodyOptions = {}) {\n this.type = options.type ?? 'dynamic';\n this._transform = createTransform(options.position?.x ?? 0, options.position?.y ?? 0, options.angle ?? 0);\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n this.linearDamping = options.linearDamping ?? 0;\n this.angularDamping = options.angularDamping ?? 0;\n this.gravityScale = options.gravityScale ?? 1;\n this.fixedRotation = options.fixedRotation ?? false;\n this.isBullet = options.isBullet ?? false;\n\n // Build up-front colliders now (no id/world registration until the body\n // joins a world via `world.add()`). They sit in `_colliders` unsynchronised;\n // `_attachToWorld` assigns ids, registers them and computes the mass model.\n if (options.colliders) {\n for (const entry of options.colliders) {\n this._colliders.push(entry instanceof Collider ? entry : new Collider(entry));\n }\n }\n }\n\n /** Stable id, assigned when the body joins a world via `world.add()`; `-1` until then. */\n public get id(): number {\n return this._id;\n }\n\n /** `true` once the body has been added to a world (guards against double-add). */\n public get attached(): boolean {\n return this._attached;\n }\n\n /** World X. */\n public get x(): number {\n return this._transform.x;\n }\n\n /** World Y. */\n public get y(): number {\n return this._transform.y;\n }\n\n /** Rotation in radians. */\n public get angle(): number {\n return this._transform.angle;\n }\n\n /**\n * World X at the start of the most recent fixed step. With {@link x} it\n * brackets the last step, which is what an interpolating presentation blends\n * between; a teleport collapses it onto {@link x}. Never read by the solver.\n */\n public get previousX(): number {\n return this._previousX;\n }\n\n /** World Y at the start of the most recent fixed step; see {@link previousX}. */\n public get previousY(): number {\n return this._previousY;\n }\n\n /**\n * Rotation in radians at the start of the most recent fixed step; see\n * {@link previousX}. Body angles are continuous and unbounded, never wrapped\n * to a range, so this and {@link angle} can be blended with a plain lerp.\n */\n public get previousAngle(): number {\n return this._previousAngle;\n }\n\n /** A fresh `Vector` copy of the body's world position. */\n public get position(): Vector {\n return new Vector(this._transform.x, this._transform.y);\n }\n\n /** The body's world transform (read-only; mutate via {@link setTransform}). */\n public get transform(): Readonly<Transform> {\n return this._transform;\n }\n\n /** The body's colliders (read-only view). */\n public get colliders(): readonly Collider[] {\n return this._colliders;\n }\n\n /** Centre of mass in body-local space (relative to the body origin). */\n public get centerOfMassX(): number {\n return this._comX;\n }\n\n /** Centre of mass in body-local space (relative to the body origin). */\n public get centerOfMassY(): number {\n return this._comY;\n }\n\n /**\n * `true` when the body is ready to simulate. Static/kinematic bodies are\n * always ready (infinite-mass semantics); a dynamic body is ready only once\n * it has at least one positive-density collider.\n */\n public get isMassReady(): boolean {\n return this.type !== 'dynamic' || this._massReady;\n }\n\n /** `true` after the owning world has destroyed this body. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /** `true` when the body is asleep - skipped by the integrator and solver until woken. */\n public get isSleeping(): boolean {\n return this._sleeping;\n }\n\n /**\n * Attach a collider to this body. Accepts a {@link Collider} instance or its\n * {@link ColliderOptions} (a convenience that constructs the collider for you).\n * When the body is already in a world, the collider is id-allocated, registered,\n * the mass model is recomputed and the world geometry synchronised immediately;\n * on a free-standing body the collider is simply held until `world.add()`.\n * Returns the collider.\n */\n public addCollider(collider: Collider | ColliderOptions): Collider {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot add a collider to a destroyed body.');\n }\n\n // Collider imports PhysicsBody type-only (erased), so this value import is\n // one-directional - no runtime cycle.\n const instance = collider instanceof Collider ? collider : new Collider(collider);\n\n this._colliders.push(instance);\n\n // Before the body joins a world there is no owner to allocate ids / register\n // with; `_attachToWorld` does that (and the mass/sync pass) for every held\n // collider. Once attached, mirror the world's create order exactly.\n if (this._attached && this._owner) {\n attachWithChainEdges(instance, this, this._owner);\n this._recomputeMass();\n this._assertDynamicCarriesMass();\n instance.synchronize(this._transform);\n this._owner._registerCollider(instance);\n }\n\n return instance;\n }\n\n /**\n * Set the body's world transform. Resets the body's cached collider geometry\n * immediately so subsequent queries see the new placement. Returns `this`.\n */\n public setTransform(position: Readonly<PointLike>, angle: number = this._transform.angle): this {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot move a destroyed body.');\n }\n\n this.wake();\n\n this._teleported = true;\n\n setTransform(this._transform, position.x, position.y, angle);\n\n // A teleport is a discontinuity, not motion - collapsing the pair keeps an\n // interpolating presentation from sweeping the node across the jump.\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n\n return this;\n }\n\n /** Refresh every collider's world geometry from the current transform. */\n public synchronizeColliders(): void {\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n }\n\n /** World-space centre of mass X (body origin + rotated local centre of mass). */\n public get worldCenterOfMassX(): number {\n return this._transform.x + this._transform.cos * this._comX - this._transform.sin * this._comY;\n }\n\n /** World-space centre of mass Y. */\n public get worldCenterOfMassY(): number {\n return this._transform.y + this._transform.sin * this._comX + this._transform.cos * this._comY;\n }\n\n /**\n * Accumulate a world-space force at the centre of mass; integrated on the next\n * sub-step and then cleared. No-op on static/kinematic bodies. Returns `this`.\n */\n public applyForce(forceX: number, forceY: number): this {\n this.wake();\n this._forceX += forceX;\n this._forceY += forceY;\n\n return this;\n }\n\n /**\n * Accumulate a torque; integrated on the next sub-step and then cleared. No-op\n * on static/kinematic bodies (and fixed-rotation bodies). Returns `this`.\n */\n public applyTorque(torque: number): this {\n this.wake();\n this._torque += torque;\n\n return this;\n }\n\n /**\n * Apply an instantaneous world-space impulse at `(pointX, pointY)` (world space;\n * defaults to the centre of mass), changing velocity immediately. No-op on\n * static/kinematic bodies (infinite mass). Returns `this`.\n */\n public applyImpulse(impulseX: number, impulseY: number, pointX?: number, pointY?: number): this {\n if (this.invMass === 0) {\n return this;\n }\n\n this.wake();\n this.linearVelocityX += impulseX * this.invMass;\n this.linearVelocityY += impulseY * this.invMass;\n\n if (pointX !== undefined && pointY !== undefined && this.invInertia !== 0) {\n const rx = pointX - this.worldCenterOfMassX;\n const ry = pointY - this.worldCenterOfMassY;\n\n this.angularVelocity += (rx * impulseY - ry * impulseX) * this.invInertia;\n }\n\n return this;\n }\n\n /**\n * @internal - integrate velocity from gravity, accumulated forces/torque and\n * damping over the sub-step `h`. No-op for static/kinematic (infinite mass\n * keeps their velocity solver-driven only). Called once per TGS sub-step, so\n * gravity/forces are applied with `h` each sub-step (`N·h = dt`, same total\n * impulse, but the small-step position error scales with `h²`). The\n * force/torque accumulators are **not** cleared here - they are consumed by\n * every sub-step and cleared once per frame by {@link _finalizePosition}.\n */\n public _integrateVelocity(h: number, gravityX: number, gravityY: number): void {\n if (this.invMass === 0 || this._sleeping) {\n return;\n }\n\n this.linearVelocityX += (gravityX * this.gravityScale + this._forceX * this.invMass) * h;\n this.linearVelocityY += (gravityY * this.gravityScale + this._forceY * this.invMass) * h;\n this.angularVelocity += this._torque * this.invInertia * h;\n\n // Exponential damping (no-op when damping is 0).\n this.linearVelocityX /= 1 + h * this.linearDamping;\n this.linearVelocityY /= 1 + h * this.linearDamping;\n this.angularVelocity /= 1 + h * this.angularDamping;\n }\n\n /**\n * @internal - accumulate this sub-step's velocity into the per-frame delta\n * position/rotation (TGS sub-stepping). The transform itself is **not** moved\n * here; {@link _finalizePosition} writes the accumulated delta once per frame.\n * Tracking the delta (rather than moving the transform each sub-step) lets the\n * solver recompute contact separation from it without re-running detection or\n * re-syncing collider geometry per sub-step. Static bodies never move.\n */\n public _integratePosition(h: number): void {\n if (this.type === 'static' || this._sleeping) {\n return;\n }\n\n this._deltaPosX += this.linearVelocityX * h;\n this._deltaPosY += this.linearVelocityY * h;\n this._deltaAngle += this.angularVelocity * h;\n\n // Cache the rotation so the solver can rotate the contact anchors by the\n // live sub-step rotation (TGS): without it the anchors stay frozen at frame\n // start and a tilting tower's restoring torque is mis-computed, so the tilt\n // grows instead of being corrected. Only non-zero rotation pays the trig.\n if (this._deltaAngle !== 0) {\n this._deltaCos = Math.cos(this._deltaAngle);\n this._deltaSin = Math.sin(this._deltaAngle);\n }\n }\n\n /**\n * @internal - advance the sleep timer over one fixed step `dt`. A body below\n * both velocity thresholds accumulates time; a too-fast body, or one that opts\n * out via {@link allowSleep}, resets it. The sleep/wake decision is made per\n * island by the world (so a stack sleeps as a unit) from {@link _sleepTime}.\n */\n public _accumulateSleepTime(dt: number, linearThreshold: number, angularThreshold: number): void {\n const tooFast =\n this.linearVelocityX * this.linearVelocityX + this.linearVelocityY * this.linearVelocityY > linearThreshold * linearThreshold ||\n Math.abs(this.angularVelocity) > angularThreshold;\n\n this._sleepTime = !this.allowSleep || tooFast ? 0 : this._sleepTime + dt;\n }\n\n /** @internal - set the sleep state. Sleeping zeroes the velocity; waking resets the sleep timer. */\n public _setSleeping(sleeping: boolean): void {\n if (this._sleeping === sleeping) {\n return;\n }\n\n this._sleeping = sleeping;\n\n if (sleeping) {\n this.linearVelocityX = 0;\n this.linearVelocityY = 0;\n this.angularVelocity = 0;\n } else {\n this._sleepTime = 0;\n }\n }\n\n /**\n * Wake the body if it is asleep, resetting its sleep timer. The rest of its\n * island wakes with it on the next step (a contact to an awake body keeps the\n * whole island awake). Returns `this`.\n */\n public wake(): this {\n this._setSleeping(false);\n this._sleepTime = 0;\n\n return this;\n }\n\n /**\n * @internal - apply the frame's accumulated delta position/rotation to the\n * transform (rotating about the centre of mass), re-sync collider geometry and\n * clear the force/torque accumulators. Called once per frame after the\n * sub-step loop. Static bodies never move; the force clear still runs (forces\n * are a no-op on infinite mass but the accumulator is reset for consistency).\n */\n public _finalizePosition(): void {\n this._forceX = 0;\n this._forceY = 0;\n this._torque = 0;\n this._teleported = false;\n\n // Captured before the step's delta is applied, and before the no-motion\n // early return below - a body that did not move must report previous ===\n // current rather than a stale pair from the last step it did move in.\n this._previousX = this._transform.x;\n this._previousY = this._transform.y;\n this._previousAngle = this._transform.angle;\n\n if (this.type === 'static' || (this._deltaPosX === 0 && this._deltaPosY === 0 && this._deltaAngle === 0)) {\n this._resetDelta();\n\n return;\n }\n\n const newComX = this.worldCenterOfMassX + this._deltaPosX;\n const newComY = this.worldCenterOfMassY + this._deltaPosY;\n const newAngle = this._transform.angle + this._deltaAngle;\n const cos = Math.cos(newAngle);\n const sin = Math.sin(newAngle);\n\n // origin = newCoM − R(newAngle)·comLocal (so rotation pivots about the CoM).\n setTransform(this._transform, newComX - (cos * this._comX - sin * this._comY), newComY - (sin * this._comX + cos * this._comY), newAngle);\n\n this._resetDelta();\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n }\n\n /** Clear the per-frame TGS delta accumulators (position, rotation and its cached cos/sin). */\n private _resetDelta(): void {\n this._deltaPosX = 0;\n this._deltaPosY = 0;\n this._deltaAngle = 0;\n this._deltaCos = 1;\n this._deltaSin = 0;\n }\n\n /** @internal - detach a collider (called by the world during destruction). */\n public _removeCollider(collider: Collider): void {\n const index = this._colliders.indexOf(collider);\n\n if (index !== -1) {\n this._colliders.splice(index, 1);\n this._recomputeMass();\n }\n }\n\n /**\n * @internal - join `owner`'s world with the allocated `id`. Allocates ids for\n * and registers every held collider, then aggregates the mass model and\n * synchronises world geometry. Called once by {@link PhysicsWorld.add}.\n *\n * Ordering matters and mirrors the per-collider create path exactly: ids and\n * the body link go on first, then a single mass recompute over the full\n * collider set (so the centre of mass / inertia aggregate is correct), then\n * `synchronize` over every collider (the cached world geometry the broad/narrow\n * phase reads), then world registration last. Recomputing mass before all\n * colliders are linked, or syncing before the mass model exists, would feed the\n * solver a stale CoM and produce subtle integration bugs.\n */\n public _attachToWorld(owner: BodyOwner, id: number): void {\n if (this._destroyed) {\n throw new Error('PhysicsBody: cannot add a destroyed body to a world.');\n }\n\n // Validate before touching `_owner`/`_id`/`_attached`: the mass check only\n // reads the held colliders, so it can run before the body claims a world at\n // all. Throwing after that point would leave the body half-attached -\n // `attached === true` with nothing else done - and unrecoverable, since a\n // second `add()` then rejects it as already-added.\n this._recomputeMass();\n this._assertDynamicCarriesMass();\n\n this._owner = owner;\n this._id = id;\n this._attached = true;\n\n for (const collider of this._colliders) {\n attachWithChainEdges(collider, this, owner);\n }\n\n for (const collider of this._colliders) {\n collider.synchronize(this._transform);\n }\n\n for (const collider of this._colliders) {\n owner._registerCollider(collider);\n }\n }\n\n /** @internal - mark destroyed (called by the world). */\n public _markDestroyed(): void {\n this._destroyed = true;\n }\n\n /**\n * A dynamic body has to carry mass. Boundary geometry (a segment, a chain)\n * reports no mass properties, and a collider may also be given zero density,\n * so a dynamic body can end up with none at all - which the solver cannot tell\n * apart from a static body, since both have `invMass === 0`. Rejecting it is\n * the difference between a clear error and a body that silently stops moving.\n */\n private _assertDynamicCarriesMass(): void {\n if (this.type !== 'dynamic' || this._massReady || this._colliders.length === 0) {\n return;\n }\n\n throw new Error(\n 'PhysicsBody: a dynamic body must carry at least one collider with mass — every collider it holds is either boundary geometry (a segment or chain, which has no interior) or has zero density. Add a solid collider, or make the body static or kinematic.',\n );\n }\n\n /** Recompute mass, centre of mass and rotational inertia from the colliders. */\n private _recomputeMass(): void {\n if (this.type !== 'dynamic') {\n this.mass = 0;\n this.invMass = 0;\n this.inertia = 0;\n this.invInertia = 0;\n this._comX = 0;\n this._comY = 0;\n this._massReady = false;\n\n return;\n }\n\n let mass = 0;\n let cx = 0;\n let cy = 0;\n let inertiaOrigin = 0;\n const point = { x: 0, y: 0 };\n\n for (const collider of this._colliders) {\n // Boundary geometry (a segment, later a chain) has no interior and reports\n // no mass properties; it contributes collision only.\n const massProperties: ShapeMassProperties | null = collider.shape.massProperties;\n\n if (massProperties === null) {\n continue;\n }\n\n const m = collider.density * massProperties.area;\n\n if (m <= 0) {\n continue;\n }\n\n // Shape centroid expressed in body-local space (offset + local rotation).\n applyTransform(collider.localTransform, massProperties.centroidX, massProperties.centroidY, point);\n mass += m;\n cx += m * point.x;\n cy += m * point.y;\n // Parallel-axis to the body origin: I_origin += I_centroid + m·d².\n inertiaOrigin += collider.density * massProperties.unitInertia + m * (point.x * point.x + point.y * point.y);\n }\n\n if (mass > 0) {\n cx /= mass;\n cy /= mass;\n }\n\n this.mass = mass;\n this.invMass = mass > 0 ? 1 / mass : 0;\n this._comX = cx;\n this._comY = cy;\n // Shift inertia from the body origin to the centre of mass.\n const inertiaCom = inertiaOrigin - mass * (cx * cx + cy * cy);\n\n this.inertia = this.fixedRotation ? 0 : inertiaCom;\n this.invInertia = this.fixedRotation || inertiaCom <= 0 ? 0 : 1 / inertiaCom;\n this._massReady = mass > 0;\n }\n}\n\n/**\n * Give a collider its id, and a chain collider's edge proxies theirs. The\n * proxies are ids in the same space as authored colliders - the contact graph\n * keys pairs on them - but they never appear in `body.colliders`.\n */\nconst attachWithChainEdges = (collider: Collider, body: PhysicsBody, owner: BodyOwner): void => {\n collider._attach(body, owner._allocateColliderId());\n\n const edges = collider.chainEdges;\n\n if (edges === null) {\n return;\n }\n\n for (const edge of edges) {\n edge._attach(body, owner._allocateColliderId());\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAmDA,IAAa,cAAb,MAAyB;CACvB,AAAgB;;CAGhB,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAGP,AAAO,OAAO;;CAEd,AAAO,UAAU;;CAEjB,AAAO,UAAU;;CAEjB,AAAO,aAAa;;CAGpB,AAAO,kBAAkB;;CAEzB,AAAO,kBAAkB;;CAEzB,AAAO,kBAAkB;;CAGzB,AAAO,aAAa;;CAGpB,AAAO,aAAa;;CAEpB,AAAO,aAAa;;CAEpB,AAAO,cAAc;;CAErB,AAAO,YAAY;;CAEnB,AAAO,YAAY;CAEnB,AAAQ,UAAU;CAClB,AAAQ,UAAU;C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PhysicsWorld implements BodyOwner {
242
242
  private readonly _ccdSweptAabb;
243
243
  /** Pooled result buffer for the CCD pass's broad-phase query (refilled per bullet collider). */
244
244
  private readonly _ccdCandidates;
245
- /**
246
- * Narrow-phase sweep tests run by the CCD pass since world creation. Pairs
247
- * rejected by the swept-AABB prune never count, so slow bullets far from any
248
- * geometry keep this at zero (the cheap path).
249
- *
250
- * @internal - test/diagnostic hook.
251
- */
252
- _ccdSweepTests: number;
253
- /**
254
- * Colliders the CCD pass pulled out of the broad phase since world creation -
255
- * the size of the candidate set the swept-AABB prune and the narrow-phase
256
- * sweep then work on. Counted separately from {@link _ccdSweepTests} because
257
- * the two measure different halves: this is what the pass looks at, that is
258
- * what it actually sweeps. Stays proportional to the geometry near the
259
- * bullets, not to the world's collider count.
260
- *
261
- * @internal - test/diagnostic hook.
262
- */
263
- _ccdBroadPhaseCandidates: number;
264
245
  private _nextBodyId;
265
246
  private _nextColliderId;
266
247
  private _dispatching;
@@ -270,13 +251,6 @@ export declare class PhysicsWorld implements BodyOwner {
270
251
  get bodies(): readonly PhysicsBody[];
271
252
  /** Live colliders (read-only view). */
272
253
  get colliders(): readonly Collider[];
273
- /**
274
- * @internal - the geometry the broad phase and the narrow phase actually hold:
275
- * every authored collider, with a chain replaced by its per-edge proxies.
276
- * Consumed by the debug draw layer, which visualises what the solver sees;
277
- * public identity stays {@link colliders}.
278
- */
279
- get detectionGeometry(): readonly Collider[];
280
254
  /**
281
255
  * Add a body to the world: allocates the body and its collider ids, registers
282
256
  * the colliders, computes the mass model and tracks the body for stepping.
@@ -396,8 +370,6 @@ export declare class PhysicsWorld implements BodyOwner {
396
370
  overlapShape(shape: AnyShape, position: Readonly<PointLike>, filter?: QueryFilter, angle?: number): Collider[];
397
371
  /** Release every body, collider, binding and backend resource. */
398
372
  destroy(): void;
399
- _allocateColliderId(): number;
400
- _registerCollider(collider: Collider): void;
401
373
  /** The detection backend (internal; consumed by the debug draw layer). */
402
374
  get backend(): PhysicsBackend;
403
375
  private _dispatchEvents;
@@ -410,11 +382,10 @@ export declare class PhysicsWorld implements BodyOwner {
410
382
  * any member does (e.g. an awake body merges into it via a new contact).
411
383
  * A boundary that is itself moving resets the sleep timer of every dynamic
412
384
  * body it touches, so a platform keeps its passengers awake however slowly it
413
- * travels; so does a contact still carrying more penetration than the solver
414
- * leaves at rest, because the push-out that resolves it is slower than the
415
- * sleep velocity threshold and a body would otherwise be frozen embedded.
416
- * Deterministic: union-find roots break ties by lower index and the contact
417
- * set is id-sorted.
385
+ * travels; so does a contact whose overlap the push-out is still working off,
386
+ * because that push-out moves bodies without showing up in their velocity and
387
+ * a body would otherwise be frozen embedded. Deterministic: union-find roots
388
+ * break ties by lower index and the contact set is id-sorted.
418
389
  */
419
390
  private _updateSleeping;
420
391
  /**
@@ -424,10 +395,10 @@ export declare class PhysicsWorld implements BodyOwner {
424
395
  * of a slow-moving platform awake - and the solver skips a contact whose
425
396
  * dynamic side is asleep, letting the platform drive straight through it.
426
397
  *
427
- * The same traversal resets the sleep timer of both sides of a contact whose
428
- * penetration the solver has not worked off yet, so the island it belongs to
429
- * stays awake until the overlap is within the tolerance the solver itself
430
- * converges to.
398
+ * The same traversal resets the sleep timer of both sides of a contact the
399
+ * push-out is still working off (see {@link isUnresolved}), so the island it
400
+ * belongs to stays awake until the overlap has reached the depth the contact's
401
+ * own load holds it at.
431
402
  */
432
403
  private _unionContactIslands;
433
404
  /** Union-find union by lower index (deterministic roots). */
@@ -1 +1 @@
1
- {"version":3,"file":"PhysicsWorld.d.ts","sourceRoot":"","sources":["../../src/PhysicsWorld.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAU,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,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Qd,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,eAAe;IAsBvB,gFAAgF;IAChF,OAAO,CAAC,wBAAwB;IAUhC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,YAAY;CAKrB"}
@@ -59,13 +59,33 @@ const assertBodyKeepsItsMass = (collider, pendingRemovals) => {
59
59
  */
60
60
  const isMovingBoundary = (body) => body._teleported || body.linearVelocityX !== 0 || body.linearVelocityY !== 0 || body.angularVelocity !== 0;
61
61
  /**
62
- * `true` while a contact still carries more overlap than the solver leaves
63
- * behind at rest. Read from the manifold detection just produced, which is the
64
- * same separation the solver's push-out bias is about to act on - the sleep gate
65
- * and the constraint it gates therefore agree by construction.
62
+ * `true` while a contact carries overlap the push-out is still working off, so
63
+ * neither of its bodies may bank sleep time. Read from the manifold detection
64
+ * just produced, which is the same separation the solver's bias is about to act
65
+ * on - the sleep gate and the constraint it gates therefore agree by
66
+ * construction.
67
+ *
68
+ * Depth alone cannot answer this. A loaded contact rests at the depth its own
69
+ * soft-constraint deflection holds it at, and in a dense pile that is several
70
+ * times the depth a lone body on a floor reaches; a depth-only gate therefore
71
+ * never lets such a pile sleep, and the scene keeps being solved in full long
72
+ * after it stopped moving. Progress is the distinguishing quantity: either the
73
+ * last step still closed the overlap, or the contact has reached its
74
+ * equilibrium and waiting changes nothing about it.
75
+ *
76
+ * A point with no penetration history - a fresh overlap, or one whose contact
77
+ * was disabled last step - counts as unresolved whatever its depth, so geometry
78
+ * appearing inside a sleeping body reopens the sleep decision.
66
79
  */
67
- const isUnresolved = (manifold) => {
68
- for (let i = 0; i < manifold.pointCount; i++) if ((i === 0 ? manifold.points[0] : manifold.points[1]).penetration > .75) return true;
80
+ const isUnresolved = (record, dt) => {
81
+ const manifold = record.manifold;
82
+ const stall = 1 * dt;
83
+ for (let i = 0; i < manifold.pointCount; i++) {
84
+ const penetration = (i === 0 ? manifold.points[0] : manifold.points[1]).penetration;
85
+ if (penetration <= .75) continue;
86
+ const previous = i === 0 ? record.previousPenetration[0] : record.previousPenetration[1];
87
+ if (previous < 0 || Math.abs(previous - penetration) > stall) return true;
88
+ }
69
89
  return false;
70
90
  };
71
91
  /**
@@ -582,9 +602,11 @@ var PhysicsWorld = class {
582
602
  this.onSensorEnter.destroy();
583
603
  this.onSensorExit.destroy();
584
604
  }
605
+ /** @internal */
585
606
  _allocateColliderId() {
586
607
  return this._nextColliderId++;
587
608
  }
609
+ /** @internal */
588
610
  _registerCollider(collider) {
589
611
  this._defer(() => {
590
612
  if (collider.destroyed) return;
@@ -619,11 +641,10 @@ var PhysicsWorld = class {
619
641
  * any member does (e.g. an awake body merges into it via a new contact).
620
642
  * A boundary that is itself moving resets the sleep timer of every dynamic
621
643
  * body it touches, so a platform keeps its passengers awake however slowly it
622
- * travels; so does a contact still carrying more penetration than the solver
623
- * leaves at rest, because the push-out that resolves it is slower than the
624
- * sleep velocity threshold and a body would otherwise be frozen embedded.
625
- * Deterministic: union-find roots break ties by lower index and the contact
626
- * set is id-sorted.
644
+ * travels; so does a contact whose overlap the push-out is still working off,
645
+ * because that push-out moves bodies without showing up in their velocity and
646
+ * a body would otherwise be frozen embedded. Deterministic: union-find roots
647
+ * break ties by lower index and the contact set is id-sorted.
627
648
  */
628
649
  _updateSleeping(dt) {
629
650
  const bodies = this._bodies;
@@ -639,7 +660,7 @@ var PhysicsWorld = class {
639
660
  }
640
661
  parent.length = count;
641
662
  minSleep.length = count;
642
- this._unionContactIslands();
663
+ this._unionContactIslands(dt);
643
664
  for (const joint of this._joints) {
644
665
  const bodyA = joint.bodyA;
645
666
  const bodyB = joint.bodyB;
@@ -665,12 +686,12 @@ var PhysicsWorld = class {
665
686
  * of a slow-moving platform awake - and the solver skips a contact whose
666
687
  * dynamic side is asleep, letting the platform drive straight through it.
667
688
  *
668
- * The same traversal resets the sleep timer of both sides of a contact whose
669
- * penetration the solver has not worked off yet, so the island it belongs to
670
- * stays awake until the overlap is within the tolerance the solver itself
671
- * converges to.
689
+ * The same traversal resets the sleep timer of both sides of a contact the
690
+ * push-out is still working off (see {@link isUnresolved}), so the island it
691
+ * belongs to stays awake until the overlap has reached the depth the contact's
692
+ * own load holds it at.
672
693
  */
673
- _unionContactIslands() {
694
+ _unionContactIslands(dt) {
674
695
  for (const contact of this._backend.contactGraph.solidContacts) {
675
696
  if (!contact.enabled) continue;
676
697
  const bodyA = contact.a.body;
@@ -680,7 +701,7 @@ var PhysicsWorld = class {
680
701
  if (dynamicA && dynamicB) this._union(bodyA._islandIndex, bodyB._islandIndex);
681
702
  else if (dynamicA && isMovingBoundary(bodyB)) bodyA._sleepTime = 0;
682
703
  else if (dynamicB && isMovingBoundary(bodyA)) bodyB._sleepTime = 0;
683
- if ((dynamicA || dynamicB) && isUnresolved(contact.manifold)) {
704
+ if ((dynamicA || dynamicB) && isUnresolved(contact, dt)) {
684
705
  if (dynamicA) bodyA._sleepTime = 0;
685
706
  if (dynamicB) bodyB._sleepTime = 0;
686
707
  }