@codexo/exojs-physics 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/Collider.d.ts +0 -33
- package/dist/esm/Collider.d.ts.map +1 -1
- package/dist/esm/Collider.js +1 -1
- package/dist/esm/Collider.js.map +1 -1
- package/dist/esm/ContactGraph.d.ts +11 -14
- package/dist/esm/ContactGraph.d.ts.map +1 -1
- package/dist/esm/ContactGraph.js +20 -4
- 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 +2 -2
- package/dist/esm/PhysicsBody.js.map +1 -1
- package/dist/esm/PhysicsWorld.d.ts +8 -37
- package/dist/esm/PhysicsWorld.d.ts.map +1 -1
- package/dist/esm/PhysicsWorld.js +39 -18
- package/dist/esm/PhysicsWorld.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 +0 -3
- package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
- package/dist/esm/joints/DistanceJoint.js +3 -0
- package/dist/esm/joints/DistanceJoint.js.map +1 -1
- package/dist/esm/joints/Joint.d.ts +0 -6
- package/dist/esm/joints/Joint.d.ts.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 +3 -0
- package/dist/esm/joints/MouseJoint.js.map +1 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +0 -3
- package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
- package/dist/esm/joints/PrismaticJoint.js +3 -0
- package/dist/esm/joints/PrismaticJoint.js.map +1 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +0 -3
- package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
- package/dist/esm/joints/RevoluteJoint.js +3 -0
- package/dist/esm/joints/RevoluteJoint.js.map +1 -1
- package/dist/esm/joints/WeldJoint.d.ts +0 -3
- package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
- package/dist/esm/joints/WeldJoint.js +3 -0
- package/dist/esm/joints/WeldJoint.js.map +1 -1
- package/dist/esm/joints/WheelJoint.d.ts +0 -3
- package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
- package/dist/esm/joints/WheelJoint.js +3 -0
- package/dist/esm/joints/WheelJoint.js.map +1 -1
- package/dist/esm/physicsBuildInfo.js +2 -2
- 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/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,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAoB/C,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B,8BAA8B;IAC9B,KAAK,EAAE,QAAQ,CAAC;IAChB,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iGAAiG;IACjG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,C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AQ,CAAC,KAAK,CAA0B;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAI1D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAC1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAW;IAC1C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAW;IAEzC,OAAO,CAAC,UAAU,CAAS;gBAYR,OAAO,EAAE,eAAe;IAyB3C,iGAAiG;IACjG,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAW,IAAI,IAAI,WAAW,CAM7B;IAED,8EAA8E;IAC9E,IAAW,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAEpC;IAED,iFAAiF;IACjF,IAAW,cAAc,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE/C;IAED,qEAAqE;IACrE,IAAW,cAAc,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE/C;IAED,qEAAqE;IACrE,IAAW,WAAW,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE5C;IAED,yFAAyF;IACzF,IAAW,aAAa,IAAI,SAAS,MAAM,EAAE,CAE5C;IAED,gGAAgG;IAChG,IAAW,YAAY,IAAI,SAAS,MAAM,EAAE,CAE3C;IAmBD,iEAAiE;IACjE,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;;;OAIG;IACI,WAAW,CAAC,aAAa,EAAE,SAAS,GAAG,IAAI;IAwBlD;;;;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
|
@@ -245,7 +245,7 @@ var Collider = class Collider {
|
|
|
245
245
|
}
|
|
246
246
|
return edges;
|
|
247
247
|
}
|
|
248
|
-
/**
|
|
248
|
+
/** @internal - mark destroyed (called by the world). */
|
|
249
249
|
_markDestroyed() {
|
|
250
250
|
this._destroyed = true;
|
|
251
251
|
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,YAAY;EACpC,KAAK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@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":";;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AAI,OAAO,IAAI,IAAI;GAC9B,OAAO,IAAI,IAAI,OAAO,IAAI,IAAI;GAE9B,cAAc,OAAO,QAAQ,IAAI,IAAK,QAAQ,IAAI,IAAI,IAAK,GAAG;GAC9D,KAAK,cAAc,IAAI,KAAK,IAAI;GAChC,KAAK,cAAc,IAAI,IAAI,KAAK,IAAI;EACtC;EAEA,KAAK,MAAM,OAAO,OAAO;EACzB,KAAK,MAAM,OAAO,OAAO;EACzB,KAAK,MAAM,OAAO,OAAO;EACzB,KAAK,MAAM,OAAO,OAAO;CAC3B;;CAGA,AAAO,QAAQ,MAAmB,IAAkB;EAClD,KAAK,QAAQ;EACb,KAAK,MAAM;CACb;;;;;;CAOA,AAAQ,iBAAiB,OAAwC;EAC/D,MAAM,QAAoB,CAAC;EAE3B,KAAK,MAAM,aAAa,MAAM,OAAO;GACnC,MAAM,OAAO,IAAI,SAAS;IACxB,OAAO;IACP,QAAQ;KAAE,GAAG,KAAK;KAAS,GAAG,KAAK;IAAQ;IAC3C,UAAU,KAAK;IAIf,SAAS;GACX,CAAC;GAED,KAAK,eAAe;GACpB,MAAM,KAAK,IAAI;EACjB;EAEA,OAAO;CACT;;CAGA,AAAO,iBAAuB;EAC5B,KAAK,aAAa;EAElB,IAAI,KAAK,gBAAgB,MACvB,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,aAAa;CAGxB;AACF;;;;;;;;;AAUA,MAAa,oBAAoB,aAAiC,SAAS,eAAe"}
|
|
@@ -38,6 +38,17 @@ export interface ContactRecord {
|
|
|
38
38
|
readonly tangentImpulse: [number, 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
|
|
@@ -109,18 +120,4 @@ export declare class ContactGraph {
|
|
|
109
120
|
*/
|
|
110
121
|
private _removeIfUnseen;
|
|
111
122
|
}
|
|
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
123
|
//# 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,U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E,aAAa,EAAE,CAAM;IAIpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAG7D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6B;IAC5D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuC;IAExE,yDAAyD;IACzD,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,uGAAuG;IAChG,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI;IAyEpD;;;;;;OAMG;IACI,aAAa,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;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
|
@@ -104,6 +104,8 @@ var ContactGraph = class {
|
|
|
104
104
|
record.tangentImpulse[1] = 0;
|
|
105
105
|
record.pointIds[0] = 0;
|
|
106
106
|
record.pointIds[1] = 0;
|
|
107
|
+
record.pointPenetration[0] = -1;
|
|
108
|
+
record.pointPenetration[1] = -1;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -209,12 +211,16 @@ const createRecord = (a, b, ownerA, ownerB, isSensor) => ({
|
|
|
209
211
|
manifold: new Manifold(),
|
|
210
212
|
normalImpulse: [0, 0],
|
|
211
213
|
tangentImpulse: [0, 0],
|
|
212
|
-
pointIds: [0, 0]
|
|
214
|
+
pointIds: [0, 0],
|
|
215
|
+
previousPenetration: [-1, -1],
|
|
216
|
+
pointPenetration: [-1, -1]
|
|
213
217
|
});
|
|
214
218
|
/**
|
|
215
219
|
* Map the previously accumulated impulses onto the new manifold points by feature
|
|
216
|
-
* id (warm-starting)
|
|
217
|
-
*
|
|
220
|
+
* id (warm-starting), and carry each point's previous penetration across the same
|
|
221
|
+
* match. Unmatched points start at zero impulse and at no penetration history;
|
|
222
|
+
* the cache is re-keyed to the new ids. Runs after `collide` has refreshed
|
|
223
|
+
* `record.manifold`.
|
|
218
224
|
*/
|
|
219
225
|
const warmStartMatch = (record) => {
|
|
220
226
|
const manifold = record.manifold;
|
|
@@ -222,25 +228,35 @@ const warmStartMatch = (record) => {
|
|
|
222
228
|
const pn1 = record.normalImpulse[1];
|
|
223
229
|
const pt0 = record.tangentImpulse[0];
|
|
224
230
|
const pt1 = record.tangentImpulse[1];
|
|
231
|
+
const pd0 = record.pointPenetration[0];
|
|
232
|
+
const pd1 = record.pointPenetration[1];
|
|
225
233
|
const pid0 = record.pointIds[0];
|
|
226
234
|
const pid1 = record.pointIds[1];
|
|
227
235
|
for (let i = 0; i < 2; i++) if (i < manifold.pointCount) {
|
|
228
|
-
const
|
|
236
|
+
const point = i === 0 ? manifold.points[0] : manifold.points[1];
|
|
237
|
+
const id = point.id;
|
|
229
238
|
let normal = 0;
|
|
230
239
|
let tangent = 0;
|
|
240
|
+
let previous = -1;
|
|
231
241
|
if (id === pid0) {
|
|
232
242
|
normal = pn0;
|
|
233
243
|
tangent = pt0;
|
|
244
|
+
previous = pd0;
|
|
234
245
|
} else if (id === pid1) {
|
|
235
246
|
normal = pn1;
|
|
236
247
|
tangent = pt1;
|
|
248
|
+
previous = pd1;
|
|
237
249
|
}
|
|
238
250
|
record.normalImpulse[i] = normal;
|
|
239
251
|
record.tangentImpulse[i] = tangent;
|
|
252
|
+
record.previousPenetration[i] = previous;
|
|
253
|
+
record.pointPenetration[i] = point.penetration;
|
|
240
254
|
record.pointIds[i] = id;
|
|
241
255
|
} else {
|
|
242
256
|
record.normalImpulse[i] = 0;
|
|
243
257
|
record.tangentImpulse[i] = 0;
|
|
258
|
+
record.previousPenetration[i] = -1;
|
|
259
|
+
record.pointPenetration[i] = -1;
|
|
244
260
|
record.pointIds[i] = 0;
|
|
245
261
|
}
|
|
246
262
|
};
|
|
@@ -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,KAAK,cAAc,SAAS;EAE5B,KAAK,SAAS,QAAQ,SAAS;EAE/B,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GAIf,MAAM,SAAS,iBAAiB,CAAC;GACjC,MAAM,SAAS,iBAAiB,CAAC;GAEjC,IAAI,CAAC,cAAc,OAAO,QAAQ,OAAO,MAAM,GAC7C;GAGF,MAAM,WAAW,OAAO,YAAY,OAAO;GAC3C,MAAM,MAAM,QAAQ,EAAE,IAAI,EAAE,EAAE;GAC9B,MAAM,WAAW,KAAK,SAAS,IAAI,GAAG;GACtC,M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,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 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 // 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\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":";;;;;;;;;;;;;;;;;;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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"}
|
|
@@ -29,8 +29,6 @@ export interface BodyOptions {
|
|
|
29
29
|
* and registered without the body importing the concrete world class.
|
|
30
30
|
*/
|
|
31
31
|
export interface BodyOwner {
|
|
32
|
-
_allocateColliderId(): number;
|
|
33
|
-
_registerCollider(collider: Collider): void;
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* A rigid body: a world transform plus mass properties aggregated from its
|
|
@@ -69,34 +67,9 @@ export declare class PhysicsBody {
|
|
|
69
67
|
angularVelocity: number;
|
|
70
68
|
/** When `false`, this body is never put to sleep. Default `true`. */
|
|
71
69
|
allowSleep: boolean;
|
|
72
|
-
/** @internal - Delta position X accumulated across the frame's sub-steps by the TGS integrator; written into the transform once per frame by {@link _finalizePosition}. */
|
|
73
|
-
_deltaPosX: number;
|
|
74
|
-
/** @internal - Delta position Y accumulated across the frame's sub-steps by the TGS integrator. */
|
|
75
|
-
_deltaPosY: number;
|
|
76
|
-
/** @internal - Delta rotation (radians) accumulated across the frame's sub-steps by the TGS integrator. */
|
|
77
|
-
_deltaAngle: number;
|
|
78
|
-
/** @internal - `cos(_deltaAngle)`, cached so the solver can rotate the contact anchors by the live sub-step rotation without a per-contact trig call. */
|
|
79
|
-
_deltaCos: number;
|
|
80
|
-
/** @internal - `sin(_deltaAngle)`, cached alongside {@link _deltaCos}. */
|
|
81
|
-
_deltaSin: number;
|
|
82
70
|
private _forceX;
|
|
83
71
|
private _forceY;
|
|
84
72
|
private _torque;
|
|
85
|
-
/** @internal - seconds the body has stayed below the sleep thresholds (frozen while asleep). Read by the world's island pass. */
|
|
86
|
-
_sleepTime: number;
|
|
87
|
-
/** @internal - dense union-find index assigned by the world's island pass each step. */
|
|
88
|
-
_islandIndex: number;
|
|
89
|
-
/**
|
|
90
|
-
* @internal - raised by {@link setTransform}, cleared once the fixed step that
|
|
91
|
-
* saw it completes. A static/kinematic body driven by teleporting carries no
|
|
92
|
-
* velocity, so this is the world's only signal that such a body moved and its
|
|
93
|
-
* sleeping contact partners must be woken.
|
|
94
|
-
*/
|
|
95
|
-
_teleported: boolean;
|
|
96
|
-
/** @internal - world-space centre of mass at the start of the current fixed step (CCD swept-test origin). */
|
|
97
|
-
_ccdPrevX: number;
|
|
98
|
-
/** @internal - see {@link _ccdPrevX}. */
|
|
99
|
-
_ccdPrevY: number;
|
|
100
73
|
private _sleeping;
|
|
101
74
|
private _id;
|
|
102
75
|
private _owner;
|
|
@@ -191,68 +164,14 @@ export declare class PhysicsBody {
|
|
|
191
164
|
* static/kinematic bodies (infinite mass). Returns `this`.
|
|
192
165
|
*/
|
|
193
166
|
applyImpulse(impulseX: number, impulseY: number, pointX?: number, pointY?: number): this;
|
|
194
|
-
/**
|
|
195
|
-
* @internal - integrate velocity from gravity, accumulated forces/torque and
|
|
196
|
-
* damping over the sub-step `h`. No-op for static/kinematic (infinite mass
|
|
197
|
-
* keeps their velocity solver-driven only). Called once per TGS sub-step, so
|
|
198
|
-
* gravity/forces are applied with `h` each sub-step (`N·h = dt`, same total
|
|
199
|
-
* impulse, but the small-step position error scales with `h²`). The
|
|
200
|
-
* force/torque accumulators are **not** cleared here - they are consumed by
|
|
201
|
-
* every sub-step and cleared once per frame by {@link _finalizePosition}.
|
|
202
|
-
*/
|
|
203
|
-
_integrateVelocity(h: number, gravityX: number, gravityY: number): void;
|
|
204
|
-
/**
|
|
205
|
-
* @internal - accumulate this sub-step's velocity into the per-frame delta
|
|
206
|
-
* position/rotation (TGS sub-stepping). The transform itself is **not** moved
|
|
207
|
-
* here; {@link _finalizePosition} writes the accumulated delta once per frame.
|
|
208
|
-
* Tracking the delta (rather than moving the transform each sub-step) lets the
|
|
209
|
-
* solver recompute contact separation from it without re-running detection or
|
|
210
|
-
* re-syncing collider geometry per sub-step. Static bodies never move.
|
|
211
|
-
*/
|
|
212
|
-
_integratePosition(h: number): void;
|
|
213
|
-
/**
|
|
214
|
-
* @internal - advance the sleep timer over one fixed step `dt`. A body below
|
|
215
|
-
* both velocity thresholds accumulates time; a too-fast body, or one that opts
|
|
216
|
-
* out via {@link allowSleep}, resets it. The sleep/wake decision is made per
|
|
217
|
-
* island by the world (so a stack sleeps as a unit) from {@link _sleepTime}.
|
|
218
|
-
*/
|
|
219
|
-
_accumulateSleepTime(dt: number, linearThreshold: number, angularThreshold: number): void;
|
|
220
|
-
/** @internal - set the sleep state. Sleeping zeroes the velocity; waking resets the sleep timer. */
|
|
221
|
-
_setSleeping(sleeping: boolean): void;
|
|
222
167
|
/**
|
|
223
168
|
* Wake the body if it is asleep, resetting its sleep timer. The rest of its
|
|
224
169
|
* island wakes with it on the next step (a contact to an awake body keeps the
|
|
225
170
|
* whole island awake). Returns `this`.
|
|
226
171
|
*/
|
|
227
172
|
wake(): this;
|
|
228
|
-
/**
|
|
229
|
-
* @internal - apply the frame's accumulated delta position/rotation to the
|
|
230
|
-
* transform (rotating about the centre of mass), re-sync collider geometry and
|
|
231
|
-
* clear the force/torque accumulators. Called once per frame after the
|
|
232
|
-
* sub-step loop. Static bodies never move; the force clear still runs (forces
|
|
233
|
-
* are a no-op on infinite mass but the accumulator is reset for consistency).
|
|
234
|
-
*/
|
|
235
|
-
_finalizePosition(): void;
|
|
236
173
|
/** Clear the per-frame TGS delta accumulators (position, rotation and its cached cos/sin). */
|
|
237
174
|
private _resetDelta;
|
|
238
|
-
/** Internal: detach a collider (called by the world during destruction). */
|
|
239
|
-
_removeCollider(collider: Collider): void;
|
|
240
|
-
/**
|
|
241
|
-
* @internal - join `owner`'s world with the allocated `id`. Allocates ids for
|
|
242
|
-
* and registers every held collider, then aggregates the mass model and
|
|
243
|
-
* synchronises world geometry. Called once by {@link PhysicsWorld.add}.
|
|
244
|
-
*
|
|
245
|
-
* Ordering matters and mirrors the per-collider create path exactly: ids and
|
|
246
|
-
* the body link go on first, then a single mass recompute over the full
|
|
247
|
-
* collider set (so the centre of mass / inertia aggregate is correct), then
|
|
248
|
-
* `synchronize` over every collider (the cached world geometry the broad/narrow
|
|
249
|
-
* phase reads), then world registration last. Recomputing mass before all
|
|
250
|
-
* colliders are linked, or syncing before the mass model exists, would feed the
|
|
251
|
-
* solver a stale CoM and produce subtle integration bugs.
|
|
252
|
-
*/
|
|
253
|
-
_attachToWorld(owner: BodyOwner, id: number): void;
|
|
254
|
-
/** Internal: mark destroyed (called by the world). */
|
|
255
|
-
_markDestroyed(): void;
|
|
256
175
|
/**
|
|
257
176
|
* A dynamic body has to carry mass. Boundary geometry (a segment, a chain)
|
|
258
177
|
* reports no mass properties, and a collider may also be given zero density,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsBody.d.ts","sourceRoot":"","sources":["../../src/PhysicsBody.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,uCAAuC;AACvC,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/B,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sFAAsF;IACtF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kJAAkJ;IAClJ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4GAA4G;IAC5G,SAAS,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;
|
|
1
|
+
{"version":3,"file":"PhysicsBody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AgF;IAChF,OAAO,CAAC,cAAc;CA2DvB"}
|
package/dist/esm/PhysicsBody.js
CHANGED
|
@@ -356,7 +356,7 @@ var PhysicsBody = class {
|
|
|
356
356
|
this._deltaCos = 1;
|
|
357
357
|
this._deltaSin = 0;
|
|
358
358
|
}
|
|
359
|
-
/**
|
|
359
|
+
/** @internal - detach a collider (called by the world during destruction). */
|
|
360
360
|
_removeCollider(collider) {
|
|
361
361
|
const index = this._colliders.indexOf(collider);
|
|
362
362
|
if (index !== -1) {
|
|
@@ -388,7 +388,7 @@ var PhysicsBody = class {
|
|
|
388
388
|
for (const collider of this._colliders) collider.synchronize(this._transform);
|
|
389
389
|
for (const collider of this._colliders) owner._registerCollider(collider);
|
|
390
390
|
}
|
|
391
|
-
/**
|
|
391
|
+
/** @internal - mark destroyed (called by the world). */
|
|
392
392
|
_markDestroyed() {
|
|
393
393
|
this._destroyed = true;
|
|
394
394
|
}
|