@codexo/exojs-physics 0.16.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -45
- package/dist/esm/Collider.d.ts +0 -33
- package/dist/esm/Collider.d.ts.map +1 -1
- package/dist/esm/Collider.js +10 -1
- package/dist/esm/Collider.js.map +1 -1
- package/dist/esm/ContactGraph.d.ts +22 -14
- package/dist/esm/ContactGraph.d.ts.map +1 -1
- package/dist/esm/ContactGraph.js +43 -5
- package/dist/esm/ContactGraph.js.map +1 -1
- package/dist/esm/ContactModifier.d.ts +0 -23
- package/dist/esm/ContactModifier.d.ts.map +1 -1
- package/dist/esm/PhysicsBody.d.ts +0 -81
- package/dist/esm/PhysicsBody.d.ts.map +1 -1
- package/dist/esm/PhysicsBody.js +37 -8
- package/dist/esm/PhysicsBody.js.map +1 -1
- package/dist/esm/PhysicsWorld.d.ts +63 -41
- package/dist/esm/PhysicsWorld.d.ts.map +1 -1
- package/dist/esm/PhysicsWorld.js +162 -36
- package/dist/esm/PhysicsWorld.js.map +1 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +22 -6
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +45 -11
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -1
- package/dist/esm/collision/chainAdjacency.d.ts +1 -28
- package/dist/esm/collision/chainAdjacency.d.ts.map +1 -1
- package/dist/esm/joints/DistanceJoint.d.ts +2 -4
- package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
- package/dist/esm/joints/DistanceJoint.js +8 -5
- package/dist/esm/joints/DistanceJoint.js.map +1 -1
- package/dist/esm/joints/Joint.d.ts +59 -9
- package/dist/esm/joints/Joint.d.ts.map +1 -1
- package/dist/esm/joints/Joint.js +39 -3
- package/dist/esm/joints/Joint.js.map +1 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -3
- package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
- package/dist/esm/joints/MouseJoint.js +4 -1
- package/dist/esm/joints/MouseJoint.js.map +1 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +2 -4
- package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
- package/dist/esm/joints/PrismaticJoint.js +5 -2
- package/dist/esm/joints/PrismaticJoint.js.map +1 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +4 -9
- package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
- package/dist/esm/joints/RevoluteJoint.js +42 -33
- package/dist/esm/joints/RevoluteJoint.js.map +1 -1
- package/dist/esm/joints/WeldJoint.d.ts +2 -4
- package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
- package/dist/esm/joints/WeldJoint.js +12 -9
- package/dist/esm/joints/WeldJoint.js.map +1 -1
- package/dist/esm/joints/WheelJoint.d.ts +2 -4
- package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
- package/dist/esm/joints/WheelJoint.js +8 -5
- package/dist/esm/joints/WheelJoint.js.map +1 -1
- package/dist/esm/physicsBuildInfo.js +2 -2
- package/dist/esm/public.d.ts +1 -1
- package/dist/esm/public.d.ts.map +1 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +1 -29
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -6
- package/dist/esm/shapes/ChainShape.d.ts.map +1 -1
- package/dist/esm/shapes/decompose.d.ts +1 -23
- package/dist/esm/shapes/decompose.d.ts.map +1 -1
- package/dist/esm/solver/ContactSolver.d.ts.map +1 -1
- package/dist/esm/solver/ContactSolver.js +16 -3
- package/dist/esm/solver/ContactSolver.js.map +1 -1
- package/dist/esm/solver/tolerances.d.ts +1 -33
- package/dist/esm/solver/tolerances.d.ts.map +1 -1
- package/dist/esm/solver/tolerances.js +14 -16
- package/dist/esm/solver/tolerances.js.map +1 -1
- package/dist/esm/sort.d.ts +1 -17
- package/dist/esm/sort.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,16 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Native 2D **rigid-body** runtime for [ExoJS](https://github.com/Exoridus/ExoJS).
|
|
4
4
|
|
|
5
|
-
Zero production dependencies, ESM-only, version-locked with the core engine.
|
|
6
|
-
It ships a fixed-step world with a warm-started **TGS-Soft** solver: shapes,
|
|
7
|
-
colliders, bodies, a dynamic-AABB broad phase, a manifold-generating narrow
|
|
8
|
-
phase, joints, sleeping islands, continuous collision for fast bodies, a
|
|
9
|
-
per-contact modifier, collision filters, sensors, events, spatial queries,
|
|
10
|
-
scene-node binding with interpolation, and a debug overlay.
|
|
5
|
+
Zero production dependencies, ESM-only, version-locked with the core engine. It ships a fixed-step world with a warm-started **TGS-Soft** solver: shapes, colliders, bodies, a dynamic-AABB broad phase, a manifold-generating narrow phase, joints, sleeping islands, continuous collision for fast bodies, a per-contact modifier, collision filters, sensors, events, spatial queries, scene-node binding with interpolation, and a debug overlay.
|
|
11
6
|
|
|
12
|
-
> **Library, not an extension.** Physics contributes no renderer or asset
|
|
13
|
-
> bindings, so there is no `/register` entry. Construct a `PhysicsWorld`
|
|
14
|
-
> directly. `@codexo/exojs` is a peer dependency.
|
|
7
|
+
> **Library, not an extension.** Physics contributes no renderer or asset bindings, so there is no `/register` entry. Construct a `PhysicsWorld` directly. `@codexo/exojs` is a peer dependency.
|
|
15
8
|
|
|
16
9
|
## Install
|
|
17
10
|
|
|
@@ -22,7 +15,7 @@ npm install @codexo/exojs @codexo/exojs-physics
|
|
|
22
15
|
## Quick start
|
|
23
16
|
|
|
24
17
|
```ts
|
|
25
|
-
import { Scene,
|
|
18
|
+
import { Scene, type Seconds, Vector } from '@codexo/exojs';
|
|
26
19
|
import { BoxShape, CircleShape, Collider, PhysicsBody, PhysicsWorld } from '@codexo/exojs-physics';
|
|
27
20
|
|
|
28
21
|
class GameScene extends Scene {
|
|
@@ -49,8 +42,8 @@ class GameScene extends Scene {
|
|
|
49
42
|
});
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
public override update(delta:
|
|
53
|
-
this.world.step(delta
|
|
45
|
+
public override update(delta: Seconds): void {
|
|
46
|
+
this.world.step(delta); // fixed-step detection + events + binding
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
49
|
```
|
|
@@ -75,42 +68,17 @@ class GameScene extends Scene {
|
|
|
75
68
|
| Binding | `bind(body, node)` — node tracks the body's position each step |
|
|
76
69
|
| Debug | `@codexo/exojs-physics/debug` → `PhysicsDebugDraw` (shapes/AABBs/contacts/normals/centres/broad-phase/joints) |
|
|
77
70
|
|
|
78
|
-
Building a level out of a tilemap? `@codexo/exojs-tilemap-physics` turns
|
|
79
|
-
`@codexo/exojs-tilemap` collision geometry into static bodies and keeps them in
|
|
80
|
-
sync with streamed chunks.
|
|
71
|
+
Building a level out of a tilemap? `@codexo/exojs-tilemap-physics` turns `@codexo/exojs-tilemap` collision geometry into static bodies and keeps them in sync with streamed chunks.
|
|
81
72
|
|
|
82
73
|
## Determinism & non-goals
|
|
83
74
|
|
|
84
|
-
Stepping is fully **caller-driven** and uses a fixed timestep with an
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
`step()` owns its own fixed-timestep accumulator, so you can drive it from
|
|
92
|
-
either the engine's `Scene.fixedUpdate` (already a constant-rate hook — the
|
|
93
|
-
idiomatic choice) or straight from `Scene.update`'s raw, variable per-frame
|
|
94
|
-
delta; either way `step` converts whatever it's given into the right number of
|
|
95
|
-
fixed sub-steps. See the "Stepping the world" section of the
|
|
96
|
-
[physics guide](https://exoridus.github.io/ExoJS/en/guide/physics/physics-basics/)
|
|
97
|
-
for the details and an interpolation note (`world.timeStepper.alpha`).
|
|
98
|
-
|
|
99
|
-
**Broad-phase scale.** Collision detection uses a dynamic AABB tree
|
|
100
|
-
(Box2D-style), incrementally updated across steps: a collider whose AABB
|
|
101
|
-
stays within its stored margin is never reinserted, so the dominant cost
|
|
102
|
-
tracks how much actually moved rather than the total live collider count
|
|
103
|
-
(there's still a cheap linear pass over all live colliders each step). Scales
|
|
104
|
-
to tens of thousands of simultaneously-live colliders.
|
|
105
|
-
|
|
106
|
-
**Solid and boundary geometry.** `CircleShape`, `CapsuleShape`, `PolygonShape`
|
|
107
|
-
and `BoxShape` enclose an area and carry mass; `SegmentShape` and `ChainShape`
|
|
108
|
-
are boundaries with no interior, so they contribute collision only and a
|
|
109
|
-
`dynamic` body needs at least one solid collider alongside them. A chain is one
|
|
110
|
-
authored collider that the engine solves edge by edge with shared-vertex
|
|
111
|
-
adjacency, so a body slides across a seam without snagging. Two boundaries never
|
|
112
|
-
collide with each other, and a boundary is never the _moving_ operand of a
|
|
113
|
-
continuous shape cast — level structure is swept against, not swept.
|
|
75
|
+
Stepping is fully **caller-driven** and uses a fixed timestep with an accumulator (`world.step(frameDeltaSeconds)`); the same build replays a scene identically given the same inputs. There are **no rollback/lockstep determinism guarantees across builds or machines** (floating-point reality). The package is single-threaded and 2D only — no workers, GPU, 3D, soft bodies, fluids or vehicles.
|
|
76
|
+
|
|
77
|
+
`step()` owns its own fixed-timestep accumulator, so you can drive it from either the engine's `Scene.fixedUpdate` (already a constant-rate hook — the idiomatic choice) or straight from `Scene.update`'s raw, variable per-frame delta; either way `step` converts whatever it's given into the right number of fixed sub-steps. See the "Stepping the world" section of the [physics guide](https://exoridus.github.io/ExoJS/en/guide/physics/physics-basics/) for the details and an interpolation note (`world.timeStepper.alpha`).
|
|
78
|
+
|
|
79
|
+
**Broad-phase scale.** Collision detection uses a dynamic AABB tree (Box2D-style), incrementally updated across steps: a collider whose AABB stays within its stored margin is never reinserted, so the dominant cost tracks how much actually moved rather than the total live collider count (there's still a cheap linear pass over all live colliders each step). Scales to tens of thousands of simultaneously-live colliders.
|
|
80
|
+
|
|
81
|
+
**Solid and boundary geometry.** `CircleShape`, `CapsuleShape`, `PolygonShape` and `BoxShape` enclose an area and carry mass; `SegmentShape` and `ChainShape` are boundaries with no interior, so they contribute collision only and a `dynamic` body needs at least one solid collider alongside them. A chain is one authored collider that the engine solves edge by edge with shared-vertex adjacency, so a body slides across a seam without snagging. Two boundaries never collide with each other, and a boundary is never the _moving_ operand of a continuous shape cast — level structure is swept against, not swept.
|
|
114
82
|
|
|
115
83
|
## License
|
|
116
84
|
|
package/dist/esm/Collider.d.ts
CHANGED
|
@@ -55,15 +55,6 @@ export declare class Collider {
|
|
|
55
55
|
private readonly _worldVertices;
|
|
56
56
|
private readonly _worldNormals;
|
|
57
57
|
private _destroyed;
|
|
58
|
-
/**
|
|
59
|
-
* @internal - proxy id in the physics world's broad-phase spatial tree; `-1`
|
|
60
|
-
* when not inserted. Like `PhysicsBody._islandIndex`/`_sleepTime`, this is a
|
|
61
|
-
* single-owner slot: exactly ONE `AabbTreeBroadPhase` may track this collider
|
|
62
|
-
* at a time (in production, the world's own broad phase for the collider's
|
|
63
|
-
* whole lifetime). A second broad phase over the same collider would clobber
|
|
64
|
-
* this value and corrupt the first's tree - never do that.
|
|
65
|
-
*/
|
|
66
|
-
_treeProxy: number;
|
|
67
58
|
constructor(options: ColliderOptions);
|
|
68
59
|
/** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */
|
|
69
60
|
get id(): number;
|
|
@@ -84,17 +75,6 @@ export declare class Collider {
|
|
|
84
75
|
get worldVertices(): readonly number[];
|
|
85
76
|
/** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */
|
|
86
77
|
get worldNormals(): readonly number[];
|
|
87
|
-
/**
|
|
88
|
-
* @internal - the engine-owned edge proxies a chain collider fans out into,
|
|
89
|
-
* one per chain edge; `null` for every other shape. They are what the broad
|
|
90
|
-
* phase, the narrow phase and the solver see, so a chain contact reuses the
|
|
91
|
-
* one-manifold-per-pair model unchanged. They are never part of
|
|
92
|
-
* `body.colliders`, `world.colliders` or any query result - the authored
|
|
93
|
-
* collider is the public identity of every contact they produce.
|
|
94
|
-
*/
|
|
95
|
-
get chainEdges(): readonly Collider[] | null;
|
|
96
|
-
/** @internal - the authored chain collider this edge proxy belongs to; `null` for an authored collider. */
|
|
97
|
-
get chainParent(): Collider | null;
|
|
98
78
|
/** `true` after the owning world has destroyed this collider. */
|
|
99
79
|
get destroyed(): boolean;
|
|
100
80
|
/**
|
|
@@ -117,24 +97,11 @@ export declare class Collider {
|
|
|
117
97
|
* capsule's spine); it is `0` for a plain polygon.
|
|
118
98
|
*/
|
|
119
99
|
private _synchronizePolygon;
|
|
120
|
-
/** @internal - bind this collider to its body and id (called when the body joins a world). */
|
|
121
|
-
_attach(body: PhysicsBody, id: number): void;
|
|
122
100
|
/**
|
|
123
101
|
* Fan a chain out into one proxy per edge. Each proxy carries the chain's own
|
|
124
102
|
* local placement, so it needs no transform of its own, and its shape carries
|
|
125
103
|
* the adjacency that keeps a body from snagging at a shared vertex.
|
|
126
104
|
*/
|
|
127
105
|
private _buildChainEdges;
|
|
128
|
-
/** Internal: mark destroyed (called by the world). */
|
|
129
|
-
_markDestroyed(): void;
|
|
130
106
|
}
|
|
131
|
-
/**
|
|
132
|
-
* The authored collider a contact, query hit or sweep target belongs to: the
|
|
133
|
-
* collider itself, or the chain it is an engine-owned edge proxy of. Every
|
|
134
|
-
* public identity - events, query results, the contact modifier - goes through
|
|
135
|
-
* this, so a solver-side partition never reaches a caller.
|
|
136
|
-
*
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
export declare const authoredCollider: (collider: Collider) => Collider;
|
|
140
107
|
//# sourceMappingURL=Collider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collider.d.ts","sourceRoot":"","sources":["../../src/Collider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,E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W,YAAY,IAAI,SAAS,MAAM,EAAE,CAE3C;IAmBD,iEAAiE;IACjE,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;;;OAIG;IACI,WAAW,CAAC,aAAa,EAAE,SAAS,GAAG,IAAI;IA0BlD;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAwBzB,gFAAgF;IAChF,OAAO,CAAC,kBAAkB;IAS1B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAiC3B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CA+BzB"}
|
package/dist/esm/Collider.js
CHANGED
|
@@ -61,6 +61,14 @@ var Collider = class Collider {
|
|
|
61
61
|
* this value and corrupt the first's tree - never do that.
|
|
62
62
|
*/
|
|
63
63
|
_treeProxy = -1;
|
|
64
|
+
/**
|
|
65
|
+
* @internal - whether {@link aabb} has changed since the owning broad phase
|
|
66
|
+
* last looked at it. Set by every write to the AABB ({@link synchronize} is
|
|
67
|
+
* the only one) and cleared when the broad phase has taken the new box, so a
|
|
68
|
+
* resting collider costs nothing to re-sync. Single-owner like
|
|
69
|
+
* {@link _treeProxy}, and for the same reason.
|
|
70
|
+
*/
|
|
71
|
+
_treeDirty = true;
|
|
64
72
|
constructor(options) {
|
|
65
73
|
const density = options.density ?? 1;
|
|
66
74
|
if (!Number.isFinite(density) || density < 0) throw new RangeError(`Collider: density must be a non-negative finite number, received ${density}.`);
|
|
@@ -141,6 +149,7 @@ var Collider = class Collider {
|
|
|
141
149
|
*/
|
|
142
150
|
synchronize(bodyTransform) {
|
|
143
151
|
const world = composeTransforms(bodyTransform, this._localTransform, this._worldTransform);
|
|
152
|
+
this._treeDirty = true;
|
|
144
153
|
switch (this.shape.type) {
|
|
145
154
|
case "circle":
|
|
146
155
|
this._synchronizeCircle(world, this.shape.radius);
|
|
@@ -245,7 +254,7 @@ var Collider = class Collider {
|
|
|
245
254
|
}
|
|
246
255
|
return edges;
|
|
247
256
|
}
|
|
248
|
-
/**
|
|
257
|
+
/** @internal - mark destroyed (called by the world). */
|
|
249
258
|
_markDestroyed() {
|
|
250
259
|
this._destroyed = true;
|
|
251
260
|
if (this._chainEdges !== null) for (const edge of this._chainEdges) edge._destroyed = true;
|
package/dist/esm/Collider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collider.js","names":[],"sources":["../../src/Collider.ts"],"sourcesContent":["import type { AabbLike, PointLike } from '@codexo/exojs';\n\nimport { createAabb } from './Aabb';\nimport type { Transform } from './math';\nimport { applyRotation, applyTransform, composeTransforms, createTransform } from './math';\nimport type { PhysicsBody } from './PhysicsBody';\nimport type { AnyShape } from './shapes/AnyShape';\nimport type { ChainShape } from './shapes/ChainShape';\nimport type { CollisionFilter } from './types';\nimport { resolveFilter } from './types';\n\n/** Number of world-space vertices a shape kind caches on its collider. */\nconst worldVertexCount = (shape: AnyShape): number => {\n switch (shape.type) {\n case 'polygon':\n return shape.count;\n case 'capsule':\n case 'segment':\n // Two endpoints. Both are a two-vertex ring, with and without a radius.\n return 2;\n case 'circle':\n case 'chain':\n // A chain caches nothing of its own: its geometry lives on the per-edge\n // child proxies, and its AABB is the union of theirs.\n return 0;\n }\n};\n\n/** Construction options for a collider. */\nexport interface ColliderOptions {\n /** The collision geometry. */\n shape: AnyShape;\n /** Density (mass per px²) for the owning body's mass; ignored for static/kinematic. Default `1`. */\n density?: number;\n /** Coulomb friction coefficient (used by the solver once dynamics ship). Default `0.2`. */\n friction?: number;\n /** Restitution / bounciness in `[0, 1]` (used by the solver once dynamics ship). Default `0`. */\n restitution?: number;\n /** When `true`, generates overlap events but no contact response. Default `false`. */\n isSensor?: boolean;\n /** Category/mask/group filter; partials merge over the defaults. */\n filter?: Partial<CollisionFilter>;\n /** Body-local offset of the shape origin. Default `(0, 0)`. */\n offset?: Readonly<PointLike>;\n /** Body-local rotation of the shape in radians (compound colliders). Default `0`. */\n rotation?: number;\n}\n\n/**\n * Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local\n * offset/rotation, material (friction/restitution/density) and a collision\n * filter. A body may own several colliders (compound). The collider also caches\n * its world-space geometry - refreshed by {@link synchronize} - which the broad\n * phase, narrow phase and queries read directly.\n *\n * Material fields and the filter are mutable; the shape and local placement are\n * immutable (rebuild the collider to change geometry).\n */\nexport class Collider {\n /** Stable id, assigned when the owning body joins a world (`-1` until then). */\n public readonly shape: AnyShape;\n public readonly offsetX: number;\n public readonly offsetY: number;\n public readonly localRotation: number;\n\n public density: number;\n public friction: number;\n public restitution: number;\n public isSensor: boolean;\n public readonly filter: CollisionFilter;\n\n private _id = -1;\n private _body: PhysicsBody | null = null;\n private readonly _chainEdges: readonly Collider[] | null;\n private _chainParent: Collider | null = null;\n private readonly _localTransform: Transform;\n private readonly _worldTransform: Transform = createTransform();\n private readonly _aabb: AabbLike = createAabb();\n private readonly _worldCenter: PointLike = { x: 0, y: 0 };\n // Reused per-vertex scratch for synchronize()'s polygon transform loop so a\n // collider sync allocates nothing. Instance-private: never held across the\n // call, never aliased between colliders.\n private readonly _syncScratch: PointLike = { x: 0, y: 0 };\n private readonly _worldVertices: number[];\n private readonly _worldNormals: number[];\n\n private _destroyed = false;\n\n /**\n * @internal - proxy id in the physics world's broad-phase spatial tree; `-1`\n * when not inserted. Like `PhysicsBody._islandIndex`/`_sleepTime`, this is a\n * single-owner slot: exactly ONE `AabbTreeBroadPhase` may track this collider\n * at a time (in production, the world's own broad phase for the collider's\n * whole lifetime). A second broad phase over the same collider would clobber\n * this value and corrupt the first's tree - never do that.\n */\n public _treeProxy = -1;\n\n public constructor(options: ColliderOptions) {\n const density = options.density ?? 1;\n\n if (!Number.isFinite(density) || density < 0) {\n throw new RangeError(`Collider: density must be a non-negative finite number, received ${density}.`);\n }\n\n this.shape = options.shape;\n this.offsetX = options.offset?.x ?? 0;\n this.offsetY = options.offset?.y ?? 0;\n this.localRotation = options.rotation ?? 0;\n this.density = density;\n this.friction = options.friction ?? 0.2;\n this.restitution = options.restitution ?? 0;\n this.isSensor = options.isSensor ?? false;\n this.filter = resolveFilter(options.filter);\n this._localTransform = createTransform(this.offsetX, this.offsetY, this.localRotation);\n\n const vertexCount = worldVertexCount(this.shape);\n\n this._worldVertices = new Array<number>(vertexCount * 2).fill(0);\n this._worldNormals = new Array<number>(vertexCount * 2).fill(0);\n this._chainEdges = this.shape.type === 'chain' ? this._buildChainEdges(this.shape) : null;\n }\n\n /** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */\n public get id(): number {\n return this._id;\n }\n\n /**\n * The body this collider belongs to. `null` until the collider has been added\n * to a body that has joined a world (free-standing colliders have no body yet).\n */\n public get body(): PhysicsBody {\n if (this._body === null) {\n throw new Error('Collider: this collider has not been attached to a body in a world yet.');\n }\n\n return this._body;\n }\n\n /** The collider's world AABB (valid after the latest {@link synchronize}). */\n public get aabb(): Readonly<AabbLike> {\n return this._aabb;\n }\n\n /** The collider's world transform (offset/rotation composed with the body's). */\n public get worldTransform(): Readonly<Transform> {\n return this._worldTransform;\n }\n\n /** The collider's body-local transform (offset + local rotation). */\n public get localTransform(): Readonly<Transform> {\n return this._localTransform;\n }\n\n /** World-space circle centre (only meaningful for circle shapes). */\n public get worldCenter(): Readonly<PointLike> {\n return this._worldCenter;\n }\n\n /** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldVertices(): readonly number[] {\n return this._worldVertices;\n }\n\n /** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldNormals(): readonly number[] {\n return this._worldNormals;\n }\n\n /**\n * @internal - the engine-owned edge proxies a chain collider fans out into,\n * one per chain edge; `null` for every other shape. They are what the broad\n * phase, the narrow phase and the solver see, so a chain contact reuses the\n * one-manifold-per-pair model unchanged. They are never part of\n * `body.colliders`, `world.colliders` or any query result - the authored\n * collider is the public identity of every contact they produce.\n */\n public get chainEdges(): readonly Collider[] | null {\n return this._chainEdges;\n }\n\n /** @internal - the authored chain collider this edge proxy belongs to; `null` for an authored collider. */\n public get chainParent(): Collider | null {\n return this._chainParent;\n }\n\n /** `true` after the owning world has destroyed this collider. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /**\n * Recompute the cached world geometry from the body's transform. Called by the\n * body on `setTransform`, on collider creation, and by the world before each\n * detection pass.\n */\n public synchronize(bodyTransform: Transform): void {\n const world = composeTransforms(bodyTransform, this._localTransform, this._worldTransform);\n\n switch (this.shape.type) {\n case 'circle':\n this._synchronizeCircle(world, this.shape.radius);\n break;\n case 'capsule':\n // A capsule is a two-vertex ring plus a radius, so it rides the polygon\n // path and only the AABB inflation differs.\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, this.shape.radius);\n break;\n case 'segment':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, 0);\n break;\n case 'polygon':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, this.shape.count, 0);\n break;\n case 'chain':\n this._synchronizeChain(bodyTransform);\n break;\n }\n }\n\n /**\n * A chain's world geometry is its edge proxies': each of them shares the\n * chain's local placement and syncs its own two endpoints, and the chain's own\n * AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.\n */\n private _synchronizeChain(bodyTransform: Transform): void {\n const edges = this._chainEdges!;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const edge of edges) {\n edge.synchronize(bodyTransform);\n\n const aabb = edge.aabb;\n\n minX = aabb.minX < minX ? aabb.minX : minX;\n minY = aabb.minY < minY ? aabb.minY : minY;\n maxX = aabb.maxX > maxX ? aabb.maxX : maxX;\n maxY = aabb.maxY > maxY ? aabb.maxY : maxY;\n }\n\n this._aabb.minX = minX;\n this._aabb.minY = minY;\n this._aabb.maxX = maxX;\n this._aabb.maxY = maxY;\n }\n\n /** A circle is its transformed centre; the local vertex buffers stay unused. */\n private _synchronizeCircle(world: Transform, radius: number): void {\n this._worldCenter.x = world.x;\n this._worldCenter.y = world.y;\n this._aabb.minX = world.x - radius;\n this._aabb.minY = world.y - radius;\n this._aabb.maxX = world.x + radius;\n this._aabb.maxY = world.y + radius;\n }\n\n /**\n * Transform a local vertex/normal ring into the world buffers and take the\n * AABB while doing it. `radius` inflates the box for a rounded outline (a\n * capsule's spine); it is `0` for a plain polygon.\n */\n private _synchronizePolygon(world: Transform, local: readonly number[], normals: readonly number[], count: number, radius: number): void {\n const out = this._syncScratch;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < count; i++) {\n applyTransform(world, local[i * 2]!, local[i * 2 + 1]!, out);\n this._worldVertices[i * 2] = out.x;\n this._worldVertices[i * 2 + 1] = out.y;\n minX = out.x < minX ? out.x : minX;\n minY = out.y < minY ? out.y : minY;\n maxX = out.x > maxX ? out.x : maxX;\n maxY = out.y > maxY ? out.y : maxY;\n\n applyRotation(world, normals[i * 2]!, normals[i * 2 + 1]!, out);\n this._worldNormals[i * 2] = out.x;\n this._worldNormals[i * 2 + 1] = out.y;\n }\n\n this._aabb.minX = minX - radius;\n this._aabb.minY = minY - radius;\n this._aabb.maxX = maxX + radius;\n this._aabb.maxY = maxY + radius;\n }\n\n /** @internal - bind this collider to its body and id (called when the body joins a world). */\n public _attach(body: PhysicsBody, id: number): void {\n this._body = body;\n this._id = id;\n }\n\n /**\n * Fan a chain out into one proxy per edge. Each proxy carries the chain's own\n * local placement, so it needs no transform of its own, and its shape carries\n * the adjacency that keeps a body from snagging at a shared vertex.\n */\n private _buildChainEdges(chain: ChainShape): readonly Collider[] {\n const edges: Collider[] = [];\n\n for (const edgeShape of chain.edges) {\n const edge = new Collider({\n shape: edgeShape,\n offset: { x: this.offsetX, y: this.offsetY },\n rotation: this.localRotation,\n // Material, filter and sensor flag stay mutable on the authored collider\n // and are read from there per pass, so copying them here would only add a\n // second, staler source of truth.\n density: 0,\n });\n\n edge._chainParent = this;\n edges.push(edge);\n }\n\n return edges;\n }\n\n /** Internal: mark destroyed (called by the world). */\n public _markDestroyed(): void {\n this._destroyed = true;\n\n if (this._chainEdges !== null) {\n for (const edge of this._chainEdges) {\n edge._destroyed = true;\n }\n }\n }\n}\n\n/**\n * The authored collider a contact, query hit or sweep target belongs to: the\n * collider itself, or the chain it is an engine-owned edge proxy of. Every\n * public identity - events, query results, the contact modifier - goes through\n * this, so a solver-side partition never reaches a caller.\n *\n * @internal\n */\nexport const authoredCollider = (collider: Collider): Collider => collider.chainParent ?? collider;\n"],"mappings":";;;;;;AAYA,MAAM,oBAAoB,UAA4B;CACpD,QAAQ,MAAM,MAAd;EACE,KAAK,WACH,OAAO,MAAM;EACf,KAAK;EACL,KAAK,WAEH,OAAO;EACT,KAAK;EACL,KAAK,SAGH,OAAO;CACX;AACF;;;;;;;;;;;AAgCA,IAAa,WAAb,MAAa,SAAS;;CAEpB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAgB;CAEhB,AAAQ,MAAM;CACd,AAAQ,QAA4B;CACpC,AAAiB;CACjB,AAAQ,eAAgC;CACxC,AAAiB;CACjB,AAAiB,kBAA6B,gBAAgB;CAC9D,AAAiB,QAAkB,WAAW;CAC9C,AAAiB,eAA0B;EAAE,GAAG;EAAG,GAAG;CAAE;CAIxD,AAAiB,eAA0B;EAAE,GAAG;EAAG,GAAG;CAAE;CACxD,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,aAAa;;;;;;;;;CAUrB,AAAO,aAAa;CAEpB,AAAO,YAAY,SAA0B;EAC3C,MAAM,UAAU,QAAQ,WAAW;EAEnC,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,UAAU,GACzC,MAAM,IAAI,WAAW,oEAAoE,QAAQ,EAAE;EAGrG,KAAK,QAAQ,QAAQ;EACrB,KAAK,UAAU,QAAQ,QAAQ,KAAK;EACpC,KAAK,UAAU,QAAQ,QAAQ,KAAK;EACpC,KAAK,gBAAgB,QAAQ,YAAY;EACzC,KAAK,UAAU;EACf,KAAK,WAAW,QAAQ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type { AabbLike, PointLike } from '@codexo/exojs';\n\nimport { createAabb } from './Aabb';\nimport type { Transform } from './math';\nimport { applyRotation, applyTransform, composeTransforms, createTransform } from './math';\nimport type { PhysicsBody } from './PhysicsBody';\nimport type { AnyShape } from './shapes/AnyShape';\nimport type { ChainShape } from './shapes/ChainShape';\nimport type { CollisionFilter } from './types';\nimport { resolveFilter } from './types';\n\n/** Number of world-space vertices a shape kind caches on its collider. */\nconst worldVertexCount = (shape: AnyShape): number => {\n switch (shape.type) {\n case 'polygon':\n return shape.count;\n case 'capsule':\n case 'segment':\n // Two endpoints. Both are a two-vertex ring, with and without a radius.\n return 2;\n case 'circle':\n case 'chain':\n // A chain caches nothing of its own: its geometry lives on the per-edge\n // child proxies, and its AABB is the union of theirs.\n return 0;\n }\n};\n\n/** Construction options for a collider. */\nexport interface ColliderOptions {\n /** The collision geometry. */\n shape: AnyShape;\n /** Density (mass per px²) for the owning body's mass; ignored for static/kinematic. Default `1`. */\n density?: number;\n /** Coulomb friction coefficient (used by the solver once dynamics ship). Default `0.2`. */\n friction?: number;\n /** Restitution / bounciness in `[0, 1]` (used by the solver once dynamics ship). Default `0`. */\n restitution?: number;\n /** When `true`, generates overlap events but no contact response. Default `false`. */\n isSensor?: boolean;\n /** Category/mask/group filter; partials merge over the defaults. */\n filter?: Partial<CollisionFilter>;\n /** Body-local offset of the shape origin. Default `(0, 0)`. */\n offset?: Readonly<PointLike>;\n /** Body-local rotation of the shape in radians (compound colliders). Default `0`. */\n rotation?: number;\n}\n\n/**\n * Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local\n * offset/rotation, material (friction/restitution/density) and a collision\n * filter. A body may own several colliders (compound). The collider also caches\n * its world-space geometry - refreshed by {@link synchronize} - which the broad\n * phase, narrow phase and queries read directly.\n *\n * Material fields and the filter are mutable; the shape and local placement are\n * immutable (rebuild the collider to change geometry).\n */\nexport class Collider {\n /** Stable id, assigned when the owning body joins a world (`-1` until then). */\n public readonly shape: AnyShape;\n public readonly offsetX: number;\n public readonly offsetY: number;\n public readonly localRotation: number;\n\n public density: number;\n public friction: number;\n public restitution: number;\n public isSensor: boolean;\n public readonly filter: CollisionFilter;\n\n private _id = -1;\n private _body: PhysicsBody | null = null;\n private readonly _chainEdges: readonly Collider[] | null;\n private _chainParent: Collider | null = null;\n private readonly _localTransform: Transform;\n private readonly _worldTransform: Transform = createTransform();\n private readonly _aabb: AabbLike = createAabb();\n private readonly _worldCenter: PointLike = { x: 0, y: 0 };\n // Reused per-vertex scratch for synchronize()'s polygon transform loop so a\n // collider sync allocates nothing. Instance-private: never held across the\n // call, never aliased between colliders.\n private readonly _syncScratch: PointLike = { x: 0, y: 0 };\n private readonly _worldVertices: number[];\n private readonly _worldNormals: number[];\n\n private _destroyed = false;\n\n /**\n * @internal - proxy id in the physics world's broad-phase spatial tree; `-1`\n * when not inserted. Like `PhysicsBody._islandIndex`/`_sleepTime`, this is a\n * single-owner slot: exactly ONE `AabbTreeBroadPhase` may track this collider\n * at a time (in production, the world's own broad phase for the collider's\n * whole lifetime). A second broad phase over the same collider would clobber\n * this value and corrupt the first's tree - never do that.\n */\n public _treeProxy = -1;\n\n /**\n * @internal - whether {@link aabb} has changed since the owning broad phase\n * last looked at it. Set by every write to the AABB ({@link synchronize} is\n * the only one) and cleared when the broad phase has taken the new box, so a\n * resting collider costs nothing to re-sync. Single-owner like\n * {@link _treeProxy}, and for the same reason.\n */\n public _treeDirty = true;\n\n public constructor(options: ColliderOptions) {\n const density = options.density ?? 1;\n\n if (!Number.isFinite(density) || density < 0) {\n throw new RangeError(`Collider: density must be a non-negative finite number, received ${density}.`);\n }\n\n this.shape = options.shape;\n this.offsetX = options.offset?.x ?? 0;\n this.offsetY = options.offset?.y ?? 0;\n this.localRotation = options.rotation ?? 0;\n this.density = density;\n this.friction = options.friction ?? 0.2;\n this.restitution = options.restitution ?? 0;\n this.isSensor = options.isSensor ?? false;\n this.filter = resolveFilter(options.filter);\n this._localTransform = createTransform(this.offsetX, this.offsetY, this.localRotation);\n\n const vertexCount = worldVertexCount(this.shape);\n\n this._worldVertices = new Array<number>(vertexCount * 2).fill(0);\n this._worldNormals = new Array<number>(vertexCount * 2).fill(0);\n this._chainEdges = this.shape.type === 'chain' ? this._buildChainEdges(this.shape) : null;\n }\n\n /** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */\n public get id(): number {\n return this._id;\n }\n\n /**\n * The body this collider belongs to. `null` until the collider has been added\n * to a body that has joined a world (free-standing colliders have no body yet).\n */\n public get body(): PhysicsBody {\n if (this._body === null) {\n throw new Error('Collider: this collider has not been attached to a body in a world yet.');\n }\n\n return this._body;\n }\n\n /** The collider's world AABB (valid after the latest {@link synchronize}). */\n public get aabb(): Readonly<AabbLike> {\n return this._aabb;\n }\n\n /** The collider's world transform (offset/rotation composed with the body's). */\n public get worldTransform(): Readonly<Transform> {\n return this._worldTransform;\n }\n\n /** The collider's body-local transform (offset + local rotation). */\n public get localTransform(): Readonly<Transform> {\n return this._localTransform;\n }\n\n /** World-space circle centre (only meaningful for circle shapes). */\n public get worldCenter(): Readonly<PointLike> {\n return this._worldCenter;\n }\n\n /** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldVertices(): readonly number[] {\n return this._worldVertices;\n }\n\n /** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldNormals(): readonly number[] {\n return this._worldNormals;\n }\n\n /**\n * @internal - the engine-owned edge proxies a chain collider fans out into,\n * one per chain edge; `null` for every other shape. They are what the broad\n * phase, the narrow phase and the solver see, so a chain contact reuses the\n * one-manifold-per-pair model unchanged. They are never part of\n * `body.colliders`, `world.colliders` or any query result - the authored\n * collider is the public identity of every contact they produce.\n */\n public get chainEdges(): readonly Collider[] | null {\n return this._chainEdges;\n }\n\n /** @internal - the authored chain collider this edge proxy belongs to; `null` for an authored collider. */\n public get chainParent(): Collider | null {\n return this._chainParent;\n }\n\n /** `true` after the owning world has destroyed this collider. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /**\n * Recompute the cached world geometry from the body's transform. Called by the\n * body on `setTransform`, on collider creation, and by the world before each\n * detection pass.\n */\n public synchronize(bodyTransform: Transform): void {\n const world = composeTransforms(bodyTransform, this._localTransform, this._worldTransform);\n\n this._treeDirty = true;\n\n switch (this.shape.type) {\n case 'circle':\n this._synchronizeCircle(world, this.shape.radius);\n break;\n case 'capsule':\n // A capsule is a two-vertex ring plus a radius, so it rides the polygon\n // path and only the AABB inflation differs.\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, this.shape.radius);\n break;\n case 'segment':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, 0);\n break;\n case 'polygon':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, this.shape.count, 0);\n break;\n case 'chain':\n this._synchronizeChain(bodyTransform);\n break;\n }\n }\n\n /**\n * A chain's world geometry is its edge proxies': each of them shares the\n * chain's local placement and syncs its own two endpoints, and the chain's own\n * AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.\n */\n private _synchronizeChain(bodyTransform: Transform): void {\n const edges = this._chainEdges!;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const edge of edges) {\n edge.synchronize(bodyTransform);\n\n const aabb = edge.aabb;\n\n minX = aabb.minX < minX ? aabb.minX : minX;\n minY = aabb.minY < minY ? aabb.minY : minY;\n maxX = aabb.maxX > maxX ? aabb.maxX : maxX;\n maxY = aabb.maxY > maxY ? aabb.maxY : maxY;\n }\n\n this._aabb.minX = minX;\n this._aabb.minY = minY;\n this._aabb.maxX = maxX;\n this._aabb.maxY = maxY;\n }\n\n /** A circle is its transformed centre; the local vertex buffers stay unused. */\n private _synchronizeCircle(world: Transform, radius: number): void {\n this._worldCenter.x = world.x;\n this._worldCenter.y = world.y;\n this._aabb.minX = world.x - radius;\n this._aabb.minY = world.y - radius;\n this._aabb.maxX = world.x + radius;\n this._aabb.maxY = world.y + radius;\n }\n\n /**\n * Transform a local vertex/normal ring into the world buffers and take the\n * AABB while doing it. `radius` inflates the box for a rounded outline (a\n * capsule's spine); it is `0` for a plain polygon.\n */\n private _synchronizePolygon(world: Transform, local: readonly number[], normals: readonly number[], count: number, radius: number): void {\n const out = this._syncScratch;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < count; i++) {\n applyTransform(world, local[i * 2]!, local[i * 2 + 1]!, out);\n this._worldVertices[i * 2] = out.x;\n this._worldVertices[i * 2 + 1] = out.y;\n minX = out.x < minX ? out.x : minX;\n minY = out.y < minY ? out.y : minY;\n maxX = out.x > maxX ? out.x : maxX;\n maxY = out.y > maxY ? out.y : maxY;\n\n applyRotation(world, normals[i * 2]!, normals[i * 2 + 1]!, out);\n this._worldNormals[i * 2] = out.x;\n this._worldNormals[i * 2 + 1] = out.y;\n }\n\n this._aabb.minX = minX - radius;\n this._aabb.minY = minY - radius;\n this._aabb.maxX = maxX + radius;\n this._aabb.maxY = maxY + radius;\n }\n\n /** @internal - bind this collider to its body and id (called when the body joins a world). */\n public _attach(body: PhysicsBody, id: number): void {\n this._body = body;\n this._id = id;\n }\n\n /**\n * Fan a chain out into one proxy per edge. Each proxy carries the chain's own\n * local placement, so it needs no transform of its own, and its shape carries\n * the adjacency that keeps a body from snagging at a shared vertex.\n */\n private _buildChainEdges(chain: ChainShape): readonly Collider[] {\n const edges: Collider[] = [];\n\n for (const edgeShape of chain.edges) {\n const edge = new Collider({\n shape: edgeShape,\n offset: { x: this.offsetX, y: this.offsetY },\n rotation: this.localRotation,\n // Material, filter and sensor flag stay mutable on the authored collider\n // and are read from there per pass, so copying them here would only add a\n // second, staler source of truth.\n density: 0,\n });\n\n edge._chainParent = this;\n edges.push(edge);\n }\n\n return edges;\n }\n\n /** @internal - mark destroyed (called by the world). */\n public _markDestroyed(): void {\n this._destroyed = true;\n\n if (this._chainEdges !== null) {\n for (const edge of this._chainEdges) {\n edge._destroyed = true;\n }\n }\n }\n}\n\n/**\n * The authored collider a contact, query hit or sweep target belongs to: the\n * collider itself, or the chain it is an engine-owned edge proxy of. Every\n * public identity - events, query results, the contact modifier - goes through\n * this, so a solver-side partition never reaches a caller.\n *\n * @internal\n */\nexport const authoredCollider = (collider: Collider): Collider => collider.chainParent ?? collider;\n"],"mappings":";;;;;;AAYA,MAAM,oBAAoB,UAA4B;CACpD,QAAQ,MAAM,MAAd;EACE,KAAK,WACH,OAAO,MAAM;EACf,KAAK;EACL,KAAK,WAEH,OAAO;EACT,KAAK;EACL,KAAK,SAGH,OAAO;CACX;AACF;;;;;;;;;;;AAgCA,IAAa,WAAb,MAAa,SAAS;;CAEpB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAgB;CAEhB,AAAQ,MAAM;CACd,AAAQ,QAA4B;CACpC,AAAiB;CACjB,AAAQ,eAAgC;CACxC,AAAiB;CACjB,AAAiB,kBAA6B,gBAAgB;CAC9D,AAAiB,QAAkB,WAAW;CAC9C,AAAiB,eAA0B;EAAE,GAAG;EAAG,GAAG;CAAE;CAIxD,AAAiB,eAA0B;EAAE,GAAG;EAAG,GAAG;CAAE;CACxD,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,aAAa;;;;;;;;;CAUrB,AAAO,aAAa;;;;;;;;CASpB,AAAO,aAAa;CAEpB,AAAO,YAAY,SAA0B;EAC3C,MAAM,UAAU,QAAQ,WAAW;EAEnC,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,UAAU,GACzC,MAAM,IAAI,WAAW,oEAAoE,QAAQ,EAAE;EAGrG,KAAK,QAAQ,QAAQ;EACrB,KAAK,UAAU,QAAQ,QAAQ,KAAK;EACpC,KAAK,UAAU,QAAQ,QAAQ,KAAK;EACpC,KAAK,gBAAgB,QAAQ,YAAY;EACzC,KAAK,UAAU;EACf,KAAK,WAAW,QAAQ,YAAY;EACpC,KAA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, number];
|
|
39
39
|
/** Feature ids the cached impulses belong to (for warm-start matching). */
|
|
40
40
|
readonly pointIds: [number, number];
|
|
41
|
+
/**
|
|
42
|
+
* Penetration each point carried on the previous detection pass, matched by
|
|
43
|
+
* feature id the same way the impulse cache is, or `-1` where the point is new
|
|
44
|
+
* and has no history. The difference against the manifold's current
|
|
45
|
+
* penetration is how much the last solve actually moved the overlap, which is
|
|
46
|
+
* what separates a contact the push-out is still working off from one that has
|
|
47
|
+
* reached the depth its load holds it at.
|
|
48
|
+
*/
|
|
49
|
+
readonly previousPenetration: [number, number];
|
|
50
|
+
/** Penetration per point as of this pass, kept so the next pass can form that difference. */
|
|
51
|
+
readonly pointPenetration: [number, number];
|
|
41
52
|
}
|
|
42
53
|
/**
|
|
43
54
|
* The persistent contact set. Each detection pass it diffs the currently
|
|
@@ -66,6 +77,17 @@ export declare class ContactGraph {
|
|
|
66
77
|
readonly sensorExit: SensorEvent[];
|
|
67
78
|
/** Touching solid contacts this pass, in deterministic order - consumed by the solver. */
|
|
68
79
|
readonly solidContacts: ContactRecord[];
|
|
80
|
+
/**
|
|
81
|
+
* Body pairs a joint has taken out of collision, keyed by
|
|
82
|
+
* {@link bodyPairKey} and reference-counted by the world; `null` until a world
|
|
83
|
+
* hands its own map over.
|
|
84
|
+
*
|
|
85
|
+
* Consulted here rather than in the solver because the cheapest contact is
|
|
86
|
+
* the one the narrow phase never computes: a chain of N links otherwise pays
|
|
87
|
+
* for N-1 manifolds, warm-start slots and event records per step that nothing
|
|
88
|
+
* is allowed to act on.
|
|
89
|
+
*/
|
|
90
|
+
private _uncollidablePairs;
|
|
69
91
|
private readonly _records;
|
|
70
92
|
private readonly _authoredPairs;
|
|
71
93
|
private readonly _modifierContext;
|
|
@@ -109,18 +131,4 @@ export declare class ContactGraph {
|
|
|
109
131
|
*/
|
|
110
132
|
private _removeIfUnseen;
|
|
111
133
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Stride for packing two collider ids into one pair key. Multiplying by this
|
|
114
|
-
* (rather than a 32-bit `<<`) keeps the key collision-free up to ~67M (2^26)
|
|
115
|
-
* ids per world, within JS's 2^53 safe-integer range.
|
|
116
|
-
* @internal
|
|
117
|
-
*/
|
|
118
|
-
export declare const pairKeyStride = 67108864;
|
|
119
|
-
/**
|
|
120
|
-
* Integer key for an unordered collider pair (`aId < bId` is guaranteed by the
|
|
121
|
-
* broad phase). The previous `(aId << 16) | bId` silently collided once any id
|
|
122
|
-
* reached 65536, because JS bitwise operators wrap at 32 bits.
|
|
123
|
-
* @internal
|
|
124
|
-
*/
|
|
125
|
-
export declare const pairKey: (aId: number, bId: number) => number;
|
|
126
134
|
//# sourceMappingURL=ContactGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactGraph.d.ts","sourceRoot":"","sources":["../../src/ContactGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAgB,WAAW,EAAE,MAAM,UAAU,CAAC;AAI1E;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC;IACrB,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,8EAA8E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;IAwBrD;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAY/C,8CAA8C;IACvC,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,QAAQ;IAYhB;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAa3B,0FAA0F;IAC1F,OAAO,CAAC,oBAAoB;IAmB5B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;CASxB"}
|
package/dist/esm/ContactGraph.js
CHANGED
|
@@ -33,6 +33,17 @@ var ContactGraph = class {
|
|
|
33
33
|
sensorExit = [];
|
|
34
34
|
/** Touching solid contacts this pass, in deterministic order - consumed by the solver. */
|
|
35
35
|
solidContacts = [];
|
|
36
|
+
/**
|
|
37
|
+
* Body pairs a joint has taken out of collision, keyed by
|
|
38
|
+
* {@link bodyPairKey} and reference-counted by the world; `null` until a world
|
|
39
|
+
* hands its own map over.
|
|
40
|
+
*
|
|
41
|
+
* Consulted here rather than in the solver because the cheapest contact is
|
|
42
|
+
* the one the narrow phase never computes: a chain of N links otherwise pays
|
|
43
|
+
* for N-1 manifolds, warm-start slots and event records per step that nothing
|
|
44
|
+
* is allowed to act on.
|
|
45
|
+
*/
|
|
46
|
+
_uncollidablePairs = null;
|
|
36
47
|
_records = /* @__PURE__ */ new Map();
|
|
37
48
|
_authoredPairs = /* @__PURE__ */ new Map();
|
|
38
49
|
_modifierContext = new MutableContactModifierContext();
|
|
@@ -40,6 +51,10 @@ var ContactGraph = class {
|
|
|
40
51
|
get recordCount() {
|
|
41
52
|
return this._records.size;
|
|
42
53
|
}
|
|
54
|
+
/** @internal - adopt the world's joint-filtered body pairs; see {@link _uncollidablePairs}. */
|
|
55
|
+
_useUncollidablePairs(pairs) {
|
|
56
|
+
this._uncollidablePairs = pairs;
|
|
57
|
+
}
|
|
43
58
|
/** Diff this pass's candidate pairs against the persistent set, collecting events + solid contacts. */
|
|
44
59
|
update(pairs) {
|
|
45
60
|
this.collisionStart.length = 0;
|
|
@@ -54,6 +69,7 @@ var ContactGraph = class {
|
|
|
54
69
|
const ownerA = authoredCollider(a);
|
|
55
70
|
const ownerB = authoredCollider(b);
|
|
56
71
|
if (!shouldCollide(ownerA.filter, ownerB.filter)) continue;
|
|
72
|
+
if (this._uncollidablePairs !== null && this._uncollidablePairs.size > 0 && this._uncollidablePairs.has(bodyPairKey(ownerA.body.id, ownerB.body.id))) continue;
|
|
57
73
|
const isSensor = ownerA.isSensor || ownerB.isSensor;
|
|
58
74
|
const key = pairKey(a.id, b.id);
|
|
59
75
|
const existing = this._records.get(key);
|
|
@@ -104,6 +120,8 @@ var ContactGraph = class {
|
|
|
104
120
|
record.tangentImpulse[1] = 0;
|
|
105
121
|
record.pointIds[0] = 0;
|
|
106
122
|
record.pointIds[1] = 0;
|
|
123
|
+
record.pointPenetration[0] = -1;
|
|
124
|
+
record.pointPenetration[1] = -1;
|
|
107
125
|
}
|
|
108
126
|
}
|
|
109
127
|
}
|
|
@@ -190,6 +208,12 @@ const pairKeyStride = 67108864;
|
|
|
190
208
|
* @internal
|
|
191
209
|
*/
|
|
192
210
|
const pairKey = (aId, bId) => aId * pairKeyStride + bId;
|
|
211
|
+
/**
|
|
212
|
+
* Integer key for an unordered BODY pair, which unlike a collider pair arrives
|
|
213
|
+
* in no guaranteed order.
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
const bodyPairKey = (aId, bId) => aId < bId ? pairKey(aId, bId) : pairKey(bId, aId);
|
|
193
217
|
const authoredPairKey = (record) => {
|
|
194
218
|
const first = record.ownerA.id;
|
|
195
219
|
const second = record.ownerB.id;
|
|
@@ -209,12 +233,16 @@ const createRecord = (a, b, ownerA, ownerB, isSensor) => ({
|
|
|
209
233
|
manifold: new Manifold(),
|
|
210
234
|
normalImpulse: [0, 0],
|
|
211
235
|
tangentImpulse: [0, 0],
|
|
212
|
-
pointIds: [0, 0]
|
|
236
|
+
pointIds: [0, 0],
|
|
237
|
+
previousPenetration: [-1, -1],
|
|
238
|
+
pointPenetration: [-1, -1]
|
|
213
239
|
});
|
|
214
240
|
/**
|
|
215
241
|
* Map the previously accumulated impulses onto the new manifold points by feature
|
|
216
|
-
* id (warm-starting)
|
|
217
|
-
*
|
|
242
|
+
* id (warm-starting), and carry each point's previous penetration across the same
|
|
243
|
+
* match. Unmatched points start at zero impulse and at no penetration history;
|
|
244
|
+
* the cache is re-keyed to the new ids. Runs after `collide` has refreshed
|
|
245
|
+
* `record.manifold`.
|
|
218
246
|
*/
|
|
219
247
|
const warmStartMatch = (record) => {
|
|
220
248
|
const manifold = record.manifold;
|
|
@@ -222,25 +250,35 @@ const warmStartMatch = (record) => {
|
|
|
222
250
|
const pn1 = record.normalImpulse[1];
|
|
223
251
|
const pt0 = record.tangentImpulse[0];
|
|
224
252
|
const pt1 = record.tangentImpulse[1];
|
|
253
|
+
const pd0 = record.pointPenetration[0];
|
|
254
|
+
const pd1 = record.pointPenetration[1];
|
|
225
255
|
const pid0 = record.pointIds[0];
|
|
226
256
|
const pid1 = record.pointIds[1];
|
|
227
257
|
for (let i = 0; i < 2; i++) if (i < manifold.pointCount) {
|
|
228
|
-
const
|
|
258
|
+
const point = i === 0 ? manifold.points[0] : manifold.points[1];
|
|
259
|
+
const id = point.id;
|
|
229
260
|
let normal = 0;
|
|
230
261
|
let tangent = 0;
|
|
262
|
+
let previous = -1;
|
|
231
263
|
if (id === pid0) {
|
|
232
264
|
normal = pn0;
|
|
233
265
|
tangent = pt0;
|
|
266
|
+
previous = pd0;
|
|
234
267
|
} else if (id === pid1) {
|
|
235
268
|
normal = pn1;
|
|
236
269
|
tangent = pt1;
|
|
270
|
+
previous = pd1;
|
|
237
271
|
}
|
|
238
272
|
record.normalImpulse[i] = normal;
|
|
239
273
|
record.tangentImpulse[i] = tangent;
|
|
274
|
+
record.previousPenetration[i] = previous;
|
|
275
|
+
record.pointPenetration[i] = point.penetration;
|
|
240
276
|
record.pointIds[i] = id;
|
|
241
277
|
} else {
|
|
242
278
|
record.normalImpulse[i] = 0;
|
|
243
279
|
record.tangentImpulse[i] = 0;
|
|
280
|
+
record.previousPenetration[i] = -1;
|
|
281
|
+
record.pointPenetration[i] = -1;
|
|
244
282
|
record.pointIds[i] = 0;
|
|
245
283
|
}
|
|
246
284
|
};
|
|
@@ -300,5 +338,5 @@ const bySensorPair = (x, y) => x.sensor.id - y.sensor.id || x.other.id - y.other
|
|
|
300
338
|
const byRecordPair = (x, y) => x.a.id - y.a.id || x.b.id - y.b.id;
|
|
301
339
|
|
|
302
340
|
//#endregion
|
|
303
|
-
export { ContactGraph, pairKey, pairKeyStride };
|
|
341
|
+
export { ContactGraph, bodyPairKey, pairKey, pairKeyStride };
|
|
304
342
|
//# sourceMappingURL=ContactGraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactGraph.js","names":[],"sources":["../../src/ContactGraph.ts"],"sourcesContent":["import type { CandidatePair } from './broadphase/BroadPhase';\nimport type { Collider } from './Collider';\nimport { authoredCollider } from './Collider';\nimport { Manifold } from './collision/Manifold';\nimport { collide, testOverlap } from './collision/narrowphase';\nimport type { ContactModifier } from './ContactModifier';\nimport { MutableContactModifierContext } from './ContactModifier';\nimport type { CollisionEvent, ContactPoint, SensorEvent } from './events';\nimport { sortInPlace } from './sort';\nimport { shouldCollide } from './types';\n\n/**\n * Persistent per-pair contact state. For solid contacts it carries a manifold\n * reused across passes plus the accumulated normal/tangent impulses (warm-start\n * cache), keyed by manifold-point feature ids. Consumed by the {@link ContactSolver}.\n */\nexport interface ContactRecord {\n readonly a: Collider;\n readonly b: Collider;\n /**\n * Authored collider behind {@link a} - itself, unless `a` is an engine-owned\n * chain edge proxy, in which case it is the chain collider the caller made.\n * Solver identity is the proxy pair; public identity is the authored pair.\n */\n readonly ownerA: Collider;\n readonly ownerB: Collider;\n readonly isSensor: boolean;\n touching: boolean;\n seen: boolean;\n /**\n * Per-step solver participation. Re-derived to `true` for every touching solid\n * contact each pass, then optionally cleared by the world's `ContactModifier`.\n */\n enabled: boolean;\n /** Per-step Coulomb friction, re-derived from the two colliders each pass. */\n friction: number;\n /** Per-step restitution, re-derived from the two colliders each pass. */\n restitution: number;\n /** Persistent manifold (solid contacts), refreshed each pass by the narrow phase. */\n readonly manifold: Manifold;\n /** Accumulated normal impulse per contact point, carried across steps (warm-start). */\n readonly normalImpulse: [number, number];\n /** Accumulated tangent impulse per contact point, carried across steps (warm-start). */\n readonly tangentImpulse: [number, number];\n /** Feature ids the cached impulses belong to (for warm-start matching). */\n readonly pointIds: [number, number];\n}\n\n/**\n * The persistent contact set. Each detection pass it diffs the currently\n * touching collider pairs against the previous pass and produces immutable\n * begin/end (and sensor enter/exit) event snapshots. Duplicate begin/end churn\n * is suppressed by the persistent records, and the produced event arrays are\n * sorted by collider id for deterministic dispatch.\n *\n * Touching solid contacts are also collected into {@link solidContacts} (with a\n * warm-start impulse cache) for the dynamics solver. The graph holds no\n * module-level state - each world owns one.\n *\n * Records are keyed on the pair the solver sees, which for a chain collider is\n * one of its edge proxies. Events are not: a body touching several edges of one\n * chain is one authored contact, so the graph reference-counts the authored pair\n * behind its records and emits begin/end only on the first and last of them.\n */\nexport class ContactGraph {\n /** Immutable solid-contact begin snapshots produced by the latest {@link update}. */\n public readonly collisionStart: CollisionEvent[] = [];\n /** Immutable solid-contact end snapshots produced by the latest {@link update}. */\n public readonly collisionEnd: CollisionEvent[] = [];\n /** Immutable sensor-enter snapshots produced by the latest {@link update}. */\n public readonly sensorEnter: SensorEvent[] = [];\n /** Immutable sensor-exit snapshots produced by the latest {@link update}. */\n public readonly sensorExit: SensorEvent[] = [];\n /** Touching solid contacts this pass, in deterministic order - consumed by the solver. */\n public readonly solidContacts: ContactRecord[] = [];\n\n // Integer pair-keys (`(a.id << 16) | b.id`, a.id < b.id guaranteed by the broad\n // phase) - cheaper than string keys on the per-step solver hot path.\n private readonly _records = new Map<number, ContactRecord>();\n // Live solver contacts per authored collider pair. Only pairs whose records\n // are engine-owned proxies appear here; everything else emits directly.\n private readonly _authoredPairs = new Map<number, number>();\n private readonly _modifierContext = new MutableContactModifierContext();\n\n /** Touching pairs currently tracked (for debug draw). */\n public get recordCount(): number {\n return this._records.size;\n }\n\n /** Diff this pass's candidate pairs against the persistent set, collecting events + solid contacts. */\n public update(pairs: readonly CandidatePair[]): void {\n this.collisionStart.length = 0;\n this.collisionEnd.length = 0;\n this.sensorEnter.length = 0;\n this.sensorExit.length = 0;\n this.solidContacts.length = 0;\n\n this._records.forEach(resetSeen);\n\n for (const pair of pairs) {\n const a = pair.a;\n const b = pair.b;\n\n // Material, filter and sensor flag live on the authored collider; an edge\n // proxy carries none of its own, so a chain stays one collider to configure.\n const ownerA = authoredCollider(a);\n const ownerB = authoredCollider(b);\n\n if (!shouldCollide(ownerA.filter, ownerB.filter)) {\n continue;\n }\n\n const isSensor = ownerA.isSensor || ownerB.isSensor;\n const key = pairKey(a.id, b.id);\n const existing = this._records.get(key);\n const record = existing ?? createRecord(a, b, ownerA, ownerB, isSensor);\n const touching = isSensor ? testOverlap(a, b) : collide(a, b, record.manifold);\n\n if (touching) {\n record.seen = true;\n\n if (existing === undefined) {\n this._records.set(key, record);\n }\n\n if (!record.touching) {\n record.touching = true;\n this._emitBegin(record);\n }\n\n if (!isSensor) {\n // Per-step controls start from the collider-derived defaults every\n // pass, so a modifier that skipped a contact last step does not leak\n // into this one.\n record.enabled = true;\n record.friction = Math.sqrt(ownerA.friction * ownerB.friction);\n record.restitution = Math.max(ownerA.restitution, ownerB.restitution);\n warmStartMatch(record);\n this.solidContacts.push(record);\n }\n } else if (existing !== undefined) {\n if (record.touching) {\n this._emitEnd(record);\n }\n\n this._records.delete(key);\n }\n }\n\n // Pairs that left the broad phase entirely while touching → fire end. forEach\n // + thisArg is the allocation-free iteration (for...of allocates an entry tuple\n // per record each step); the thisArg binds `this`, so unbound-method is a\n // false positive here.\n // eslint-disable-next-line @typescript-eslint/unbound-method -- the thisArg above binds it\n this._records.forEach(this._removeIfUnseen, this);\n\n sortInPlace(this.collisionStart, byColliderPair);\n sortInPlace(this.collisionEnd, byColliderPair);\n sortInPlace(this.sensorEnter, bySensorPair);\n sortInPlace(this.sensorExit, bySensorPair);\n sortInPlace(this.solidContacts, byRecordPair);\n }\n\n /**\n * Run `modifier` over every touching solid contact of this pass. Called after\n * detection and before island building, so a contact the modifier disables\n * neither reaches the solver nor couples its two bodies into one sleeping\n * island. A disabled contact's warm-start cache is dropped, so re-enabling it\n * later starts from zero instead of releasing a stale impulse.\n */\n public applyModifier(modifier: ContactModifier): void {\n const context = this._modifierContext;\n\n for (const record of this.solidContacts) {\n context.bind(record);\n modifier(context);\n context.flush(record);\n\n if (!record.enabled) {\n record.normalImpulse[0] = 0;\n record.normalImpulse[1] = 0;\n record.tangentImpulse[0] = 0;\n record.tangentImpulse[1] = 0;\n record.pointIds[0] = 0;\n record.pointIds[1] = 0;\n }\n }\n }\n\n /**\n * Remove every record referencing `collider` (called when a collider is\n * destroyed). Passing an authored chain collider also drops the records of\n * every edge proxy it owns.\n */\n public removeCollider(collider: Collider): void {\n for (const [key, record] of this._records) {\n if (record.a === collider || record.b === collider || record.ownerA === collider || record.ownerB === collider) {\n if (record.touching) {\n this._releaseAuthoredPair(record);\n }\n\n this._records.delete(key);\n }\n }\n }\n\n /** Drop all records (world reset/destroy). */\n public clear(): void {\n this._records.clear();\n this._authoredPairs.clear();\n }\n\n private _emitBegin(record: ContactRecord): void {\n if (!this._retainAuthoredPair(record)) {\n return;\n }\n\n if (record.isSensor) {\n this.sensorEnter.push(makeSensorEvent(record.ownerA, record.ownerB));\n } else {\n this.collisionStart.push(makeCollisionEvent(record.ownerA, record.ownerB, record.manifold));\n }\n }\n\n private _emitEnd(record: ContactRecord): void {\n if (!this._releaseAuthoredPair(record)) {\n return;\n }\n\n if (record.isSensor) {\n this.sensorExit.push(makeSensorEvent(record.ownerA, record.ownerB));\n } else {\n this.collisionEnd.push(makeEndEvent(record.ownerA, record.ownerB));\n }\n }\n\n /**\n * Count one more solver contact against the authored pair, reporting whether\n * it is the first - the only one that may emit a begin event. A record whose\n * colliders are the authored ones needs no counting at all, so a world without\n * chains never touches the map.\n */\n private _retainAuthoredPair(record: ContactRecord): boolean {\n if (record.a === record.ownerA && record.b === record.ownerB) {\n return true;\n }\n\n const key = authoredPairKey(record);\n const count = this._authoredPairs.get(key) ?? 0;\n\n this._authoredPairs.set(key, count + 1);\n\n return count === 0;\n }\n\n /** Counterpart of {@link _retainAuthoredPair}: `true` on the last contact of the pair. */\n private _releaseAuthoredPair(record: ContactRecord): boolean {\n if (record.a === record.ownerA && record.b === record.ownerB) {\n return true;\n }\n\n const key = authoredPairKey(record);\n const count = (this._authoredPairs.get(key) ?? 1) - 1;\n\n if (count <= 0) {\n this._authoredPairs.delete(key);\n\n return true;\n }\n\n this._authoredPairs.set(key, count);\n\n return false;\n }\n\n /**\n * `Map.forEach` callback (its `this` bound via the forEach thisArg) - drops a\n * record the latest pass did not see, firing an end event if it was touching.\n * A method reference + thisArg keeps the per-step iteration allocation-free,\n * unlike `for (const [key, record] of map)` which allocates an entry tuple per\n * record (~1000/step). Deleting the current entry during forEach is safe.\n */\n private _removeIfUnseen(record: ContactRecord, key: number): void {\n if (!record.seen) {\n if (record.touching) {\n this._emitEnd(record);\n }\n\n this._records.delete(key);\n }\n }\n}\n\n/** `Map.forEach` callback - clears the per-pass `seen` flag (no iterator allocation). */\nconst resetSeen = (record: ContactRecord): void => {\n record.seen = false;\n};\n\n/**\n * Stride for packing two collider ids into one pair key. Multiplying by this\n * (rather than a 32-bit `<<`) keeps the key collision-free up to ~67M (2^26)\n * ids per world, within JS's 2^53 safe-integer range.\n * @internal\n */\nexport const pairKeyStride = 0x4000000; // 2^26\n\n/**\n * Integer key for an unordered collider pair (`aId < bId` is guaranteed by the\n * broad phase). The previous `(aId << 16) | bId` silently collided once any id\n * reached 65536, because JS bitwise operators wrap at 32 bits.\n * @internal\n */\nexport const pairKey = (aId: number, bId: number): number => aId * pairKeyStride + bId;\n\nconst authoredPairKey = (record: ContactRecord): number => {\n const first = record.ownerA.id;\n const second = record.ownerB.id;\n\n return first < second ? pairKey(first, second) : pairKey(second, first);\n};\n\nconst createRecord = (a: Collider, b: Collider, ownerA: Collider, ownerB: Collider, isSensor: boolean): ContactRecord => ({\n a,\n b,\n ownerA,\n ownerB,\n isSensor,\n touching: false,\n seen: true,\n enabled: true,\n friction: 0,\n restitution: 0,\n manifold: new Manifold(),\n normalImpulse: [0, 0],\n tangentImpulse: [0, 0],\n pointIds: [0, 0],\n});\n\n/**\n * Map the previously accumulated impulses onto the new manifold points by feature\n * id (warm-starting). Unmatched points start at zero; the cache is re-keyed to the\n * new ids. Runs after `collide` has refreshed `record.manifold`.\n */\nconst warmStartMatch = (record: ContactRecord): void => {\n const manifold = record.manifold;\n const pn0 = record.normalImpulse[0];\n const pn1 = record.normalImpulse[1];\n const pt0 = record.tangentImpulse[0];\n const pt1 = record.tangentImpulse[1];\n const pid0 = record.pointIds[0];\n const pid1 = record.pointIds[1];\n\n for (let i = 0; i < 2; i++) {\n if (i < manifold.pointCount) {\n // i ∈ {0,1} and within pointCount, so the manifold point exists.\n const id = (i === 0 ? manifold.points[0] : manifold.points[1]).id;\n let normal = 0;\n let tangent = 0;\n\n if (id === pid0) {\n normal = pn0;\n tangent = pt0;\n } else if (id === pid1) {\n normal = pn1;\n tangent = pt1;\n }\n\n record.normalImpulse[i] = normal;\n record.tangentImpulse[i] = tangent;\n record.pointIds[i] = id;\n } else {\n record.normalImpulse[i] = 0;\n record.tangentImpulse[i] = 0;\n record.pointIds[i] = 0;\n }\n }\n};\n\nconst makeCollisionEvent = (a: Collider, b: Collider, manifold: Manifold): CollisionEvent => {\n const points: ContactPoint[] = [];\n\n for (let i = 0; i < manifold.pointCount; i++) {\n // i in 0..pointCount-1 and pointCount ≤ 2, so the manifold point exists.\n const p = i === 0 ? manifold.points[0] : manifold.points[1];\n\n points.push(Object.freeze({ x: p.x, y: p.y, penetration: p.penetration }));\n }\n\n return Object.freeze({\n bodyA: a.body,\n bodyB: b.body,\n colliderA: a,\n colliderB: b,\n normal: Object.freeze({ x: manifold.normalX, y: manifold.normalY }),\n points: Object.freeze(points),\n });\n};\n\nconst makeEndEvent = (a: Collider, b: Collider): CollisionEvent =>\n Object.freeze({\n bodyA: a.body,\n bodyB: b.body,\n colliderA: a,\n colliderB: b,\n normal: Object.freeze({ x: 0, y: 0 }),\n points: Object.freeze([] as ContactPoint[]),\n });\n\nconst makeSensorEvent = (a: Collider, b: Collider): SensorEvent => {\n let sensor: Collider;\n let other: Collider;\n\n if (a.isSensor && b.isSensor) {\n sensor = a.id < b.id ? a : b;\n other = sensor === a ? b : a;\n } else if (a.isSensor) {\n sensor = a;\n other = b;\n } else {\n sensor = b;\n other = a;\n }\n\n return Object.freeze({ sensor, other });\n};\n\nconst byColliderPair = (x: CollisionEvent, y: CollisionEvent): number => x.colliderA.id - y.colliderA.id || x.colliderB.id - y.colliderB.id;\n\nconst bySensorPair = (x: SensorEvent, y: SensorEvent): number => x.sensor.id - y.sensor.id || x.other.id - y.other.id;\n\nconst byRecordPair = (x: ContactRecord, y: ContactRecord): number => x.a.id - y.a.id || x.b.id - y.b.id;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAa,eAAb,MAA0B;;CAExB,AAAgB,iBAAmC,CAAC;;CAEpD,AAAgB,eAAiC,CAAC;;CAElD,AAAgB,cAA6B,CAAC;;CAE9C,AAAgB,aAA4B,CAAC;;CAE7C,AAAgB,gBAAiC,CAAC;CAIlD,AAAiB,2BAAW,IAAI,IAA2B;CAG3D,AAAiB,iCAAiB,IAAI,IAAoB;CAC1D,AAAiB,mBAAmB,IAAI,8BAA8B;;CAGtE,IAAW,cAAsB;EAC/B,OAAO,KAAK,SAAS;CACvB;;CAGA,AAAO,OAAO,OAAuC;EACnD,KAAK,eAAe,SAAS;EAC7B,KAAK,aAAa,SAAS;EAC3B,KAAK,YAAY,SAAS;EAC1B,KAAK,WAAW,SAAS;EACzB,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X,WAAW;CACX,QAAQ,OAAO,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC;CACpC,QAAQ,OAAO,OAAO,CAAC,CAAmB;AAC5C,CAAC;AAEH,MAAM,mBAAmB,GAAa,MAA6B;CACjE,IAAI;CACJ,IAAI;CAEJ,IAAI,EAAE,YAAY,EAAE,UAAU;EAC5B,SAAS,EAAE,KAAK,EAAE,KAAK,IAAI;EAC3B,QAAQ,WAAW,IAAI,IAAI;CAC7B,OAAO,IAAI,EAAE,UAAU;EACrB,SAAS;EACT,QAAQ;CACV,OAAO;EACL,SAAS;EACT,QAAQ;CACV;CAEA,OAAO,OAAO,OAAO;EAAE;EAAQ;CAAM,CAAC;AACxC;AAEA,MAAM,kBAAkB,GAAmB,MAA8B,EAAE,UAAU,KAAK,EAAE,UAAU,MAAM,EAAE,UAAU,KAAK,EAAE,UAAU;AAEzI,MAAM,gBAAgB,GAAgB,MAA2B,EAAE,OAAO,KAAK,EAAE,OAAO,MAAM,EAAE,MAAM,KAAK,EAAE,MAAM;AAEnH,MAAM,gBAAgB,GAAkB,MAA6B,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE"}
|
|
1
|
+
{"version":3,"file":"ContactGraph.js","names":[],"sources":["../../src/ContactGraph.ts"],"sourcesContent":["import type { CandidatePair } from './broadphase/BroadPhase';\nimport type { Collider } from './Collider';\nimport { authoredCollider } from './Collider';\nimport { Manifold } from './collision/Manifold';\nimport { collide, testOverlap } from './collision/narrowphase';\nimport type { ContactModifier } from './ContactModifier';\nimport { MutableContactModifierContext } from './ContactModifier';\nimport type { CollisionEvent, ContactPoint, SensorEvent } from './events';\nimport { sortInPlace } from './sort';\nimport { shouldCollide } from './types';\n\n/**\n * Persistent per-pair contact state. For solid contacts it carries a manifold\n * reused across passes plus the accumulated normal/tangent impulses (warm-start\n * cache), keyed by manifold-point feature ids. Consumed by the {@link ContactSolver}.\n */\nexport interface ContactRecord {\n readonly a: Collider;\n readonly b: Collider;\n /**\n * Authored collider behind {@link a} - itself, unless `a` is an engine-owned\n * chain edge proxy, in which case it is the chain collider the caller made.\n * Solver identity is the proxy pair; public identity is the authored pair.\n */\n readonly ownerA: Collider;\n readonly ownerB: Collider;\n readonly isSensor: boolean;\n touching: boolean;\n seen: boolean;\n /**\n * Per-step solver participation. Re-derived to `true` for every touching solid\n * contact each pass, then optionally cleared by the world's `ContactModifier`.\n */\n enabled: boolean;\n /** Per-step Coulomb friction, re-derived from the two colliders each pass. */\n friction: number;\n /** Per-step restitution, re-derived from the two colliders each pass. */\n restitution: number;\n /** Persistent manifold (solid contacts), refreshed each pass by the narrow phase. */\n readonly manifold: Manifold;\n /** Accumulated normal impulse per contact point, carried across steps (warm-start). */\n readonly normalImpulse: [number, number];\n /** Accumulated tangent impulse per contact point, carried across steps (warm-start). */\n readonly tangentImpulse: [number, number];\n /** Feature ids the cached impulses belong to (for warm-start matching). */\n readonly pointIds: [number, number];\n /**\n * Penetration each point carried on the previous detection pass, matched by\n * feature id the same way the impulse cache is, or `-1` where the point is new\n * and has no history. The difference against the manifold's current\n * penetration is how much the last solve actually moved the overlap, which is\n * what separates a contact the push-out is still working off from one that has\n * reached the depth its load holds it at.\n */\n readonly previousPenetration: [number, number];\n /** Penetration per point as of this pass, kept so the next pass can form that difference. */\n readonly pointPenetration: [number, number];\n}\n\n/**\n * The persistent contact set. Each detection pass it diffs the currently\n * touching collider pairs against the previous pass and produces immutable\n * begin/end (and sensor enter/exit) event snapshots. Duplicate begin/end churn\n * is suppressed by the persistent records, and the produced event arrays are\n * sorted by collider id for deterministic dispatch.\n *\n * Touching solid contacts are also collected into {@link solidContacts} (with a\n * warm-start impulse cache) for the dynamics solver. The graph holds no\n * module-level state - each world owns one.\n *\n * Records are keyed on the pair the solver sees, which for a chain collider is\n * one of its edge proxies. Events are not: a body touching several edges of one\n * chain is one authored contact, so the graph reference-counts the authored pair\n * behind its records and emits begin/end only on the first and last of them.\n */\nexport class ContactGraph {\n /** Immutable solid-contact begin snapshots produced by the latest {@link update}. */\n public readonly collisionStart: CollisionEvent[] = [];\n /** Immutable solid-contact end snapshots produced by the latest {@link update}. */\n public readonly collisionEnd: CollisionEvent[] = [];\n /** Immutable sensor-enter snapshots produced by the latest {@link update}. */\n public readonly sensorEnter: SensorEvent[] = [];\n /** Immutable sensor-exit snapshots produced by the latest {@link update}. */\n public readonly sensorExit: SensorEvent[] = [];\n /** Touching solid contacts this pass, in deterministic order - consumed by the solver. */\n public readonly solidContacts: ContactRecord[] = [];\n\n // Integer pair-keys (`(a.id << 16) | b.id`, a.id < b.id guaranteed by the broad\n // phase) - cheaper than string keys on the per-step solver hot path.\n /**\n * Body pairs a joint has taken out of collision, keyed by\n * {@link bodyPairKey} and reference-counted by the world; `null` until a world\n * hands its own map over.\n *\n * Consulted here rather than in the solver because the cheapest contact is\n * the one the narrow phase never computes: a chain of N links otherwise pays\n * for N-1 manifolds, warm-start slots and event records per step that nothing\n * is allowed to act on.\n */\n private _uncollidablePairs: ReadonlyMap<number, number> | null = null;\n\n private readonly _records = new Map<number, ContactRecord>();\n // Live solver contacts per authored collider pair. Only pairs whose records\n // are engine-owned proxies appear here; everything else emits directly.\n private readonly _authoredPairs = new Map<number, number>();\n private readonly _modifierContext = new MutableContactModifierContext();\n\n /** Touching pairs currently tracked (for debug draw). */\n public get recordCount(): number {\n return this._records.size;\n }\n\n /** @internal - adopt the world's joint-filtered body pairs; see {@link _uncollidablePairs}. */\n public _useUncollidablePairs(pairs: ReadonlyMap<number, number>): void {\n this._uncollidablePairs = pairs;\n }\n\n /** Diff this pass's candidate pairs against the persistent set, collecting events + solid contacts. */\n public update(pairs: readonly CandidatePair[]): void {\n this.collisionStart.length = 0;\n this.collisionEnd.length = 0;\n this.sensorEnter.length = 0;\n this.sensorExit.length = 0;\n this.solidContacts.length = 0;\n\n this._records.forEach(resetSeen);\n\n for (const pair of pairs) {\n const a = pair.a;\n const b = pair.b;\n\n // Material, filter and sensor flag live on the authored collider; an edge\n // proxy carries none of its own, so a chain stays one collider to configure.\n const ownerA = authoredCollider(a);\n const ownerB = authoredCollider(b);\n\n if (!shouldCollide(ownerA.filter, ownerB.filter)) {\n continue;\n }\n\n // Checked against the size first so a world without such a joint pays one\n // property read per pair rather than a map lookup.\n if (this._uncollidablePairs !== null && this._uncollidablePairs.size > 0 && this._uncollidablePairs.has(bodyPairKey(ownerA.body.id, ownerB.body.id))) {\n continue;\n }\n\n const isSensor = ownerA.isSensor || ownerB.isSensor;\n const key = pairKey(a.id, b.id);\n const existing = this._records.get(key);\n const record = existing ?? createRecord(a, b, ownerA, ownerB, isSensor);\n const touching = isSensor ? testOverlap(a, b) : collide(a, b, record.manifold);\n\n if (touching) {\n record.seen = true;\n\n if (existing === undefined) {\n this._records.set(key, record);\n }\n\n if (!record.touching) {\n record.touching = true;\n this._emitBegin(record);\n }\n\n if (!isSensor) {\n // Per-step controls start from the collider-derived defaults every\n // pass, so a modifier that skipped a contact last step does not leak\n // into this one.\n record.enabled = true;\n record.friction = Math.sqrt(ownerA.friction * ownerB.friction);\n record.restitution = Math.max(ownerA.restitution, ownerB.restitution);\n warmStartMatch(record);\n this.solidContacts.push(record);\n }\n } else if (existing !== undefined) {\n if (record.touching) {\n this._emitEnd(record);\n }\n\n this._records.delete(key);\n }\n }\n\n // Pairs that left the broad phase entirely while touching → fire end. forEach\n // + thisArg is the allocation-free iteration (for...of allocates an entry tuple\n // per record each step); the thisArg binds `this`, so unbound-method is a\n // false positive here.\n // eslint-disable-next-line @typescript-eslint/unbound-method -- the thisArg above binds it\n this._records.forEach(this._removeIfUnseen, this);\n\n sortInPlace(this.collisionStart, byColliderPair);\n sortInPlace(this.collisionEnd, byColliderPair);\n sortInPlace(this.sensorEnter, bySensorPair);\n sortInPlace(this.sensorExit, bySensorPair);\n sortInPlace(this.solidContacts, byRecordPair);\n }\n\n /**\n * Run `modifier` over every touching solid contact of this pass. Called after\n * detection and before island building, so a contact the modifier disables\n * neither reaches the solver nor couples its two bodies into one sleeping\n * island. A disabled contact's warm-start cache is dropped, so re-enabling it\n * later starts from zero instead of releasing a stale impulse.\n */\n public applyModifier(modifier: ContactModifier): void {\n const context = this._modifierContext;\n\n for (const record of this.solidContacts) {\n context.bind(record);\n modifier(context);\n context.flush(record);\n\n if (!record.enabled) {\n record.normalImpulse[0] = 0;\n record.normalImpulse[1] = 0;\n record.tangentImpulse[0] = 0;\n record.tangentImpulse[1] = 0;\n record.pointIds[0] = 0;\n record.pointIds[1] = 0;\n // Same reasoning for the penetration history: a contact that carried no\n // impulse this step did not move its overlap, so the next pass must read\n // the point as new rather than as one whose push-out has converged.\n record.pointPenetration[0] = -1;\n record.pointPenetration[1] = -1;\n }\n }\n }\n\n /**\n * Remove every record referencing `collider` (called when a collider is\n * destroyed). Passing an authored chain collider also drops the records of\n * every edge proxy it owns.\n */\n public removeCollider(collider: Collider): void {\n for (const [key, record] of this._records) {\n if (record.a === collider || record.b === collider || record.ownerA === collider || record.ownerB === collider) {\n if (record.touching) {\n this._releaseAuthoredPair(record);\n }\n\n this._records.delete(key);\n }\n }\n }\n\n /** Drop all records (world reset/destroy). */\n public clear(): void {\n this._records.clear();\n this._authoredPairs.clear();\n }\n\n private _emitBegin(record: ContactRecord): void {\n if (!this._retainAuthoredPair(record)) {\n return;\n }\n\n if (record.isSensor) {\n this.sensorEnter.push(makeSensorEvent(record.ownerA, record.ownerB));\n } else {\n this.collisionStart.push(makeCollisionEvent(record.ownerA, record.ownerB, record.manifold));\n }\n }\n\n private _emitEnd(record: ContactRecord): void {\n if (!this._releaseAuthoredPair(record)) {\n return;\n }\n\n if (record.isSensor) {\n this.sensorExit.push(makeSensorEvent(record.ownerA, record.ownerB));\n } else {\n this.collisionEnd.push(makeEndEvent(record.ownerA, record.ownerB));\n }\n }\n\n /**\n * Count one more solver contact against the authored pair, reporting whether\n * it is the first - the only one that may emit a begin event. A record whose\n * colliders are the authored ones needs no counting at all, so a world without\n * chains never touches the map.\n */\n private _retainAuthoredPair(record: ContactRecord): boolean {\n if (record.a === record.ownerA && record.b === record.ownerB) {\n return true;\n }\n\n const key = authoredPairKey(record);\n const count = this._authoredPairs.get(key) ?? 0;\n\n this._authoredPairs.set(key, count + 1);\n\n return count === 0;\n }\n\n /** Counterpart of {@link _retainAuthoredPair}: `true` on the last contact of the pair. */\n private _releaseAuthoredPair(record: ContactRecord): boolean {\n if (record.a === record.ownerA && record.b === record.ownerB) {\n return true;\n }\n\n const key = authoredPairKey(record);\n const count = (this._authoredPairs.get(key) ?? 1) - 1;\n\n if (count <= 0) {\n this._authoredPairs.delete(key);\n\n return true;\n }\n\n this._authoredPairs.set(key, count);\n\n return false;\n }\n\n /**\n * `Map.forEach` callback (its `this` bound via the forEach thisArg) - drops a\n * record the latest pass did not see, firing an end event if it was touching.\n * A method reference + thisArg keeps the per-step iteration allocation-free,\n * unlike `for (const [key, record] of map)` which allocates an entry tuple per\n * record (~1000/step). Deleting the current entry during forEach is safe.\n */\n private _removeIfUnseen(record: ContactRecord, key: number): void {\n if (!record.seen) {\n if (record.touching) {\n this._emitEnd(record);\n }\n\n this._records.delete(key);\n }\n }\n}\n\n/** `Map.forEach` callback - clears the per-pass `seen` flag (no iterator allocation). */\nconst resetSeen = (record: ContactRecord): void => {\n record.seen = false;\n};\n\n/**\n * Stride for packing two collider ids into one pair key. Multiplying by this\n * (rather than a 32-bit `<<`) keeps the key collision-free up to ~67M (2^26)\n * ids per world, within JS's 2^53 safe-integer range.\n * @internal\n */\nexport const pairKeyStride = 0x4000000; // 2^26\n\n/**\n * Integer key for an unordered collider pair (`aId < bId` is guaranteed by the\n * broad phase). The previous `(aId << 16) | bId` silently collided once any id\n * reached 65536, because JS bitwise operators wrap at 32 bits.\n * @internal\n */\nexport const pairKey = (aId: number, bId: number): number => aId * pairKeyStride + bId;\n\n/**\n * Integer key for an unordered BODY pair, which unlike a collider pair arrives\n * in no guaranteed order.\n * @internal\n */\nexport const bodyPairKey = (aId: number, bId: number): number => (aId < bId ? pairKey(aId, bId) : pairKey(bId, aId));\n\nconst authoredPairKey = (record: ContactRecord): number => {\n const first = record.ownerA.id;\n const second = record.ownerB.id;\n\n return first < second ? pairKey(first, second) : pairKey(second, first);\n};\n\nconst createRecord = (a: Collider, b: Collider, ownerA: Collider, ownerB: Collider, isSensor: boolean): ContactRecord => ({\n a,\n b,\n ownerA,\n ownerB,\n isSensor,\n touching: false,\n seen: true,\n enabled: true,\n friction: 0,\n restitution: 0,\n manifold: new Manifold(),\n normalImpulse: [0, 0],\n tangentImpulse: [0, 0],\n pointIds: [0, 0],\n previousPenetration: [-1, -1],\n pointPenetration: [-1, -1],\n});\n\n/**\n * Map the previously accumulated impulses onto the new manifold points by feature\n * id (warm-starting), and carry each point's previous penetration across the same\n * match. Unmatched points start at zero impulse and at no penetration history;\n * the cache is re-keyed to the new ids. Runs after `collide` has refreshed\n * `record.manifold`.\n */\nconst warmStartMatch = (record: ContactRecord): void => {\n const manifold = record.manifold;\n const pn0 = record.normalImpulse[0];\n const pn1 = record.normalImpulse[1];\n const pt0 = record.tangentImpulse[0];\n const pt1 = record.tangentImpulse[1];\n const pd0 = record.pointPenetration[0];\n const pd1 = record.pointPenetration[1];\n const pid0 = record.pointIds[0];\n const pid1 = record.pointIds[1];\n\n for (let i = 0; i < 2; i++) {\n if (i < manifold.pointCount) {\n // i ∈ {0,1} and within pointCount, so the manifold point exists.\n const point = i === 0 ? manifold.points[0] : manifold.points[1];\n const id = point.id;\n let normal = 0;\n let tangent = 0;\n let previous = -1;\n\n if (id === pid0) {\n normal = pn0;\n tangent = pt0;\n previous = pd0;\n } else if (id === pid1) {\n normal = pn1;\n tangent = pt1;\n previous = pd1;\n }\n\n record.normalImpulse[i] = normal;\n record.tangentImpulse[i] = tangent;\n record.previousPenetration[i] = previous;\n record.pointPenetration[i] = point.penetration;\n record.pointIds[i] = id;\n } else {\n record.normalImpulse[i] = 0;\n record.tangentImpulse[i] = 0;\n record.previousPenetration[i] = -1;\n record.pointPenetration[i] = -1;\n record.pointIds[i] = 0;\n }\n }\n};\n\nconst makeCollisionEvent = (a: Collider, b: Collider, manifold: Manifold): CollisionEvent => {\n const points: ContactPoint[] = [];\n\n for (let i = 0; i < manifold.pointCount; i++) {\n // i in 0..pointCount-1 and pointCount ≤ 2, so the manifold point exists.\n const p = i === 0 ? manifold.points[0] : manifold.points[1];\n\n points.push(Object.freeze({ x: p.x, y: p.y, penetration: p.penetration }));\n }\n\n return Object.freeze({\n bodyA: a.body,\n bodyB: b.body,\n colliderA: a,\n colliderB: b,\n normal: Object.freeze({ x: manifold.normalX, y: manifold.normalY }),\n points: Object.freeze(points),\n });\n};\n\nconst makeEndEvent = (a: Collider, b: Collider): CollisionEvent =>\n Object.freeze({\n bodyA: a.body,\n bodyB: b.body,\n colliderA: a,\n colliderB: b,\n normal: Object.freeze({ x: 0, y: 0 }),\n points: Object.freeze([] as ContactPoint[]),\n });\n\nconst makeSensorEvent = (a: Collider, b: Collider): SensorEvent => {\n let sensor: Collider;\n let other: Collider;\n\n if (a.isSensor && b.isSensor) {\n sensor = a.id < b.id ? a : b;\n other = sensor === a ? b : a;\n } else if (a.isSensor) {\n sensor = a;\n other = b;\n } else {\n sensor = b;\n other = a;\n }\n\n return Object.freeze({ sensor, other });\n};\n\nconst byColliderPair = (x: CollisionEvent, y: CollisionEvent): number => x.colliderA.id - y.colliderA.id || x.colliderB.id - y.colliderB.id;\n\nconst bySensorPair = (x: SensorEvent, y: SensorEvent): number => x.sensor.id - y.sensor.id || x.other.id - y.other.id;\n\nconst byRecordPair = (x: ContactRecord, y: ContactRecord): number => x.a.id - y.a.id || x.b.id - y.b.id;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2EA,IAAa,eAAb,MAA0B;;CAExB,AAAgB,iBAAmC,CAAC;;CAEpD,AAAgB,eAAiC,CAAC;;CAElD,AAAgB,cAA6B,CAAC;;CAE9C,AAAgB,aAA4B,CAAC;;CAE7C,AAAgB,gBAAiC,CAAC;;;;;;;;;;;CAclD,AAAQ,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AC7B,OAAO,IAAI,EAAE,UAAU;EACrB,SAAS;EACT,QAAQ;CACV,OAAO;EACL,SAAS;EACT,QAAQ;CACV;CAEA,OAAO,OAAO,OAAO;EAAE;EAAQ;CAAM,CAAC;AACxC;AAEA,MAAM,kBAAkB,GAAmB,MAA8B,EAAE,UAAU,KAAK,EAAE,UAAU,MAAM,EAAE,UAAU,KAAK,EAAE,UAAU;AAEzI,MAAM,gBAAgB,GAAgB,MAA2B,EAAE,OAAO,KAAK,EAAE,OAAO,MAAM,EAAE,MAAM,KAAK,EAAE,MAAM;AAEnH,MAAM,gBAAgB,GAAkB,MAA6B,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Collider } from './Collider';
|
|
2
|
-
import type { ContactRecord } from './ContactGraph';
|
|
3
2
|
import type { PhysicsBody } from './PhysicsBody';
|
|
4
3
|
/**
|
|
5
4
|
* A solid contact as the world's {@link ContactModifier} sees it: the pair that
|
|
@@ -60,26 +59,4 @@ export interface ContactModifierContext {
|
|
|
60
59
|
* disabling a contact also keeps the two bodies from sleeping as one.
|
|
61
60
|
*/
|
|
62
61
|
export type ContactModifier = (contact: ContactModifierContext) => void;
|
|
63
|
-
/**
|
|
64
|
-
* The single reused {@link ContactModifierContext} instance. Bound to one record
|
|
65
|
-
* at a time so a step over thousands of contacts allocates nothing.
|
|
66
|
-
* @internal
|
|
67
|
-
*/
|
|
68
|
-
export declare class MutableContactModifierContext implements ContactModifierContext {
|
|
69
|
-
colliderA: Collider;
|
|
70
|
-
colliderB: Collider;
|
|
71
|
-
bodyA: PhysicsBody;
|
|
72
|
-
bodyB: PhysicsBody;
|
|
73
|
-
normalX: number;
|
|
74
|
-
normalY: number;
|
|
75
|
-
pointCount: number;
|
|
76
|
-
maxPenetration: number;
|
|
77
|
-
enabled: boolean;
|
|
78
|
-
friction: number;
|
|
79
|
-
restitution: number;
|
|
80
|
-
/** Point this context at `record` and load its current per-step values. */
|
|
81
|
-
bind(record: ContactRecord): void;
|
|
82
|
-
/** Write the (possibly modified) controls back onto the bound record. */
|
|
83
|
-
flush(record: ContactRecord): void;
|
|
84
|
-
}
|
|
85
62
|
//# sourceMappingURL=ContactModifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactModifier.d.ts","sourceRoot":"","sources":["../../src/ContactModifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ContactModifier.d.ts","sourceRoot":"","sources":["../../src/ContactModifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gGAAgG;IAChG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;;;;;OAOG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC"}
|