@codexo/exojs-physics 0.17.0 → 0.19.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 (91) hide show
  1. package/README.md +59 -97
  2. package/dist/esm/Aabb.d.ts.map +1 -1
  3. package/dist/esm/Collider.d.ts.map +1 -1
  4. package/dist/esm/Collider.js +18 -0
  5. package/dist/esm/Collider.js.map +1 -1
  6. package/dist/esm/ContactGraph.d.ts +34 -3
  7. package/dist/esm/ContactGraph.d.ts.map +1 -1
  8. package/dist/esm/ContactGraph.js +68 -5
  9. package/dist/esm/ContactGraph.js.map +1 -1
  10. package/dist/esm/PhysicsBody.d.ts.map +1 -1
  11. package/dist/esm/PhysicsBody.js +67 -6
  12. package/dist/esm/PhysicsBody.js.map +1 -1
  13. package/dist/esm/PhysicsBodyComponent.d.ts +45 -0
  14. package/dist/esm/PhysicsBodyComponent.d.ts.map +1 -0
  15. package/dist/esm/PhysicsBodyComponent.js +77 -0
  16. package/dist/esm/PhysicsBodyComponent.js.map +1 -0
  17. package/dist/esm/PhysicsWorld.d.ts +104 -9
  18. package/dist/esm/PhysicsWorld.d.ts.map +1 -1
  19. package/dist/esm/PhysicsWorld.js +235 -65
  20. package/dist/esm/PhysicsWorld.js.map +1 -1
  21. package/dist/esm/TimeStepper.d.ts.map +1 -1
  22. package/dist/esm/backend/NativePhysicsBackend.d.ts.map +1 -1
  23. package/dist/esm/binding/BindingRegistry.d.ts.map +1 -1
  24. package/dist/esm/binding/PhysicsBinding.d.ts +6 -2
  25. package/dist/esm/binding/PhysicsBinding.d.ts.map +1 -1
  26. package/dist/esm/binding/PhysicsBinding.js +8 -4
  27. package/dist/esm/binding/PhysicsBinding.js.map +1 -1
  28. package/dist/esm/binding/nodeWorldTransform.d.ts +18 -0
  29. package/dist/esm/binding/nodeWorldTransform.d.ts.map +1 -0
  30. package/dist/esm/binding/nodeWorldTransform.js +41 -0
  31. package/dist/esm/binding/nodeWorldTransform.js.map +1 -0
  32. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +22 -6
  33. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -1
  34. package/dist/esm/broadphase/AabbTreeBroadPhase.js +45 -11
  35. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -1
  36. package/dist/esm/collision/Manifold.d.ts.map +1 -1
  37. package/dist/esm/collision/dispatch.d.ts.map +1 -1
  38. package/dist/esm/collision/narrowphase.d.ts.map +1 -1
  39. package/dist/esm/collision/segments.d.ts.map +1 -1
  40. package/dist/esm/collision/sweep.d.ts.map +1 -1
  41. package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +1 -1
  42. package/dist/esm/debug/PhysicsDebugDraw.js +13 -11
  43. package/dist/esm/debug/PhysicsDebugDraw.js.map +1 -1
  44. package/dist/esm/index.js +2 -1
  45. package/dist/esm/joints/DistanceJoint.d.ts +2 -1
  46. package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
  47. package/dist/esm/joints/DistanceJoint.js +5 -5
  48. package/dist/esm/joints/DistanceJoint.js.map +1 -1
  49. package/dist/esm/joints/Joint.d.ts +59 -3
  50. package/dist/esm/joints/Joint.d.ts.map +1 -1
  51. package/dist/esm/joints/Joint.js +39 -3
  52. package/dist/esm/joints/Joint.js.map +1 -1
  53. package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
  54. package/dist/esm/joints/MouseJoint.js +1 -1
  55. package/dist/esm/joints/MouseJoint.js.map +1 -1
  56. package/dist/esm/joints/PrismaticJoint.d.ts +2 -1
  57. package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
  58. package/dist/esm/joints/PrismaticJoint.js +2 -2
  59. package/dist/esm/joints/PrismaticJoint.js.map +1 -1
  60. package/dist/esm/joints/RevoluteJoint.d.ts +4 -6
  61. package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
  62. package/dist/esm/joints/RevoluteJoint.js +39 -33
  63. package/dist/esm/joints/RevoluteJoint.js.map +1 -1
  64. package/dist/esm/joints/WeldJoint.d.ts +2 -1
  65. package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
  66. package/dist/esm/joints/WeldJoint.js +9 -9
  67. package/dist/esm/joints/WeldJoint.js.map +1 -1
  68. package/dist/esm/joints/WheelJoint.d.ts +2 -1
  69. package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
  70. package/dist/esm/joints/WheelJoint.js +5 -5
  71. package/dist/esm/joints/WheelJoint.js.map +1 -1
  72. package/dist/esm/math.d.ts.map +1 -1
  73. package/dist/esm/physicsBuildInfo.js +2 -2
  74. package/dist/esm/public.d.ts +2 -1
  75. package/dist/esm/public.d.ts.map +1 -1
  76. package/dist/esm/query/QueryEngine.d.ts.map +1 -1
  77. package/dist/esm/shapes/BoxShape.d.ts.map +1 -1
  78. package/dist/esm/shapes/CapsuleShape.d.ts +1 -1
  79. package/dist/esm/shapes/CapsuleShape.d.ts.map +1 -1
  80. package/dist/esm/shapes/ChainShape.d.ts +1 -1
  81. package/dist/esm/shapes/ChainShape.d.ts.map +1 -1
  82. package/dist/esm/shapes/CircleShape.d.ts +1 -1
  83. package/dist/esm/shapes/CircleShape.d.ts.map +1 -1
  84. package/dist/esm/shapes/PolygonShape.d.ts +1 -1
  85. package/dist/esm/shapes/PolygonShape.d.ts.map +1 -1
  86. package/dist/esm/shapes/SegmentShape.d.ts +1 -1
  87. package/dist/esm/shapes/SegmentShape.d.ts.map +1 -1
  88. package/dist/esm/shapes/convexParts.d.ts.map +1 -1
  89. package/dist/esm/solver/ContactSolver.d.ts.map +1 -1
  90. package/dist/esm/types.d.ts.map +1 -1
  91. package/package.json +5 -5
@@ -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,UAAW,MAAM,gBAAgB,MAAM,KAAK,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,EAIpF;CAYF"}
@@ -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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5B,KAAK,EAAE,MAAM,CAAC;IACrB,iCAAiC;IAC1B,YAAY,EAAE,MAAM,CAAC;IAC5B,6BAA6B;IACtB,QAAQ,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,WAAW,CAAK;IAExB,YAAmB,OAAO,EAAE,iBAAiB,EAe5C;IAED,mGAAmG;IACnG,IAAW,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,CAEvC;IAED,IAAW,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,EAI3C;IA2FD,OAAO,CAAC,aAAa;CAOtB"}
@@ -67,7 +67,7 @@ var MouseJoint = class extends Joint {
67
67
  this.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,AAAQ,MAAM;CACd,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,YAAY;CACpB,AAAQ,aAAa;CACrB,AAAQ,gBAAgB;CACxB,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAQ,cAAc;CAEtB,AAAO,YAAY,SAA4B;EAI7C,MAAM,IAAI,YAAY;GAAE,MAAM;GAAU,UAAU,QAAQ;EAAO,CAAC,GAAG,QAAQ,IAAI;EAEjF,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K,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.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,AAAQ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B,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,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,+CAA+C;IAC/C,KAAK,EAAE,WAAW,CAAC;IACnB,gCAAgC;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,6CAA6C;IAC7C,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC5B,kHAAkH;IAClH,IAAI,EAAE,QAAQ,CAAC,S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AM,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;IAE1B,YAAmB,OAAO,EAAE,qBAAqB,EA2BhD;IA0JD,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 b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BAAmB,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,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,AA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1B,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,EA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AO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,EAAE,CAAK;IACf,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;IAE1B,YAAmB,OAAO,EAAE,oBAAoB,EAmB/C;IA4MD,OAAO,CAAC,aAAa;CAWtB"}
@@ -37,11 +37,8 @@ var RevoluteJoint = class extends Joint {
37
37
  _rAy = 0;
38
38
  _rBx = 0;
39
39
  _rBy = 0;
40
- _cx = 0;
41
- _cy = 0;
42
- _invK11 = 0;
43
- _invK12 = 0;
44
- _invK22 = 0;
40
+ _c0x = 0;
41
+ _c0y = 0;
45
42
  _biasRate = 0;
46
43
  _massScale = 1;
47
44
  _impulseScale = 0;
@@ -55,7 +52,7 @@ var RevoluteJoint = class extends Joint {
55
52
  _lowerImpulse = 0;
56
53
  _upperImpulse = 0;
57
54
  constructor(options) {
58
- super(options.bodyA, options.bodyB);
55
+ super(options.bodyA, options.bodyB, options.collideConnected);
59
56
  applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
60
57
  this._localAnchorAx = scratch.x;
61
58
  this._localAnchorAy = scratch.y;
@@ -73,7 +70,7 @@ var RevoluteJoint = class extends Joint {
73
70
  this._referenceAngle = options.bodyB.angle - options.bodyA.angle;
74
71
  }
75
72
  /** @internal */
76
- _prepare(h) {
73
+ _prepare(h, rigid) {
77
74
  const bodyA = this.bodyA;
78
75
  const bodyB = this.bodyB;
79
76
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -88,20 +85,10 @@ var RevoluteJoint = class extends Joint {
88
85
  this._rAy = pAy - bodyA.worldCenterOfMassY;
89
86
  this._rBx = pBx - bodyB.worldCenterOfMassX;
90
87
  this._rBy = pBy - bodyB.worldCenterOfMassY;
91
- this._cx = pBx - pAx;
92
- this._cy = pBy - pAy;
93
- const mA = bodyA.invMass;
94
- const mB = bodyB.invMass;
88
+ this._c0x = pBx - pAx;
89
+ this._c0y = pBy - pAy;
95
90
  const iA = bodyA.invInertia;
96
91
  const iB = bodyB.invInertia;
97
- const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;
98
- const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;
99
- const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;
100
- const det = k11 * k22 - k12 * k12;
101
- const invDet = det !== 0 ? 1 / det : 0;
102
- this._invK11 = invDet * k22;
103
- this._invK12 = -invDet * k12;
104
- this._invK22 = invDet * k11;
105
92
  this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;
106
93
  this._h = h;
107
94
  this._invH = 1 / h;
@@ -119,9 +106,9 @@ var RevoluteJoint = class extends Joint {
119
106
  this._massScale = a2 * a3;
120
107
  this._impulseScale = a3;
121
108
  } else {
122
- this._biasRate = .2 / h;
123
- this._massScale = 1;
124
- this._impulseScale = 0;
109
+ this._biasRate = rigid.biasRate;
110
+ this._massScale = rigid.massScale;
111
+ this._impulseScale = rigid.impulseScale;
125
112
  }
126
113
  }
127
114
  /** @internal */
@@ -130,7 +117,13 @@ var RevoluteJoint = class extends Joint {
130
117
  const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
131
118
  this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;
132
119
  this.bodyB.angularVelocity += this.bodyB.invInertia * axial;
133
- this._applyImpulse(this._impulseX, this._impulseY);
120
+ const bodyA = this.bodyA;
121
+ const bodyB = this.bodyB;
122
+ const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;
123
+ const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;
124
+ const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;
125
+ const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;
126
+ this._applyImpulse(this._impulseX, this._impulseY, rotAx, rotAy, rotBx, rotBy);
134
127
  }
135
128
  /** @internal */
136
129
  _solve(useBias) {
@@ -169,27 +162,40 @@ var RevoluteJoint = class extends Joint {
169
162
  bodyA.angularVelocity += iA * appliedUpper;
170
163
  bodyB.angularVelocity -= iB * appliedUpper;
171
164
  }
172
- const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);
173
- const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);
174
- const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);
175
- const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);
176
- const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;
177
- const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;
165
+ const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;
166
+ const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;
167
+ const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;
168
+ const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;
169
+ const cx = this._c0x + (bodyB._deltaPosX + rotBx - this._rBx) - (bodyA._deltaPosX + rotAx - this._rAx);
170
+ const cy = this._c0y + (bodyB._deltaPosY + rotBy - this._rBy) - (bodyA._deltaPosY + rotAy - this._rAy);
171
+ const mA = bodyA.invMass;
172
+ const mB = bodyB.invMass;
173
+ const k11 = mA + mB + iA * rotAy * rotAy + iB * rotBy * rotBy;
174
+ const k12 = -iA * rotAx * rotAy - iB * rotBx * rotBy;
175
+ const k22 = mA + mB + iA * rotAx * rotAx + iB * rotBx * rotBx;
176
+ const det = k11 * k22 - k12 * k12;
177
+ const invDet = det !== 0 ? 1 / det : 0;
178
+ const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * rotBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rotAy);
179
+ const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * rotBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rotAx);
180
+ const rhsX = cdotX + (useBias ? this._biasRate * cx : 0);
181
+ const rhsY = cdotY + (useBias ? this._biasRate * cy : 0);
182
+ const solvedX = invDet * (k22 * rhsX - k12 * rhsY);
183
+ const solvedY = invDet * (k11 * rhsY - k12 * rhsX);
178
184
  const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;
179
185
  const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;
180
186
  this._impulseX += impulseX;
181
187
  this._impulseY += impulseY;
182
- this._applyImpulse(impulseX, impulseY);
188
+ this._applyImpulse(impulseX, impulseY, rotAx, rotAy, rotBx, rotBy);
183
189
  }
184
- _applyImpulse(jx, jy) {
190
+ _applyImpulse(jx, jy, rAx, rAy, rBx, rBy) {
185
191
  const bodyA = this.bodyA;
186
192
  const bodyB = this.bodyB;
187
193
  bodyA.linearVelocityX -= bodyA.invMass * jx;
188
194
  bodyA.linearVelocityY -= bodyA.invMass * jy;
189
- bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);
195
+ bodyA.angularVelocity -= bodyA.invInertia * (rAx * jy - rAy * jx);
190
196
  bodyB.linearVelocityX += bodyB.invMass * jx;
191
197
  bodyB.linearVelocityY += bodyB.invMass * jy;
192
- bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);
198
+ bodyB.angularVelocity += bodyB.invInertia * (rBx * jy - rBy * jx);
193
199
  }
194
200
  };
195
201
 
@@ -1 +1 @@
1
- {"version":3,"file":"RevoluteJoint.js","names":[],"sources":["../../../src/joints/RevoluteJoint.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 RevoluteJoint}. */\nexport interface RevoluteJointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */\n anchor: Readonly<PointLike>;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /** Enable the angular motor (drives `ωB − ωA` toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */\n motorSpeed?: number;\n /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */\n maxMotorTorque?: number;\n /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower relative-angle limit in radians (relative to the angle at creation). Default `0`. */\n lowerAngle?: number;\n /** Upper relative-angle limit in radians. Default `0`. */\n upperAngle?: 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 * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate\n * freely about the pivot but the anchor points stay coincident. Solved as a\n * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.\n */\nexport class RevoluteJoint extends Joint {\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target relative angular velocity (rad/s) for the motor. */\n public motorSpeed: number;\n /** Maximum motor torque. */\n public maxMotorTorque: number;\n /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */\n public enableLimit: boolean;\n /** Lower relative-angle limit (radians, relative to the creation angle). */\n public lowerAngle: number;\n /** Upper relative-angle limit (radians). */\n public upperAngle: number;\n\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 _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 readonly _referenceAngle: number;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: RevoluteJointOptions) {\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 this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorTorque = options.maxMotorTorque ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerAngle = options.lowerAngle ?? 0;\n this.upperAngle = options.upperAngle ?? 0;\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\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 // Position error (the anchors should coincide).\n this._cx = pBx - pAx;\n this._cy = pBy - pAy;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // 2×2 effective-mass matrix K and its inverse.\n const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;\n const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;\n const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;\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\n // Angular (motor/limit) effective mass + sub-step rate.\n this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;\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 if (this.hertz > 0) {\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 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 return;\n }\n\n // Angular warm-start: motor + limits (lower pushes +, upper pushes −).\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;\n this.bodyB.angularVelocity += this.bodyB.invInertia * axial;\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 bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // Angular motor: drive ωB − ωA toward motorSpeed, clamped to ±maxMotorTorque·h.\n if (this.enableMotor) {\n const cdot = bodyB.angularVelocity - bodyA.angularVelocity - this.motorSpeed;\n const max = this.maxMotorTorque * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n\n const applied = this._motorImpulse - old;\n bodyA.angularVelocity -= iA * applied;\n bodyB.angularVelocity += iB * applied;\n }\n\n // Angle limits: one-sided constraints keeping the relative angle in [lower, upper].\n if (this.enableLimit) {\n const angle = bodyB.angle + bodyB._deltaAngle - (bodyA.angle + bodyA._deltaAngle) - this._referenceAngle;\n\n // Lower limit (angle ≥ lowerAngle): a positive impulse increases the angle.\n const cLower = angle - this.lowerAngle;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH; // speculative: allow approach, engage at the surface\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower; // Baumgarte push-back when violated\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (bodyB.angularVelocity - bodyA.angularVelocity + biasLower));\n\n const appliedLower = this._lowerImpulse - oldLower;\n bodyA.angularVelocity -= iA * appliedLower;\n bodyB.angularVelocity += iB * appliedLower;\n\n // Upper limit (angle ≤ upperAngle): a positive impulse decreases the angle.\n const cUpper = this.upperAngle - angle;\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 * (bodyA.angularVelocity - bodyB.angularVelocity + biasUpper));\n\n const appliedUpper = this._upperImpulse - oldUpper;\n bodyA.angularVelocity += iA * appliedUpper;\n bodyB.angularVelocity -= iB * appliedUpper;\n }\n\n // Relative velocity of the anchors.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);\n\n const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);\n\n // Solve K·λ = −rhs, then apply the soft mass/impulse scaling.\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyImpulse(impulseX, impulseY);\n }\n\n private _applyImpulse(jx: number, jy: number): void {\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":";;;;;AAiCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;AAOxC,IAAa,gBAAb,cAAmC,MAAM;;CAEvC,AAAO;;C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AAK,aAAa;EAClB,KAAK,cAAc,UAAU,QAAQ;CACvC;CAEA,AAAQ,cAAc,IAAY,IAAkB;EAClD,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":"RevoluteJoint.js","names":[],"sources":["../../../src/joints/RevoluteJoint.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 RevoluteJoint}. */\nexport interface RevoluteJointOptions extends JointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */\n anchor: Readonly<PointLike>;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /** Enable the angular motor (drives `ωB − ωA` toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */\n motorSpeed?: number;\n /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */\n maxMotorTorque?: number;\n /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower relative-angle limit in radians (relative to the angle at creation). Default `0`. */\n lowerAngle?: number;\n /** Upper relative-angle limit in radians. Default `0`. */\n upperAngle?: 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 * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate\n * freely about the pivot but the anchor points stay coincident. Solved as a\n * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.\n */\nexport class RevoluteJoint extends Joint {\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target relative angular velocity (rad/s) for the motor. */\n public motorSpeed: number;\n /** Maximum motor torque. */\n public maxMotorTorque: number;\n /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */\n public enableLimit: boolean;\n /** Lower relative-angle limit (radians, relative to the creation angle). */\n public lowerAngle: number;\n /** Upper relative-angle limit (radians). */\n public upperAngle: number;\n\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 _c0x = 0;\n private _c0y = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private readonly _referenceAngle: number;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: RevoluteJointOptions) {\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 this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorTorque = options.maxMotorTorque ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerAngle = options.lowerAngle ?? 0;\n this.upperAngle = options.upperAngle ?? 0;\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\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 // Frame-start arms and anchor error. Both are the BASE the sub-step solve\n // advances from; neither is used directly as the constraint's current state.\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 this._c0x = pBx - pAx;\n this._c0y = pBy - pAy;\n\n // Angular (motor/limit) effective mass + sub-step rate.\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;\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 if (this.hertz > 0) {\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, not a raw Baumgarte term. `0.2 / h` turns\n // the whole position error into a bias velocity every sub-step and\n // relaxes none of the impulse behind it; a hanging chain of seven or more\n // links then gains speed without bound along its own axis.\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 return;\n }\n\n // Angular warm-start: motor + limits (lower pushes +, upper pushes −).\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;\n this.bodyB.angularVelocity += this.bodyB.invInertia * axial;\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;\n const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;\n const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;\n const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;\n\n this._applyImpulse(this._impulseX, this._impulseY, rotAx, rotAy, rotBx, rotBy);\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 const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // Angular motor: drive ωB − ωA toward motorSpeed, clamped to ±maxMotorTorque·h.\n if (this.enableMotor) {\n const cdot = bodyB.angularVelocity - bodyA.angularVelocity - this.motorSpeed;\n const max = this.maxMotorTorque * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n\n const applied = this._motorImpulse - old;\n bodyA.angularVelocity -= iA * applied;\n bodyB.angularVelocity += iB * applied;\n }\n\n // Angle limits: one-sided constraints keeping the relative angle in [lower, upper].\n if (this.enableLimit) {\n const angle = bodyB.angle + bodyB._deltaAngle - (bodyA.angle + bodyA._deltaAngle) - this._referenceAngle;\n\n // Lower limit (angle ≥ lowerAngle): a positive impulse increases the angle.\n const cLower = angle - this.lowerAngle;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH; // speculative: allow approach, engage at the surface\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower; // Baumgarte push-back when violated\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (bodyB.angularVelocity - bodyA.angularVelocity + biasLower));\n\n const appliedLower = this._lowerImpulse - oldLower;\n bodyA.angularVelocity -= iA * appliedLower;\n bodyB.angularVelocity += iB * appliedLower;\n\n // Upper limit (angle ≤ upperAngle): a positive impulse decreases the angle.\n const cUpper = this.upperAngle - angle;\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 * (bodyA.angularVelocity - bodyB.angularVelocity + biasUpper));\n\n const appliedUpper = this._upperImpulse - oldUpper;\n bodyA.angularVelocity += iA * appliedUpper;\n bodyB.angularVelocity -= iB * appliedUpper;\n }\n\n /*\n * The point constraint is solved against the geometry as it stands NOW, not\n * as it stood at frame start.\n *\n * Each sub-step moves the bodies, so the arms have rotated and the anchors\n * have separated by a different amount than `_prepare` measured. Applying\n * the frame-start error as the bias in every sub-step re-corrects an error\n * the earlier sub-steps already took out - and with a rigid bias rate of\n * `0.2 / h` that over-correction is an impulse the chain has no way to\n * dissipate. In a serial chain it compounds link by link: a hanging chain\n * of seven or more equal links left to itself gained velocity without\n * bound, purely along its own axis, until it diverged. The contact solver\n * has always advanced its separation this way; the joint now does too.\n */\n const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;\n const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;\n const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;\n const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;\n\n // Anchor displacement since frame start: linear delta plus the shift the\n // body's own rotation gave the arm.\n const cx = this._c0x + (bodyB._deltaPosX + rotBx - this._rBx) - (bodyA._deltaPosX + rotAx - this._rAx);\n const cy = this._c0y + (bodyB._deltaPosY + rotBy - this._rBy) - (bodyA._deltaPosY + rotAy - this._rAy);\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n\n // K follows the live arms for the same reason the bias does: an effective\n // mass built from the frame-start geometry solves a different constraint\n // than the one the bias is now asking for.\n const k11 = mA + mB + iA * rotAy * rotAy + iB * rotBy * rotBy;\n const k12 = -iA * rotAx * rotAy - iB * rotBx * rotBy;\n const k22 = mA + mB + iA * rotAx * rotAx + iB * rotBx * rotBx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n // Relative velocity of the anchors.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * rotBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rotAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * rotBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rotAx);\n\n const rhsX = cdotX + (useBias ? this._biasRate * cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * cy : 0);\n\n // Solve K·λ = −rhs, then apply the soft mass/impulse scaling.\n const solvedX = invDet * (k22 * rhsX - k12 * rhsY);\n const solvedY = invDet * (k11 * rhsY - k12 * rhsX);\n const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyImpulse(impulseX, impulseY, rotAx, rotAy, rotBx, rotBy);\n }\n\n private _applyImpulse(jx: number, jy: number, rAx: number, rAy: number, rBx: number, rBy: number): void {\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 * (rAx * jy - rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (rBx * jy - rBy * jx);\n }\n}\n"],"mappings":";;;;;AAkCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;AAOxC,IAAa,gBAAb,cAAmC,MAAM;;CAEvC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,YAAY;CACpB,AAAQ,aAAa;CACrB,AAAQ,gBAAgB;CACxB,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAiB;CACjB,AAAQ,aAAa;CACrB,AAAQ,KAAK;CACb,AAAQ,QAAQ;CAChB,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CAExB,AAAO,YAAY,SAA+B;EAChD,MAAM,QAAQ,OAAO,QAAQ,OAAO,QAAQ,gBAAgB;EAE5D,sBAAsB,QAAQ,MAAM,WAAW,QAAQ,OAAO,GAAG,QAAQ,OAAO,GAAG,OAAO;EAC1F,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,iBAAiB,QAAQ;EAC9B,sBAAsB,QAAQ,MAAM,WAAW,QAAQ,OAAO,GAAG,QAAQ,OAAO,GAAG,OAAO;EAC1F,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,iBAAiB,QAAQ;EAE9B,KAAK,QAAQ,QAAQ,SAAS;EAC9B,KAAK,eAAe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mB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,MAAM,KAAK,MAAM;CAChE;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 WeldJoint}. */
5
- export interface WeldJointOptions {
6
+ export interface WeldJointOptions extends JointOptions {
6
7
  /** First body. */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body. */
@@ -1 +1 @@
1
- {"version":3,"file":"WeldJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/WeldJoint.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,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,iGAAiG;IACjG,MAAM,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7B,gGAAgG;IAChG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6BD;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,+CAA+C;IACxC,cAAc,EAAE,MAAM,CAAC;IAC9B,0DAA0D;IACnD,WAAW,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IAChD,YAAY,EAAE,MAAM,CAAC;IAC5B,0BAA0B;IACnB,YAAY,EAAE,MAAM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mBAAmB;CAW5B"}
@@ -7,8 +7,8 @@ const scratch = {
7
7
  x: 0,
8
8
  y: 0
9
9
  };
10
- /** Box2D-v3 soft-constraint factors at sub-step `h`, or rigid Baumgarte when `hertz === 0`. */
11
- const computeSoftFactors = (hertz, dampingRatio, h, out) => {
10
+ /** Soft-constraint factors at sub-step `h`, or the solver's own rigid factors when `hertz === 0`. */
11
+ const computeSoftFactors = (hertz, dampingRatio, h, rigid, out) => {
12
12
  if (hertz > 0) {
13
13
  const omega = 2 * Math.PI * hertz;
14
14
  const a1 = 2 * dampingRatio + h * omega;
@@ -18,9 +18,9 @@ const computeSoftFactors = (hertz, dampingRatio, h, out) => {
18
18
  out.massScale = a2 * a3;
19
19
  out.impulseScale = a3;
20
20
  } else {
21
- out.biasRate = .2 / h;
22
- out.massScale = 1;
23
- out.impulseScale = 0;
21
+ out.biasRate = rigid.biasRate;
22
+ out.massScale = rigid.massScale;
23
+ out.impulseScale = rigid.impulseScale;
24
24
  }
25
25
  };
26
26
  /**
@@ -67,7 +67,7 @@ var WeldJoint = class extends Joint {
67
67
  _impulseY = 0;
68
68
  _impulseAngle = 0;
69
69
  constructor(options) {
70
- super(options.bodyA, options.bodyB);
70
+ super(options.bodyA, options.bodyB, options.collideConnected);
71
71
  const ax = options.anchor?.x ?? (options.bodyA.x + options.bodyB.x) / 2;
72
72
  const ay = options.anchor?.y ?? (options.bodyA.y + options.bodyB.y) / 2;
73
73
  applyInverseTransform(options.bodyA.transform, ax, ay, scratch);
@@ -82,7 +82,7 @@ var WeldJoint = class extends Joint {
82
82
  this.dampingRatio = options.dampingRatio ?? 1;
83
83
  }
84
84
  /** @internal */
85
- _prepare(h) {
85
+ _prepare(h, rigid) {
86
86
  const bodyA = this.bodyA;
87
87
  const bodyB = this.bodyB;
88
88
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -114,8 +114,8 @@ var WeldJoint = class extends Joint {
114
114
  this._angleError = bodyB.angle - bodyA.angle - this.referenceAngle;
115
115
  const kAngle = iA + iB;
116
116
  this._effMassAngle = kAngle > 0 ? 1 / kAngle : 0;
117
- computeSoftFactors(this.linearHertz, this.dampingRatio, h, this._linear);
118
- computeSoftFactors(this.angularHertz, this.dampingRatio, h, this._angular);
117
+ computeSoftFactors(this.linearHertz, this.dampingRatio, h, rigid, this._linear);
118
+ computeSoftFactors(this.angularHertz, this.dampingRatio, h, rigid, this._angular);
119
119
  }
120
120
  /** @internal */
121
121
  _warmStart() {