@codexo/exojs-physics 0.17.0 → 0.18.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 (50) hide show
  1. package/README.md +13 -45
  2. package/dist/esm/Collider.d.ts.map +1 -1
  3. package/dist/esm/Collider.js +9 -0
  4. package/dist/esm/Collider.js.map +1 -1
  5. package/dist/esm/ContactGraph.d.ts +11 -0
  6. package/dist/esm/ContactGraph.d.ts.map +1 -1
  7. package/dist/esm/ContactGraph.js +23 -1
  8. package/dist/esm/ContactGraph.js.map +1 -1
  9. package/dist/esm/PhysicsBody.d.ts.map +1 -1
  10. package/dist/esm/PhysicsBody.js +35 -6
  11. package/dist/esm/PhysicsBody.js.map +1 -1
  12. package/dist/esm/PhysicsWorld.d.ts +55 -4
  13. package/dist/esm/PhysicsWorld.d.ts.map +1 -1
  14. package/dist/esm/PhysicsWorld.js +124 -19
  15. package/dist/esm/PhysicsWorld.js.map +1 -1
  16. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +22 -6
  17. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -1
  18. package/dist/esm/broadphase/AabbTreeBroadPhase.js +45 -11
  19. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -1
  20. package/dist/esm/joints/DistanceJoint.d.ts +2 -1
  21. package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
  22. package/dist/esm/joints/DistanceJoint.js +5 -5
  23. package/dist/esm/joints/DistanceJoint.js.map +1 -1
  24. package/dist/esm/joints/Joint.d.ts +59 -3
  25. package/dist/esm/joints/Joint.d.ts.map +1 -1
  26. package/dist/esm/joints/Joint.js +39 -3
  27. package/dist/esm/joints/Joint.js.map +1 -1
  28. package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
  29. package/dist/esm/joints/MouseJoint.js +1 -1
  30. package/dist/esm/joints/MouseJoint.js.map +1 -1
  31. package/dist/esm/joints/PrismaticJoint.d.ts +2 -1
  32. package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
  33. package/dist/esm/joints/PrismaticJoint.js +2 -2
  34. package/dist/esm/joints/PrismaticJoint.js.map +1 -1
  35. package/dist/esm/joints/RevoluteJoint.d.ts +4 -6
  36. package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
  37. package/dist/esm/joints/RevoluteJoint.js +39 -33
  38. package/dist/esm/joints/RevoluteJoint.js.map +1 -1
  39. package/dist/esm/joints/WeldJoint.d.ts +2 -1
  40. package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
  41. package/dist/esm/joints/WeldJoint.js +9 -9
  42. package/dist/esm/joints/WeldJoint.js.map +1 -1
  43. package/dist/esm/joints/WheelJoint.d.ts +2 -1
  44. package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
  45. package/dist/esm/joints/WheelJoint.js +5 -5
  46. package/dist/esm/joints/WheelJoint.js.map +1 -1
  47. package/dist/esm/physicsBuildInfo.js +2 -2
  48. package/dist/esm/public.d.ts +1 -1
  49. package/dist/esm/public.d.ts.map +1 -1
  50. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"AabbTreeBroadPhase.js","names":[],"sources":["../../../src/broadphase/AabbTreeBroadPhase.ts"],"sourcesContent":["import type { AabbLike } from '@codexo/exojs';\nimport { DynamicAabbTree } from '@codexo/exojs';\n\nimport { aabbOverlap } from '../Aabb';\nimport type { Collider } from '../Collider';\nimport { pairKey } from '../ContactGraph';\nimport type { SpatialIndex } from '../query/SpatialIndex';\nimport { sortInPlace } from '../sort';\nimport type { BroadPhase, CandidatePair } from './BroadPhase';\n\n/**\n * Fixed fat-AABB margin (world px) applied to every collider's tree leaf.\n * Chosen relative to the engine's typical small-collider scale (test/example\n * shapes commonly span 10-30px): large enough that a few steps of ordinary\n * motion stay inside the margin (skipping the sync phase's remove+reinsert),\n * small enough it doesn't inflate fat AABBs into spurious candidates for\n * densely packed scenes. Fixed per the design's v1 scope (no velocity-based\n * predictive expansion) - revisit if benchmarks want a different value.\n */\nconst AABB_MARGIN = 4;\n\nconst byPairId = (p: CandidatePair, q: CandidatePair): number => p.a.id - q.a.id || p.b.id - q.b.id;\n\n/**\n * Dynamic-AABB-tree broad phase (Box2D-style), wrapping a generic\n * `DynamicAabbTree<Collider>`. Stateful across steps: a collider whose tight\n * AABB stays inside its stored fat AABB costs nothing to re-sync.\n *\n * Three phases per `computePairs` call: (1) sync every live collider (insert\n * new ones, reinsert moved ones, querying only around reinsertions to discover\n * NEW fat-overlap candidates); (2) one full pass over the persistent pair set\n * dropping any pair whose fat AABBs no longer overlap - cheap (O(1) per pair)\n * and run every step regardless of movement, exactly mirroring Box2D's own\n * `b2ContactManager::Collide` (see the design's correctness argument for why a\n * single global pass, not a per-moved-leaf rescan, is both correct and the\n * right complexity); (3) emit, keeping only pairs whose *tight* AABBs overlap.\n *\n * The persistent set is intentionally keyed on *fat* overlap so temporal\n * coherence carries across steps (a leaf that stays inside its fat AABB is\n * never re-discovered). Emitting is filtered to tight-AABB overlap so the\n * candidate set the caller sees is exact - the fat margin never leaks a false\n * positive downstream, and a fat-but-not-tight pair simply stays parked in the\n * set (costing one O(1) re-check per step) until the leaves separate.\n *\n * **Single-owner contract.** A collider's tree membership is tracked through its\n * `Collider._treeProxy` field, which - like `PhysicsBody._islandIndex` /\n * `_sleepTime` - is a single slot on the shared object. Exactly ONE\n * `AabbTreeBroadPhase` instance may track a given collider at a time (in\n * production that is the world's own `_broadPhase`, for the collider's whole\n * lifetime until `removeCollider`). Do NOT stand up a second, throwaway\n * `AabbTreeBroadPhase` over colliders another instance already owns (e.g. for\n * debug visualization): the second instance would clobber the first's\n * `_treeProxy` values and corrupt its tree. Use a plain brute-force scan for\n * such one-off, read-only needs instead.\n */\nexport class AabbTreeBroadPhase implements BroadPhase, SpatialIndex {\n private readonly _tree = new DynamicAabbTree<Collider>(AABB_MARGIN);\n private readonly _pairs = new Map<number, CandidatePair>();\n private readonly _scratchFatAabb: AabbLike = { minX: 0, minY: 0, maxX: 0, maxY: 0 };\n\n private _syncingCollider: Collider | null = null;\n private _syncingProxy = -1;\n private readonly _onNeighborFound = (payload: Collider, proxy: number): void => {\n if (proxy === this._syncingProxy) {\n return;\n }\n\n this._addPair(this._syncingCollider!, payload);\n };\n\n private readonly _dropIfStale = (pair: CandidatePair, key: number): void => {\n if (!this._tree.fatOverlaps(pair.a._treeProxy, pair.b._treeProxy)) {\n this._pairs.delete(key);\n }\n };\n\n private _collectTarget: CandidatePair[] = [];\n private readonly _collectPair = (pair: CandidatePair): void => {\n // Emit only true (tight-AABB) overlaps; the persistent set is fat-keyed for\n // coherence, so a fat-but-not-tight pair is parked here, not a candidate.\n if (aabbOverlap(pair.a.aabb, pair.b.aabb)) {\n this._collectTarget.push(pair);\n }\n };\n\n private _queryTarget: Collider[] = [];\n private readonly _onQueryHit = (payload: Collider): void => {\n this._queryTarget.push(payload);\n };\n\n private readonly _resetTreeProxy = (payload: Collider): void => {\n payload._treeProxy = -1;\n };\n\n public computePairs(colliders: readonly Collider[], out: CandidatePair[]): CandidatePair[] {\n this.sync(colliders);\n\n this._pairs.forEach(this._dropIfStale);\n\n out.length = 0;\n this._collectTarget = out;\n this._pairs.forEach(this._collectPair);\n sortInPlace(out, byPairId);\n\n return out;\n }\n\n /**\n * Insert every not-yet-tracked collider and reinsert every moved one (the\n * `computePairs` phase-1 loop, extracted so {@link queryAabb} callers can\n * force it independently of a full detection pass - see {@link SpatialIndex.sync}).\n */\n public sync(colliders: readonly Collider[]): void {\n for (const collider of colliders) {\n this._sync(collider);\n }\n }\n\n /** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */\n public queryAabb(aabb: Readonly<AabbLike>, out: Collider[]): Collider[] {\n out.length = 0;\n this._queryTarget = out;\n this._tree.query(aabb.minX, aabb.minY, aabb.maxX, aabb.maxY, this._onQueryHit);\n\n return out;\n }\n\n /** Colliders whose AABB the ray could cross within `maxDistance`, via the tree's own ray-cast prune. */\n public rayCast(originX: number, originY: number, dirX: number, dirY: number, maxDistance: number, callback: (collider: Collider) => void): void {\n this._tree.rayCast(originX, originY, dirX, dirY, maxDistance, callback);\n }\n\n /** Drop `collider`'s leaf and every pair referencing it. Called when a collider is destroyed. */\n public removeCollider(collider: Collider): void {\n if (collider._treeProxy === -1) {\n return;\n }\n\n this._tree.remove(collider._treeProxy);\n collider._treeProxy = -1;\n\n for (const [key, pair] of this._pairs) {\n if (pair.a === collider || pair.b === collider) {\n this._pairs.delete(key);\n }\n }\n }\n\n public destroy(): void {\n // Reset `_treeProxy` on every still-tracked collider before tearing down the\n // tree: the single-owner contract only guarantees at most one owner AT A\n // TIME, so a collider handed to a later `AabbTreeBroadPhase` (sequential\n // reuse, not concurrent dual-ownership) must not carry a stale non-`-1`\n // proxy from this instance forward. `query` with infinite bounds visits\n // every leaf currently in the tree, allocation-free.\n this._tree.query(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, this._resetTreeProxy);\n this._tree.destroy();\n this._pairs.clear();\n }\n\n private _sync(collider: Collider): void {\n const box = collider.aabb;\n\n if (collider._treeProxy === -1) {\n collider._treeProxy = this._tree.insert(box.minX, box.minY, box.maxX, box.maxY, collider);\n this._discoverNeighbors(collider);\n\n return;\n }\n\n const moved = this._tree.update(collider._treeProxy, box.minX, box.minY, box.maxX, box.maxY);\n\n if (moved) {\n this._discoverNeighbors(collider);\n }\n }\n\n private _discoverNeighbors(collider: Collider): void {\n const proxy = collider._treeProxy;\n const fat = this._tree.fatAabbOf(proxy, this._scratchFatAabb);\n\n this._syncingCollider = collider;\n this._syncingProxy = proxy;\n this._tree.query(fat.minX, fat.minY, fat.maxX, fat.maxY, this._onNeighborFound);\n }\n\n private _addPair(a: Collider, b: Collider): void {\n // Two colliders of the same body are a compound shape, not a collision.\n // Rejecting the pair here rather than downstream also keeps it out of the\n // persistent set, so a compound body costs nothing per step - which matters\n // once convex decomposition attaches many edge-sharing colliders to one body.\n if (a.body === b.body) {\n return;\n }\n\n const lo = a.id < b.id ? a : b;\n const hi = a.id < b.id ? b : a;\n const key = pairKey(lo.id, hi.id);\n\n if (!this._pairs.has(key)) {\n this._pairs.set(key, { a: lo, b: hi });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAM,cAAc;AAEpB,MAAM,YAAY,GAAkB,MAA6B,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCjG,IAAa,qBAAb,MAAoE;CAClE,AAAiB,QAAQ,IAAI,gBAA0B,WAAW;CAClE,AAAiB,yBAAS,IAAI,IAA2B;CACzD,AAAiB,kBAA4B;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,MAAM;CAAE;CAElF,AAAQ,mBAAoC;CAC5C,AAAQ,gBAAgB;CACxB,AAAiB,oBAAoB,SAAmB,UAAwB;EAC9E,IAAI,UAAU,KAAK,eACjB;EAGF,KAAK,SAAS,KAAK,kBAAmB,OAAO;CAC/C;CAEA,AAAiB,gBAAgB,MAAqB,QAAsB;EAC1E,IAAI,CAAC,KAAK,MAAM,YAAY,KAAK,EAAE,YAAY,KAAK,EAAE,UAAU,GAC9D,KAAK,OAAO,OAAO,GAAG;CAE1B;CAEA,AAAQ,iBAAkC,CAAC;CAC3C,AAAiB,gBAAgB,SAA8B;EAG7D,IAAI,YAAY,KAAK,EAAE,MAAM,KAAK,EAAE,IAAI,GACtC,KAAK,eAAe,KAAK,IAAI;CAEjC;CAEA,AAAQ,eAA2B,CAAC;CACpC,AAAiB,eAAe,YAA4B;EAC1D,KAAK,aAAa,KAAK,OAAO;CAChC;CAEA,AAAiB,mBAAmB,YAA4B;EAC9D,QAAQ,aAAa;CACvB;CAEA,AAAO,aAAa,WAAgC,KAAuC;EACzF,KAAK,KAAK,SAAS;EAEnB,KAAK,OAAO,QAAQ,KAAK,YAAY;EAErC,IAAI,SAAS;EACb,KA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A,AAAQ,mBAAmB,UAA0B;EACnD,MAAM,QAAQ,SAAS;EACvB,MAAM,MAAM,KAAK,MAAM,UAAU,OAAO,KAAK,eAAe;EAE5D,KAAK,mBAAmB;EACxB,KAAK,gBAAgB;EACrB,KAAK,MAAM,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,KAAK,gBAAgB;CAChF;CAEA,AAAQ,SAAS,GAAa,GAAmB;EAK/C,IAAI,EAAE,SAAS,EAAE,MACf;EAGF,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE;EAEhC,IAAI,CAAC,KAAK,OAAO,IAAI,GAAG,GACtB,KAAK,OAAO,IAAI,KAAK;GAAE,GAAG;GAAI,GAAG;EAAG,CAAC;CAEzC;AACF"}
1
+ {"version":3,"file":"AabbTreeBroadPhase.js","names":[],"sources":["../../../src/broadphase/AabbTreeBroadPhase.ts"],"sourcesContent":["import type { AabbLike } from '@codexo/exojs';\nimport { DynamicAabbTree } from '@codexo/exojs';\n\nimport { aabbOverlap } from '../Aabb';\nimport type { Collider } from '../Collider';\nimport { pairKey } from '../ContactGraph';\nimport type { SpatialIndex } from '../query/SpatialIndex';\nimport { sortInPlace } from '../sort';\nimport type { BroadPhase, CandidatePair } from './BroadPhase';\n\n/**\n * Fixed fat-AABB margin (world px) applied to every collider's tree leaf.\n * Chosen relative to the engine's typical small-collider scale (test/example\n * shapes commonly span 10-30px): large enough that a few steps of ordinary\n * motion stay inside the margin (skipping the sync phase's remove+reinsert),\n * small enough it doesn't inflate fat AABBs into spurious candidates for\n * densely packed scenes. Fixed per the design's v1 scope (no velocity-based\n * predictive expansion) - revisit if benchmarks want a different value.\n */\nconst AABB_MARGIN = 4;\n\nconst byPairId = (p: CandidatePair, q: CandidatePair): number => p.a.id - q.a.id || p.b.id - q.b.id;\n\n/**\n * Dynamic-AABB-tree broad phase (Box2D-style), wrapping a generic\n * `DynamicAabbTree<Collider>`. Stateful across steps: a collider whose tight\n * AABB stays inside its stored fat AABB costs nothing to re-sync.\n *\n * Three phases per `computePairs` call: (1) sync every live collider (insert\n * new ones, reinsert moved ones, querying only around reinsertions to discover\n * NEW fat-overlap candidates; a collider whose AABB has not been rewritten\n * since its last sync is skipped outright via `Collider._treeDirty`, so a\n * sleeping world pays one flag read per collider); (2) one full pass over the\n * persistent pair set dropping any pair whose fat AABBs no longer overlap -\n * cheap (O(1) per pair) and run every step regardless of movement, exactly\n * mirroring Box2D's own `b2ContactManager::Collide` (see the design's\n * correctness argument for why a single global pass, not a per-moved-leaf\n * rescan, is both correct and the right complexity); (3) emit, keeping only\n * pairs whose *tight* AABBs overlap.\n *\n * Phases 2 and 3 are skipped whole when nothing they read has changed since the\n * last call: the emitted list is a function of the pair set and the tight AABBs\n * alone, and a step that rewrote no collider geometry touched neither.\n *\n * The persistent set is intentionally keyed on *fat* overlap so temporal\n * coherence carries across steps (a leaf that stays inside its fat AABB is\n * never re-discovered). Emitting is filtered to tight-AABB overlap so the\n * candidate set the caller sees is exact - the fat margin never leaks a false\n * positive downstream, and a fat-but-not-tight pair simply stays parked in the\n * set (costing one O(1) re-check per step) until the leaves separate.\n *\n * **Single-owner contract.** A collider's tree membership is tracked through its\n * `Collider._treeProxy` field, which - like `PhysicsBody._islandIndex` /\n * `_sleepTime` - is a single slot on the shared object. Exactly ONE\n * `AabbTreeBroadPhase` instance may track a given collider at a time (in\n * production that is the world's own `_broadPhase`, for the collider's whole\n * lifetime until `removeCollider`). Do NOT stand up a second, throwaway\n * `AabbTreeBroadPhase` over colliders another instance already owns (e.g. for\n * debug visualization): the second instance would clobber the first's\n * `_treeProxy` values and corrupt its tree. Use a plain brute-force scan for\n * such one-off, read-only needs instead.\n */\nexport class AabbTreeBroadPhase implements BroadPhase, SpatialIndex {\n private readonly _tree = new DynamicAabbTree<Collider>(AABB_MARGIN);\n private readonly _pairs = new Map<number, CandidatePair>();\n private readonly _scratchFatAabb: AabbLike = { minX: 0, minY: 0, maxX: 0, maxY: 0 };\n\n private _syncingCollider: Collider | null = null;\n private _syncingProxy = -1;\n\n /**\n * Whether anything the emitted candidate list is a function of has changed\n * since it was built: a collider AABB taken into the tree, or a pair added or\n * dropped. While it stays `false` the previous list is still exactly right.\n */\n private _emitStale = true;\n /** The buffer the current candidate list was emitted into, so a caller that swaps or clears its own buffer still gets a rebuild. */\n private _emitTarget: CandidatePair[] | null = null;\n private _emitLength = -1;\n\n private readonly _onNeighborFound = (payload: Collider, proxy: number): void => {\n if (proxy === this._syncingProxy) {\n return;\n }\n\n this._addPair(this._syncingCollider!, payload);\n };\n\n private readonly _dropIfStale = (pair: CandidatePair, key: number): void => {\n if (!this._tree.fatOverlaps(pair.a._treeProxy, pair.b._treeProxy)) {\n this._pairs.delete(key);\n this._emitStale = true;\n }\n };\n\n private _collectTarget: CandidatePair[] = [];\n private readonly _collectPair = (pair: CandidatePair): void => {\n // Emit only true (tight-AABB) overlaps; the persistent set is fat-keyed for\n // coherence, so a fat-but-not-tight pair is parked here, not a candidate.\n if (aabbOverlap(pair.a.aabb, pair.b.aabb)) {\n this._collectTarget.push(pair);\n }\n };\n\n private _queryTarget: Collider[] = [];\n private readonly _onQueryHit = (payload: Collider): void => {\n this._queryTarget.push(payload);\n };\n\n private readonly _resetTreeProxy = (payload: Collider): void => {\n payload._treeProxy = -1;\n };\n\n public computePairs(colliders: readonly Collider[], out: CandidatePair[]): CandidatePair[] {\n this.sync(colliders);\n\n // The candidate list is a function of the pair set and the tight AABBs\n // alone. A step in which no collider's geometry was rewritten and no pair\n // moved leaves both untouched, so the list already in `out` is the one both\n // passes below would rebuild - and a settled world is every such step.\n if (!this._emitStale && out === this._emitTarget && out.length === this._emitLength) {\n return out;\n }\n\n this._pairs.forEach(this._dropIfStale);\n\n out.length = 0;\n this._collectTarget = out;\n this._pairs.forEach(this._collectPair);\n sortInPlace(out, byPairId);\n\n this._emitStale = false;\n this._emitTarget = out;\n this._emitLength = out.length;\n\n return out;\n }\n\n /**\n * Insert every not-yet-tracked collider and reinsert every moved one (the\n * `computePairs` phase-1 loop, extracted so {@link queryAabb} callers can\n * force it independently of a full detection pass - see {@link SpatialIndex.sync}).\n */\n public sync(colliders: readonly Collider[]): void {\n for (const collider of colliders) {\n this._sync(collider);\n }\n }\n\n /** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */\n public queryAabb(aabb: Readonly<AabbLike>, out: Collider[]): Collider[] {\n out.length = 0;\n this._queryTarget = out;\n this._tree.query(aabb.minX, aabb.minY, aabb.maxX, aabb.maxY, this._onQueryHit);\n\n return out;\n }\n\n /** Colliders whose AABB the ray could cross within `maxDistance`, via the tree's own ray-cast prune. */\n public rayCast(originX: number, originY: number, dirX: number, dirY: number, maxDistance: number, callback: (collider: Collider) => void): void {\n this._tree.rayCast(originX, originY, dirX, dirY, maxDistance, callback);\n }\n\n /** Drop `collider`'s leaf and every pair referencing it. Called when a collider is destroyed. */\n public removeCollider(collider: Collider): void {\n if (collider._treeProxy === -1) {\n return;\n }\n\n this._emitStale = true;\n this._tree.remove(collider._treeProxy);\n collider._treeProxy = -1;\n\n for (const [key, pair] of this._pairs) {\n if (pair.a === collider || pair.b === collider) {\n this._pairs.delete(key);\n }\n }\n }\n\n public destroy(): void {\n // Reset `_treeProxy` on every still-tracked collider before tearing down the\n // tree: the single-owner contract only guarantees at most one owner AT A\n // TIME, so a collider handed to a later `AabbTreeBroadPhase` (sequential\n // reuse, not concurrent dual-ownership) must not carry a stale non-`-1`\n // proxy from this instance forward. `query` with infinite bounds visits\n // every leaf currently in the tree, allocation-free.\n this._tree.query(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, this._resetTreeProxy);\n this._tree.destroy();\n this._pairs.clear();\n this._emitStale = true;\n this._emitTarget = null;\n }\n\n private _sync(collider: Collider): void {\n const box = collider.aabb;\n\n if (collider._treeProxy === -1) {\n collider._treeDirty = false;\n this._emitStale = true;\n collider._treeProxy = this._tree.insert(box.minX, box.minY, box.maxX, box.maxY, collider);\n this._discoverNeighbors(collider);\n\n return;\n }\n\n // The leaf already holds this box, so `update` would do nothing but repeat\n // the containment test. A settled world is almost entirely this case.\n if (!collider._treeDirty) {\n return;\n }\n\n collider._treeDirty = false;\n this._emitStale = true;\n\n const moved = this._tree.update(collider._treeProxy, box.minX, box.minY, box.maxX, box.maxY);\n\n if (moved) {\n this._discoverNeighbors(collider);\n }\n }\n\n private _discoverNeighbors(collider: Collider): void {\n const proxy = collider._treeProxy;\n const fat = this._tree.fatAabbOf(proxy, this._scratchFatAabb);\n\n this._syncingCollider = collider;\n this._syncingProxy = proxy;\n this._tree.query(fat.minX, fat.minY, fat.maxX, fat.maxY, this._onNeighborFound);\n }\n\n private _addPair(a: Collider, b: Collider): void {\n // Two colliders of the same body are a compound shape, not a collision.\n // Rejecting the pair here rather than downstream also keeps it out of the\n // persistent set, so a compound body costs nothing per step - which matters\n // once convex decomposition attaches many edge-sharing colliders to one body.\n if (a.body === b.body) {\n return;\n }\n\n const lo = a.id < b.id ? a : b;\n const hi = a.id < b.id ? b : a;\n const key = pairKey(lo.id, hi.id);\n\n if (!this._pairs.has(key)) {\n this._pairs.set(key, { a: lo, b: hi });\n this._emitStale = true;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAM,cAAc;AAEpB,MAAM,YAAY,GAAkB,MAA6B,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCjG,IAAa,qBAAb,MAAoE;CAClE,AAAiB,QAAQ,IAAI,gBAA0B,WAAW;CAClE,AAAiB,yBAAS,IAAI,IAA2B;CACzD,AAAiB,kBAA4B;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,MAAM;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D,KAAK,mBAAmB;EACxB,KAAK,gBAAgB;EACrB,KAAK,MAAM,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,KAAK,gBAAgB;CAChF;CAEA,AAAQ,SAAS,GAAa,GAAmB;EAK/C,IAAI,EAAE,SAAS,EAAE,MACf;EAGF,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE;EAEhC,IAAI,CAAC,KAAK,OAAO,IAAI,GAAG,GAAG;GACzB,KAAK,OAAO,IAAI,KAAK;IAAE,GAAG;IAAI,GAAG;GAAG,CAAC;GACrC,KAAK,aAAa;EACpB;CACF;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link DistanceJoint}. */
5
- export interface DistanceJointOptions {
6
+ export interface DistanceJointOptions extends JointOptions {
6
7
  /** First body (often a static anchor). */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body. */
@@ -1 +1 @@
1
- {"version":3,"file":"DistanceJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/DistanceJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC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AAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,WAAW,CAAY;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAK;gBAEF,OAAO,EAAE,oBAAoB;IA8IhD,OAAO,CAAC,iBAAiB;CAa1B"}
@@ -44,7 +44,7 @@ var DistanceJoint = class extends Joint {
44
44
  _impulseScale = 0;
45
45
  _impulse = 0;
46
46
  constructor(options) {
47
- super(options.bodyA, options.bodyB);
47
+ super(options.bodyA, options.bodyB, options.collideConnected);
48
48
  const ax = options.anchorA?.x ?? options.bodyA.x;
49
49
  const ay = options.anchorA?.y ?? options.bodyA.y;
50
50
  const bx = options.anchorB?.x ?? options.bodyB.x;
@@ -63,7 +63,7 @@ var DistanceJoint = class extends Joint {
63
63
  this.maxLength = options.maxLength ?? (this._limited ? Infinity : this.length);
64
64
  }
65
65
  /** @internal */
66
- _prepare(h) {
66
+ _prepare(h, rigid) {
67
67
  const bodyA = this.bodyA;
68
68
  const bodyB = this.bodyB;
69
69
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -122,9 +122,9 @@ var DistanceJoint = class extends Joint {
122
122
  this._massScale = a2 * a3;
123
123
  this._impulseScale = a3;
124
124
  } else {
125
- this._biasRate = .2 / h;
126
- this._massScale = 1;
127
- this._impulseScale = 0;
125
+ this._biasRate = rigid.biasRate;
126
+ this._massScale = rigid.massScale;
127
+ this._impulseScale = rigid.impulseScale;
128
128
  }
129
129
  }
130
130
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"DistanceJoint.js","names":[],"sources":["../../../src/joints/DistanceJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link DistanceJoint}. */\nexport interface DistanceJointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** World-space anchor on body A at creation. Default: body A's position. */\n anchorA?: Readonly<PointLike>;\n /** World-space anchor on body B at creation. Default: body B's position. */\n anchorB?: Readonly<PointLike>;\n /** Target distance between the anchors. Default: their initial distance. */\n length?: number;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid constraint. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /**\n * Minimum allowed distance. Specifying `minLength` and/or `maxLength` turns the\n * joint into a **rope/limit** (distance kept within `[minLength, maxLength]`,\n * slack between, rigid limits). Otherwise the joint is a rigid/soft **equality**\n * at `length`. Defaults to `0` in limit mode.\n */\n minLength?: number;\n /** Maximum allowed distance (the rope length). See {@link minLength}. Defaults to `Infinity` in limit mode. */\n maxLength?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Holds the anchor points on two bodies at a target {@link length} along their\n * connecting axis. With `hertz === 0` it is rigid; with `hertz > 0` it behaves\n * as a damped spring. Solved as a soft constraint in the sub-step loop, warm-\n * started across frames.\n */\nexport class DistanceJoint extends Joint {\n /** Target distance between the anchors. */\n public length: number;\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** Minimum allowed distance (rope/limit mode). */\n public minLength: number;\n /** Maximum allowed distance (rope/limit mode). */\n public maxLength: number;\n\n private readonly _limited: boolean;\n private _minImpulse = -Infinity;\n private _maxImpulse = Infinity;\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _nx = 0;\n private _ny = 0;\n private _separation = 0;\n private _effMass = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulse = 0;\n\n public constructor(options: DistanceJointOptions) {\n super(options.bodyA, options.bodyB);\n\n const ax = options.anchorA?.x ?? options.bodyA.x;\n const ay = options.anchorA?.y ?? options.bodyA.y;\n const bx = options.anchorB?.x ?? options.bodyB.x;\n const by = options.anchorB?.y ?? options.bodyB.y;\n\n applyInverseTransform(options.bodyA.transform, ax, ay, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, bx, by, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.length = options.length ?? Math.hypot(bx - ax, by - ay);\n this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this._limited = options.minLength !== undefined || options.maxLength !== undefined;\n this.minLength = options.minLength ?? (this._limited ? 0 : this.length);\n this.maxLength = options.maxLength ?? (this._limited ? Infinity : this.length);\n }\n\n /** @internal */\n public override _prepare(h: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n\n let dx = pBx - pAx;\n let dy = pBy - pAy;\n const len = Math.hypot(dx, dy);\n\n if (len > 1e-9) {\n dx /= len;\n dy /= len;\n } else {\n dx = 1;\n dy = 0;\n }\n\n this._nx = dx;\n this._ny = dy;\n\n const crA = this._rAx * dy - this._rAy * dx;\n const crB = this._rBx * dy - this._rBy * dx;\n const k = bodyA.invMass + bodyB.invMass + bodyA.invInertia * crA * crA + bodyB.invInertia * crB * crB;\n this._effMass = k > 0 ? 1 / k : 0;\n\n if (this._limited) {\n // Rope/limit: solve only the violated bound; slack between min and max.\n if (len > this.maxLength) {\n this._separation = len - this.maxLength;\n this._minImpulse = -Infinity; // pull together only (tension)\n this._maxImpulse = 0;\n } else if (len < this.minLength) {\n this._separation = len - this.minLength;\n this._minImpulse = 0; // push apart only (compression)\n this._maxImpulse = Infinity;\n } else {\n this._active = false; // slack — nothing to solve this frame\n this._impulse = 0;\n\n return;\n }\n } else {\n this._separation = len - this.length;\n this._minImpulse = -Infinity;\n this._maxImpulse = Infinity;\n }\n\n // Soft spring only for the equality joint; rope limits are rigid.\n if (this.hertz > 0 && !this._limited) {\n // Box2D-v3 soft factors from a damped spring at the sub-step `h`.\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n } else {\n // Rigid: full mass, Baumgarte position bias, no impulse decay.\n this._biasRate = 0.2 / h;\n this._massScale = 1;\n this._impulseScale = 0;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (this._active) {\n this._applyAxisImpulse(this._impulse);\n }\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Relative velocity of the anchors projected onto the axis.\n const vax = bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy;\n const vay = bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx;\n const vbx = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy;\n const vby = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx;\n const cdot = (vbx - vax) * this._nx + (vby - vay) * this._ny;\n\n const bias = useBias ? this._biasRate * this._separation : 0;\n const raw = -this._effMass * this._massScale * (cdot + bias) - this._impulseScale * this._impulse;\n // Clamp the accumulated impulse to the limit's sign range (±Infinity = equality, no clamp).\n const clamped = Math.min(this._maxImpulse, Math.max(this._minImpulse, this._impulse + raw));\n const applied = clamped - this._impulse;\n\n this._impulse = clamped;\n this._applyAxisImpulse(applied);\n }\n\n private _applyAxisImpulse(impulse: number): void {\n const jx = impulse * this._nx;\n const jy = impulse * this._ny;\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);\n }\n}\n"],"mappings":";;;;;AAkCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxC,IAAa,gBAAb,cAAmC,MAAM;;CAEvC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAE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EAC1B,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;EAC1E,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;CAC5E;AACF"}
1
+ {"version":3,"file":"DistanceJoint.js","names":[],"sources":["../../../src/joints/DistanceJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { JointOptions, JointSoftness } from './Joint';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link DistanceJoint}. */\nexport interface DistanceJointOptions extends JointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** World-space anchor on body A at creation. Default: body A's position. */\n anchorA?: Readonly<PointLike>;\n /** World-space anchor on body B at creation. Default: body B's position. */\n anchorB?: Readonly<PointLike>;\n /** Target distance between the anchors. Default: their initial distance. */\n length?: number;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid constraint. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /**\n * Minimum allowed distance. Specifying `minLength` and/or `maxLength` turns the\n * joint into a **rope/limit** (distance kept within `[minLength, maxLength]`,\n * slack between, rigid limits). Otherwise the joint is a rigid/soft **equality**\n * at `length`. Defaults to `0` in limit mode.\n */\n minLength?: number;\n /** Maximum allowed distance (the rope length). See {@link minLength}. Defaults to `Infinity` in limit mode. */\n maxLength?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Holds the anchor points on two bodies at a target {@link length} along their\n * connecting axis. With `hertz === 0` it is rigid; with `hertz > 0` it behaves\n * as a damped spring. Solved as a soft constraint in the sub-step loop, warm-\n * started across frames.\n */\nexport class DistanceJoint extends Joint {\n /** Target distance between the anchors. */\n public length: number;\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** Minimum allowed distance (rope/limit mode). */\n public minLength: number;\n /** Maximum allowed distance (rope/limit mode). */\n public maxLength: number;\n\n private readonly _limited: boolean;\n private _minImpulse = -Infinity;\n private _maxImpulse = Infinity;\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _nx = 0;\n private _ny = 0;\n private _separation = 0;\n private _effMass = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulse = 0;\n\n public constructor(options: DistanceJointOptions) {\n super(options.bodyA, options.bodyB, options.collideConnected);\n\n const ax = options.anchorA?.x ?? options.bodyA.x;\n const ay = options.anchorA?.y ?? options.bodyA.y;\n const bx = options.anchorB?.x ?? options.bodyB.x;\n const by = options.anchorB?.y ?? options.bodyB.y;\n\n applyInverseTransform(options.bodyA.transform, ax, ay, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, bx, by, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.length = options.length ?? Math.hypot(bx - ax, by - ay);\n this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this._limited = options.minLength !== undefined || options.maxLength !== undefined;\n this.minLength = options.minLength ?? (this._limited ? 0 : this.length);\n this.maxLength = options.maxLength ?? (this._limited ? Infinity : this.length);\n }\n\n /** @internal */\n public override _prepare(h: number, rigid: JointSoftness): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n\n let dx = pBx - pAx;\n let dy = pBy - pAy;\n const len = Math.hypot(dx, dy);\n\n if (len > 1e-9) {\n dx /= len;\n dy /= len;\n } else {\n dx = 1;\n dy = 0;\n }\n\n this._nx = dx;\n this._ny = dy;\n\n const crA = this._rAx * dy - this._rAy * dx;\n const crB = this._rBx * dy - this._rBy * dx;\n const k = bodyA.invMass + bodyB.invMass + bodyA.invInertia * crA * crA + bodyB.invInertia * crB * crB;\n this._effMass = k > 0 ? 1 / k : 0;\n\n if (this._limited) {\n // Rope/limit: solve only the violated bound; slack between min and max.\n if (len > this.maxLength) {\n this._separation = len - this.maxLength;\n this._minImpulse = -Infinity; // pull together only (tension)\n this._maxImpulse = 0;\n } else if (len < this.minLength) {\n this._separation = len - this.minLength;\n this._minImpulse = 0; // push apart only (compression)\n this._maxImpulse = Infinity;\n } else {\n this._active = false; // slack — nothing to solve this frame\n this._impulse = 0;\n\n return;\n }\n } else {\n this._separation = len - this.length;\n this._minImpulse = -Infinity;\n this._maxImpulse = Infinity;\n }\n\n // Soft spring only for the equality joint; rope limits are rigid.\n if (this.hertz > 0 && !this._limited) {\n // Box2D-v3 soft factors from a damped spring at the sub-step `h`.\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n } else {\n // The solver's own softness rather than a raw Baumgarte term; see\n // `softConstraint`. An unscaled bias relaxes no impulse, which a chain of\n // these constraints turns into energy.\n this._biasRate = rigid.biasRate;\n this._massScale = rigid.massScale;\n this._impulseScale = rigid.impulseScale;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (this._active) {\n this._applyAxisImpulse(this._impulse);\n }\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Relative velocity of the anchors projected onto the axis.\n const vax = bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy;\n const vay = bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx;\n const vbx = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy;\n const vby = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx;\n const cdot = (vbx - vax) * this._nx + (vby - vay) * this._ny;\n\n const bias = useBias ? this._biasRate * this._separation : 0;\n const raw = -this._effMass * this._massScale * (cdot + bias) - this._impulseScale * this._impulse;\n // Clamp the accumulated impulse to the limit's sign range (±Infinity = equality, no clamp).\n const clamped = Math.min(this._maxImpulse, Math.max(this._minImpulse, this._impulse + raw));\n const applied = clamped - this._impulse;\n\n this._impulse = clamped;\n this._applyAxisImpulse(applied);\n }\n\n private _applyAxisImpulse(impulse: number): void {\n const jx = impulse * this._nx;\n const jy = impulse * this._ny;\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rB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,IAAI,KAAK,aAAa,KAAK,WAAW,GAAG,CAAC;EAC1F,MAAM,UAAU,UAAU,KAAK;EAE/B,KAAK,WAAW;EAChB,KAAK,kBAAkB,OAAO;CAChC;CAEA,AAAQ,kBAAkB,SAAuB;EAC/C,MAAM,KAAK,UAAU,KAAK;EAC1B,MAAM,KAAK,UAAU,KAAK;EAC1B,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;EAC1E,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;CAC5E;AACF"}
@@ -1,4 +1,60 @@
1
1
  import type { PhysicsBody } from '../PhysicsBody';
2
+ /**
3
+ * Soft-constraint factors for one sub-step, as the solver's "soft step" uses
4
+ * them: how fast a position error is turned into a bias velocity, how much of
5
+ * the solved impulse is applied, and how much of the accumulated impulse is
6
+ * relaxed away again.
7
+ */
8
+ export interface JointSoftness {
9
+ readonly biasRate: number;
10
+ readonly massScale: number;
11
+ readonly impulseScale: number;
12
+ }
13
+ /**
14
+ * Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a
15
+ * sub-step of `h` seconds.
16
+ *
17
+ * The same formulation the contact solver uses. A joint asked for no stiffness
18
+ * of its own still gets these rather than a raw Baumgarte term: an unscaled
19
+ * `0.2 / h` bias applies the full position correction as a velocity every
20
+ * sub-step and relaxes none of the impulse it accumulated, which a single joint
21
+ * absorbs and a serial chain does not - each link hands its neighbour an
22
+ * over-correction that the next sub-step corrects again.
23
+ */
24
+ export declare const softConstraint: (hertz: number, dampingRatio: number, h: number) => JointSoftness;
25
+ /** Options every joint accepts, whatever it constrains. */
26
+ export interface JointOptions {
27
+ /**
28
+ * Whether the two bodies this joint connects also collide with each other.
29
+ * Default `true`.
30
+ *
31
+ * `false` is what a chain, a ragdoll, a pendulum or a vehicle assembly
32
+ * usually wants, and what Box2D defaults to: a joint already decides how its
33
+ * two bodies may move relative to one another, so letting their touching
34
+ * colliders push each other apart at the same time gives the pair two
35
+ * constraint systems with different opinions, plus a contact per link that
36
+ * nothing needs.
37
+ *
38
+ * The default is nevertheless `true`, which is the behaviour every joint has
39
+ * had so far: an existing scene built against it would change shape under an
40
+ * update that flipped it. Nothing else argues for `true` any more - a chain
41
+ * of seven links and up used to gain energy without these contacts, and that
42
+ * defect is fixed in the joint solver rather than damped by them - so the
43
+ * default is a compatibility choice and is free to be revisited.
44
+ *
45
+ * Nothing about a contact is weakened under `true`: the narrow phase
46
+ * produces it, the contact graph holds it, collision events fire, a
47
+ * {@link ContactModifier} sees it and the solver resolves it, exactly as for
48
+ * any unjointed pair.
49
+ *
50
+ * It is fixed at construction, and it follows the joint's presence in the
51
+ * world rather than {@link Joint.enabled}: disabling a joint suspends its
52
+ * constraint, and a ragdoll whose joints are momentarily disabled must not
53
+ * start pushing its own limbs apart. Removing the joint from the world does
54
+ * let the pair collide again, and both bodies are woken so they respond to it.
55
+ */
56
+ collideConnected?: boolean;
57
+ }
2
58
  /**
3
59
  * Base class for a two-body constraint solved alongside contacts in the
4
60
  * sub-step loop. Concrete joints (distance, revolute, weld) implement the
@@ -11,10 +67,10 @@ export declare abstract class Joint {
11
67
  readonly bodyA: PhysicsBody;
12
68
  /** Second constrained body. */
13
69
  readonly bodyB: PhysicsBody;
70
+ /** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */
71
+ readonly collideConnected: boolean;
14
72
  /** When `false`, the joint is skipped by the solver (but still tracked by the world). */
15
73
  enabled: boolean;
16
- /** Whether this joint solves this frame - set in {@link _prepare} (disabled, sleeping or two static bodies → `false`). */
17
- protected _active: boolean;
18
- protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody);
74
+ protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody, collideConnected?: boolean);
19
75
  }
20
76
  //# sourceMappingURL=Joint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Joint.d.ts","sourceRoot":"","sources":["../../../src/joints/Joint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;GAMG;AACH,8BAAsB,KAAK;IACzB,8BAA8B;IAC9B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,+BAA+B;IAC/B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,yFAAyF;IAClF,OAAO,UAAQ;IAEtB,0HAA0H;IAC1H,SAAS,CAAC,OAAO,UAAS;IAE1B,SAAS,aAAa,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW;CAW7D"}
1
+ {"version":3,"file":"Joint.d.ts","sourceRoot":"","sources":["../../../src/joints/Joint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,cAAc,MAAM,EAAE,GAAG,MAAM,KAAG,aAW/E,CAAC;AAEF,2DAA2D;AAC3D,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,8BAAsB,KAAK;IACzB,8BAA8B;IAC9B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,+BAA+B;IAC/B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,uHAAuH;IACvH,SAAgB,gBAAgB,EAAE,OAAO,CAAC;IAC1C,yFAAyF;IAClF,OAAO,UAAQ;IAWtB,SAAS,aAAa,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,gBAAgB,UAAO;CAgBtF"}
@@ -1,5 +1,32 @@
1
1
  //#region src/joints/Joint.ts
2
2
  /**
3
+ * Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a
4
+ * sub-step of `h` seconds.
5
+ *
6
+ * The same formulation the contact solver uses. A joint asked for no stiffness
7
+ * of its own still gets these rather than a raw Baumgarte term: an unscaled
8
+ * `0.2 / h` bias applies the full position correction as a velocity every
9
+ * sub-step and relaxes none of the impulse it accumulated, which a single joint
10
+ * absorbs and a serial chain does not - each link hands its neighbour an
11
+ * over-correction that the next sub-step corrects again.
12
+ */
13
+ const softConstraint = (hertz, dampingRatio, h) => {
14
+ if (hertz <= 0) return {
15
+ biasRate: 0,
16
+ massScale: 1,
17
+ impulseScale: 0
18
+ };
19
+ const omega = 2 * Math.PI * hertz;
20
+ const a1 = 2 * dampingRatio + h * omega;
21
+ const a2 = h * omega * a1;
22
+ const a3 = 1 / (1 + a2);
23
+ return {
24
+ biasRate: omega / a1,
25
+ massScale: a2 * a3,
26
+ impulseScale: a3
27
+ };
28
+ };
29
+ /**
3
30
  * Base class for a two-body constraint solved alongside contacts in the
4
31
  * sub-step loop. Concrete joints (distance, revolute, weld) implement the
5
32
  * three solver hooks; the world owns the joint list and drives them, and joins
@@ -11,16 +38,25 @@ var Joint = class {
11
38
  bodyA;
12
39
  /** Second constrained body. */
13
40
  bodyB;
41
+ /** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */
42
+ collideConnected;
14
43
  /** When `false`, the joint is skipped by the solver (but still tracked by the world). */
15
44
  enabled = true;
16
- /** Whether this joint solves this frame - set in {@link _prepare} (disabled, sleeping or two static bodies → `false`). */
45
+ /**
46
+ * @internal - whether this joint solves this frame. Set in {@link _prepare}
47
+ * (disabled, sleeping or two static bodies → `false`), and read by the world
48
+ * right after it to collect the joints the sub-steps actually have to touch.
49
+ * A subclass may still clear it inside `_prepare` once it knows there is
50
+ * nothing to solve (a slack rope limit, say).
51
+ */
17
52
  _active = false;
18
- constructor(bodyA, bodyB) {
53
+ constructor(bodyA, bodyB, collideConnected = true) {
19
54
  this.bodyA = bodyA;
20
55
  this.bodyB = bodyB;
56
+ this.collideConnected = collideConnected;
21
57
  }
22
58
  };
23
59
 
24
60
  //#endregion
25
- export { Joint };
61
+ export { Joint, softConstraint };
26
62
  //# sourceMappingURL=Joint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Joint.js","names":[],"sources":["../../../src/joints/Joint.ts"],"sourcesContent":["import type { PhysicsBody } from '../PhysicsBody';\n\n/**\n * Base class for a two-body constraint solved alongside contacts in the\n * sub-step loop. Concrete joints (distance, revolute, weld) implement the\n * three solver hooks; the world owns the joint list and drives them, and joins\n * the two bodies into one sleep island so a jointed pair sleeps and wakes\n * together.\n */\nexport abstract class Joint {\n /** First constrained body. */\n public readonly bodyA: PhysicsBody;\n /** Second constrained body. */\n public readonly bodyB: PhysicsBody;\n /** When `false`, the joint is skipped by the solver (but still tracked by the world). */\n public enabled = true;\n\n /** Whether this joint solves this frame - set in {@link _prepare} (disabled, sleeping or two static bodies → `false`). */\n protected _active = false;\n\n protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody) {\n this.bodyA = bodyA;\n this.bodyB = bodyB;\n }\n\n /** @internal - build this frame's constraint data; called once per fixed step after detection. */\n public abstract _prepare(h: number): void;\n /** @internal - re-apply the accumulated impulse; called each sub-step (TGS-Soft warm-start). */\n public abstract _warmStart(): void;\n /** @internal - one velocity pass; `useBias` is the soft-bias pass, `false` the relax pass. */\n public abstract _solve(useBias: boolean): void;\n}\n"],"mappings":";;;;;;;;AASA,IAAsB,QAAtB,MAA4B;;CAE1B,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAO,UAAU;;CAGjB,AAAU,UAAU;CAEpB,AAAU,YAAY,OAAoB,OAAoB;EAC5D,KAAK,QAAQ;EACb,KAAK,QAAQ;CACf;AAQF"}
1
+ {"version":3,"file":"Joint.js","names":[],"sources":["../../../src/joints/Joint.ts"],"sourcesContent":["import type { PhysicsBody } from '../PhysicsBody';\n\n/**\n * Soft-constraint factors for one sub-step, as the solver's \"soft step\" uses\n * them: how fast a position error is turned into a bias velocity, how much of\n * the solved impulse is applied, and how much of the accumulated impulse is\n * relaxed away again.\n */\nexport interface JointSoftness {\n readonly biasRate: number;\n readonly massScale: number;\n readonly impulseScale: number;\n}\n\n/**\n * Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a\n * sub-step of `h` seconds.\n *\n * The same formulation the contact solver uses. A joint asked for no stiffness\n * of its own still gets these rather than a raw Baumgarte term: an unscaled\n * `0.2 / h` bias applies the full position correction as a velocity every\n * sub-step and relaxes none of the impulse it accumulated, which a single joint\n * absorbs and a serial chain does not - each link hands its neighbour an\n * over-correction that the next sub-step corrects again.\n */\nexport const softConstraint = (hertz: number, dampingRatio: number, h: number): JointSoftness => {\n if (hertz <= 0) {\n return { biasRate: 0, massScale: 1, impulseScale: 0 };\n }\n\n const omega = 2 * Math.PI * hertz;\n const a1 = 2 * dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n return { biasRate: omega / a1, massScale: a2 * a3, impulseScale: a3 };\n};\n\n/** Options every joint accepts, whatever it constrains. */\nexport interface JointOptions {\n /**\n * Whether the two bodies this joint connects also collide with each other.\n * Default `true`.\n *\n * `false` is what a chain, a ragdoll, a pendulum or a vehicle assembly\n * usually wants, and what Box2D defaults to: a joint already decides how its\n * two bodies may move relative to one another, so letting their touching\n * colliders push each other apart at the same time gives the pair two\n * constraint systems with different opinions, plus a contact per link that\n * nothing needs.\n *\n * The default is nevertheless `true`, which is the behaviour every joint has\n * had so far: an existing scene built against it would change shape under an\n * update that flipped it. Nothing else argues for `true` any more - a chain\n * of seven links and up used to gain energy without these contacts, and that\n * defect is fixed in the joint solver rather than damped by them - so the\n * default is a compatibility choice and is free to be revisited.\n *\n * Nothing about a contact is weakened under `true`: the narrow phase\n * produces it, the contact graph holds it, collision events fire, a\n * {@link ContactModifier} sees it and the solver resolves it, exactly as for\n * any unjointed pair.\n *\n * It is fixed at construction, and it follows the joint's presence in the\n * world rather than {@link Joint.enabled}: disabling a joint suspends its\n * constraint, and a ragdoll whose joints are momentarily disabled must not\n * start pushing its own limbs apart. Removing the joint from the world does\n * let the pair collide again, and both bodies are woken so they respond to it.\n */\n collideConnected?: boolean;\n}\n\n/**\n * Base class for a two-body constraint solved alongside contacts in the\n * sub-step loop. Concrete joints (distance, revolute, weld) implement the\n * three solver hooks; the world owns the joint list and drives them, and joins\n * the two bodies into one sleep island so a jointed pair sleeps and wakes\n * together.\n */\nexport abstract class Joint {\n /** First constrained body. */\n public readonly bodyA: PhysicsBody;\n /** Second constrained body. */\n public readonly bodyB: PhysicsBody;\n /** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */\n public readonly collideConnected: boolean;\n /** When `false`, the joint is skipped by the solver (but still tracked by the world). */\n public enabled = true;\n\n /**\n * @internal - whether this joint solves this frame. Set in {@link _prepare}\n * (disabled, sleeping or two static bodies → `false`), and read by the world\n * right after it to collect the joints the sub-steps actually have to touch.\n * A subclass may still clear it inside `_prepare` once it knows there is\n * nothing to solve (a slack rope limit, say).\n */\n public _active = false;\n\n protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody, collideConnected = true) {\n this.bodyA = bodyA;\n this.bodyB = bodyB;\n this.collideConnected = collideConnected;\n }\n\n /**\n * @internal - build this frame's constraint data; called once per fixed step\n * after detection. `rigid` carries the solver's soft factors for a joint that\n * asks for no stiffness of its own.\n */\n public abstract _prepare(h: number, rigid: JointSoftness): void;\n /** @internal - re-apply the accumulated impulse; called each sub-step (TGS-Soft warm-start). */\n public abstract _warmStart(): void;\n /** @internal - one velocity pass; `useBias` is the soft-bias pass, `false` the relax pass. */\n public abstract _solve(useBias: boolean): void;\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAa,kBAAkB,OAAe,cAAsB,MAA6B;CAC/F,IAAI,SAAS,GACX,OAAO;EAAE,UAAU;EAAG,WAAW;EAAG,cAAc;CAAE;CAGtD,MAAM,QAAQ,IAAI,KAAK,KAAK;CAC5B,MAAM,KAAK,IAAI,eAAe,IAAI;CAClC,MAAM,KAAK,IAAI,QAAQ;CACvB,MAAM,KAAK,KAAK,IAAI;CAEpB,OAAO;EAAE,UAAU,QAAQ;EAAI,WAAW,KAAK;EAAI,cAAc;CAAG;AACtE;;;;;;;;AA2CA,IAAsB,QAAtB,MAA4B;;CAE1B,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAO,UAAU;;;;;;;;CASjB,AAAO,UAAU;CAEjB,AAAU,YAAY,OAAoB,OAAoB,mBAAmB,MAAM;EACrF,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,mBAAmB;CAC1B;AAYF"}
@@ -1 +1 @@
1
- {"version":3,"file":"MouseJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/MouseJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,wBAAwB;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,yFAAyF;IACzF,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC5B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mGAAmG;IACnG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;A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bodyB.wake();
68
68
  }
69
69
  /** @internal */
70
- _prepare(h) {
70
+ _prepare(h, _rigid) {
71
71
  const body = this.bodyB;
72
72
  this._active = this.enabled && !body.isSleeping && body.invMass > 0;
73
73
  if (!this._active) return;
@@ -1 +1 @@
1
- {"version":3,"file":"MouseJoint.js","names":[],"sources":["../../../src/joints/MouseJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link MouseJoint}. */\nexport interface MouseJointOptions {\n /** The body to drag. */\n body: PhysicsBody;\n /** World point to pull the body toward - also the grab point on the body at creation. */\n target: Readonly<PointLike>;\n /** Soft-spring frequency in Hz (higher = snappier). Default `5`. */\n hertz?: number;\n /** Soft-spring damping ratio. Default `0.7`. */\n dampingRatio?: number;\n /** Maximum pulling force - clamps the per-step impulse so heavy bodies lag. Default `Infinity`. */\n maxForce?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Softly pulls a single body's grab point toward a movable **target** point\n * (typically the mouse cursor). The grab point is fixed on the body at creation;\n * update {@link target} each frame to drag. A soft constraint bounded by\n * {@link maxForce} - solved in the sub-step loop, warm-started. Internally the\n * \"other\" body is a private static ground sentinel, so this is a single-body\n * constraint that touches only the dragged body.\n */\nexport class MouseJoint extends Joint {\n /** Soft-spring frequency in Hz. */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** Maximum pulling force. */\n public maxForce: number;\n\n private readonly _localAnchorX: number;\n private readonly _localAnchorY: number;\n private _targetX: number;\n private _targetY: number;\n\n private _rx = 0;\n private _ry = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private _maxImpulse = 0;\n\n public constructor(options: MouseJointOptions) {\n // Single-body constraint: a private static ground stands in for bodyA so the\n // island/solver machinery (which assumes two bodies) sees a static anchor that\n // it never integrates, unions or mutates.\n super(new PhysicsBody({ type: 'static', position: options.target }), options.body);\n\n applyInverseTransform(options.body.transform, options.target.x, options.target.y, scratch);\n this._localAnchorX = scratch.x;\n this._localAnchorY = scratch.y;\n this._targetX = options.target.x;\n this._targetY = options.target.y;\n\n this.hertz = options.hertz ?? 5;\n this.dampingRatio = options.dampingRatio ?? 0.7;\n this.maxForce = options.maxForce ?? Infinity;\n }\n\n /** The world point the body is pulled toward. Reassigning wakes the body so a drag tracks live. */\n public get target(): Readonly<PointLike> {\n return { x: this._targetX, y: this._targetY };\n }\n\n public set target(value: Readonly<PointLike>) {\n this._targetX = value.x;\n this._targetY = value.y;\n this.bodyB.wake();\n }\n\n /** @internal */\n public override _prepare(h: number): void {\n const body = this.bodyB;\n\n this._active = this.enabled && !body.isSleeping && body.invMass > 0;\n\n if (!this._active) {\n return;\n }\n\n applyTransform(body.transform, this._localAnchorX, this._localAnchorY, scratch);\n this._rx = scratch.x - body.worldCenterOfMassX;\n this._ry = scratch.y - body.worldCenterOfMassY;\n this._cx = scratch.x - this._targetX;\n this._cy = scratch.y - this._targetY;\n\n const m = body.invMass;\n const i = body.invInertia;\n\n // 2×2 effective-mass matrix K (only the dragged body contributes) and its inverse.\n const k11 = m + i * this._ry * this._ry;\n const k12 = -i * this._rx * this._ry;\n const k22 = m + i * this._rx * this._rx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n this._maxImpulse = this.maxForce * h;\n\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n this._applyImpulse(this._impulseX, this._impulseY);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const body = this.bodyB;\n\n // Velocity of the grab point.\n const cdotX = body.linearVelocityX - body.angularVelocity * this._ry;\n const cdotY = body.linearVelocityY + body.angularVelocity * this._rx;\n const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);\n\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n let impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n let impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n // Clamp the accumulated impulse magnitude to maxForce·h (a heavy body lags).\n const oldX = this._impulseX;\n const oldY = this._impulseY;\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n\n const magnitude = Math.hypot(this._impulseX, this._impulseY);\n\n if (magnitude > this._maxImpulse) {\n const scale = this._maxImpulse / magnitude;\n\n this._impulseX *= scale;\n this._impulseY *= scale;\n }\n\n impulseX = this._impulseX - oldX;\n impulseY = this._impulseY - oldY;\n this._applyImpulse(impulseX, impulseY);\n }\n\n private _applyImpulse(jx: number, jy: number): void {\n const body = this.bodyB;\n\n body.linearVelocityX += body.invMass * jx;\n body.linearVelocityY += body.invMass * jy;\n body.angularVelocity += body.invInertia * (this._rx * jy - this._ry * jx);\n }\n}\n"],"mappings":";;;;;;AAqBA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;;;AAUxC,IAAa,aAAb,cAAgC,MAAM;;CAEpC,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAQ;CACR,AAAQ;CAER,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,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,MAAM,YAAY,KAAK,MAAM,KAAK,WAAW,KAAK,SAAS;EAE3D,IAAI,YAAY,KAAK,aAAa;GAChC,MAAM,QAAQ,KAAK,cAAc;GAEjC,KAAK,aAAa;GAClB,KAAK,aAAa;EACpB;EAEA,WAAW,KAAK,YAAY;EAC5B,WAAW,KAAK,YAAY;EAC5B,KAAK,cAAc,UAAU,QAAQ;CACvC;CAEA,AAAQ,cAAc,IAAY,IAAkB;EAClD,MAAM,OAAO,KAAK;EAElB,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,cAAc,KAAK,MAAM,KAAK,KAAK,MAAM;CACxE;AACF"}
1
+ {"version":3,"file":"MouseJoint.js","names":[],"sources":["../../../src/joints/MouseJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport { PhysicsBody } from '../PhysicsBody';\nimport { Joint, type JointSoftness } from './Joint';\n\n/** Construction options for a {@link MouseJoint}. */\nexport interface MouseJointOptions {\n /** The body to drag. */\n body: PhysicsBody;\n /** World point to pull the body toward - also the grab point on the body at creation. */\n target: Readonly<PointLike>;\n /** Soft-spring frequency in Hz (higher = snappier). Default `5`. */\n hertz?: number;\n /** Soft-spring damping ratio. Default `0.7`. */\n dampingRatio?: number;\n /** Maximum pulling force - clamps the per-step impulse so heavy bodies lag. Default `Infinity`. */\n maxForce?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Softly pulls a single body's grab point toward a movable **target** point\n * (typically the mouse cursor). The grab point is fixed on the body at creation;\n * update {@link target} each frame to drag. A soft constraint bounded by\n * {@link maxForce} - solved in the sub-step loop, warm-started. Internally the\n * \"other\" body is a private static ground sentinel, so this is a single-body\n * constraint that touches only the dragged body.\n */\nexport class MouseJoint extends Joint {\n /** Soft-spring frequency in Hz. */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** Maximum pulling force. */\n public maxForce: number;\n\n private readonly _localAnchorX: number;\n private readonly _localAnchorY: number;\n private _targetX: number;\n private _targetY: number;\n\n private _rx = 0;\n private _ry = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private _maxImpulse = 0;\n\n public constructor(options: MouseJointOptions) {\n // Single-body constraint: a private static ground stands in for bodyA so the\n // island/solver machinery (which assumes two bodies) sees a static anchor that\n // it never integrates, unions or mutates.\n super(new PhysicsBody({ type: 'static', position: options.target }), options.body);\n\n applyInverseTransform(options.body.transform, options.target.x, options.target.y, scratch);\n this._localAnchorX = scratch.x;\n this._localAnchorY = scratch.y;\n this._targetX = options.target.x;\n this._targetY = options.target.y;\n\n this.hertz = options.hertz ?? 5;\n this.dampingRatio = options.dampingRatio ?? 0.7;\n this.maxForce = options.maxForce ?? Infinity;\n }\n\n /** The world point the body is pulled toward. Reassigning wakes the body so a drag tracks live. */\n public get target(): Readonly<PointLike> {\n return { x: this._targetX, y: this._targetY };\n }\n\n public set target(value: Readonly<PointLike>) {\n this._targetX = value.x;\n this._targetY = value.y;\n this.bodyB.wake();\n }\n\n /** @internal */\n public override _prepare(h: number, _rigid: JointSoftness): void {\n const body = this.bodyB;\n\n this._active = this.enabled && !body.isSleeping && body.invMass > 0;\n\n if (!this._active) {\n return;\n }\n\n applyTransform(body.transform, this._localAnchorX, this._localAnchorY, scratch);\n this._rx = scratch.x - body.worldCenterOfMassX;\n this._ry = scratch.y - body.worldCenterOfMassY;\n this._cx = scratch.x - this._targetX;\n this._cy = scratch.y - this._targetY;\n\n const m = body.invMass;\n const i = body.invInertia;\n\n // 2×2 effective-mass matrix K (only the dragged body contributes) and its inverse.\n const k11 = m + i * this._ry * this._ry;\n const k12 = -i * this._rx * this._ry;\n const k22 = m + i * this._rx * this._rx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n this._maxImpulse = this.maxForce * h;\n\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n this._applyImpulse(this._impulseX, this._impulseY);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const body = this.bodyB;\n\n // Velocity of the grab point.\n const cdotX = body.linearVelocityX - body.angularVelocity * this._ry;\n const cdotY = body.linearVelocityY + body.angularVelocity * this._rx;\n const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);\n\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n let impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n let impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n // Clamp the accumulated impulse magnitude to maxForce·h (a heavy body lags).\n const oldX = this._impulseX;\n const oldY = this._impulseY;\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n\n const magnitude = Math.hypot(this._impulseX, this._impulseY);\n\n if (magnitude > this._maxImpulse) {\n const scale = this._maxImpulse / magnitude;\n\n this._impulseX *= scale;\n this._impulseY *= scale;\n }\n\n impulseX = this._impulseX - oldX;\n impulseY = this._impulseY - oldY;\n this._applyImpulse(impulseX, impulseY);\n }\n\n private _applyImpulse(jx: number, jy: number): void {\n const body = this.bodyB;\n\n body.linearVelocityX += body.invMass * jx;\n body.linearVelocityY += body.invMass * jy;\n body.angularV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E5D,MAAM,UAAU,KAAK,UAAU,OAAO,KAAK,UAAU;EACrD,MAAM,UAAU,KAAK,UAAU,OAAO,KAAK,UAAU;EACrD,IAAI,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EACtE,IAAI,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EAGtE,MAAM,OAAO,KAAK;EAClB,MAAM,OAAO,KAAK;EAClB,KAAK,aAAa;EAClB,KAAK,aAAa;EAElB,MAAM,YAAY,KAAK,MAAM,KAAK,WAAW,KAAK,SAAS;EAE3D,IAAI,YAAY,KAAK,aAAa;GAChC,MAAM,QAAQ,KAAK,cAAc;GAEjC,KAAK,aAAa;GAClB,KAAK,aAAa;EACpB;EAEA,WAAW,KAAK,YAAY;EAC5B,WAAW,KAAK,YAAY;EAC5B,KAAK,cAAc,UAAU,QAAQ;CACvC;CAEA,AAAQ,cAAc,IAAY,IAAkB;EAClD,MAAM,OAAO,KAAK;EAElB,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,cAAc,KAAK,MAAM,KAAK,KAAK,MAAM;CACxE;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link PrismaticJoint}. */
5
- export interface PrismaticJointOptions {
6
+ export interface PrismaticJointOptions extends JointOptions {
6
7
  /** First body (often a static rail anchor). */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body (the slider). */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismaticJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/PrismaticJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM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CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,EAAE,CAAK;IACf,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;gBAEP,OAAO,EAAE,qBAAqB;IAqLjD,iFAAiF;IACjF,OAAO,CAAC,aAAa;IAYrB,0FAA0F;IAC1F,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,WAAW;CAapB"}
@@ -56,7 +56,7 @@ var PrismaticJoint = class extends Joint {
56
56
  _lowerImpulse = 0;
57
57
  _upperImpulse = 0;
58
58
  constructor(options) {
59
- super(options.bodyA, options.bodyB);
59
+ super(options.bodyA, options.bodyB, options.collideConnected);
60
60
  applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
61
61
  this._localAnchorAx = scratch.x;
62
62
  this._localAnchorAy = scratch.y;
@@ -77,7 +77,7 @@ var PrismaticJoint = class extends Joint {
77
77
  this.upperTranslation = options.upperTranslation ?? 0;
78
78
  }
79
79
  /** @internal */
80
- _prepare(h) {
80
+ _prepare(h, _rigid) {
81
81
  const bodyA = this.bodyA;
82
82
  const bodyB = this.bodyB;
83
83
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -1 +1 @@
1
- {"version":3,"file":"PrismaticJoint.js","names":[],"sources":["../../../src/joints/PrismaticJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link PrismaticJoint}. */\nexport interface PrismaticJointOptions {\n /** First body (often a static rail anchor). */\n bodyA: PhysicsBody;\n /** Second body (the slider). */\n bodyB: PhysicsBody;\n /** Shared world-space anchor at creation. */\n anchor: Readonly<PointLike>;\n /** Slide axis in world space at creation (normalised internally). The body may only translate along this axis. */\n axis: Readonly<PointLike>;\n /** Enable the linear motor (drives translation along the axis toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target translation speed along the axis (px/s). Default `0`. */\n motorSpeed?: number;\n /** Maximum motor force - clamps the per-step motor impulse. Default `0`. */\n maxMotorForce?: number;\n /** Enable the translation limit (keeps the axis translation in `[lowerTranslation, upperTranslation]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower translation limit along the axis (relative to the creation position). Default `0`. */\n lowerTranslation?: number;\n /** Upper translation limit along the axis. Default `0`. */\n upperTranslation?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Constrains a body to **slide along a single axis** relative to another: the\n * perpendicular translation and the relative rotation are locked (a 2×2 block);\n * only translation along the axis is free, optionally driven by a motor and/or\n * bounded by a translation limit. Solved in the sub-step loop, warm-started.\n */\nexport class PrismaticJoint extends Joint {\n /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target translation speed along the axis (px/s). */\n public motorSpeed: number;\n /** Maximum motor force. */\n public maxMotorForce: number;\n /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */\n public enableLimit: boolean;\n /** Lower translation limit along the axis. */\n public lowerTranslation: number;\n /** Upper translation limit along the axis. */\n public upperTranslation: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n private readonly _localAxisAx: number;\n private readonly _localAxisAy: number;\n private readonly _referenceAngle: number;\n\n private _axisX = 1;\n private _axisY = 0;\n private _perpX = 0;\n private _perpY = 1;\n private _a1 = 0;\n private _a2 = 0;\n private _s1 = 0;\n private _s2 = 0;\n private _k11 = 0;\n private _k12 = 0;\n private _k22 = 0;\n private _cPerp = 0;\n private _cAngle = 0;\n private _translation = 0;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _perpImpulse = 0;\n private _angularImpulse = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: PrismaticJointOptions) {\n super(options.bodyA, options.bodyB);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n const axisLength = Math.hypot(options.axis.x, options.axis.y);\n\n if (!Number.isFinite(axisLength) || axisLength === 0) {\n throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);\n }\n\n applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);\n this._localAxisAx = scratch.x;\n this._localAxisAy = scratch.y;\n\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorForce = options.maxMotorForce ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerTranslation = options.lowerTranslation ?? 0;\n this.upperTranslation = options.upperTranslation ?? 0;\n }\n\n /** @internal */\n public override _prepare(h: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n // World axis + perpendicular (axis is local to body A).\n applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);\n const axisX = scratch.x;\n const axisY = scratch.y;\n const perpX = -axisY;\n const perpY = axisX;\n\n this._axisX = axisX;\n this._axisY = axisY;\n this._perpX = perpX;\n this._perpY = perpY;\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n const rAx = pAx - bodyA.worldCenterOfMassX;\n const rAy = pAy - bodyA.worldCenterOfMassY;\n const rBx = pBx - bodyB.worldCenterOfMassX;\n const rBy = pBy - bodyB.worldCenterOfMassY;\n const dx = pBx - pAx;\n const dy = pBy - pAy;\n\n // Jacobian cross terms for the axis (motor/limit) and the perpendicular (lock).\n this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;\n this._a2 = rBx * axisY - rBy * axisX;\n this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;\n this._s2 = rBx * perpY - rBy * perpX;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;\n this._axialMass = kAxial > 0 ? 1 / kAxial : 0;\n\n // Perpendicular + angular 2×2 block.\n this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;\n this._k12 = iA * this._s1 + iB * this._s2;\n this._k22 = iA + iB;\n\n if (this._k22 === 0) {\n this._k22 = 1; // both bodies rotation-locked — keep the block invertible\n }\n\n this._cPerp = dx * perpX + dy * perpY;\n this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;\n this._translation = dx * axisX + dy * axisY;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this._applyBlock(this._perpImpulse, this._angularImpulse);\n this._applyAxial(axial);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Motor along the axis.\n if (this.enableMotor) {\n const cdot = this._axisVelocity() - this.motorSpeed;\n const max = this.maxMotorForce * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n this._applyAxial(this._motorImpulse - old);\n }\n\n // Translation limits along the axis.\n if (this.enableLimit) {\n // Lower limit (translation ≥ lowerTranslation): positive impulse pushes along +axis.\n const cLower = this._translation - this.lowerTranslation;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH;\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower;\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));\n this._applyAxial(this._lowerImpulse - oldLower);\n\n // Upper limit (translation ≤ upperTranslation): impulse pushes along −axis.\n const cUpper = this.upperTranslation - this._translation;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));\n this._applyAxial(-(this._upperImpulse - oldUpper));\n }\n\n // Perpendicular + angular lock (2×2 block).\n const cdotPerp = this._perpVelocity();\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const rhs1 = -(cdotPerp + (useBias ? 0.2 * this._invH * this._cPerp : 0));\n const rhs2 = -(cdotAngle + (useBias ? 0.2 * this._invH * this._cAngle : 0));\n const det = this._k11 * this._k22 - this._k12 * this._k12;\n const invDet = det !== 0 ? 1 / det : 0;\n const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);\n const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);\n\n this._perpImpulse += dPerp;\n this._angularImpulse += dAngle;\n this._applyBlock(dPerp, dAngle);\n }\n\n /** Relative velocity projected onto the axis (plus the rotation cross terms). */\n private _axisVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._a2 * bodyB.angularVelocity -\n this._a1 * bodyA.angularVelocity\n );\n }\n\n /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */\n private _perpVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._s2 * bodyB.angularVelocity -\n this._s1 * bodyA.angularVelocity\n );\n }\n\n private _applyAxial(impulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = impulse * this._axisX;\n const py = impulse * this._axisY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;\n }\n\n private _applyBlock(perpImpulse: number, angularImpulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = perpImpulse * this._perpX;\n const py = perpImpulse * this._perpY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxC,IAAa,iBAAb,cAAoC,MAAM;;CAExC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,SAAS;CACjB,AAAQ,UAAU;CAClB,AAAQ,eAAe;CACvB,AAAQ,aAAa;CACrB,AAAQ,KAAK;CACb,AAAQ,QAAQ;CAChB,AAAQ,eAAe;CACvB,AAAQ,kBAAkB;CAC1B,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CAExB,AAAO,YAAY,SAAgC;EACjD,MAAM,QAAQ,OAAO,QAAQ,KAAK;EAElC,sBAAsB,QAAQ,MAAM,WAAW,QAAQ,OAAO,GAAG,QAAQ,OAAO,GAAG,OAAO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AmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;CAC7D;CAEA,AAAQ,YAAY,aAAqB,gBAA8B;EACrE,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,cAAc,KAAK;EAC9B,MAAM,KAAK,cAAc,KAAK;EAE9B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;EACtE,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;CACxE;AACF"}
1
+ {"version":3,"file":"PrismaticJoint.js","names":[],"sources":["../../../src/joints/PrismaticJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { JointOptions, JointSoftness } from './Joint';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link PrismaticJoint}. */\nexport interface PrismaticJointOptions extends JointOptions {\n /** First body (often a static rail anchor). */\n bodyA: PhysicsBody;\n /** Second body (the slider). */\n bodyB: PhysicsBody;\n /** Shared world-space anchor at creation. */\n anchor: Readonly<PointLike>;\n /** Slide axis in world space at creation (normalised internally). The body may only translate along this axis. */\n axis: Readonly<PointLike>;\n /** Enable the linear motor (drives translation along the axis toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target translation speed along the axis (px/s). Default `0`. */\n motorSpeed?: number;\n /** Maximum motor force - clamps the per-step motor impulse. Default `0`. */\n maxMotorForce?: number;\n /** Enable the translation limit (keeps the axis translation in `[lowerTranslation, upperTranslation]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower translation limit along the axis (relative to the creation position). Default `0`. */\n lowerTranslation?: number;\n /** Upper translation limit along the axis. Default `0`. */\n upperTranslation?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Constrains a body to **slide along a single axis** relative to another: the\n * perpendicular translation and the relative rotation are locked (a 2×2 block);\n * only translation along the axis is free, optionally driven by a motor and/or\n * bounded by a translation limit. Solved in the sub-step loop, warm-started.\n */\nexport class PrismaticJoint extends Joint {\n /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target translation speed along the axis (px/s). */\n public motorSpeed: number;\n /** Maximum motor force. */\n public maxMotorForce: number;\n /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */\n public enableLimit: boolean;\n /** Lower translation limit along the axis. */\n public lowerTranslation: number;\n /** Upper translation limit along the axis. */\n public upperTranslation: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n private readonly _localAxisAx: number;\n private readonly _localAxisAy: number;\n private readonly _referenceAngle: number;\n\n private _axisX = 1;\n private _axisY = 0;\n private _perpX = 0;\n private _perpY = 1;\n private _a1 = 0;\n private _a2 = 0;\n private _s1 = 0;\n private _s2 = 0;\n private _k11 = 0;\n private _k12 = 0;\n private _k22 = 0;\n private _cPerp = 0;\n private _cAngle = 0;\n private _translation = 0;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _perpImpulse = 0;\n private _angularImpulse = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: PrismaticJointOptions) {\n super(options.bodyA, options.bodyB, options.collideConnected);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n const axisLength = Math.hypot(options.axis.x, options.axis.y);\n\n if (!Number.isFinite(axisLength) || axisLength === 0) {\n throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);\n }\n\n applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);\n this._localAxisAx = scratch.x;\n this._localAxisAy = scratch.y;\n\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorForce = options.maxMotorForce ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerTranslation = options.lowerTranslation ?? 0;\n this.upperTranslation = options.upperTranslation ?? 0;\n }\n\n /** @internal */\n public override _prepare(h: number, _rigid: JointSoftness): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n // World axis + perpendicular (axis is local to body A).\n applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);\n const axisX = scratch.x;\n const axisY = scratch.y;\n const perpX = -axisY;\n const perpY = axisX;\n\n this._axisX = axisX;\n this._axisY = axisY;\n this._perpX = perpX;\n this._perpY = perpY;\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n const rAx = pAx - bodyA.worldCenterOfMassX;\n const rAy = pAy - bodyA.worldCenterOfMassY;\n const rBx = pBx - bodyB.worldCenterOfMassX;\n const rBy = pBy - bodyB.worldCenterOfMassY;\n const dx = pBx - pAx;\n const dy = pBy - pAy;\n\n // Jacobian cross terms for the axis (motor/limit) and the perpendicular (lock).\n this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;\n this._a2 = rBx * axisY - rBy * axisX;\n this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;\n this._s2 = rBx * perpY - rBy * perpX;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;\n this._axialMass = kAxial > 0 ? 1 / kAxial : 0;\n\n // Perpendicular + angular 2×2 block.\n this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;\n this._k12 = iA * this._s1 + iB * this._s2;\n this._k22 = iA + iB;\n\n if (this._k22 === 0) {\n this._k22 = 1; // both bodies rotation-locked — keep the block invertible\n }\n\n this._cPerp = dx * perpX + dy * perpY;\n this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;\n this._translation = dx * axisX + dy * axisY;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this._applyBlock(this._perpImpulse, this._angularImpulse);\n this._applyAxial(axial);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Motor along the axis.\n if (this.enableMotor) {\n const cdot = this._axisVelocity() - this.motorSpeed;\n const max = this.maxMotorForce * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n this._applyAxial(this._motorImpulse - old);\n }\n\n // Translation limits along the axis.\n if (this.enableLimit) {\n // Lower limit (translation ≥ lowerTranslation): positive impulse pushes along +axis.\n const cLower = this._translation - this.lowerTranslation;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH;\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower;\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));\n this._applyAxial(this._lowerImpulse - oldLower);\n\n // Upper limit (translation ≤ upperTranslation): impulse pushes along −axis.\n const cUpper = this.upperTranslation - this._translation;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));\n this._applyAxial(-(this._upperImpulse - oldUpper));\n }\n\n // Perpendicular + angular lock (2×2 block).\n const cdotPerp = this._perpVelocity();\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const rhs1 = -(cdotPerp + (useBias ? 0.2 * this._invH * this._cPerp : 0));\n const rhs2 = -(cdotAngle + (useBias ? 0.2 * this._invH * this._cAngle : 0));\n const det = this._k11 * this._k22 - this._k12 * this._k12;\n const invDet = det !== 0 ? 1 / det : 0;\n const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);\n const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);\n\n this._perpImpulse += dPerp;\n this._angularImpulse += dAngle;\n this._applyBlock(dPerp, dAngle);\n }\n\n /** Relative velocity projected onto the axis (plus the rotation cross terms). */\n private _axisVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._a2 * bodyB.angularVelocity -\n this._a1 * bodyA.angularVelocity\n );\n }\n\n /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */\n private _perpVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._s2 * bodyB.angularVelocity -\n this._s1 * bodyA.angularVelocity\n );\n }\n\n private _applyAxial(impulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = impulse * this._axisX;\n const py = impulse * this._axisY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;\n }\n\n private _applyBlock(perpImpulse: number, angularImpulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = perpImpulse * this._perpX;\n const py = perpImpulse * this._perpY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);\n }\n}\n"],"mappings":";;;;;AAgCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxC,IAAa,iBAAb,cAAoC,MAAM;;CAExC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AA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Q,KAAK;EAEnB,OACE,KAAK,UAAU,MAAM,kBAAkB,MAAM,mBAC7C,KAAK,UAAU,MAAM,kBAAkB,MAAM,mBAC7C,KAAK,MAAM,MAAM,kBACjB,KAAK,MAAM,MAAM;CAErB;CAEA,AAAQ,YAAY,SAAuB;EACzC,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,UAAU,KAAK;EAC1B,MAAM,KAAK,UAAU,KAAK;EAE1B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;EAC3D,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;CAC7D;CAEA,AAAQ,YAAY,aAAqB,gBAA8B;EACrE,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,cAAc,KAAK;EAC9B,MAAM,KAAK,cAAc,KAAK;EAE9B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;EACtE,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;CACxE;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link RevoluteJoint}. */
5
- export interface RevoluteJointOptions {
6
+ export interface RevoluteJointOptions extends JointOptions {
6
7
  /** First body (often a static anchor). */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body. */
@@ -56,11 +57,8 @@ export declare class RevoluteJoint extends Joint {
56
57
  private _rAy;
57
58
  private _rBx;
58
59
  private _rBy;
59
- private _cx;
60
- private _cy;
61
- private _invK11;
62
- private _invK12;
63
- private _invK22;
60
+ private _c0x;
61
+ private _c0y;
64
62
  private _biasRate;
65
63
  private _massScale;
66
64
  private _impulseScale;
@@ -1 +1 @@
1
- {"version":3,"file":"RevoluteJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/RevoluteJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,iHAAiH;IACjH,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC5B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wGAAwG;IACxG,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8FAA8F;IAC9F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,iDAAiD;IAC1C,KAAK,EAAE,MAAM,CAAC;IACrB,iCAAiC;IAC1B,YAAY,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IAClE,WAAW,EAAE,OAAO,CAAC;IA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