@codexo/exojs-physics 0.15.3 → 0.16.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 +51 -23
- package/dist/esm/Aabb.d.ts +6 -10
- package/dist/esm/Aabb.d.ts.map +1 -0
- package/dist/esm/Aabb.js +9 -5
- package/dist/esm/Aabb.js.map +1 -1
- package/dist/esm/Collider.d.ts +62 -10
- package/dist/esm/Collider.d.ts.map +1 -0
- package/dist/esm/Collider.js +263 -157
- package/dist/esm/Collider.js.map +1 -1
- package/dist/esm/ContactGraph.d.ts +51 -5
- package/dist/esm/ContactGraph.d.ts.map +1 -0
- package/dist/esm/ContactGraph.js +282 -223
- package/dist/esm/ContactGraph.js.map +1 -1
- package/dist/esm/ContactModifier.d.ts +85 -0
- package/dist/esm/ContactModifier.d.ts.map +1 -0
- package/dist/esm/ContactModifier.js +49 -0
- package/dist/esm/ContactModifier.js.map +1 -0
- package/dist/esm/PhysicsBody.d.ts +56 -22
- package/dist/esm/PhysicsBody.d.ts.map +1 -0
- package/dist/esm/PhysicsBody.js +461 -443
- package/dist/esm/PhysicsBody.js.map +1 -1
- package/dist/esm/PhysicsWorld.d.ts +276 -43
- package/dist/esm/PhysicsWorld.d.ts.map +1 -0
- package/dist/esm/PhysicsWorld.js +890 -626
- package/dist/esm/PhysicsWorld.js.map +1 -1
- package/dist/esm/TimeStepper.d.ts +3 -2
- package/dist/esm/TimeStepper.d.ts.map +1 -0
- package/dist/esm/TimeStepper.js +56 -67
- package/dist/esm/TimeStepper.js.map +1 -1
- package/dist/esm/backend/NativePhysicsBackend.d.ts +8 -4
- package/dist/esm/backend/NativePhysicsBackend.d.ts.map +1 -0
- package/dist/esm/backend/NativePhysicsBackend.js +48 -41
- package/dist/esm/backend/NativePhysicsBackend.js.map +1 -1
- package/dist/esm/backend/PhysicsBackend.d.ts +9 -2
- package/dist/esm/backend/PhysicsBackend.d.ts.map +1 -0
- package/dist/esm/binding/BindingRegistry.d.ts +25 -4
- package/dist/esm/binding/BindingRegistry.d.ts.map +1 -0
- package/dist/esm/binding/BindingRegistry.js +70 -36
- package/dist/esm/binding/BindingRegistry.js.map +1 -1
- package/dist/esm/binding/PhysicsBinding.d.ts +22 -5
- package/dist/esm/binding/PhysicsBinding.d.ts.map +1 -0
- package/dist/esm/binding/PhysicsBinding.js +46 -21
- package/dist/esm/binding/PhysicsBinding.js.map +1 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +68 -0
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -0
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +149 -0
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -0
- package/dist/esm/broadphase/BroadPhase.d.ts +7 -4
- package/dist/esm/broadphase/BroadPhase.d.ts.map +1 -0
- package/dist/esm/broadphase/index.d.ts +2 -1
- package/dist/esm/broadphase/index.d.ts.map +1 -0
- package/dist/esm/collision/CollisionProxy.d.ts +3 -2
- package/dist/esm/collision/CollisionProxy.d.ts.map +1 -0
- package/dist/esm/collision/Manifold.d.ts +5 -4
- package/dist/esm/collision/Manifold.d.ts.map +1 -0
- package/dist/esm/collision/Manifold.js +34 -25
- package/dist/esm/collision/Manifold.js.map +1 -1
- package/dist/esm/collision/chainAdjacency.d.ts +29 -0
- package/dist/esm/collision/chainAdjacency.d.ts.map +1 -0
- package/dist/esm/collision/chainAdjacency.js +44 -0
- package/dist/esm/collision/chainAdjacency.js.map +1 -0
- package/dist/esm/collision/dispatch.d.ts +35 -0
- package/dist/esm/collision/dispatch.d.ts.map +1 -0
- package/dist/esm/collision/dispatch.js +58 -0
- package/dist/esm/collision/dispatch.js.map +1 -0
- package/dist/esm/collision/index.d.ts +2 -0
- package/dist/esm/collision/index.d.ts.map +1 -0
- package/dist/esm/collision/narrowphase.d.ts +5 -2
- package/dist/esm/collision/narrowphase.d.ts.map +1 -0
- package/dist/esm/collision/narrowphase.js +524 -399
- package/dist/esm/collision/narrowphase.js.map +1 -1
- package/dist/esm/collision/segments.d.ts +19 -0
- package/dist/esm/collision/segments.d.ts.map +1 -0
- package/dist/esm/collision/segments.js +36 -0
- package/dist/esm/collision/segments.js.map +1 -0
- package/dist/esm/collision/sweep.d.ts +35 -0
- package/dist/esm/collision/sweep.d.ts.map +1 -0
- package/dist/esm/collision/sweep.js +437 -0
- package/dist/esm/collision/sweep.js.map +1 -0
- package/dist/esm/debug/PhysicsDebugDraw.d.ts +23 -4
- package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +1 -0
- package/dist/esm/debug/PhysicsDebugDraw.js +230 -188
- package/dist/esm/debug/PhysicsDebugDraw.js.map +1 -1
- package/dist/esm/debug/index.d.ts +1 -0
- package/dist/esm/debug/index.d.ts.map +1 -0
- package/dist/esm/debug/index.js +3 -2
- package/dist/esm/events.d.ts +1 -0
- package/dist/esm/events.d.ts.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +24 -19
- package/dist/esm/joints/DistanceJoint.d.ts +4 -3
- package/dist/esm/joints/DistanceJoint.d.ts.map +1 -0
- package/dist/esm/joints/DistanceJoint.js +160 -172
- package/dist/esm/joints/DistanceJoint.js.map +1 -1
- package/dist/esm/joints/Joint.d.ts +5 -4
- package/dist/esm/joints/Joint.d.ts.map +1 -0
- package/dist/esm/joints/Joint.js +23 -21
- package/dist/esm/joints/Joint.js.map +1 -1
- package/dist/esm/joints/MouseJoint.d.ts +8 -7
- package/dist/esm/joints/MouseJoint.d.ts.map +1 -0
- package/dist/esm/joints/MouseJoint.js +132 -133
- package/dist/esm/joints/MouseJoint.js.map +1 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +5 -4
- package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -0
- package/dist/esm/joints/PrismaticJoint.js +211 -240
- package/dist/esm/joints/PrismaticJoint.js.map +1 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +4 -3
- package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -0
- package/dist/esm/joints/RevoluteJoint.js +191 -213
- package/dist/esm/joints/RevoluteJoint.js.map +1 -1
- package/dist/esm/joints/WeldJoint.d.ts +3 -2
- package/dist/esm/joints/WeldJoint.d.ts.map +1 -0
- package/dist/esm/joints/WeldJoint.js +156 -152
- package/dist/esm/joints/WeldJoint.js.map +1 -1
- package/dist/esm/joints/WheelJoint.d.ts +4 -3
- package/dist/esm/joints/WheelJoint.d.ts.map +1 -0
- package/dist/esm/joints/WheelJoint.js +228 -255
- package/dist/esm/joints/WheelJoint.js.map +1 -1
- package/dist/esm/math.d.ts +6 -9
- package/dist/esm/math.d.ts.map +1 -0
- package/dist/esm/math.js +37 -39
- package/dist/esm/math.js.map +1 -1
- package/dist/esm/physicsBuildInfo.d.ts +1 -0
- package/dist/esm/physicsBuildInfo.d.ts.map +1 -0
- package/dist/esm/physicsBuildInfo.js +6 -4
- package/dist/esm/physicsBuildInfo.js.map +1 -1
- package/dist/esm/public.d.ts +8 -3
- package/dist/esm/public.d.ts.map +1 -0
- package/dist/esm/query/QueryEngine.d.ts +56 -12
- package/dist/esm/query/QueryEngine.d.ts.map +1 -0
- package/dist/esm/query/QueryEngine.js +494 -237
- package/dist/esm/query/QueryEngine.js.map +1 -1
- package/dist/esm/query/SpatialIndex.d.ts +34 -0
- package/dist/esm/query/SpatialIndex.d.ts.map +1 -0
- package/dist/esm/shapes/AnyShape.d.ts +9 -4
- package/dist/esm/shapes/AnyShape.d.ts.map +1 -0
- package/dist/esm/shapes/BoxShape.d.ts +2 -1
- package/dist/esm/shapes/BoxShape.d.ts.map +1 -0
- package/dist/esm/shapes/BoxShape.js +37 -25
- package/dist/esm/shapes/BoxShape.js.map +1 -1
- package/dist/esm/shapes/CapsuleShape.d.ts +30 -0
- package/dist/esm/shapes/CapsuleShape.d.ts.map +1 -0
- package/dist/esm/shapes/CapsuleShape.js +88 -0
- package/dist/esm/shapes/CapsuleShape.js.map +1 -0
- package/dist/esm/shapes/ChainEdgeShape.d.ts +30 -0
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -0
- package/dist/esm/shapes/ChainEdgeShape.js +66 -0
- package/dist/esm/shapes/ChainEdgeShape.js.map +1 -0
- package/dist/esm/shapes/ChainShape.d.ts +52 -0
- package/dist/esm/shapes/ChainShape.d.ts.map +1 -0
- package/dist/esm/shapes/ChainShape.js +85 -0
- package/dist/esm/shapes/ChainShape.js.map +1 -0
- package/dist/esm/shapes/CircleShape.d.ts +3 -4
- package/dist/esm/shapes/CircleShape.d.ts.map +1 -0
- package/dist/esm/shapes/CircleShape.js +27 -26
- package/dist/esm/shapes/CircleShape.js.map +1 -1
- package/dist/esm/shapes/PolygonShape.d.ts +7 -8
- package/dist/esm/shapes/PolygonShape.d.ts.map +1 -0
- package/dist/esm/shapes/PolygonShape.js +131 -162
- package/dist/esm/shapes/PolygonShape.js.map +1 -1
- package/dist/esm/shapes/SegmentShape.d.ts +31 -0
- package/dist/esm/shapes/SegmentShape.d.ts.map +1 -0
- package/dist/esm/shapes/SegmentShape.js +62 -0
- package/dist/esm/shapes/SegmentShape.js.map +1 -0
- package/dist/esm/shapes/Shape.d.ts +28 -17
- package/dist/esm/shapes/Shape.d.ts.map +1 -0
- package/dist/esm/shapes/Shape.js +12 -13
- package/dist/esm/shapes/Shape.js.map +1 -1
- package/dist/esm/shapes/convexParts.d.ts +21 -0
- package/dist/esm/shapes/convexParts.d.ts.map +1 -0
- package/dist/esm/shapes/convexParts.js +26 -0
- package/dist/esm/shapes/convexParts.js.map +1 -0
- package/dist/esm/shapes/decompose.d.ts +24 -0
- package/dist/esm/shapes/decompose.d.ts.map +1 -0
- package/dist/esm/shapes/decompose.js +272 -0
- package/dist/esm/shapes/decompose.js.map +1 -0
- package/dist/esm/shapes/index.d.ts +4 -0
- package/dist/esm/shapes/index.d.ts.map +1 -0
- package/dist/esm/solver/ContactSolver.d.ts +12 -5
- package/dist/esm/solver/ContactSolver.d.ts.map +1 -0
- package/dist/esm/solver/ContactSolver.js +425 -471
- package/dist/esm/solver/ContactSolver.js.map +1 -1
- package/dist/esm/solver/tolerances.d.ts +34 -0
- package/dist/esm/solver/tolerances.d.ts.map +1 -0
- package/dist/esm/solver/tolerances.js +38 -0
- package/dist/esm/solver/tolerances.js.map +1 -0
- package/dist/esm/sort.d.ts +5 -4
- package/dist/esm/sort.d.ts.map +1 -0
- package/dist/esm/sort.js +41 -51
- package/dist/esm/sort.js.map +1 -1
- package/dist/esm/types.d.ts +4 -8
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +15 -17
- package/dist/esm/types.js.map +1 -1
- package/package.json +6 -6
- package/dist/esm/broadphase/SweepAndPrune.d.ts +0 -15
- package/dist/esm/broadphase/SweepAndPrune.js +0 -77
- package/dist/esm/broadphase/SweepAndPrune.js.map +0 -1
- package/dist/esm/debug/index.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @codexo/exojs-physics
|
|
2
2
|
|
|
3
|
-
Native 2D **
|
|
3
|
+
Native 2D **rigid-body** runtime for [ExoJS](https://github.com/Exoridus/ExoJS).
|
|
4
4
|
|
|
5
|
-
Zero production dependencies, ESM-only, version-locked with the core engine.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Zero production dependencies, ESM-only, version-locked with the core engine.
|
|
6
|
+
It ships a fixed-step world with a warm-started **TGS-Soft** solver: shapes,
|
|
7
|
+
colliders, bodies, a dynamic-AABB broad phase, a manifold-generating narrow
|
|
8
|
+
phase, joints, sleeping islands, continuous collision for fast bodies, a
|
|
9
|
+
per-contact modifier, collision filters, sensors, events, spatial queries,
|
|
10
|
+
scene-node binding with interpolation, and a debug overlay.
|
|
11
11
|
|
|
12
12
|
> **Library, not an extension.** Physics contributes no renderer or asset
|
|
13
13
|
> bindings, so there is no `/register` entry. Construct a `PhysicsWorld`
|
|
@@ -57,18 +57,27 @@ class GameScene extends Scene {
|
|
|
57
57
|
|
|
58
58
|
## What it does
|
|
59
59
|
|
|
60
|
-
| Area
|
|
61
|
-
|
|
62
|
-
| World
|
|
63
|
-
| Bodies
|
|
64
|
-
| Colliders
|
|
65
|
-
| Attach
|
|
66
|
-
| Shapes
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
60
|
+
| Area | API |
|
|
61
|
+
| -------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| World | `PhysicsWorld`, `step`, `gravity`, `timeStepper`, `destroy` |
|
|
63
|
+
| Bodies | `new PhysicsBody` + `world.add` (`dynamic`/`static`/`kinematic`), `setTransform`, mass/inertia from colliders |
|
|
64
|
+
| Colliders | `new Collider` + `body.addCollider` / `colliders: [...]`, density/friction/restitution, `isSensor`, filter, offset |
|
|
65
|
+
| Attach | `world.attach(node, def)` — body + collider + `bind` in one call |
|
|
66
|
+
| Shapes | solid: `CircleShape`, `CapsuleShape`, `PolygonShape` (convex-validated), `BoxShape`; boundary: `SegmentShape`, `ChainShape` |
|
|
67
|
+
| Concave outlines | `toConvexPolygonShapes(vertices)` — one possibly-concave outline into the convex `PolygonShape`s for a single body |
|
|
68
|
+
| Dynamics | fixed-step TGS-Soft solver, gravity, forces/impulses, friction/restitution, sleeping islands |
|
|
69
|
+
| Joints | `DistanceJoint`, `RevoluteJoint`, `PrismaticJoint`, `WheelJoint`, `WeldJoint`, `MouseJoint` |
|
|
70
|
+
| Continuous collision | `body.isBullet` — exact translational shape cast of the whole shape, not just its centre |
|
|
71
|
+
| Contact policy | `world.contactModifier` — per-contact material/enable decisions (one-way platforms, conditional friction) |
|
|
72
|
+
| Filtering | `CollisionFilter` (category/mask/group), `shouldCollide` |
|
|
73
|
+
| Events | `onCollisionStart` / `onCollisionEnd` / `onSensorEnter` / `onSensorExit` — immutable snapshots |
|
|
74
|
+
| Queries | `queryPoint`, `queryAabb` (+ `out` / `forEachAabbHit`), `rayCast`, `rayCastAll`, `overlapShape` |
|
|
75
|
+
| Binding | `bind(body, node)` — node tracks the body's position each step |
|
|
76
|
+
| Debug | `@codexo/exojs-physics/debug` → `PhysicsDebugDraw` (shapes/AABBs/contacts/normals/centres/broad-phase/joints) |
|
|
77
|
+
|
|
78
|
+
Building a level out of a tilemap? `@codexo/exojs-tilemap-physics` turns
|
|
79
|
+
`@codexo/exojs-tilemap` collision geometry into static bodies and keeps them in
|
|
80
|
+
sync with streamed chunks.
|
|
72
81
|
|
|
73
82
|
## Determinism & non-goals
|
|
74
83
|
|
|
@@ -79,10 +88,29 @@ guarantees across builds or machines** (floating-point reality). The package is
|
|
|
79
88
|
single-threaded and 2D only — no workers, GPU, 3D, soft bodies, fluids or
|
|
80
89
|
vehicles.
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
`step()` owns its own fixed-timestep accumulator, so you can drive it from
|
|
92
|
+
either the engine's `Scene.fixedUpdate` (already a constant-rate hook — the
|
|
93
|
+
idiomatic choice) or straight from `Scene.update`'s raw, variable per-frame
|
|
94
|
+
delta; either way `step` converts whatever it's given into the right number of
|
|
95
|
+
fixed sub-steps. See the "Stepping the world" section of the
|
|
96
|
+
[physics guide](https://exoridus.github.io/ExoJS/en/guide/physics/physics-basics/)
|
|
97
|
+
for the details and an interpolation note (`world.timeStepper.alpha`).
|
|
98
|
+
|
|
99
|
+
**Broad-phase scale.** Collision detection uses a dynamic AABB tree
|
|
100
|
+
(Box2D-style), incrementally updated across steps: a collider whose AABB
|
|
101
|
+
stays within its stored margin is never reinserted, so the dominant cost
|
|
102
|
+
tracks how much actually moved rather than the total live collider count
|
|
103
|
+
(there's still a cheap linear pass over all live colliders each step). Scales
|
|
104
|
+
to tens of thousands of simultaneously-live colliders.
|
|
105
|
+
|
|
106
|
+
**Solid and boundary geometry.** `CircleShape`, `CapsuleShape`, `PolygonShape`
|
|
107
|
+
and `BoxShape` enclose an area and carry mass; `SegmentShape` and `ChainShape`
|
|
108
|
+
are boundaries with no interior, so they contribute collision only and a
|
|
109
|
+
`dynamic` body needs at least one solid collider alongside them. A chain is one
|
|
110
|
+
authored collider that the engine solves edge by edge with shared-vertex
|
|
111
|
+
adjacency, so a body slides across a seam without snagging. Two boundaries never
|
|
112
|
+
collide with each other, and a boundary is never the _moving_ operand of a
|
|
113
|
+
continuous shape cast — level structure is swept against, not swept.
|
|
86
114
|
|
|
87
115
|
## License
|
|
88
116
|
|
package/dist/esm/Aabb.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
minX: number;
|
|
3
|
-
minY: number;
|
|
4
|
-
maxX: number;
|
|
5
|
-
maxY: number;
|
|
6
|
-
}
|
|
1
|
+
import type { AabbLike } from '@codexo/exojs';
|
|
7
2
|
/** Create a zero-extent AABB at the origin. */
|
|
8
|
-
export declare const createAabb: () =>
|
|
3
|
+
export declare const createAabb: () => AabbLike;
|
|
9
4
|
/** `true` when two AABBs overlap (touching edges count as overlapping). */
|
|
10
|
-
export declare const aabbOverlap: (a:
|
|
5
|
+
export declare const aabbOverlap: (a: AabbLike, b: AabbLike) => boolean;
|
|
11
6
|
/** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */
|
|
12
|
-
export declare const aabbContainsPoint: (aabb:
|
|
7
|
+
export declare const aabbContainsPoint: (aabb: AabbLike, x: number, y: number) => boolean;
|
|
13
8
|
/** Grow `aabb` outward by `margin` on every side, in place. */
|
|
14
|
-
export declare const expandAabb: (aabb:
|
|
9
|
+
export declare const expandAabb: (aabb: AabbLike, margin: number) => AabbLike;
|
|
10
|
+
//# sourceMappingURL=Aabb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Aabb.d.ts","sourceRoot":"","sources":["../../src/Aabb.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,+CAA+C;AAC/C,eAAO,MAAM,UAAU,QAAO,QAAoD,CAAC;AAEnF,2EAA2E;AAC3E,eAAO,MAAM,WAAW,GAAI,GAAG,QAAQ,EAAE,GAAG,QAAQ,KAAG,OAAuF,CAAC;AAE/I,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,GAAI,MAAM,QAAQ,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAA+E,CAAC;AAEzJ,+DAA+D;AAC/D,eAAO,MAAM,UAAU,GAAI,MAAM,QAAQ,EAAE,QAAQ,MAAM,KAAG,QAO3D,CAAC"}
|
package/dist/esm/Aabb.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
// min/max extents (not centre + half-extent) because the sweep-and-prune broad
|
|
3
|
-
// phase and overlap tests read the edges directly.
|
|
1
|
+
//#region src/Aabb.ts
|
|
4
2
|
/** Create a zero-extent AABB at the origin. */
|
|
5
|
-
const createAabb = () => ({
|
|
3
|
+
const createAabb = () => ({
|
|
4
|
+
minX: 0,
|
|
5
|
+
minY: 0,
|
|
6
|
+
maxX: 0,
|
|
7
|
+
maxY: 0
|
|
8
|
+
});
|
|
6
9
|
/** `true` when two AABBs overlap (touching edges count as overlapping). */
|
|
7
10
|
const aabbOverlap = (a, b) => a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY;
|
|
8
11
|
/** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */
|
|
9
12
|
const aabbContainsPoint = (aabb, x, y) => x >= aabb.minX && x <= aabb.maxX && y >= aabb.minY && y <= aabb.maxY;
|
|
10
13
|
|
|
14
|
+
//#endregion
|
|
11
15
|
export { aabbContainsPoint, aabbOverlap, createAabb };
|
|
12
|
-
//# sourceMappingURL=Aabb.js.map
|
|
16
|
+
//# sourceMappingURL=Aabb.js.map
|
package/dist/esm/Aabb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aabb.js","sources":["
|
|
1
|
+
{"version":3,"file":"Aabb.js","names":[],"sources":["../../src/Aabb.ts"],"sourcesContent":["// Axis-aligned bounding box helpers for the broad phase and AABB queries. The\n// box itself is core's structural `AabbLike` (min/max extents, not centre +\n// half-extent) - the broad-phase tree and the overlap tests read the edges\n// directly, and sharing one contract keeps colliders, spatial trees and query\n// bounds interchangeable across package boundaries.\n\nimport type { AabbLike } from '@codexo/exojs';\n\n/** Create a zero-extent AABB at the origin. */\nexport const createAabb = (): AabbLike => ({ minX: 0, minY: 0, maxX: 0, maxY: 0 });\n\n/** `true` when two AABBs overlap (touching edges count as overlapping). */\nexport const aabbOverlap = (a: AabbLike, b: AabbLike): boolean => a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY;\n\n/** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */\nexport const aabbContainsPoint = (aabb: AabbLike, x: number, y: number): boolean => x >= aabb.minX && x <= aabb.maxX && y >= aabb.minY && y <= aabb.maxY;\n\n/** Grow `aabb` outward by `margin` on every side, in place. */\nexport const expandAabb = (aabb: AabbLike, margin: number): AabbLike => {\n aabb.minX -= margin;\n aabb.minY -= margin;\n aabb.maxX += margin;\n aabb.maxY += margin;\n\n return aabb;\n};\n"],"mappings":";;AASA,MAAa,oBAA8B;CAAE,MAAM;CAAG,MAAM;CAAG,MAAM;CAAG,MAAM;AAAE;;AAGhF,MAAa,eAAe,GAAa,MAAyB,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE;;AAG1I,MAAa,qBAAqB,MAAgB,GAAW,MAAuB,KAAK,KAAK,QAAQ,KAAK,KAAK,QAAQ,KAAK,KAAK,QAAQ,KAAK,KAAK"}
|
package/dist/esm/Collider.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AabbLike, PointLike } from '@codexo/exojs';
|
|
2
|
+
import type { Transform } from './math';
|
|
3
3
|
import type { PhysicsBody } from './PhysicsBody';
|
|
4
4
|
import type { AnyShape } from './shapes/AnyShape';
|
|
5
|
-
import type { CollisionFilter
|
|
5
|
+
import type { CollisionFilter } from './types';
|
|
6
6
|
/** Construction options for a collider. */
|
|
7
7
|
export interface ColliderOptions {
|
|
8
8
|
/** The collision geometry. */
|
|
@@ -18,7 +18,7 @@ export interface ColliderOptions {
|
|
|
18
18
|
/** Category/mask/group filter; partials merge over the defaults. */
|
|
19
19
|
filter?: Partial<CollisionFilter>;
|
|
20
20
|
/** Body-local offset of the shape origin. Default `(0, 0)`. */
|
|
21
|
-
offset?:
|
|
21
|
+
offset?: Readonly<PointLike>;
|
|
22
22
|
/** Body-local rotation of the shape in radians (compound colliders). Default `0`. */
|
|
23
23
|
rotation?: number;
|
|
24
24
|
}
|
|
@@ -26,7 +26,7 @@ export interface ColliderOptions {
|
|
|
26
26
|
* Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local
|
|
27
27
|
* offset/rotation, material (friction/restitution/density) and a collision
|
|
28
28
|
* filter. A body may own several colliders (compound). The collider also caches
|
|
29
|
-
* its world-space geometry
|
|
29
|
+
* its world-space geometry - refreshed by {@link synchronize} - which the broad
|
|
30
30
|
* phase, narrow phase and queries read directly.
|
|
31
31
|
*
|
|
32
32
|
* Material fields and the filter are mutable; the shape and local placement are
|
|
@@ -45,6 +45,8 @@ export declare class Collider {
|
|
|
45
45
|
readonly filter: CollisionFilter;
|
|
46
46
|
private _id;
|
|
47
47
|
private _body;
|
|
48
|
+
private readonly _chainEdges;
|
|
49
|
+
private _chainParent;
|
|
48
50
|
private readonly _localTransform;
|
|
49
51
|
private readonly _worldTransform;
|
|
50
52
|
private readonly _aabb;
|
|
@@ -53,6 +55,15 @@ export declare class Collider {
|
|
|
53
55
|
private readonly _worldVertices;
|
|
54
56
|
private readonly _worldNormals;
|
|
55
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;
|
|
56
67
|
constructor(options: ColliderOptions);
|
|
57
68
|
/** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */
|
|
58
69
|
get id(): number;
|
|
@@ -62,17 +73,28 @@ export declare class Collider {
|
|
|
62
73
|
*/
|
|
63
74
|
get body(): PhysicsBody;
|
|
64
75
|
/** The collider's world AABB (valid after the latest {@link synchronize}). */
|
|
65
|
-
get aabb(): Readonly<
|
|
76
|
+
get aabb(): Readonly<AabbLike>;
|
|
66
77
|
/** The collider's world transform (offset/rotation composed with the body's). */
|
|
67
78
|
get worldTransform(): Readonly<Transform>;
|
|
68
79
|
/** The collider's body-local transform (offset + local rotation). */
|
|
69
80
|
get localTransform(): Readonly<Transform>;
|
|
70
81
|
/** World-space circle centre (only meaningful for circle shapes). */
|
|
71
|
-
get worldCenter(): Readonly<
|
|
72
|
-
/** World-space polygon vertices `[x0, y0,
|
|
82
|
+
get worldCenter(): Readonly<PointLike>;
|
|
83
|
+
/** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */
|
|
73
84
|
get worldVertices(): readonly number[];
|
|
74
|
-
/** World-space polygon outward normals `[x0, y0,
|
|
85
|
+
/** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */
|
|
75
86
|
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;
|
|
76
98
|
/** `true` after the owning world has destroyed this collider. */
|
|
77
99
|
get destroyed(): boolean;
|
|
78
100
|
/**
|
|
@@ -81,8 +103,38 @@ export declare class Collider {
|
|
|
81
103
|
* detection pass.
|
|
82
104
|
*/
|
|
83
105
|
synchronize(bodyTransform: Transform): void;
|
|
84
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* A chain's world geometry is its edge proxies': each of them shares the
|
|
108
|
+
* chain's local placement and syncs its own two endpoints, and the chain's own
|
|
109
|
+
* AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.
|
|
110
|
+
*/
|
|
111
|
+
private _synchronizeChain;
|
|
112
|
+
/** A circle is its transformed centre; the local vertex buffers stay unused. */
|
|
113
|
+
private _synchronizeCircle;
|
|
114
|
+
/**
|
|
115
|
+
* Transform a local vertex/normal ring into the world buffers and take the
|
|
116
|
+
* AABB while doing it. `radius` inflates the box for a rounded outline (a
|
|
117
|
+
* capsule's spine); it is `0` for a plain polygon.
|
|
118
|
+
*/
|
|
119
|
+
private _synchronizePolygon;
|
|
120
|
+
/** @internal - bind this collider to its body and id (called when the body joins a world). */
|
|
85
121
|
_attach(body: PhysicsBody, id: number): void;
|
|
122
|
+
/**
|
|
123
|
+
* Fan a chain out into one proxy per edge. Each proxy carries the chain's own
|
|
124
|
+
* local placement, so it needs no transform of its own, and its shape carries
|
|
125
|
+
* the adjacency that keeps a body from snagging at a shared vertex.
|
|
126
|
+
*/
|
|
127
|
+
private _buildChainEdges;
|
|
86
128
|
/** Internal: mark destroyed (called by the world). */
|
|
87
129
|
_markDestroyed(): void;
|
|
88
130
|
}
|
|
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
|
+
//# sourceMappingURL=Collider.d.ts.map
|
|
@@ -0,0 +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,CAAC,CAAC;IAClC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7B,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;A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