@melonjs/rapier3d-adapter 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +341 -2
  4. package/build/Rapier3dAdapter.d.ts +395 -0
  5. package/build/Rapier3dAdapter.d.ts.map +1 -0
  6. package/build/Simulation.d.ts +35 -0
  7. package/build/Simulation.d.ts.map +1 -0
  8. package/build/bodies/Motion.d.ts +64 -0
  9. package/build/bodies/Motion.d.ts.map +1 -0
  10. package/build/bodies/RuntimeOverrides.d.ts +16 -0
  11. package/build/bodies/RuntimeOverrides.d.ts.map +1 -0
  12. package/build/bodies/helpers.d.ts +30 -0
  13. package/build/bodies/helpers.d.ts.map +1 -0
  14. package/build/bodies/pose.d.ts +34 -0
  15. package/build/bodies/pose.d.ts.map +1 -0
  16. package/build/colliders/CollisionFilters.d.ts +60 -0
  17. package/build/colliders/CollisionFilters.d.ts.map +1 -0
  18. package/build/colliders/footprint.d.ts +22 -0
  19. package/build/colliders/footprint.d.ts.map +1 -0
  20. package/build/colliders/shapes.d.ts +18 -0
  21. package/build/colliders/shapes.d.ts.map +1 -0
  22. package/build/colliders/types.d.ts +48 -0
  23. package/build/colliders/types.d.ts.map +1 -0
  24. package/build/contacts/ContactDispatcher.d.ts +80 -0
  25. package/build/contacts/ContactDispatcher.d.ts.map +1 -0
  26. package/build/index.d.ts +9 -0
  27. package/build/index.d.ts.map +1 -0
  28. package/build/index.js +1938 -0
  29. package/build/index.js.map +7 -0
  30. package/build/joints/Joints.d.ts +51 -0
  31. package/build/joints/Joints.d.ts.map +1 -0
  32. package/build/loader.d.ts +20 -0
  33. package/build/loader.d.ts.map +1 -0
  34. package/build/math/units.d.ts +44 -0
  35. package/build/math/units.d.ts.map +1 -0
  36. package/build/queries/queries.d.ts +40 -0
  37. package/build/queries/queries.d.ts.map +1 -0
  38. package/build/types.d.ts +77 -0
  39. package/build/types.d.ts.map +1 -0
  40. package/package.json +71 -5
@@ -0,0 +1,60 @@
1
+ /**
2
+ * melonJS collision types and masks on Rapier colliders.
3
+ *
4
+ * Rapier's own collision groups hold 16 bits of membership and 16 of filter,
5
+ * where melonJS types and masks are 32 bits: a collider whose values do not
6
+ * fit is filtered by Rapier's `filterContactPair` / `filterIntersectionPair`
7
+ * hooks instead, on the full 32 bits.
8
+ */
9
+ import type * as RAPIER from "@dimforge/rapier3d-compat";
10
+ /** a collider's melonJS collision type and mask */
11
+ export interface Filter {
12
+ category: number;
13
+ mask: number;
14
+ }
15
+ export declare class CollisionFilters {
16
+ /** The hooks Rapier calls for a pair that needs the full 32 bits. */
17
+ readonly hooks: RAPIER.PhysicsHooks;
18
+ private readonly rapier;
19
+ /** collider handle -> its type and mask */
20
+ private readonly filters;
21
+ /**
22
+ * @param rapier - the Rapier module
23
+ */
24
+ constructor(rapier: typeof RAPIER);
25
+ /**
26
+ * A collider's type and mask.
27
+ * @param handle - the collider handle
28
+ * @returns its filter, if it has one
29
+ */
30
+ get(handle: number): Filter | undefined;
31
+ /**
32
+ * Give a collider its melonJS collision type and mask.
33
+ * @param collider - the collider to configure
34
+ * @param category - its collision type
35
+ * @param mask - the collision types it collides with
36
+ */
37
+ apply(collider: RAPIER.Collider, category: number, mask: number): void;
38
+ /**
39
+ * Change the type and/or the mask of several colliders.
40
+ * @param colliders - the colliders
41
+ * @param category - the new type, or undefined to keep each collider's
42
+ * @param mask - the new mask, or undefined to keep each collider's
43
+ */
44
+ update(colliders: RAPIER.Collider[], category: number | undefined, mask: number | undefined): void;
45
+ /**
46
+ * Forget a collider that left the world.
47
+ * @param handle - its handle
48
+ */
49
+ forget(handle: number): void;
50
+ /** Forget every collider. */
51
+ clear(): void;
52
+ /**
53
+ * Whether two colliders collide, by their full 32-bit types and masks.
54
+ * @param c1 - a collider handle
55
+ * @param c2 - the other
56
+ * @returns true when each one's mask includes the other's type
57
+ */
58
+ private passes;
59
+ }
60
+ //# sourceMappingURL=CollisionFilters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CollisionFilters.d.ts","sourceRoot":"","sources":["../../src/colliders/CollisionFilters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGzD,mDAAmD;AACnD,MAAM,WAAW,MAAM;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAKD,qBAAa,gBAAgB;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD;;OAEG;gBACS,MAAM,EAAE,OAAO,MAAM;IAajC;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvC;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAmBtE;;;;;OAKG;IACH,MAAM,CACL,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,EAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,IAAI,EAAE,MAAM,GAAG,SAAS,GACtB,IAAI;IAWP;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI5B,6BAA6B;IAC7B,KAAK,IAAI,IAAI;IAIb;;;;;OAKG;IACH,OAAO,CAAC,MAAM;CAQd"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A collider's footprint in XY, as its body is turned: what `getBodyAABB`
3
+ * reports and `queryAABB` tests against.
4
+ */
5
+ import type * as RAPIER from "@dimforge/rapier3d-compat";
6
+ import type { ColliderEntry } from "./types";
7
+ /** A box in XY: min x, min y, max x, max y. */
8
+ export type Footprint = [number, number, number, number];
9
+ /**
10
+ * An empty footprint, ready to grow.
11
+ * @returns a box that contains nothing
12
+ */
13
+ export declare function emptyFootprint(): Footprint;
14
+ /**
15
+ * Grow a box in XY by a collider's footprint as its body is turned, in
16
+ * pixels, relative to the body's origin.
17
+ * @param entry - the collider's entry
18
+ * @param q - its body's turn
19
+ * @param box - the box to grow
20
+ */
21
+ export declare function growFootprint(entry: ColliderEntry, q: RAPIER.Rotation, box: Footprint): void;
22
+ //# sourceMappingURL=footprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"footprint.d.ts","sourceRoot":"","sources":["../../src/colliders/footprint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,SAAS,CAE1C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,aAAa,EACpB,CAAC,EAAE,MAAM,CAAC,QAAQ,EAClB,GAAG,EAAE,SAAS,GACZ,IAAI,CAsCN"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The Rapier colliders melonJS's 3D shapes become.
3
+ */
4
+ import type * as RAPIER from "@dimforge/rapier3d-compat";
5
+ import { type BodyShape } from "melonjs";
6
+ import type { Units } from "../math/units";
7
+ import type { ColliderPart } from "./types";
8
+ /**
9
+ * The colliders a list of shapes becomes, not yet in the world. A shape with
10
+ * `isActive: false` makes none.
11
+ * @param rapier - the Rapier module
12
+ * @param units - the scale between pixels and meters
13
+ * @param shapes - the shapes of a body definition
14
+ * @returns one part per active shape
15
+ * @throws {Error} for a shape this adapter cannot build
16
+ */
17
+ export declare function buildColliderParts(rapier: typeof RAPIER, units: Units, shapes: BodyShape[]): ColliderPart[];
18
+ //# sourceMappingURL=shapes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["../../src/colliders/shapes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACN,KAAK,SAAS,EAMd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,KAAK,EAAO,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAgB5C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,OAAO,MAAM,EACrB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,SAAS,EAAE,GACjB,YAAY,EAAE,CAUhB"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * What the adapter keeps about a collider.
3
+ */
4
+ import type * as RAPIER from "@dimforge/rapier3d-compat";
5
+ import type { BodyShape, Renderable } from "melonjs";
6
+ import type { XYZ } from "../math/units";
7
+ /**
8
+ * A sphere or a capsule as the segment its radius sweeps, in body space and
9
+ * pixels: its bounds once turned are those of the turned segment, a radius
10
+ * wider, where its turned box would be too large.
11
+ */
12
+ export interface RoundShape {
13
+ a: XYZ;
14
+ b: XYZ;
15
+ r: number;
16
+ }
17
+ /** What the adapter knows about one Rapier collider. */
18
+ export interface ColliderEntry {
19
+ renderable: Renderable;
20
+ /** the melonJS shape it was built from */
21
+ shape: BodyShape;
22
+ /** that shape's index in the body definition */
23
+ index: number;
24
+ /** the collider's box in body space, in pixels, before the body turns */
25
+ min: XYZ;
26
+ max: XYZ;
27
+ round?: RoundShape;
28
+ }
29
+ /** A collider ready to be made: its description, and what is kept about it. */
30
+ export interface ColliderPart {
31
+ shape: BodyShape;
32
+ index: number;
33
+ desc: RAPIER.ColliderDesc;
34
+ min: XYZ;
35
+ max: XYZ;
36
+ round?: RoundShape;
37
+ }
38
+ /**
39
+ * What was changed on every collider of a body at run time, so that
40
+ * `updateShape()` gives it to the new ones.
41
+ */
42
+ export interface ColliderOverrides {
43
+ category?: number;
44
+ mask?: number;
45
+ sensor?: boolean;
46
+ restitution?: number;
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colliders/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,GAAG,CAAC;IACP,CAAC,EAAE,GAAG,CAAC;IACP,CAAC,EAAE,MAAM,CAAC;CACV;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,0CAA0C;IAC1C,KAAK,EAAE,SAAS,CAAC;IACjB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC;IAC1B,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Collision events: Rapier's start and end events, and every pair still
3
+ * touching once a frame, turned into melonJS's collision hooks.
4
+ *
5
+ * On each renderable of a pair it fires the shape-level hook
6
+ * (`onShapeCollisionStart`, `…Active`, `…End`), then the body-level one
7
+ * (`onCollisionStart`, `onCollisionActive` or the legacy `onCollision`,
8
+ * `onCollisionEnd`). A hook may take a body out of the world, even one of the
9
+ * pair it is told about: the bookkeeping here makes sure no one hears of an
10
+ * end before its start, nor of anything once its body is gone.
11
+ */
12
+ import type * as RAPIER from "@dimforge/rapier3d-compat";
13
+ import type { Simulation } from "../Simulation";
14
+ export declare class ContactDispatcher {
15
+ /** touching pairs, from Rapier's start events until their end */
16
+ readonly activePairs: Map<string, [number, number]>;
17
+ private readonly sim;
18
+ private eventQueue;
19
+ /** a step's events, collected before any is dispatched */
20
+ private readonly pendingEvents;
21
+ /** the pairs whose start or active hooks are running, innermost last */
22
+ private readonly dispatching;
23
+ /**
24
+ * @param sim - the simulation it reports on
25
+ */
26
+ constructor(sim: Simulation);
27
+ /**
28
+ * The queue Rapier writes a step's start and end events to.
29
+ * @returns the event queue to pass to `world.step`
30
+ */
31
+ get queue(): RAPIER.EventQueue;
32
+ /** Make the event queue, with the Rapier world. */
33
+ open(): void;
34
+ /** Free the event queue, and forget every pair. */
35
+ close(): void;
36
+ /**
37
+ * Dispatch the start and end events Rapier queued during the last step.
38
+ * They are all read before any is dispatched, so a handler that removes a
39
+ * body cannot disturb the queue.
40
+ */
41
+ dispatchQueuedEvents(): void;
42
+ /** Once per frame: the active hooks of every pair still touching. */
43
+ dispatchActiveContacts(): void;
44
+ /**
45
+ * Tell the pairs touching colliders that are about to go that their
46
+ * contact ended. The colliders must still be known: forget them after.
47
+ * @param colliders - the colliders leaving the world
48
+ */
49
+ endContacts(colliders: RAPIER.Collider[]): void;
50
+ /**
51
+ * Fire the hooks of one pair of colliders, on both renderables. A start or
52
+ * active hook may take a body of the pair out: see {@link Dispatch}.
53
+ * @param h1 - the first collider handle
54
+ * @param h2 - the second
55
+ * @param phase - which lifecycle hook to fire
56
+ */
57
+ private dispatchPair;
58
+ /**
59
+ * Fire one phase of a pair's hooks: the shape-level ones, then the
60
+ * renderables' own. A renderable whose body is gone hears nothing.
61
+ * @param e1 - the first collider's entry
62
+ * @param e2 - the second collider's entry
63
+ * @param h1 - the first collider handle
64
+ * @param h2 - the second
65
+ * @param phase - which lifecycle hook to fire
66
+ * @param sides - the sides and levels to fire it on, as bits
67
+ * @param [record] - where to note each side reached, before its hook runs
68
+ */
69
+ private dispatch;
70
+ /**
71
+ * The contact between two colliders: the normal from the first to the
72
+ * second, and how deep they overlap, in pixels. Zero for a sensor pair,
73
+ * which Rapier computes no contact for.
74
+ * @param h1 - the first collider handle
75
+ * @param h2 - the second
76
+ * @returns the normal and the depth
77
+ */
78
+ private contact;
79
+ }
80
+ //# sourceMappingURL=ContactDispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContactDispatcher.d.ts","sourceRoot":"","sources":["../../src/contacts/ContactDispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAyChD,qBAAa,iBAAiB;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,WAAW,gCAAuC;IAC3D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IACjC,OAAO,CAAC,UAAU,CAAqB;IACvC,0DAA0D;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkB;IAE9C;;OAEG;gBACS,GAAG,EAAE,UAAU;IAI3B;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAAC,UAAU,CAE7B;IAED,mDAAmD;IACnD,IAAI,IAAI,IAAI;IAIZ,mDAAmD;IACnD,KAAK,IAAI,IAAI;IAOb;;;;OAIG;IACH,oBAAoB,IAAI,IAAI;IAwB5B,qEAAqE;IACrE,sBAAsB,IAAI,IAAI;IAM9B;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,IAAI;IA4B/C;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAsCpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,QAAQ;IAsIhB;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO;CAiCf"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@melonjs/rapier3d-adapter`: Rapier 3D physics for melonJS.
3
+ *
4
+ * The adapter is {@link Rapier3dAdapter}; the rest of `src/` is its parts,
5
+ * one concern per file (see the top of `Rapier3dAdapter.ts`).
6
+ */
7
+ export { Rapier3dAdapter } from "./Rapier3dAdapter";
8
+ export { type Rapier3dAdapterOptions, type Rapier3dJointDefinition, REQUIRED_MELONJS_VERSION, type Vector3Like, } from "./types";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,wBAAwB,EACxB,KAAK,WAAW,GAChB,MAAM,SAAS,CAAC"}