@codexo/exojs-physics 0.19.1 → 0.20.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 +8 -73
- package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
- package/debug.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -23
- package/dist/esm/Aabb.d.ts +0 -10
- package/dist/esm/Aabb.d.ts.map +0 -1
- package/dist/esm/Aabb.js +0 -16
- package/dist/esm/Aabb.js.map +0 -1
- package/dist/esm/Collider.d.ts +0 -107
- package/dist/esm/Collider.d.ts.map +0 -1
- package/dist/esm/Collider.js +0 -284
- package/dist/esm/Collider.js.map +0 -1
- package/dist/esm/ContactGraph.d.ts +0 -154
- package/dist/esm/ContactGraph.d.ts.map +0 -1
- package/dist/esm/ContactGraph.js +0 -383
- package/dist/esm/ContactGraph.js.map +0 -1
- package/dist/esm/ContactModifier.d.ts +0 -62
- package/dist/esm/ContactModifier.d.ts.map +0 -1
- package/dist/esm/ContactModifier.js +0 -49
- package/dist/esm/ContactModifier.js.map +0 -1
- package/dist/esm/PhysicsBody.d.ts +0 -186
- package/dist/esm/PhysicsBody.d.ts.map +0 -1
- package/dist/esm/PhysicsBody.js +0 -526
- package/dist/esm/PhysicsBody.js.map +0 -1
- package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
- package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
- package/dist/esm/PhysicsBodyComponent.js +0 -77
- package/dist/esm/PhysicsBodyComponent.js.map +0 -1
- package/dist/esm/PhysicsWorld.d.ts +0 -567
- package/dist/esm/PhysicsWorld.d.ts.map +0 -1
- package/dist/esm/PhysicsWorld.js +0 -1096
- package/dist/esm/PhysicsWorld.js.map +0 -1
- package/dist/esm/TimeStepper.d.ts +0 -40
- package/dist/esm/TimeStepper.d.ts.map +0 -1
- package/dist/esm/TimeStepper.js +0 -59
- package/dist/esm/TimeStepper.js.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
- package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.js +0 -52
- package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
- package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
- package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.d.ts +0 -48
- package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.js +0 -81
- package/dist/esm/binding/BindingRegistry.js.map +0 -1
- package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
- package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
- package/dist/esm/binding/PhysicsBinding.js +0 -54
- package/dist/esm/binding/PhysicsBinding.js.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
- package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.js +0 -41
- package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
- package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
- package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/index.d.ts +0 -3
- package/dist/esm/broadphase/index.d.ts.map +0 -1
- package/dist/esm/collision/CollisionProxy.d.ts +0 -15
- package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.d.ts +0 -34
- package/dist/esm/collision/Manifold.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.js +0 -37
- package/dist/esm/collision/Manifold.js.map +0 -1
- package/dist/esm/collision/chainAdjacency.d.ts +0 -2
- package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
- package/dist/esm/collision/chainAdjacency.js +0 -44
- package/dist/esm/collision/chainAdjacency.js.map +0 -1
- package/dist/esm/collision/dispatch.d.ts +0 -35
- package/dist/esm/collision/dispatch.d.ts.map +0 -1
- package/dist/esm/collision/dispatch.js +0 -58
- package/dist/esm/collision/dispatch.js.map +0 -1
- package/dist/esm/collision/index.d.ts +0 -5
- package/dist/esm/collision/index.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.d.ts +0 -17
- package/dist/esm/collision/narrowphase.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.js +0 -555
- package/dist/esm/collision/narrowphase.js.map +0 -1
- package/dist/esm/collision/segments.d.ts +0 -19
- package/dist/esm/collision/segments.d.ts.map +0 -1
- package/dist/esm/collision/segments.js +0 -36
- package/dist/esm/collision/segments.js.map +0 -1
- package/dist/esm/collision/sweep.d.ts +0 -35
- package/dist/esm/collision/sweep.d.ts.map +0 -1
- package/dist/esm/collision/sweep.js +0 -437
- package/dist/esm/collision/sweep.js.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
- package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
- package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
- package/dist/esm/debug/index.d.ts.map +0 -1
- package/dist/esm/debug/index.js +0 -3
- package/dist/esm/events.d.ts +0 -36
- package/dist/esm/events.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -25
- package/dist/esm/joints/DistanceJoint.d.ts +0 -70
- package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
- package/dist/esm/joints/DistanceJoint.js +0 -167
- package/dist/esm/joints/DistanceJoint.js.map +0 -1
- package/dist/esm/joints/Joint.d.ts +0 -76
- package/dist/esm/joints/Joint.d.ts.map +0 -1
- package/dist/esm/joints/Joint.js +0 -62
- package/dist/esm/joints/Joint.js.map +0 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -55
- package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
- package/dist/esm/joints/MouseJoint.js +0 -139
- package/dist/esm/joints/MouseJoint.js.map +0 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
- package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
- package/dist/esm/joints/PrismaticJoint.js +0 -218
- package/dist/esm/joints/PrismaticJoint.js.map +0 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
- package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
- package/dist/esm/joints/RevoluteJoint.js +0 -204
- package/dist/esm/joints/RevoluteJoint.js.map +0 -1
- package/dist/esm/joints/WeldJoint.d.ts +0 -60
- package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
- package/dist/esm/joints/WeldJoint.js +0 -166
- package/dist/esm/joints/WeldJoint.js.map +0 -1
- package/dist/esm/joints/WheelJoint.d.ts +0 -91
- package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
- package/dist/esm/joints/WheelJoint.js +0 -235
- package/dist/esm/joints/WheelJoint.js.map +0 -1
- package/dist/esm/math.d.ts +0 -29
- package/dist/esm/math.d.ts.map +0 -1
- package/dist/esm/math.js +0 -60
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/physicsBuildInfo.d.ts +0 -16
- package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
- package/dist/esm/physicsBuildInfo.js +0 -10
- package/dist/esm/physicsBuildInfo.js.map +0 -1
- package/dist/esm/public.d.ts +0 -34
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.d.ts +0 -95
- package/dist/esm/query/QueryEngine.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.js +0 -512
- package/dist/esm/query/QueryEngine.js.map +0 -1
- package/dist/esm/query/SpatialIndex.d.ts +0 -34
- package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
- package/dist/esm/shapes/AnyShape.d.ts +0 -14
- package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.d.ts +0 -12
- package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.js +0 -41
- package/dist/esm/shapes/BoxShape.js.map +0 -1
- package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
- package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CapsuleShape.js +0 -88
- package/dist/esm/shapes/CapsuleShape.js.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.js +0 -66
- package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -46
- package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainShape.js +0 -85
- package/dist/esm/shapes/ChainShape.js.map +0 -1
- package/dist/esm/shapes/CircleShape.d.ts +0 -14
- package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CircleShape.js +0 -31
- package/dist/esm/shapes/CircleShape.js.map +0 -1
- package/dist/esm/shapes/PolygonShape.d.ts +0 -24
- package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
- package/dist/esm/shapes/PolygonShape.js +0 -153
- package/dist/esm/shapes/PolygonShape.js.map +0 -1
- package/dist/esm/shapes/SegmentShape.d.ts +0 -31
- package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
- package/dist/esm/shapes/SegmentShape.js +0 -62
- package/dist/esm/shapes/SegmentShape.js.map +0 -1
- package/dist/esm/shapes/Shape.d.ts +0 -37
- package/dist/esm/shapes/Shape.d.ts.map +0 -1
- package/dist/esm/shapes/Shape.js +0 -15
- package/dist/esm/shapes/Shape.js.map +0 -1
- package/dist/esm/shapes/convexParts.d.ts +0 -21
- package/dist/esm/shapes/convexParts.d.ts.map +0 -1
- package/dist/esm/shapes/convexParts.js +0 -26
- package/dist/esm/shapes/convexParts.js.map +0 -1
- package/dist/esm/shapes/decompose.d.ts +0 -2
- package/dist/esm/shapes/decompose.d.ts.map +0 -1
- package/dist/esm/shapes/decompose.js +0 -272
- package/dist/esm/shapes/decompose.js.map +0 -1
- package/dist/esm/shapes/index.d.ts +0 -9
- package/dist/esm/shapes/index.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.d.ts +0 -94
- package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.js +0 -457
- package/dist/esm/solver/ContactSolver.js.map +0 -1
- package/dist/esm/solver/tolerances.d.ts +0 -2
- package/dist/esm/solver/tolerances.d.ts.map +0 -1
- package/dist/esm/solver/tolerances.js +0 -36
- package/dist/esm/solver/tolerances.js.map +0 -1
- package/dist/esm/sort.d.ts +0 -2
- package/dist/esm/sort.d.ts.map +0 -1
- package/dist/esm/sort.js +0 -44
- package/dist/esm/sort.js.map +0 -1
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -26
- package/dist/esm/types.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BindingRegistry.js","names":[],"sources":["../../../src/binding/BindingRegistry.ts"],"sourcesContent":["import { logger, type SceneNode } from '@codexo/exojs';\n\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { PhysicsBinding } from './PhysicsBinding';\n\n/** `true` when `ancestor` contributes anything beyond identity to a descendant's world transform. */\nconst hasNonIdentityTransform = (ancestor: SceneNode): boolean =>\n ancestor.x !== 0 ||\n ancestor.y !== 0 ||\n ancestor.rotation !== 0 ||\n ancestor.skewX !== 0 ||\n ancestor.skewY !== 0 ||\n ancestor.scale.x !== 1 ||\n ancestor.scale.y !== 1 ||\n ancestor.origin.x !== 0 ||\n ancestor.origin.y !== 0;\n\n/**\n * Dev-only bind-time guard (F16): {@link PhysicsBinding.sync} writes the\n * body's WORLD transform into the node's LOCAL position/rotation, which is\n * only correct when local space == world space. Walk the parent chain and\n * warn when an ancestor either carries a non-identity transform or is a\n * transform-group boundary (RetainedContainer) - in both cases the ancestor\n * contribution is applied ON TOP of the world-space values sync() writes,\n * double-transforming the node on screen.\n */\nconst warnUnlessWorldSpaceRooted = (node: SceneNode): void => {\n // Duck-typed test doubles may omit `parent`; treat that as world-space-rooted.\n let ancestor: SceneNode | null = node.parent ?? null;\n\n while (ancestor !== null) {\n if (ancestor._isTransformGroupBoundary || hasNonIdentityTransform(ancestor)) {\n const nodeName = node.name !== null && node.name !== '' ? ` '${node.name}'` : '';\n const ancestorName = ancestor.name !== null && ancestor.name !== '' ? ` '${ancestor.name}'` : '';\n\n logger.warn(\n `PhysicsBinding: the bound node${nodeName} is not world-space-rooted — ancestor${ancestorName} ${\n ancestor._isTransformGroupBoundary ? 'is a transform-group boundary (RetainedContainer)' : 'has a non-identity transform'\n }. sync() writes the body's WORLD transform into the node's LOCAL position/rotation, so nesting it under a ` +\n 'moved/rotated/scaled container (or a transform group) will double-transform it on screen. Re-parent the node ' +\n 'to a world-space-rooted container.',\n { source: 'physics' },\n );\n\n return;\n }\n\n ancestor = ancestor.parent ?? null;\n }\n};\n\n/**\n * Owns the body ↔ node links and writes bound node transforms after each step.\n * Backend-agnostic (frontend-level) - it reads only the public body transform.\n */\nexport class BindingRegistry {\n private readonly _bindings = new Map<PhysicsBody, PhysicsBinding>();\n\n /**\n * Link `body` to `node`. Rejects destroyed nodes and nodes with non-zero\n * skew; runtime scale is ignored. In dev builds, warns when the node is not\n * world-space-rooted (moved ancestor or transform-group boundary above it) -\n * see {@link PhysicsBinding} for the local==world contract.\n */\n public bind(body: PhysicsBody, node: SceneNode): PhysicsBinding {\n if (node.destroyed) {\n throw new Error('PhysicsBinding: cannot bind a destroyed node — its pooled transform has already been released.');\n }\n\n if (node.skewX !== 0 || node.skewY !== 0) {\n throw new Error(`PhysicsBinding: the bound node has non-zero skew (${node.skewX}°, ${node.skewY}°); skewed nodes are not supported.`);\n }\n\n if (__DEV__) {\n warnUnlessWorldSpaceRooted(node);\n }\n\n const binding = new PhysicsBinding(body, node);\n\n this._bindings.set(body, binding);\n binding.sync();\n\n return binding;\n }\n\n /** Remove the link for `body`, if any. */\n public unbind(body: PhysicsBody): void {\n this._bindings.delete(body);\n }\n\n /**\n * Write every bound node's transform from its body, dropping links whose node\n * has been destroyed.\n *\n * `SceneNode.destroy()` returns the node's position/rotation state to a shared\n * pool, so a `sync()` that kept writing would not merely update a dead node -\n * it would write through recycled state into whichever live node next takes\n * that slot. Pruning here (rather than only on an explicit `unbind`) is what\n * makes destroying a bound node safe from THAT hazard without a\n * physics-side call.\n *\n * It does not remove the body: pruning only drops this registry's link, so\n * a destroyed node's body stays in {@link PhysicsWorld}, keeps being\n * integrated, and keeps generating contacts and query results with nothing\n * on screen. The body's owner is responsible for destroying it (or calling\n * {@link unbind} first) when the node it was driving is destroyed.\n */\n public sync(): void {\n for (const [body, binding] of this._bindings) {\n if (binding.node.destroyed) {\n this._bindings.delete(body);\n continue;\n }\n\n binding.sync();\n }\n }\n\n /**\n * Like {@link sync}, but places each node `alpha` of the way from its body's\n * previous fixed state to its current one - see\n * {@link PhysicsBinding.syncInterpolated}. Same destroyed-node pruning.\n */\n public syncInterpolated(alpha: number): void {\n for (const [body, binding] of this._bindings) {\n if (binding.node.destroyed) {\n this._bindings.delete(body);\n continue;\n }\n\n binding.syncInterpolated(alpha);\n }\n }\n\n /** `true` when at least one binding exists. */\n public get size(): number {\n return this._bindings.size;\n }\n\n /** Drop all links. */\n public clear(): void {\n this._bindings.clear();\n }\n}\n"],"mappings":";;;;;;;;AAuDA,IAAa,kBAAb,MAA6B;CAC3B,AAAiB,4BAAY,IAAI,IAAiC;;;;;;;CAQlE,AAAO,KAAK,MAAmB,MAAiC;EAC9D,IAAI,KAAK,WACP,MAAM,IAAI,MAAM,gGAAgG;EAGlH,IAAI,KAAK,UAAU,KAAK,KAAK,UAAU,GACrC,MAAM,IAAI,MAAM,qDAAqD,KAAK,MAAM,KAAK,KAAK,MAAM,oCAAoC;EAOtI,MAAM,UAAU,IAAI,eAAe,MAAM,IAAI;EAE7C,KAAK,UAAU,IAAI,MAAM,OAAO;EAChC,QAAQ,KAAK;EAEb,OAAO;CACT;;CAGA,AAAO,OAAO,MAAyB;EACrC,KAAK,UAAU,OAAO,IAAI;CAC5B;;;;;;;;;;;;;;;;;;CAmBA,AAAO,OAAa;EAClB,KAAK,MAAM,CAAC,MAAM,YAAY,KAAK,WAAW;GAC5C,IAAI,QAAQ,KAAK,WAAW;IAC1B,KAAK,UAAU,OAAO,IAAI;IAC1B;GACF;GAEA,QAAQ,KAAK;EACf;CACF;;;;;;CAOA,AAAO,iBAAiB,OAAqB;EAC3C,KAAK,MAAM,CAAC,MAAM,YAAY,KAAK,WAAW;GAC5C,IAAI,QAAQ,KAAK,WAAW;IAC1B,KAAK,UAAU,OAAO,IAAI;IAC1B;GACF;GAEA,QAAQ,iBAAiB,KAAK;EAChC;CACF;;CAGA,IAAW,OAAe;EACxB,OAAO,KAAK,UAAU;CACxB;;CAGA,AAAO,QAAc;EACnB,KAAK,UAAU,MAAM;CACvB;AACF"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { type SceneNode } from '@codexo/exojs';
|
|
2
|
-
import type { PhysicsBody } from '../PhysicsBody';
|
|
3
|
-
/**
|
|
4
|
-
* A link between a {@link PhysicsBody} and a {@link SceneNode}. The body's world
|
|
5
|
-
* position **and rotation** are written onto the node, so the node renders
|
|
6
|
-
* exactly where the body's colliders are. The node must be world-space-rooted;
|
|
7
|
-
* runtime scale is ignored and non-zero skew is rejected at bind time.
|
|
8
|
-
*
|
|
9
|
-
* The two angles have opposite signs: a body angle turns clockwise on the Y-down
|
|
10
|
-
* screen, a `SceneNode.rotation` counter-clockwise, so a body at `+30°` (in
|
|
11
|
-
* radians) shows as a node rotation of `-30°`.
|
|
12
|
-
*
|
|
13
|
-
* By default the node snaps to the latest fixed-step state after each step. With
|
|
14
|
-
* `PhysicsWorld`'s interpolation enabled the node is instead placed between the
|
|
15
|
-
* body's previous and current fixed states, which smooths motion when the fixed
|
|
16
|
-
* rate is below the frame rate. Either way this is presentation: nothing written
|
|
17
|
-
* onto the node is read back into the simulation.
|
|
18
|
-
*/
|
|
19
|
-
export declare class PhysicsBinding {
|
|
20
|
-
readonly body: PhysicsBody;
|
|
21
|
-
readonly node: SceneNode;
|
|
22
|
-
constructor(body: PhysicsBody, node: SceneNode);
|
|
23
|
-
/** Write the body's current transform (position + rotation) onto the bound node. */
|
|
24
|
-
sync(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Place the node `alpha` of the way from the body's previous fixed state to
|
|
27
|
-
* its current one. `alpha` is the host's leftover sub-step fraction, so `0`
|
|
28
|
-
* renders the state the last fixed step started from and values approaching
|
|
29
|
-
* `1` render the state it produced.
|
|
30
|
-
*
|
|
31
|
-
* A plain lerp is correct for the angle too: body angles are continuous and
|
|
32
|
-
* unbounded, never wrapped into a range, so there is no shortest-arc case to
|
|
33
|
-
* resolve.
|
|
34
|
-
*/
|
|
35
|
-
syncInterpolated(alpha: number): void;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=PhysicsBinding.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsBinding.d.ts","sourceRoot":"","sources":["../../../src/binding/PhysicsBinding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,cAAc;aAEP,IAAI,EAAE,WAAW;aACjB,IAAI,EAAE,SAAS;IAFjC,YACkB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,SAAS,EAC7B;IAEJ,oFAAoF;IAC7E,IAAI,IAAI,IAAI,CAGlB;IAED;;;;;;;;;OASG;IACI,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ3C;CACF"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { radiansToDegrees } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/binding/PhysicsBinding.ts
|
|
4
|
-
/**
|
|
5
|
-
* A link between a {@link PhysicsBody} and a {@link SceneNode}. The body's world
|
|
6
|
-
* position **and rotation** are written onto the node, so the node renders
|
|
7
|
-
* exactly where the body's colliders are. The node must be world-space-rooted;
|
|
8
|
-
* runtime scale is ignored and non-zero skew is rejected at bind time.
|
|
9
|
-
*
|
|
10
|
-
* The two angles have opposite signs: a body angle turns clockwise on the Y-down
|
|
11
|
-
* screen, a `SceneNode.rotation` counter-clockwise, so a body at `+30°` (in
|
|
12
|
-
* radians) shows as a node rotation of `-30°`.
|
|
13
|
-
*
|
|
14
|
-
* By default the node snaps to the latest fixed-step state after each step. With
|
|
15
|
-
* `PhysicsWorld`'s interpolation enabled the node is instead placed between the
|
|
16
|
-
* body's previous and current fixed states, which smooths motion when the fixed
|
|
17
|
-
* rate is below the frame rate. Either way this is presentation: nothing written
|
|
18
|
-
* onto the node is read back into the simulation.
|
|
19
|
-
*/
|
|
20
|
-
var PhysicsBinding = class {
|
|
21
|
-
body;
|
|
22
|
-
node;
|
|
23
|
-
constructor(body, node) {
|
|
24
|
-
this.body = body;
|
|
25
|
-
this.node = node;
|
|
26
|
-
}
|
|
27
|
-
/** Write the body's current transform (position + rotation) onto the bound node. */
|
|
28
|
-
sync() {
|
|
29
|
-
this.node.setPosition(this.body.x, this.body.y);
|
|
30
|
-
this.node.setRotation(-radiansToDegrees(this.body.angle));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Place the node `alpha` of the way from the body's previous fixed state to
|
|
34
|
-
* its current one. `alpha` is the host's leftover sub-step fraction, so `0`
|
|
35
|
-
* renders the state the last fixed step started from and values approaching
|
|
36
|
-
* `1` render the state it produced.
|
|
37
|
-
*
|
|
38
|
-
* A plain lerp is correct for the angle too: body angles are continuous and
|
|
39
|
-
* unbounded, never wrapped into a range, so there is no shortest-arc case to
|
|
40
|
-
* resolve.
|
|
41
|
-
*/
|
|
42
|
-
syncInterpolated(alpha) {
|
|
43
|
-
const body = this.body;
|
|
44
|
-
const previousX = body.previousX;
|
|
45
|
-
const previousY = body.previousY;
|
|
46
|
-
const previousAngle = body.previousAngle;
|
|
47
|
-
this.node.setPosition(previousX + (body.x - previousX) * alpha, previousY + (body.y - previousY) * alpha);
|
|
48
|
-
this.node.setRotation(-radiansToDegrees(previousAngle + (body.angle - previousAngle) * alpha));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
export { PhysicsBinding };
|
|
54
|
-
//# sourceMappingURL=PhysicsBinding.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsBinding.js","names":[],"sources":["../../../src/binding/PhysicsBinding.ts"],"sourcesContent":["import { radiansToDegrees, type SceneNode } from '@codexo/exojs';\n\nimport type { PhysicsBody } from '../PhysicsBody';\n\n/**\n * A link between a {@link PhysicsBody} and a {@link SceneNode}. The body's world\n * position **and rotation** are written onto the node, so the node renders\n * exactly where the body's colliders are. The node must be world-space-rooted;\n * runtime scale is ignored and non-zero skew is rejected at bind time.\n *\n * The two angles have opposite signs: a body angle turns clockwise on the Y-down\n * screen, a `SceneNode.rotation` counter-clockwise, so a body at `+30°` (in\n * radians) shows as a node rotation of `-30°`.\n *\n * By default the node snaps to the latest fixed-step state after each step. With\n * `PhysicsWorld`'s interpolation enabled the node is instead placed between the\n * body's previous and current fixed states, which smooths motion when the fixed\n * rate is below the frame rate. Either way this is presentation: nothing written\n * onto the node is read back into the simulation.\n */\nexport class PhysicsBinding {\n public constructor(\n public readonly body: PhysicsBody,\n public readonly node: SceneNode,\n ) {}\n\n /** Write the body's current transform (position + rotation) onto the bound node. */\n public sync(): void {\n this.node.setPosition(this.body.x, this.body.y);\n this.node.setRotation(-radiansToDegrees(this.body.angle));\n }\n\n /**\n * Place the node `alpha` of the way from the body's previous fixed state to\n * its current one. `alpha` is the host's leftover sub-step fraction, so `0`\n * renders the state the last fixed step started from and values approaching\n * `1` render the state it produced.\n *\n * A plain lerp is correct for the angle too: body angles are continuous and\n * unbounded, never wrapped into a range, so there is no shortest-arc case to\n * resolve.\n */\n public syncInterpolated(alpha: number): void {\n const body = this.body;\n const previousX = body.previousX;\n const previousY = body.previousY;\n const previousAngle = body.previousAngle;\n\n this.node.setPosition(previousX + (body.x - previousX) * alpha, previousY + (body.y - previousY) * alpha);\n this.node.setRotation(-radiansToDegrees(previousAngle + (body.angle - previousAngle) * alpha));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,IAAa,iBAAb,MAA4B;CAER;CACA;CAFlB,AAAO,YACL,AAAgB,MAChB,AAAgB,MAChB;EAFgB;EACA;CACf;;CAGH,AAAO,OAAa;EAClB,KAAK,KAAK,YAAY,KAAK,KAAK,GAAG,KAAK,KAAK,CAAC;EAC9C,KAAK,KAAK,YAAY,CAAC,iBAAiB,KAAK,KAAK,KAAK,CAAC;CAC1D;;;;;;;;;;;CAYA,AAAO,iBAAiB,OAAqB;EAC3C,MAAM,OAAO,KAAK;EAClB,MAAM,YAAY,KAAK;EACvB,MAAM,YAAY,KAAK;EACvB,MAAM,gBAAgB,KAAK;EAE3B,KAAK,KAAK,YAAY,aAAa,KAAK,IAAI,aAAa,OAAO,aAAa,KAAK,IAAI,aAAa,KAAK;EACxG,KAAK,KAAK,YAAY,CAAC,iBAAiB,iBAAiB,KAAK,QAAQ,iBAAiB,KAAK,CAAC;CAC/F;AACF"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { PointLike, SceneNode } from '@codexo/exojs';
|
|
2
|
-
/**
|
|
3
|
-
* A node's current WORLD translation: where a body placed for it starts.
|
|
4
|
-
* Duck-typed the same way `AudioListener` reads a follow target - real
|
|
5
|
-
* {@link SceneNode}s expose `getWorldTransform()`, test doubles that omit it
|
|
6
|
-
* fall back to `(0, 0)`.
|
|
7
|
-
*/
|
|
8
|
-
export declare const nodeWorldPosition: (node: SceneNode) => Readonly<PointLike>;
|
|
9
|
-
/**
|
|
10
|
-
* The body angle (radians) whose colliders line up with a node's current
|
|
11
|
-
* WORLD rotation. `SceneNode` builds its rotation block as
|
|
12
|
-
* `[[cos, sin], [-sin, cos]]`, which turns counter-clockwise on the Y-down
|
|
13
|
-
* screen while a body angle turns clockwise, so the angle is `atan2(c, a)`,
|
|
14
|
-
* the inverse of the negation `PhysicsBinding.sync` applies. Falls back to `0`
|
|
15
|
-
* for a duck-typed node without `getWorldTransform`.
|
|
16
|
-
*/
|
|
17
|
-
export declare const nodeWorldAngle: (node: SceneNode) => number;
|
|
18
|
-
//# sourceMappingURL=nodeWorldTransform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeWorldTransform.d.ts","sourceRoot":"","sources":["../../../src/binding/nodeWorldTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,SAAU,SAAS,KAAG,QAAQ,CAAC,SAAS,CAUrE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,SAAU,SAAS,KAAG,MAUhD,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/binding/nodeWorldTransform.ts
|
|
2
|
-
/**
|
|
3
|
-
* A node's current WORLD translation: where a body placed for it starts.
|
|
4
|
-
* Duck-typed the same way `AudioListener` reads a follow target - real
|
|
5
|
-
* {@link SceneNode}s expose `getWorldTransform()`, test doubles that omit it
|
|
6
|
-
* fall back to `(0, 0)`.
|
|
7
|
-
*/
|
|
8
|
-
const nodeWorldPosition = (node) => {
|
|
9
|
-
const asNode = node;
|
|
10
|
-
if (typeof asNode.getWorldTransform === "function") {
|
|
11
|
-
const world = asNode.getWorldTransform();
|
|
12
|
-
return {
|
|
13
|
-
x: world.x,
|
|
14
|
-
y: world.y
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
x: 0,
|
|
19
|
-
y: 0
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* The body angle (radians) whose colliders line up with a node's current
|
|
24
|
-
* WORLD rotation. `SceneNode` builds its rotation block as
|
|
25
|
-
* `[[cos, sin], [-sin, cos]]`, which turns counter-clockwise on the Y-down
|
|
26
|
-
* screen while a body angle turns clockwise, so the angle is `atan2(c, a)`,
|
|
27
|
-
* the inverse of the negation `PhysicsBinding.sync` applies. Falls back to `0`
|
|
28
|
-
* for a duck-typed node without `getWorldTransform`.
|
|
29
|
-
*/
|
|
30
|
-
const nodeWorldAngle = (node) => {
|
|
31
|
-
const asNode = node;
|
|
32
|
-
if (typeof asNode.getWorldTransform === "function") {
|
|
33
|
-
const world = asNode.getWorldTransform();
|
|
34
|
-
return Math.atan2(world.c, world.a);
|
|
35
|
-
}
|
|
36
|
-
return 0;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { nodeWorldAngle, nodeWorldPosition };
|
|
41
|
-
//# sourceMappingURL=nodeWorldTransform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeWorldTransform.js","names":[],"sources":["../../../src/binding/nodeWorldTransform.ts"],"sourcesContent":["import type { PointLike, SceneNode } from '@codexo/exojs';\n\n/**\n * A node's current WORLD translation: where a body placed for it starts.\n * Duck-typed the same way `AudioListener` reads a follow target - real\n * {@link SceneNode}s expose `getWorldTransform()`, test doubles that omit it\n * fall back to `(0, 0)`.\n */\nexport const nodeWorldPosition = (node: SceneNode): Readonly<PointLike> => {\n const asNode = node as Partial<SceneNode>;\n\n if (typeof asNode.getWorldTransform === 'function') {\n const world = asNode.getWorldTransform();\n\n return { x: world.x, y: world.y };\n }\n\n return { x: 0, y: 0 };\n};\n\n/**\n * The body angle (radians) whose colliders line up with a node's current\n * WORLD rotation. `SceneNode` builds its rotation block as\n * `[[cos, sin], [-sin, cos]]`, which turns counter-clockwise on the Y-down\n * screen while a body angle turns clockwise, so the angle is `atan2(c, a)`,\n * the inverse of the negation `PhysicsBinding.sync` applies. Falls back to `0`\n * for a duck-typed node without `getWorldTransform`.\n */\nexport const nodeWorldAngle = (node: SceneNode): number => {\n const asNode = node as Partial<SceneNode>;\n\n if (typeof asNode.getWorldTransform === 'function') {\n const world = asNode.getWorldTransform();\n\n return Math.atan2(world.c, world.a);\n }\n\n return 0;\n};\n"],"mappings":";;;;;;;AAQA,MAAa,qBAAqB,SAAyC;CACzE,MAAM,SAAS;CAEf,IAAI,OAAO,OAAO,sBAAsB,YAAY;EAClD,MAAM,QAAQ,OAAO,kBAAkB;EAEvC,OAAO;GAAE,GAAG,MAAM;GAAG,GAAG,MAAM;EAAE;CAClC;CAEA,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;AACtB;;;;;;;;;AAUA,MAAa,kBAAkB,SAA4B;CACzD,MAAM,SAAS;CAEf,IAAI,OAAO,OAAO,sBAAsB,YAAY;EAClD,MAAM,QAAQ,OAAO,kBAAkB;EAEvC,OAAO,KAAK,MAAM,MAAM,GAAG,MAAM,CAAC;CACpC;CAEA,OAAO;AACT"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { AabbLike } from '@codexo/exojs';
|
|
2
|
-
import type { Collider } from '../Collider';
|
|
3
|
-
import type { SpatialIndex } from '../query/SpatialIndex';
|
|
4
|
-
import type { BroadPhase, CandidatePair } from './BroadPhase';
|
|
5
|
-
/**
|
|
6
|
-
* Dynamic-AABB-tree broad phase (Box2D-style), wrapping a generic
|
|
7
|
-
* `DynamicAabbTree<Collider>`. Stateful across steps: a collider whose tight
|
|
8
|
-
* AABB stays inside its stored fat AABB costs nothing to re-sync.
|
|
9
|
-
*
|
|
10
|
-
* Three phases per `computePairs` call: (1) sync every live collider (insert
|
|
11
|
-
* new ones, reinsert moved ones, querying only around reinsertions to discover
|
|
12
|
-
* NEW fat-overlap candidates; a collider whose AABB has not been rewritten
|
|
13
|
-
* since its last sync is skipped outright via `Collider._treeDirty`, so a
|
|
14
|
-
* sleeping world pays one flag read per collider); (2) one full pass over the
|
|
15
|
-
* persistent pair set dropping any pair whose fat AABBs no longer overlap -
|
|
16
|
-
* cheap (O(1) per pair) and run every step regardless of movement, exactly
|
|
17
|
-
* mirroring Box2D's own `b2ContactManager::Collide` (see the design's
|
|
18
|
-
* correctness argument for why a single global pass, not a per-moved-leaf
|
|
19
|
-
* rescan, is both correct and the right complexity); (3) emit, keeping only
|
|
20
|
-
* pairs whose *tight* AABBs overlap.
|
|
21
|
-
*
|
|
22
|
-
* Phases 2 and 3 are skipped whole when nothing they read has changed since the
|
|
23
|
-
* last call: the emitted list is a function of the pair set and the tight AABBs
|
|
24
|
-
* alone, and a step that rewrote no collider geometry touched neither.
|
|
25
|
-
*
|
|
26
|
-
* The persistent set is intentionally keyed on *fat* overlap so temporal
|
|
27
|
-
* coherence carries across steps (a leaf that stays inside its fat AABB is
|
|
28
|
-
* never re-discovered). Emitting is filtered to tight-AABB overlap so the
|
|
29
|
-
* candidate set the caller sees is exact - the fat margin never leaks a false
|
|
30
|
-
* positive downstream, and a fat-but-not-tight pair simply stays parked in the
|
|
31
|
-
* set (costing one O(1) re-check per step) until the leaves separate.
|
|
32
|
-
*
|
|
33
|
-
* **Single-owner contract.** A collider's tree membership is tracked through its
|
|
34
|
-
* `Collider._treeProxy` field, which - like `PhysicsBody._islandIndex` /
|
|
35
|
-
* `_sleepTime` - is a single slot on the shared object. Exactly ONE
|
|
36
|
-
* `AabbTreeBroadPhase` instance may track a given collider at a time (in
|
|
37
|
-
* production that is the world's own `_broadPhase`, for the collider's whole
|
|
38
|
-
* lifetime until `removeCollider`). Do NOT stand up a second, throwaway
|
|
39
|
-
* `AabbTreeBroadPhase` over colliders another instance already owns (e.g. for
|
|
40
|
-
* debug visualization): the second instance would clobber the first's
|
|
41
|
-
* `_treeProxy` values and corrupt its tree. Use a plain brute-force scan for
|
|
42
|
-
* such one-off, read-only needs instead.
|
|
43
|
-
*/
|
|
44
|
-
export declare class AabbTreeBroadPhase implements BroadPhase, SpatialIndex {
|
|
45
|
-
private readonly _tree;
|
|
46
|
-
private readonly _pairs;
|
|
47
|
-
private readonly _scratchFatAabb;
|
|
48
|
-
private _syncingCollider;
|
|
49
|
-
private _syncingProxy;
|
|
50
|
-
/**
|
|
51
|
-
* Whether anything the emitted candidate list is a function of has changed
|
|
52
|
-
* since it was built: a collider AABB taken into the tree, or a pair added or
|
|
53
|
-
* dropped. While it stays `false` the previous list is still exactly right.
|
|
54
|
-
*/
|
|
55
|
-
private _emitStale;
|
|
56
|
-
/** The buffer the current candidate list was emitted into, so a caller that swaps or clears its own buffer still gets a rebuild. */
|
|
57
|
-
private _emitTarget;
|
|
58
|
-
private _emitLength;
|
|
59
|
-
private readonly _onNeighborFound;
|
|
60
|
-
private readonly _dropIfStale;
|
|
61
|
-
private _collectTarget;
|
|
62
|
-
private readonly _collectPair;
|
|
63
|
-
private _queryTarget;
|
|
64
|
-
private readonly _onQueryHit;
|
|
65
|
-
private readonly _resetTreeProxy;
|
|
66
|
-
computePairs(colliders: readonly Collider[], out: CandidatePair[]): CandidatePair[];
|
|
67
|
-
/**
|
|
68
|
-
* Insert every not-yet-tracked collider and reinsert every moved one (the
|
|
69
|
-
* `computePairs` phase-1 loop, extracted so {@link queryAabb} callers can
|
|
70
|
-
* force it independently of a full detection pass - see {@link SpatialIndex.sync}).
|
|
71
|
-
*/
|
|
72
|
-
sync(colliders: readonly Collider[]): void;
|
|
73
|
-
/** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */
|
|
74
|
-
queryAabb(aabb: Readonly<AabbLike>, out: Collider[]): Collider[];
|
|
75
|
-
/** Colliders whose AABB the ray could cross within `maxDistance`, via the tree's own ray-cast prune. */
|
|
76
|
-
rayCast(originX: number, originY: number, dirX: number, dirY: number, maxDistance: number, callback: (collider: Collider) => void): void;
|
|
77
|
-
/** Drop `collider`'s leaf and every pair referencing it. Called when a collider is destroyed. */
|
|
78
|
-
removeCollider(collider: Collider): void;
|
|
79
|
-
destroy(): void;
|
|
80
|
-
private _sync;
|
|
81
|
-
private _discoverNeighbors;
|
|
82
|
-
private _addPair;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=AabbTreeBroadPhase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AabbTreeBroadPhase.d.ts","sourceRoot":"","sources":["../../../src/broadphase/AabbTreeBroadPhase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAe9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,kBAAmB,YAAW,UAAU,EAAE,YAAY;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8C;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoD;IAEpF,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,aAAa,CAAM;IAE3B;;;;OAIG;IACH,OAAO,CAAC,UAAU,CAAQ;IAC1B,oIAAoI;IACpI,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,WAAW,CAAM;IAEzB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAM/B;IAEF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAK3B;IAEF,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAM3B;IAEF,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAE1B;IAEF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAE9B;IAEK,YAAY,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,CAuBzF;IAED;;;;OAIG;IACI,IAAI,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,CAIhD;IAED,8FAA8F;IACvF,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAMtE;IAED,wGAAwG;IACjG,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,GAAG,IAAI,CAE9I;IAED,iGAAiG;IAC1F,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAc9C;IAEM,OAAO,IAAI,IAAI,CAYrB;IAED,OAAO,CAAC,KAAK;IA4Bb,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,QAAQ;CAkBjB"}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { aabbOverlap } from "../Aabb.js";
|
|
2
|
-
import { sortInPlace } from "../sort.js";
|
|
3
|
-
import { pairKey } from "../ContactGraph.js";
|
|
4
|
-
import { DynamicAabbTree } from "@codexo/exojs";
|
|
5
|
-
|
|
6
|
-
//#region src/broadphase/AabbTreeBroadPhase.ts
|
|
7
|
-
/**
|
|
8
|
-
* Fixed fat-AABB margin (world px) applied to every collider's tree leaf.
|
|
9
|
-
* Chosen relative to the engine's typical small-collider scale (test/example
|
|
10
|
-
* shapes commonly span 10-30px): large enough that a few steps of ordinary
|
|
11
|
-
* motion stay inside the margin (skipping the sync phase's remove+reinsert),
|
|
12
|
-
* small enough it doesn't inflate fat AABBs into spurious candidates for
|
|
13
|
-
* densely packed scenes. Fixed per the design's v1 scope (no velocity-based
|
|
14
|
-
* predictive expansion) - revisit if benchmarks want a different value.
|
|
15
|
-
*/
|
|
16
|
-
const AABB_MARGIN = 4;
|
|
17
|
-
const byPairId = (p, q) => p.a.id - q.a.id || p.b.id - q.b.id;
|
|
18
|
-
/**
|
|
19
|
-
* Dynamic-AABB-tree broad phase (Box2D-style), wrapping a generic
|
|
20
|
-
* `DynamicAabbTree<Collider>`. Stateful across steps: a collider whose tight
|
|
21
|
-
* AABB stays inside its stored fat AABB costs nothing to re-sync.
|
|
22
|
-
*
|
|
23
|
-
* Three phases per `computePairs` call: (1) sync every live collider (insert
|
|
24
|
-
* new ones, reinsert moved ones, querying only around reinsertions to discover
|
|
25
|
-
* NEW fat-overlap candidates; a collider whose AABB has not been rewritten
|
|
26
|
-
* since its last sync is skipped outright via `Collider._treeDirty`, so a
|
|
27
|
-
* sleeping world pays one flag read per collider); (2) one full pass over the
|
|
28
|
-
* persistent pair set dropping any pair whose fat AABBs no longer overlap -
|
|
29
|
-
* cheap (O(1) per pair) and run every step regardless of movement, exactly
|
|
30
|
-
* mirroring Box2D's own `b2ContactManager::Collide` (see the design's
|
|
31
|
-
* correctness argument for why a single global pass, not a per-moved-leaf
|
|
32
|
-
* rescan, is both correct and the right complexity); (3) emit, keeping only
|
|
33
|
-
* pairs whose *tight* AABBs overlap.
|
|
34
|
-
*
|
|
35
|
-
* Phases 2 and 3 are skipped whole when nothing they read has changed since the
|
|
36
|
-
* last call: the emitted list is a function of the pair set and the tight AABBs
|
|
37
|
-
* alone, and a step that rewrote no collider geometry touched neither.
|
|
38
|
-
*
|
|
39
|
-
* The persistent set is intentionally keyed on *fat* overlap so temporal
|
|
40
|
-
* coherence carries across steps (a leaf that stays inside its fat AABB is
|
|
41
|
-
* never re-discovered). Emitting is filtered to tight-AABB overlap so the
|
|
42
|
-
* candidate set the caller sees is exact - the fat margin never leaks a false
|
|
43
|
-
* positive downstream, and a fat-but-not-tight pair simply stays parked in the
|
|
44
|
-
* set (costing one O(1) re-check per step) until the leaves separate.
|
|
45
|
-
*
|
|
46
|
-
* **Single-owner contract.** A collider's tree membership is tracked through its
|
|
47
|
-
* `Collider._treeProxy` field, which - like `PhysicsBody._islandIndex` /
|
|
48
|
-
* `_sleepTime` - is a single slot on the shared object. Exactly ONE
|
|
49
|
-
* `AabbTreeBroadPhase` instance may track a given collider at a time (in
|
|
50
|
-
* production that is the world's own `_broadPhase`, for the collider's whole
|
|
51
|
-
* lifetime until `removeCollider`). Do NOT stand up a second, throwaway
|
|
52
|
-
* `AabbTreeBroadPhase` over colliders another instance already owns (e.g. for
|
|
53
|
-
* debug visualization): the second instance would clobber the first's
|
|
54
|
-
* `_treeProxy` values and corrupt its tree. Use a plain brute-force scan for
|
|
55
|
-
* such one-off, read-only needs instead.
|
|
56
|
-
*/
|
|
57
|
-
var AabbTreeBroadPhase = class {
|
|
58
|
-
_tree = new DynamicAabbTree(AABB_MARGIN);
|
|
59
|
-
_pairs = /* @__PURE__ */ new Map();
|
|
60
|
-
_scratchFatAabb = {
|
|
61
|
-
minX: 0,
|
|
62
|
-
minY: 0,
|
|
63
|
-
maxX: 0,
|
|
64
|
-
maxY: 0
|
|
65
|
-
};
|
|
66
|
-
_syncingCollider = null;
|
|
67
|
-
_syncingProxy = -1;
|
|
68
|
-
/**
|
|
69
|
-
* Whether anything the emitted candidate list is a function of has changed
|
|
70
|
-
* since it was built: a collider AABB taken into the tree, or a pair added or
|
|
71
|
-
* dropped. While it stays `false` the previous list is still exactly right.
|
|
72
|
-
*/
|
|
73
|
-
_emitStale = true;
|
|
74
|
-
/** The buffer the current candidate list was emitted into, so a caller that swaps or clears its own buffer still gets a rebuild. */
|
|
75
|
-
_emitTarget = null;
|
|
76
|
-
_emitLength = -1;
|
|
77
|
-
_onNeighborFound = (payload, proxy) => {
|
|
78
|
-
if (proxy === this._syncingProxy) return;
|
|
79
|
-
this._addPair(this._syncingCollider, payload);
|
|
80
|
-
};
|
|
81
|
-
_dropIfStale = (pair, key) => {
|
|
82
|
-
if (!this._tree.fatOverlaps(pair.a._treeProxy, pair.b._treeProxy)) {
|
|
83
|
-
this._pairs.delete(key);
|
|
84
|
-
this._emitStale = true;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
_collectTarget = [];
|
|
88
|
-
_collectPair = (pair) => {
|
|
89
|
-
if (aabbOverlap(pair.a.aabb, pair.b.aabb)) this._collectTarget.push(pair);
|
|
90
|
-
};
|
|
91
|
-
_queryTarget = [];
|
|
92
|
-
_onQueryHit = (payload) => {
|
|
93
|
-
this._queryTarget.push(payload);
|
|
94
|
-
};
|
|
95
|
-
_resetTreeProxy = (payload) => {
|
|
96
|
-
payload._treeProxy = -1;
|
|
97
|
-
};
|
|
98
|
-
computePairs(colliders, out) {
|
|
99
|
-
this.sync(colliders);
|
|
100
|
-
if (!this._emitStale && out === this._emitTarget && out.length === this._emitLength) return out;
|
|
101
|
-
this._pairs.forEach(this._dropIfStale);
|
|
102
|
-
out.length = 0;
|
|
103
|
-
this._collectTarget = out;
|
|
104
|
-
this._pairs.forEach(this._collectPair);
|
|
105
|
-
sortInPlace(out, byPairId);
|
|
106
|
-
this._emitStale = false;
|
|
107
|
-
this._emitTarget = out;
|
|
108
|
-
this._emitLength = out.length;
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Insert every not-yet-tracked collider and reinsert every moved one (the
|
|
113
|
-
* `computePairs` phase-1 loop, extracted so {@link queryAabb} callers can
|
|
114
|
-
* force it independently of a full detection pass - see {@link SpatialIndex.sync}).
|
|
115
|
-
*/
|
|
116
|
-
sync(colliders) {
|
|
117
|
-
for (const collider of colliders) this._sync(collider);
|
|
118
|
-
}
|
|
119
|
-
/** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */
|
|
120
|
-
queryAabb(aabb, out) {
|
|
121
|
-
out.length = 0;
|
|
122
|
-
this._queryTarget = out;
|
|
123
|
-
this._tree.query(aabb.minX, aabb.minY, aabb.maxX, aabb.maxY, this._onQueryHit);
|
|
124
|
-
return out;
|
|
125
|
-
}
|
|
126
|
-
/** Colliders whose AABB the ray could cross within `maxDistance`, via the tree's own ray-cast prune. */
|
|
127
|
-
rayCast(originX, originY, dirX, dirY, maxDistance, callback) {
|
|
128
|
-
this._tree.rayCast(originX, originY, dirX, dirY, maxDistance, callback);
|
|
129
|
-
}
|
|
130
|
-
/** Drop `collider`'s leaf and every pair referencing it. Called when a collider is destroyed. */
|
|
131
|
-
removeCollider(collider) {
|
|
132
|
-
if (collider._treeProxy === -1) return;
|
|
133
|
-
this._emitStale = true;
|
|
134
|
-
this._tree.remove(collider._treeProxy);
|
|
135
|
-
collider._treeProxy = -1;
|
|
136
|
-
for (const [key, pair] of this._pairs) if (pair.a === collider || pair.b === collider) this._pairs.delete(key);
|
|
137
|
-
}
|
|
138
|
-
destroy() {
|
|
139
|
-
this._tree.query(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, this._resetTreeProxy);
|
|
140
|
-
this._tree.destroy();
|
|
141
|
-
this._pairs.clear();
|
|
142
|
-
this._emitStale = true;
|
|
143
|
-
this._emitTarget = null;
|
|
144
|
-
}
|
|
145
|
-
_sync(collider) {
|
|
146
|
-
const box = collider.aabb;
|
|
147
|
-
if (collider._treeProxy === -1) {
|
|
148
|
-
collider._treeDirty = false;
|
|
149
|
-
this._emitStale = true;
|
|
150
|
-
collider._treeProxy = this._tree.insert(box.minX, box.minY, box.maxX, box.maxY, collider);
|
|
151
|
-
this._discoverNeighbors(collider);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (!collider._treeDirty) return;
|
|
155
|
-
collider._treeDirty = false;
|
|
156
|
-
this._emitStale = true;
|
|
157
|
-
if (this._tree.update(collider._treeProxy, box.minX, box.minY, box.maxX, box.maxY)) this._discoverNeighbors(collider);
|
|
158
|
-
}
|
|
159
|
-
_discoverNeighbors(collider) {
|
|
160
|
-
const proxy = collider._treeProxy;
|
|
161
|
-
const fat = this._tree.fatAabbOf(proxy, this._scratchFatAabb);
|
|
162
|
-
this._syncingCollider = collider;
|
|
163
|
-
this._syncingProxy = proxy;
|
|
164
|
-
this._tree.query(fat.minX, fat.minY, fat.maxX, fat.maxY, this._onNeighborFound);
|
|
165
|
-
}
|
|
166
|
-
_addPair(a, b) {
|
|
167
|
-
if (a.body === b.body) return;
|
|
168
|
-
const lo = a.id < b.id ? a : b;
|
|
169
|
-
const hi = a.id < b.id ? b : a;
|
|
170
|
-
const key = pairKey(lo.id, hi.id);
|
|
171
|
-
if (!this._pairs.has(key)) {
|
|
172
|
-
this._pairs.set(key, {
|
|
173
|
-
a: lo,
|
|
174
|
-
b: hi
|
|
175
|
-
});
|
|
176
|
-
this._emitStale = true;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
//#endregion
|
|
182
|
-
export { AabbTreeBroadPhase };
|
|
183
|
-
//# sourceMappingURL=AabbTreeBroadPhase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AabbTreeBroadPhase.js","names":[],"sources":["../../../src/broadphase/AabbTreeBroadPhase.ts"],"sourcesContent":["import type { AabbLike } from '@codexo/exojs';\nimport { DynamicAabbTree } from '@codexo/exojs';\n\nimport { aabbOverlap } from '../Aabb';\nimport type { Collider } from '../Collider';\nimport { pairKey } from '../ContactGraph';\nimport type { SpatialIndex } from '../query/SpatialIndex';\nimport { sortInPlace } from '../sort';\nimport type { BroadPhase, CandidatePair } from './BroadPhase';\n\n/**\n * Fixed fat-AABB margin (world px) applied to every collider's tree leaf.\n * Chosen relative to the engine's typical small-collider scale (test/example\n * shapes commonly span 10-30px): large enough that a few steps of ordinary\n * motion stay inside the margin (skipping the sync phase's remove+reinsert),\n * small enough it doesn't inflate fat AABBs into spurious candidates for\n * densely packed scenes. Fixed per the design's v1 scope (no velocity-based\n * predictive expansion) - revisit if benchmarks want a different value.\n */\nconst AABB_MARGIN = 4;\n\nconst byPairId = (p: CandidatePair, q: CandidatePair): number => p.a.id - q.a.id || p.b.id - q.b.id;\n\n/**\n * Dynamic-AABB-tree broad phase (Box2D-style), wrapping a generic\n * `DynamicAabbTree<Collider>`. Stateful across steps: a collider whose tight\n * AABB stays inside its stored fat AABB costs nothing to re-sync.\n *\n * Three phases per `computePairs` call: (1) sync every live collider (insert\n * new ones, reinsert moved ones, querying only around reinsertions to discover\n * NEW fat-overlap candidates; a collider whose AABB has not been rewritten\n * since its last sync is skipped outright via `Collider._treeDirty`, so a\n * sleeping world pays one flag read per collider); (2) one full pass over the\n * persistent pair set dropping any pair whose fat AABBs no longer overlap -\n * cheap (O(1) per pair) and run every step regardless of movement, exactly\n * mirroring Box2D's own `b2ContactManager::Collide` (see the design's\n * correctness argument for why a single global pass, not a per-moved-leaf\n * rescan, is both correct and the right complexity); (3) emit, keeping only\n * pairs whose *tight* AABBs overlap.\n *\n * Phases 2 and 3 are skipped whole when nothing they read has changed since the\n * last call: the emitted list is a function of the pair set and the tight AABBs\n * alone, and a step that rewrote no collider geometry touched neither.\n *\n * The persistent set is intentionally keyed on *fat* overlap so temporal\n * coherence carries across steps (a leaf that stays inside its fat AABB is\n * never re-discovered). Emitting is filtered to tight-AABB overlap so the\n * candidate set the caller sees is exact - the fat margin never leaks a false\n * positive downstream, and a fat-but-not-tight pair simply stays parked in the\n * set (costing one O(1) re-check per step) until the leaves separate.\n *\n * **Single-owner contract.** A collider's tree membership is tracked through its\n * `Collider._treeProxy` field, which - like `PhysicsBody._islandIndex` /\n * `_sleepTime` - is a single slot on the shared object. Exactly ONE\n * `AabbTreeBroadPhase` instance may track a given collider at a time (in\n * production that is the world's own `_broadPhase`, for the collider's whole\n * lifetime until `removeCollider`). Do NOT stand up a second, throwaway\n * `AabbTreeBroadPhase` over colliders another instance already owns (e.g. for\n * debug visualization): the second instance would clobber the first's\n * `_treeProxy` values and corrupt its tree. Use a plain brute-force scan for\n * such one-off, read-only needs instead.\n */\nexport class AabbTreeBroadPhase implements BroadPhase, SpatialIndex {\n private readonly _tree = new DynamicAabbTree<Collider>(AABB_MARGIN);\n private readonly _pairs = new Map<number, CandidatePair>();\n private readonly _scratchFatAabb: AabbLike = { minX: 0, minY: 0, maxX: 0, maxY: 0 };\n\n private _syncingCollider: Collider | null = null;\n private _syncingProxy = -1;\n\n /**\n * Whether anything the emitted candidate list is a function of has changed\n * since it was built: a collider AABB taken into the tree, or a pair added or\n * dropped. While it stays `false` the previous list is still exactly right.\n */\n private _emitStale = true;\n /** The buffer the current candidate list was emitted into, so a caller that swaps or clears its own buffer still gets a rebuild. */\n private _emitTarget: CandidatePair[] | null = null;\n private _emitLength = -1;\n\n private readonly _onNeighborFound = (payload: Collider, proxy: number): void => {\n if (proxy === this._syncingProxy) {\n return;\n }\n\n this._addPair(this._syncingCollider!, payload);\n };\n\n private readonly _dropIfStale = (pair: CandidatePair, key: number): void => {\n if (!this._tree.fatOverlaps(pair.a._treeProxy, pair.b._treeProxy)) {\n this._pairs.delete(key);\n this._emitStale = true;\n }\n };\n\n private _collectTarget: CandidatePair[] = [];\n private readonly _collectPair = (pair: CandidatePair): void => {\n // Emit only true (tight-AABB) overlaps; the persistent set is fat-keyed for\n // coherence, so a fat-but-not-tight pair is parked here, not a candidate.\n if (aabbOverlap(pair.a.aabb, pair.b.aabb)) {\n this._collectTarget.push(pair);\n }\n };\n\n private _queryTarget: Collider[] = [];\n private readonly _onQueryHit = (payload: Collider): void => {\n this._queryTarget.push(payload);\n };\n\n private readonly _resetTreeProxy = (payload: Collider): void => {\n payload._treeProxy = -1;\n };\n\n public computePairs(colliders: readonly Collider[], out: CandidatePair[]): CandidatePair[] {\n this.sync(colliders);\n\n // The candidate list is a function of the pair set and the tight AABBs\n // alone. A step in which no collider's geometry was rewritten and no pair\n // moved leaves both untouched, so the list already in `out` is the one both\n // passes below would rebuild - and a settled world is every such step.\n if (!this._emitStale && out === this._emitTarget && out.length === this._emitLength) {\n return out;\n }\n\n this._pairs.forEach(this._dropIfStale);\n\n out.length = 0;\n this._collectTarget = out;\n this._pairs.forEach(this._collectPair);\n sortInPlace(out, byPairId);\n\n this._emitStale = false;\n this._emitTarget = out;\n this._emitLength = out.length;\n\n return out;\n }\n\n /**\n * Insert every not-yet-tracked collider and reinsert every moved one (the\n * `computePairs` phase-1 loop, extracted so {@link queryAabb} callers can\n * force it independently of a full detection pass - see {@link SpatialIndex.sync}).\n */\n public sync(colliders: readonly Collider[]): void {\n for (const collider of colliders) {\n this._sync(collider);\n }\n }\n\n /** Colliders whose AABB overlaps `aabb`. Writes into `out` (cleared first) and returns it. */\n public queryAabb(aabb: Readonly<AabbLike>, out: Collider[]): Collider[] {\n out.length = 0;\n this._queryTarget = out;\n this._tree.query(aabb.minX, aabb.minY, aabb.maxX, aabb.maxY, this._onQueryHit);\n\n return out;\n }\n\n /** Colliders whose AABB the ray could cross within `maxDistance`, via the tree's own ray-cast prune. */\n public rayCast(originX: number, originY: number, dirX: number, dirY: number, maxDistance: number, callback: (collider: Collider) => void): void {\n this._tree.rayCast(originX, originY, dirX, dirY, maxDistance, callback);\n }\n\n /** Drop `collider`'s leaf and every pair referencing it. Called when a collider is destroyed. */\n public removeCollider(collider: Collider): void {\n if (collider._treeProxy === -1) {\n return;\n }\n\n this._emitStale = true;\n this._tree.remove(collider._treeProxy);\n collider._treeProxy = -1;\n\n for (const [key, pair] of this._pairs) {\n if (pair.a === collider || pair.b === collider) {\n this._pairs.delete(key);\n }\n }\n }\n\n public destroy(): void {\n // Reset `_treeProxy` on every still-tracked collider before tearing down the\n // tree: the single-owner contract only guarantees at most one owner AT A\n // TIME, so a collider handed to a later `AabbTreeBroadPhase` (sequential\n // reuse, not concurrent dual-ownership) must not carry a stale non-`-1`\n // proxy from this instance forward. `query` with infinite bounds visits\n // every leaf currently in the tree, allocation-free.\n this._tree.query(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, this._resetTreeProxy);\n this._tree.destroy();\n this._pairs.clear();\n this._emitStale = true;\n this._emitTarget = null;\n }\n\n private _sync(collider: Collider): void {\n const box = collider.aabb;\n\n if (collider._treeProxy === -1) {\n collider._treeDirty = false;\n this._emitStale = true;\n collider._treeProxy = this._tree.insert(box.minX, box.minY, box.maxX, box.maxY, collider);\n this._discoverNeighbors(collider);\n\n return;\n }\n\n // The leaf already holds this box, so `update` would do nothing but repeat\n // the containment test. A settled world is almost entirely this case.\n if (!collider._treeDirty) {\n return;\n }\n\n collider._treeDirty = false;\n this._emitStale = true;\n\n const moved = this._tree.update(collider._treeProxy, box.minX, box.minY, box.maxX, box.maxY);\n\n if (moved) {\n this._discoverNeighbors(collider);\n }\n }\n\n private _discoverNeighbors(collider: Collider): void {\n const proxy = collider._treeProxy;\n const fat = this._tree.fatAabbOf(proxy, this._scratchFatAabb);\n\n this._syncingCollider = collider;\n this._syncingProxy = proxy;\n this._tree.query(fat.minX, fat.minY, fat.maxX, fat.maxY, this._onNeighborFound);\n }\n\n private _addPair(a: Collider, b: Collider): void {\n // Two colliders of the same body are a compound shape, not a collision.\n // Rejecting the pair here rather than downstream also keeps it out of the\n // persistent set, so a compound body costs nothing per step - which matters\n // once convex decomposition attaches many edge-sharing colliders to one body.\n if (a.body === b.body) {\n return;\n }\n\n const lo = a.id < b.id ? a : b;\n const hi = a.id < b.id ? b : a;\n const key = pairKey(lo.id, hi.id);\n\n if (!this._pairs.has(key)) {\n this._pairs.set(key, { a: lo, b: hi });\n this._emitStale = true;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAM,cAAc;AAEpB,MAAM,YAAY,GAAkB,MAA6B,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCjG,IAAa,qBAAb,MAAoE;CAClE,AAAiB,QAAQ,IAAI,gBAA0B,WAAW;CAClE,AAAiB,yBAAS,IAAI,IAA2B;CACzD,AAAiB,kBAA4B;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,MAAM;CAAE;CAElF,AAAQ,mBAAoC;CAC5C,AAAQ,gBAAgB;;;;;;CAOxB,AAAQ,aAAa;;CAErB,AAAQ,cAAsC;CAC9C,AAAQ,cAAc;CAEtB,AAAiB,oBAAoB,SAAmB,UAAwB;EAC9E,IAAI,UAAU,KAAK,eACjB;EAGF,KAAK,SAAS,KAAK,kBAAmB,OAAO;CAC/C;CAEA,AAAiB,gBAAgB,MAAqB,QAAsB;EAC1E,IAAI,CAAC,KAAK,MAAM,YAAY,KAAK,EAAE,YAAY,KAAK,EAAE,UAAU,GAAG;GACjE,KAAK,OAAO,OAAO,GAAG;GACtB,KAAK,aAAa;EACpB;CACF;CAEA,AAAQ,iBAAkC,CAAC;CAC3C,AAAiB,gBAAgB,SAA8B;EAG7D,IAAI,YAAY,KAAK,EAAE,MAAM,KAAK,EAAE,IAAI,GACtC,KAAK,eAAe,KAAK,IAAI;CAEjC;CAEA,AAAQ,eAA2B,CAAC;CACpC,AAAiB,eAAe,YAA4B;EAC1D,KAAK,aAAa,KAAK,OAAO;CAChC;CAEA,AAAiB,mBAAmB,YAA4B;EAC9D,QAAQ,aAAa;CACvB;CAEA,AAAO,aAAa,WAAgC,KAAuC;EACzF,KAAK,KAAK,SAAS;EAMnB,IAAI,CAAC,KAAK,cAAc,QAAQ,KAAK,eAAe,IAAI,WAAW,KAAK,aACtE,OAAO;EAGT,KAAK,OAAO,QAAQ,KAAK,YAAY;EAErC,IAAI,SAAS;EACb,KAAK,iBAAiB;EACtB,KAAK,OAAO,QAAQ,KAAK,YAAY;EACrC,YAAY,KAAK,QAAQ;EAEzB,KAAK,aAAa;EAClB,KAAK,cAAc;EACnB,KAAK,cAAc,IAAI;EAEvB,OAAO;CACT;;;;;;CAOA,AAAO,KAAK,WAAsC;EAChD,KAAK,MAAM,YAAY,WACrB,KAAK,MAAM,QAAQ;CAEvB;;CAGA,AAAO,UAAU,MAA0B,KAA6B;EACtE,IAAI,SAAS;EACb,KAAK,eAAe;EACpB,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,WAAW;EAE7E,OAAO;CACT;;CAGA,AAAO,QAAQ,SAAiB,SAAiB,MAAc,MAAc,aAAqB,UAA8C;EAC9I,KAAK,MAAM,QAAQ,SAAS,SAAS,MAAM,MAAM,aAAa,QAAQ;CACxE;;CAGA,AAAO,eAAe,UAA0B;EAC9C,IAAI,SAAS,eAAe,IAC1B;EAGF,KAAK,aAAa;EAClB,KAAK,MAAM,OAAO,SAAS,UAAU;EACrC,SAAS,aAAa;EAEtB,KAAK,MAAM,CAAC,KAAK,SAAS,KAAK,QAC7B,IAAI,KAAK,MAAM,YAAY,KAAK,MAAM,UACpC,KAAK,OAAO,OAAO,GAAG;CAG5B;CAEA,AAAO,UAAgB;EAOrB,KAAK,MAAM,MAAM,OAAO,mBAAmB,OAAO,mBAAmB,OAAO,mBAAmB,OAAO,mBAAmB,KAAK,eAAe;EAC7I,KAAK,MAAM,QAAQ;EACnB,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa;EAClB,KAAK,cAAc;CACrB;CAEA,AAAQ,MAAM,UAA0B;EACtC,MAAM,MAAM,SAAS;EAErB,IAAI,SAAS,eAAe,IAAI;GAC9B,SAAS,aAAa;GACtB,KAAK,aAAa;GAClB,SAAS,aAAa,KAAK,MAAM,OAAO,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,QAAQ;GACxF,KAAK,mBAAmB,QAAQ;GAEhC;EACF;EAIA,IAAI,CAAC,SAAS,YACZ;EAGF,SAAS,aAAa;EACtB,KAAK,aAAa;EAIlB,IAFc,KAAK,MAAM,OAAO,SAAS,YAAY,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,IAE/E,GACN,KAAK,mBAAmB,QAAQ;CAEpC;CAEA,AAAQ,mBAAmB,UAA0B;EACnD,MAAM,QAAQ,SAAS;EACvB,MAAM,MAAM,KAAK,MAAM,UAAU,OAAO,KAAK,eAAe;EAE5D,KAAK,mBAAmB;EACxB,KAAK,gBAAgB;EACrB,KAAK,MAAM,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,KAAK,gBAAgB;CAChF;CAEA,AAAQ,SAAS,GAAa,GAAmB;EAK/C,IAAI,EAAE,SAAS,EAAE,MACf;EAGF,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI;EAC7B,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE;EAEhC,IAAI,CAAC,KAAK,OAAO,IAAI,GAAG,GAAG;GACzB,KAAK,OAAO,IAAI,KAAK;IAAE,GAAG;IAAI,GAAG;GAAG,CAAC;GACrC,KAAK,aAAa;EACpB;CACF;AACF"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Collider } from '../Collider';
|
|
2
|
-
/** An unordered pair of colliders whose AABBs the broad phase reports as overlapping. */
|
|
3
|
-
export interface CandidatePair {
|
|
4
|
-
a: Collider;
|
|
5
|
-
b: Collider;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Broad-phase contract: reduce the O(n²) all-pairs test to a candidate set of
|
|
9
|
-
* AABB-overlapping pairs. The candidate set must contain **every** truly
|
|
10
|
-
* overlapping pair of colliders on *different* bodies (zero false negatives);
|
|
11
|
-
* false positives are resolved by the narrow phase. Two colliders of the same
|
|
12
|
-
* body form a compound shape and must never be paired. This interface is the
|
|
13
|
-
* seam behind which broad-phase implementations (currently the
|
|
14
|
-
* dynamic-AABB-tree-backed `AabbTreeBroadPhase`) can be swapped without
|
|
15
|
-
* touching callers.
|
|
16
|
-
*/
|
|
17
|
-
export interface BroadPhase {
|
|
18
|
-
/**
|
|
19
|
-
* Fill `out` with the candidate pairs for the current collider set and return
|
|
20
|
-
* it. Each pair is ordered `a.id < b.id`, and the array is sorted by
|
|
21
|
-
* `(a.id, b.id)` for deterministic downstream processing.
|
|
22
|
-
*/
|
|
23
|
-
computePairs(colliders: readonly Collider[], out: CandidatePair[]): CandidatePair[];
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=BroadPhase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BroadPhase.d.ts","sourceRoot":"","sources":["../../../src/broadphase/BroadPhase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,QAAQ,CAAC;IACZ,CAAC,EAAE,QAAQ,CAAC;CACb;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,CAAC;CACrF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/broadphase/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PointLike } from '@codexo/exojs';
|
|
2
|
-
import type { AnyShape } from '../shapes/AnyShape';
|
|
3
|
-
/**
|
|
4
|
-
* The geometric surface the narrow phase needs: a shape plus its cached world
|
|
5
|
-
* data. {@link Collider} satisfies this structurally, and shape-overlap queries
|
|
6
|
-
* build a throwaway proxy to test an arbitrary shape against the world without
|
|
7
|
-
* allocating a body/collider.
|
|
8
|
-
*/
|
|
9
|
-
export interface CollisionProxy {
|
|
10
|
-
readonly shape: AnyShape;
|
|
11
|
-
readonly worldCenter: Readonly<PointLike>;
|
|
12
|
-
readonly worldVertices: readonly number[];
|
|
13
|
-
readonly worldNormals: readonly number[];
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=CollisionProxy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CollisionProxy.d.ts","sourceRoot":"","sources":["../../../src/collision/CollisionProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/** A single point of a {@link Manifold}. */
|
|
2
|
-
export interface ManifoldPoint {
|
|
3
|
-
/** World-space contact position X. */
|
|
4
|
-
x: number;
|
|
5
|
-
/** World-space contact position Y. */
|
|
6
|
-
y: number;
|
|
7
|
-
/** Penetration depth in px (≥ 0). */
|
|
8
|
-
penetration: number;
|
|
9
|
-
/**
|
|
10
|
-
* Stable feature id identifying which geometric features produced this point.
|
|
11
|
-
* Constant across frames while the contact features are unchanged - the basis
|
|
12
|
-
* for warm-starting the solver later.
|
|
13
|
-
*/
|
|
14
|
-
id: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A contact manifold: the collision normal (oriented from collider A toward
|
|
18
|
-
* collider B) plus 1-2 contact points. A `Manifold` is reused across narrow-phase
|
|
19
|
-
* calls - it preallocates its two points and `reset()`s `pointCount` to 0. The
|
|
20
|
-
* generation here is forward-looking work for the dynamics solver; in this
|
|
21
|
-
* collision/query release it drives debug draw and validates the narrow phase.
|
|
22
|
-
*/
|
|
23
|
-
export declare class Manifold {
|
|
24
|
-
/** Collision normal X (unit, A → B). */
|
|
25
|
-
normalX: number;
|
|
26
|
-
/** Collision normal Y (unit, A → B). */
|
|
27
|
-
normalY: number;
|
|
28
|
-
/** Number of valid entries in {@link points} (0, 1 or 2). */
|
|
29
|
-
pointCount: number;
|
|
30
|
-
readonly points: readonly [ManifoldPoint, ManifoldPoint];
|
|
31
|
-
/** Clear the manifold for reuse. */
|
|
32
|
-
reset(): void;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Manifold.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Manifold.d.ts","sourceRoot":"","sources":["../../../src/collision/Manifold.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,CAAC,EAAE,MAAM,CAAC;IACV,sCAAsC;IACtC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;GAMG;AACH,qBAAa,QAAQ;IACnB,wCAAwC;IACjC,OAAO,SAAK;IACnB,wCAAwC;IACjC,OAAO,SAAK;IACnB,6DAA6D;IACtD,UAAU,SAAK;IAEtB,SAAgB,MAAM,EAAE,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAG7D;IAEF,oCAAoC;IAC7B,KAAK,IAAI,IAAI,CAInB;CACF"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//#region src/collision/Manifold.ts
|
|
2
|
-
/**
|
|
3
|
-
* A contact manifold: the collision normal (oriented from collider A toward
|
|
4
|
-
* collider B) plus 1-2 contact points. A `Manifold` is reused across narrow-phase
|
|
5
|
-
* calls - it preallocates its two points and `reset()`s `pointCount` to 0. The
|
|
6
|
-
* generation here is forward-looking work for the dynamics solver; in this
|
|
7
|
-
* collision/query release it drives debug draw and validates the narrow phase.
|
|
8
|
-
*/
|
|
9
|
-
var Manifold = class {
|
|
10
|
-
/** Collision normal X (unit, A → B). */
|
|
11
|
-
normalX = 0;
|
|
12
|
-
/** Collision normal Y (unit, A → B). */
|
|
13
|
-
normalY = 0;
|
|
14
|
-
/** Number of valid entries in {@link points} (0, 1 or 2). */
|
|
15
|
-
pointCount = 0;
|
|
16
|
-
points = [{
|
|
17
|
-
x: 0,
|
|
18
|
-
y: 0,
|
|
19
|
-
penetration: 0,
|
|
20
|
-
id: 0
|
|
21
|
-
}, {
|
|
22
|
-
x: 0,
|
|
23
|
-
y: 0,
|
|
24
|
-
penetration: 0,
|
|
25
|
-
id: 0
|
|
26
|
-
}];
|
|
27
|
-
/** Clear the manifold for reuse. */
|
|
28
|
-
reset() {
|
|
29
|
-
this.pointCount = 0;
|
|
30
|
-
this.normalX = 0;
|
|
31
|
-
this.normalY = 0;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
export { Manifold };
|
|
37
|
-
//# sourceMappingURL=Manifold.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Manifold.js","names":[],"sources":["../../../src/collision/Manifold.ts"],"sourcesContent":["/** A single point of a {@link Manifold}. */\nexport interface ManifoldPoint {\n /** World-space contact position X. */\n x: number;\n /** World-space contact position Y. */\n y: number;\n /** Penetration depth in px (≥ 0). */\n penetration: number;\n /**\n * Stable feature id identifying which geometric features produced this point.\n * Constant across frames while the contact features are unchanged - the basis\n * for warm-starting the solver later.\n */\n id: number;\n}\n\n/**\n * A contact manifold: the collision normal (oriented from collider A toward\n * collider B) plus 1-2 contact points. A `Manifold` is reused across narrow-phase\n * calls - it preallocates its two points and `reset()`s `pointCount` to 0. The\n * generation here is forward-looking work for the dynamics solver; in this\n * collision/query release it drives debug draw and validates the narrow phase.\n */\nexport class Manifold {\n /** Collision normal X (unit, A → B). */\n public normalX = 0;\n /** Collision normal Y (unit, A → B). */\n public normalY = 0;\n /** Number of valid entries in {@link points} (0, 1 or 2). */\n public pointCount = 0;\n\n public readonly points: readonly [ManifoldPoint, ManifoldPoint] = [\n { x: 0, y: 0, penetration: 0, id: 0 },\n { x: 0, y: 0, penetration: 0, id: 0 },\n ];\n\n /** Clear the manifold for reuse. */\n public reset(): void {\n this.pointCount = 0;\n this.normalX = 0;\n this.normalY = 0;\n }\n}\n"],"mappings":";;;;;;;;AAuBA,IAAa,WAAb,MAAsB;;CAEpB,AAAO,UAAU;;CAEjB,AAAO,UAAU;;CAEjB,AAAO,aAAa;CAEpB,AAAgB,SAAkD,CAChE;EAAE,GAAG;EAAG,GAAG;EAAG,aAAa;EAAG,IAAI;CAAE,GACpC;EAAE,GAAG;EAAG,GAAG;EAAG,aAAa;EAAG,IAAI;CAAE,CACtC;;CAGA,AAAO,QAAc;EACnB,KAAK,aAAa;EAClB,KAAK,UAAU;EACf,KAAK,UAAU;CACjB;AACF"}
|