@melonjs/rapier3d-adapter 1.0.0 → 1.0.1
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/CHANGELOG.md +5 -0
- package/build/Rapier3dAdapter.d.ts +2 -1
- package/build/Rapier3dAdapter.d.ts.map +1 -1
- package/build/index.js +7 -3
- package/build/index.js.map +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.1 - _2026-11-17_
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- `setPosition()` with a coordinate that is not a finite number (`NaN`, `Infinity`) leaves the body and its renderable where they are, as `setAngle()` and the velocity, force and turn setters already do. The body and its renderable, `depth` included, were put at `NaN` and stayed there until the next valid position
|
|
7
|
+
|
|
3
8
|
## 1.0.0 - _2026-11-17_
|
|
4
9
|
|
|
5
10
|
### Added
|
|
@@ -201,7 +201,8 @@ export declare class Rapier3dAdapter implements PhysicsAdapter {
|
|
|
201
201
|
/**
|
|
202
202
|
* Move the body and its renderable, at once. A {@link Vector3d} sets the
|
|
203
203
|
* depth too; a {@link Vector2d} keeps it. A renderable with no body here
|
|
204
|
-
* is moved all the same, as on every adapter.
|
|
204
|
+
* is moved all the same, as on every adapter. A coordinate that is not a
|
|
205
|
+
* finite number leaves the body and its renderable where they are.
|
|
205
206
|
* @param renderable - the body's renderable
|
|
206
207
|
* @param p - the new position, in `renderable.pos` space
|
|
207
208
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rapier3dAdapter.d.ts","sourceRoot":"","sources":["../src/Rapier3dAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,SAAS,EAC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/*!
|
|
2
|
-
* melonJS physics adapter for Rapier 3D (WebAssembly) - 1.0.
|
|
2
|
+
* melonJS physics adapter for Rapier 3D (WebAssembly) - 1.0.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* @melonjs/rapier3d-adapter is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -1208,7 +1208,7 @@ var _turn2 = new Quaternion3();
|
|
|
1208
1208
|
var Rapier3dAdapter = class {
|
|
1209
1209
|
physicLabel = "rapier3d";
|
|
1210
1210
|
name = "@melonjs/rapier3d-adapter";
|
|
1211
|
-
version = "1.0.
|
|
1211
|
+
version = "1.0.1";
|
|
1212
1212
|
url = "https://www.npmjs.com/package/@melonjs/rapier3d-adapter";
|
|
1213
1213
|
capabilities = {
|
|
1214
1214
|
constraints: true,
|
|
@@ -1567,12 +1567,16 @@ var Rapier3dAdapter = class {
|
|
|
1567
1567
|
/**
|
|
1568
1568
|
* Move the body and its renderable, at once. A {@link Vector3d} sets the
|
|
1569
1569
|
* depth too; a {@link Vector2d} keeps it. A renderable with no body here
|
|
1570
|
-
* is moved all the same, as on every adapter.
|
|
1570
|
+
* is moved all the same, as on every adapter. A coordinate that is not a
|
|
1571
|
+
* finite number leaves the body and its renderable where they are.
|
|
1571
1572
|
* @param renderable - the body's renderable
|
|
1572
1573
|
* @param p - the new position, in `renderable.pos` space
|
|
1573
1574
|
*/
|
|
1574
1575
|
setPosition(renderable, p) {
|
|
1575
1576
|
const depth = zOf(p) ?? renderable.depth;
|
|
1577
|
+
if (!Number.isFinite(p.x) || !Number.isFinite(p.y) || !Number.isFinite(depth)) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1576
1580
|
renderable.setPosition(p.x, p.y, depth);
|
|
1577
1581
|
renderable.isDirty = true;
|
|
1578
1582
|
this.sim.bodies.get(renderable)?.setTranslation(this.sim.units.inMeters(p.x, p.y, depth), true);
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Rapier3dAdapter.ts", "../src/bodies/helpers.ts", "../src/math/units.ts", "../src/bodies/Motion.ts", "../src/bodies/pose.ts", "../src/bodies/RuntimeOverrides.ts", "../src/colliders/CollisionFilters.ts", "../src/colliders/footprint.ts", "../src/colliders/shapes.ts", "../src/contacts/ContactDispatcher.ts", "../src/joints/Joints.ts", "../src/loader.ts", "../src/queries/queries.ts", "../src/Simulation.ts", "../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The adapter: the melonJS `PhysicsAdapter` interface on Rapier 3D.\n *\n * It owns the lifecycle (making and freeing the Rapier world, stepping it)\n * and the bodies (making them from a `bodyDef`, removing them), and answers\n * the portable API. The work itself is done by:\n *\n * - `Simulation`: the Rapier world and which body and colliders each\n * renderable has, shared by every part below\n * - `colliders/`: the colliders the 3D shapes become, their collision types\n * and masks, and their footprints\n * - `contacts/`: the collision hooks\n * - `bodies/`: the body's pose on its renderable, its motion, what was set on\n * it at run time, and the helpers on `renderable.body`\n * - `joints/` and `queries/`\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype AdapterCapabilities,\n\ttype BodyDefinition,\n\ttype BodyShape,\n\ttype Bounds,\n\tcollision,\n\tversion as melonjsVersion,\n\ttype PhysicsAdapter,\n\ttype PhysicsBody,\n\tQuaternion,\n\ttype RaycastHit3d,\n\ttype Rect,\n\ttype Renderable,\n\ttype Sphere,\n\tstate,\n\tutils,\n\tVector2d,\n\tVector3d,\n\ttype World,\n} from \"melonjs\";\nimport { spliceHelpers } from \"./bodies/helpers\";\nimport { Motion } from \"./bodies/Motion\";\nimport { type Pose, poseOf, writePose } from \"./bodies/pose\";\nimport { RuntimeOverrides } from \"./bodies/RuntimeOverrides\";\nimport { CollisionFilters } from \"./colliders/CollisionFilters\";\nimport { emptyFootprint, growFootprint } from \"./colliders/footprint\";\nimport { buildColliderParts } from \"./colliders/shapes\";\nimport type { ColliderEntry, ColliderPart } from \"./colliders/types\";\nimport { ContactDispatcher } from \"./contacts/ContactDispatcher\";\nimport { Joints } from \"./joints/Joints\";\nimport { loadedRapier, loadRapier } from \"./loader\";\nimport { Units, zOf } from \"./math/units\";\nimport * as queries from \"./queries/queries\";\nimport { Simulation } from \"./Simulation\";\nimport {\n\ttype Rapier3dAdapterOptions,\n\ttype Rapier3dJointDefinition,\n\tREQUIRED_MELONJS_VERSION,\n\ttype Vector3Like,\n} from \"./types\";\n\n// a body's turn about Z, set by `setAngle`\nconst _turn = new Quaternion();\n\ndeclare const __VERSION__: string;\n\n/**\n * melonJS physics adapter for Rapier 3D (https://rapier.rs), compiled to\n * WebAssembly: rigid bodies that move and turn in three dimensions, for a\n * game drawn with `Camera3d`.\n *\n * Bodies are declared as on every adapter, with a `bodyDef`, from the 3D\n * shapes: {@link Box3d}, {@link Sphere}, {@link Capsule3d},\n * {@link ConvexHull3d} and {@link TriangleMesh3d}. Shapes are in the\n * renderable's space, relative to its `pos` (and `depth`), which is where the\n * body sits; each frame the body's position is written back to `pos` /\n * `depth`, and its turn onto `currentTransform`, so a {@link Mesh}, a\n * `Sprite3d` or a `GLTFModel` tumbles as it is simulated.\n *\n * The adapter takes the 3D form of the portable API: `setVelocity`,\n * `applyForce`, `applyImpulse` and `setPosition` take a {@link Vector3d},\n * and `getVelocity3d`, `getRotation` / `setRotation` and\n * `getAngularVelocity3d` read the rest. The 2D calls still work, in the\n * plane of the body: a `Vector2d` leaves the depth as it was.\n *\n * Rapier's WebAssembly has to be compiled before an adapter can be\n * constructed: {@link Rapier3dAdapter.create} does both.\n * @example\n * import { Application, Camera3d } from \"melonjs\";\n * import { Rapier3dAdapter } from \"@melonjs/rapier3d-adapter\";\n *\n * const app = new Application(800, 600, {\n * parent: \"screen\",\n * cameraClass: Camera3d,\n * physic: await Rapier3dAdapter.create(),\n * });\n * @category Plugins\n * @document ../README.md\n */\nexport class Rapier3dAdapter implements PhysicsAdapter {\n\treadonly physicLabel = \"rapier3d\";\n\treadonly name = \"@melonjs/rapier3d-adapter\";\n\treadonly version = __VERSION__;\n\treadonly url = \"https://www.npmjs.com/package/@melonjs/rapier3d-adapter\";\n\n\treadonly capabilities: AdapterCapabilities = {\n\t\tconstraints: true,\n\t\t// opt-in per body: `(body as Rapier3dAdapter.Body).enableCcd(true)`\n\t\tcontinuousCollisionDetection: true,\n\t\tsleepingBodies: true,\n\t\t// a 3D world is queried with `raycast3d`\n\t\traycasts: false,\n\t\traycasts3d: true,\n\t\tvelocityLimit: true,\n\t\tisGrounded: true,\n\t\tbodies3d: true,\n\t};\n\n\t/**\n\t * World gravity, in pixels per second\u00B2. Change it at any time; read at\n\t * every step.\n\t */\n\tgravity: Vector3d;\n\n\t/**\n\t * The Rapier module: an escape hatch for what the portable\n\t * {@link PhysicsAdapter} interface does not cover (other joints, the\n\t * character controller, native queries). See the README.\n\t * @see {@link https://rapier.rs/docs/user_guides/javascript/getting_started_js Rapier JavaScript user guide}\n\t */\n\treadonly rapier: typeof RAPIER;\n\n\t/** Spatial conversion factor between melonJS pixels and Rapier meters. */\n\treadonly pixelsPerMeter: number;\n\n\t/** Back-reference to the owning melonJS world (set in {@link init}). */\n\tmelonWorld!: World;\n\n\tprivate readonly subSteps: number;\n\tprivate readonly sim: Simulation;\n\tprivate readonly filters: CollisionFilters;\n\tprivate readonly contacts: ContactDispatcher;\n\tprivate readonly motion: Motion;\n\tprivate readonly joints: Joints;\n\t/** what was set on every collider of a body at run time */\n\tprivate readonly overrides = new RuntimeOverrides();\n\t/** each body's definition, which `updateShape()` builds from again */\n\tprivate readonly defs = new Map<Renderable, BodyDefinition>();\n\t/** each renderable's transform when its body was made, and its bridge */\n\tprivate readonly poses = new Map<Renderable, Pose>();\n\t/** the shapes {@link Rapier3dAdapter.getBodyShapes} reports */\n\tprivate readonly reportedShapes = new Map<Renderable, BodyShape[]>();\n\n\t/**\n\t * Download and compile Rapier's WebAssembly. Every call returns the same\n\t * promise, so it can be started early and awaited wherever it is needed;\n\t * a failed load rejects, and a later call tries again.\n\t *\n\t * Rapier is imported with `import()`, so bundlers put it in a chunk of its\n\t * own, downloaded only when this is called.\n\t * @returns a promise that resolves once the adapter can be constructed\n\t * @example\n\t * const rapierReady = Rapier3dAdapter.load();\n\t * await loader.preload(assets);\n\t * await rapierReady;\n\t * app.world.setAdapter(new Rapier3dAdapter());\n\t */\n\tstatic load(): Promise<void> {\n\t\treturn loadRapier();\n\t}\n\n\t/**\n\t * Whether {@link Rapier3dAdapter.load} has finished, so that\n\t * `new Rapier3dAdapter()` can be called.\n\t * @returns true once Rapier is compiled\n\t */\n\tstatic get loaded(): boolean {\n\t\treturn loadedRapier() !== undefined;\n\t}\n\n\t/**\n\t * Create an adapter, the same way for every adapter: wait for\n\t * {@link Rapier3dAdapter.load}, then construct it.\n\t * @param options - the constructor's options\n\t * @returns the new adapter, an instance of the class `create` is called on\n\t */\n\tstatic async create<T extends PhysicsAdapter>(\n\t\tthis: Pick<typeof Rapier3dAdapter, \"load\"> &\n\t\t\t(new (\n\t\t\t\toptions?: Rapier3dAdapterOptions,\n\t\t\t) => T),\n\t\toptions?: Rapier3dAdapterOptions,\n\t): Promise<T> {\n\t\tawait this.load();\n\t\treturn new this(options);\n\t}\n\n\t/**\n\t * Construct an adapter. Rapier must be loaded first: use\n\t * {@link Rapier3dAdapter.create}, or await {@link Rapier3dAdapter.load}.\n\t * @param options - see {@link Rapier3dAdapterOptions}\n\t */\n\tconstructor(options: Rapier3dAdapterOptions = {}) {\n\t\tif (utils.checkVersion(REQUIRED_MELONJS_VERSION, melonjsVersion) > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`@melonjs/rapier3d-adapter requires melonJS >= ${REQUIRED_MELONJS_VERSION}, ` +\n\t\t\t\t\t`but the loaded melonJS is ${melonjsVersion}.`,\n\t\t\t);\n\t\t}\n\t\tconst rapier = loadedRapier();\n\t\tif (rapier === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: Rapier is not loaded yet. Use \" +\n\t\t\t\t\t\"`await Rapier3dAdapter.create(options)`, or `await Rapier3dAdapter.load()` \" +\n\t\t\t\t\t\"before `new Rapier3dAdapter(options)`.\",\n\t\t\t);\n\t\t}\n\t\tthis.rapier = rapier;\n\t\tconst ppm = options.pixelsPerMeter ?? 32;\n\t\tif (!(ppm > 0) || !Number.isFinite(ppm)) {\n\t\t\tthrow new Error(\n\t\t\t\t`@melonjs/rapier3d-adapter: pixelsPerMeter must be a positive number (got ${ppm}).`,\n\t\t\t);\n\t\t}\n\t\tthis.pixelsPerMeter = ppm;\n\t\tthis.subSteps = Math.max(1, Math.floor(options.subSteps ?? 1));\n\t\tconst g = options.gravity ?? { x: 0, y: 320, z: 0 };\n\t\tthis.gravity = new Vector3d(g.x, g.y, g.z ?? 0);\n\n\t\tthis.sim = new Simulation(rapier, new Units(ppm));\n\t\tthis.filters = new CollisionFilters(rapier);\n\t\tthis.contacts = new ContactDispatcher(this.sim);\n\t\tthis.motion = new Motion(this.sim);\n\t\tthis.joints = new Joints(this.sim);\n\t}\n\n\t/** The Rapier world; exposed for advanced use. Made in {@link init}. */\n\tget world(): RAPIER.World {\n\t\treturn this.sim.world;\n\t}\n\n\t// \u2500\u2500 lifecycle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tinit(world: World): void {\n\t\tthis.melonWorld = world;\n\t\tthis.sim.open(this.gravityInMeters());\n\t\tthis.contacts.open();\n\t}\n\n\tdestroy(): void {\n\t\t// nothing to free before `init()`, or a second time\n\t\tif (!this.sim.alive) {\n\t\t\treturn;\n\t\t}\n\t\tthis.contacts.close();\n\t\tthis.sim.close();\n\t\tthis.filters.clear();\n\t\tthis.motion.clear();\n\t\tthis.joints.clear();\n\t\tthis.overrides.clear();\n\t\tthis.defs.clear();\n\t\tthis.poses.clear();\n\t\tthis.reportedShapes.clear();\n\t}\n\n\tstep(dt: number): void {\n\t\tif (!this.sim.alive) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: step() on an adapter with no Rapier world: it was destroyed, or never installed with `world.setAdapter()`.\",\n\t\t\t);\n\t\t}\n\t\t// as the other adapters: no simulation while the game is paused\n\t\tif (state.isPaused()) {\n\t\t\treturn;\n\t\t}\n\t\t// a step of no length simulates nothing, and one that is not a number\n\t\t// would leave every body it touched stuck for good\n\t\tif (!(dt > 0) || !Number.isFinite(dt)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { world } = this.sim;\n\t\t// read every step, so `adapter.gravity` can change while the game runs\n\t\tworld.gravity = this.gravityInMeters();\n\t\t// melonJS passes dt in ms; Rapier wants seconds\n\t\tworld.timestep = dt / 1000 / this.subSteps;\n\t\tfor (let i = 0; i < this.subSteps; i++) {\n\t\t\tworld.step(this.contacts.queue, this.filters.hooks);\n\t\t\tthis.contacts.dispatchQueuedEvents();\n\t\t}\n\t\t// a force is for this frame, across every sub-step\n\t\tthis.motion.clearForces();\n\t\tthis.motion.clampVelocities();\n\t\tthis.contacts.dispatchActiveContacts();\n\t}\n\n\tsyncFromPhysics(): void {\n\t\tfor (const [renderable, body] of this.sim.bodies) {\n\t\t\t// a body at rest, or that never moves, has nothing new to write;\n\t\t\t// `setPosition` / `setRotation` write a moved one themselves\n\t\t\tif (body.isFixed() || body.isSleeping()) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.writePose(renderable, body);\n\t\t}\n\t}\n\n\t// \u2500\u2500 bodies \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\taddBody(renderable: Renderable, def: BodyDefinition): Rapier3dAdapter.Body {\n\t\tconst { rapier, units, world } = this.sim;\n\t\t// build every collider first, so a refused shape leaves no body behind,\n\t\t// nor takes away the one the renderable had\n\t\tconst parts = buildColliderParts(rapier, units, def.shapes);\n\t\t// a renderable has one body: a second one replaces the first\n\t\tthis.removeBody(renderable);\n\t\tconst { RigidBodyDesc } = rapier;\n\t\tconst desc =\n\t\t\tdef.type === \"static\"\n\t\t\t\t? RigidBodyDesc.fixed()\n\t\t\t\t: def.type === \"kinematic\"\n\t\t\t\t\t? // moved by its velocity, as on the other adapters\n\t\t\t\t\t\tRigidBodyDesc.kinematicVelocityBased()\n\t\t\t\t\t: RigidBodyDesc.dynamic();\n\t\t// the body sits where the renderable is: shapes are relative to it\n\t\tdesc.setTranslation(\n\t\t\tunits.toMeters(renderable.pos.x),\n\t\t\tunits.toMeters(renderable.pos.y),\n\t\t\tunits.toMeters(renderable.depth),\n\t\t);\n\t\t// `frictionAir` damps rotation as well as movement, as on the 2D\n\t\t// adapter: Rapier damping, a rate per second\n\t\tconst damping = averageOf(def.frictionAir) ?? 0;\n\t\tdesc.setLinearDamping(damping);\n\t\tdesc.setAngularDamping(damping);\n\t\tdesc.setGravityScale(def.gravityScale ?? 1);\n\t\t// unset means a rigid body turns\n\t\tif (def.fixedRotation === true) {\n\t\t\tdesc.lockRotations();\n\t\t}\n\t\tconst body = world.createRigidBody(desc);\n\t\tconst colliders: RAPIER.Collider[] = [];\n\t\tthis.sim.bodies.set(renderable, body);\n\t\tthis.sim.collidersOf.set(renderable, colliders);\n\t\tthis.defs.set(renderable, def);\n\t\tthis.createColliders(renderable, body, def, parts, colliders);\n\n\t\tif (def.maxVelocity) {\n\t\t\tthis.setMaxVelocity(renderable, def.maxVelocity);\n\t\t}\n\t\tthis.poses.set(renderable, poseOf(renderable));\n\n\t\tspliceHelpers(this.helperContext(), renderable, body, colliders);\n\t\tconst adapterBody = body as Rapier3dAdapter.Body;\n\t\trenderable.body = adapterBody;\n\t\t// as the builtin `Body` constructor does: a renderable with a body\n\t\t// takes part in physics and receives pointer events\n\t\trenderable.isKinematic = false;\n\t\treturn adapterBody;\n\t}\n\n\tremoveBody(renderable: Renderable): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body === undefined) {\n\t\t\treturn;\n\t\t}\n\t\t// a partner still touching this body learns the contact ended\n\t\tthis.forgetColliders(this.sim.collidersOf.get(renderable) ?? []);\n\t\t// one of their hooks may have taken this body out already\n\t\tif (this.sim.bodies.get(renderable) !== body) {\n\t\t\treturn;\n\t\t}\n\t\t// Rapier removes the body's joints and colliders with it\n\t\tthis.joints.forgetJointsOf(body);\n\t\tthis.sim.world.removeRigidBody(body);\n\t\tthis.motion.forget(renderable, body);\n\t\tthis.sim.bodies.delete(renderable);\n\t\tthis.sim.collidersOf.delete(renderable);\n\t\tthis.defs.delete(renderable);\n\t\tthis.poses.delete(renderable);\n\t\tthis.reportedShapes.delete(renderable);\n\t\tthis.overrides.delete(renderable);\n\t}\n\n\t/**\n\t * Give a body new shapes. The body itself stays: its position, turn and\n\t * velocities, its joints, what was changed on it at run time (static or\n\t * not, gravity scale, damping, sensor, collision type and mask, bounce,\n\t * speed cap, Rapier's own settings such as CCD) and the handle on\n\t * `renderable.body`. Its colliders are replaced, so the pairs touching\n\t * it end and start again, and its mass is that of the new shapes.\n\t *\n\t * A shape this adapter cannot build throws before anything is changed.\n\t * @param renderable - the body's renderable\n\t * @param shapes - the new shapes, relative to `pos`\n\t */\n\tupdateShape(renderable: Renderable, shapes: BodyShape[]): void {\n\t\tconst def = this.defs.get(renderable);\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (!def || !body || !colliders) {\n\t\t\treturn;\n\t\t}\n\t\t// every new collider is built before an old one goes\n\t\tconst parts = buildColliderParts(this.sim.rapier, this.sim.units, shapes);\n\t\tthis.forgetColliders(colliders);\n\t\t// one of the hooks told so may have taken this body out\n\t\tif (this.sim.bodies.get(renderable) !== body) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const collider of colliders) {\n\t\t\tthis.sim.world.removeCollider(collider, false);\n\t\t}\n\t\t// emptied in place: the body's helpers hold this array\n\t\tcolliders.length = 0;\n\t\tconst next = { ...def, shapes };\n\t\tthis.defs.set(renderable, next);\n\t\tthis.reportedShapes.delete(renderable);\n\t\tthis.createColliders(renderable, body, next, parts, colliders);\n\t\t// the mass and the inertia of the new shapes, from now\n\t\tbody.recomputeMassPropertiesFromColliders();\n\t\tbody.wakeUp();\n\t}\n\n\t// \u2500\u2500 joints \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * Make a joint between two bodies: what `world.addJoint()` calls, which\n\t * game code uses instead. A `\"hinge\"` is a Rapier revolute joint about\n\t * `axis` (default Z), a `\"rope\"` a rope joint, a `\"weld\"` a fixed joint\n\t * and a `\"slider\"` a prismatic joint along `axis` (default X). Anchors\n\t * are in each renderable's own space, relative to its `pos`, in pixels,\n\t * and the axis in `a`'s; a `z` left out is `0`.\n\t *\n\t * The bodies are joined as they stand, however each is turned: a weld\n\t * and a slider keep the turn between them, and a hinge leaves them only\n\t * the turn about its axis.\n\t * @param def - what to join, and how, in pixels and radians\n\t * @returns the Rapier joint\n\t */\n\taddJoint(def: Rapier3dJointDefinition): RAPIER.ImpulseJoint {\n\t\treturn this.joints.add(def);\n\t}\n\n\t/**\n\t * Remove a joint {@link Rapier3dAdapter.addJoint} made: what\n\t * `world.removeJoint()` calls. A joint already gone, with one of its\n\t * bodies, is ignored.\n\t * @param joint - the Rapier joint\n\t */\n\tremoveJoint(joint: RAPIER.ImpulseJoint): void {\n\t\tthis.joints.remove(joint);\n\t}\n\n\t// \u2500\u2500 velocity, forces and position \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tgetVelocity(renderable: Renderable, out?: Vector2d): Vector2d {\n\t\tconst target = out ?? new Vector2d();\n\t\tconst v = this.sim.bodies.get(renderable)?.linvel();\n\t\tconst { units } = this.sim;\n\t\treturn v\n\t\t\t? target.set(units.toPixels(v.x), units.toPixels(v.y))\n\t\t\t: target.set(0, 0);\n\t}\n\n\t/**\n\t * The body's velocity on all three axes, in pixels per second.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the vector to write into\n\t * @returns the velocity; zero for a renderable with no body here\n\t */\n\tgetVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d {\n\t\tconst target = out ?? new Vector3d();\n\t\tconst v = this.sim.bodies.get(renderable)?.linvel();\n\t\tconst { units } = this.sim;\n\t\treturn v\n\t\t\t? target.set(\n\t\t\t\t\tunits.toPixels(v.x),\n\t\t\t\t\tunits.toPixels(v.y),\n\t\t\t\t\tunits.toPixels(v.z),\n\t\t\t\t)\n\t\t\t: target.set(0, 0, 0);\n\t}\n\n\t/**\n\t * Set the body's velocity, in pixels per second. A {@link Vector3d} sets\n\t * all three axes; a {@link Vector2d} sets x and y and keeps the depth\n\t * velocity as it was.\n\t * @param renderable - the body's renderable\n\t * @param v - the velocity\n\t */\n\tsetVelocity(renderable: Renderable, v: Vector2d | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.setVelocity(body, v.x, v.y, zOf(v));\n\t\t}\n\t}\n\n\t/**\n\t * Push the body for this frame, across every sub-step: it accelerates by\n\t * `force / mass` pixels per second\u00B2. A force at `point` (in world pixels)\n\t * also turns it. A force or point given as a {@link Vector2d} acts in\n\t * the plane of the body.\n\t * @param renderable - the body's renderable\n\t * @param force - the force\n\t * @param [point] - where it pushes, in world space\n\t */\n\tapplyForce(\n\t\trenderable: Renderable,\n\t\tforce: Vector2d | Vector3d,\n\t\tpoint?: Vector2d | Vector3d,\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.addForce(body, force, point);\n\t\t}\n\t}\n\n\t/**\n\t * Strike the body once: its velocity changes by `impulse / mass` pixels\n\t * per second, at once. An impulse at `point` (in world pixels) also turns\n\t * it. A {@link Vector2d} strikes in the plane of the body.\n\t * @param renderable - the body's renderable\n\t * @param impulse - the impulse\n\t * @param [point] - where it strikes, in world space\n\t */\n\tapplyImpulse(\n\t\trenderable: Renderable,\n\t\timpulse: Vector2d | Vector3d,\n\t\tpoint?: Vector2d | Vector3d,\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tconst j = this.sim.units.inMeters(impulse.x, impulse.y, zOf(impulse) ?? 0);\n\t\tif (point) {\n\t\t\tbody.applyImpulseAtPoint(j, this.motion.pointInMeters(body, point), true);\n\t\t} else {\n\t\t\t// Rapier's own method, not the portable helper spliced over it\n\t\t\tthis.rapier.RigidBody.prototype.applyImpulse.call(body, j, true);\n\t\t}\n\t}\n\n\t/**\n\t * Move the body and its renderable, at once. A {@link Vector3d} sets the\n\t * depth too; a {@link Vector2d} keeps it. A renderable with no body here\n\t * is moved all the same, as on every adapter.\n\t * @param renderable - the body's renderable\n\t * @param p - the new position, in `renderable.pos` space\n\t */\n\tsetPosition(renderable: Renderable, p: Vector2d | Vector3d): void {\n\t\tconst depth = zOf(p) ?? renderable.depth;\n\t\t// one batched write, as the pose is written each frame\n\t\trenderable.setPosition(p.x, p.y, depth);\n\t\trenderable.isDirty = true;\n\t\tthis.sim.bodies\n\t\t\t.get(renderable)\n\t\t\t?.setTranslation(this.sim.units.inMeters(p.x, p.y, depth), true);\n\t}\n\n\t// \u2500\u2500 turn and spin \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The body's orientation, from the one it had when it was made.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the quaternion to write into\n\t * @returns the orientation; identity for a renderable with no body here\n\t */\n\tgetRotation(renderable: Renderable, out?: Quaternion): Quaternion {\n\t\tconst target = out ?? new Quaternion();\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) {\n\t\t\treturn target.identity();\n\t\t}\n\t\tconst q = body.rotation();\n\t\treturn target.set(q.x, q.y, q.z, q.w);\n\t}\n\n\t/**\n\t * Turn the body, and its renderable with it, to an orientation, from the\n\t * one it had when it was made.\n\t * @param renderable - the body's renderable\n\t * @param q - the orientation\n\t */\n\tsetRotation(renderable: Renderable, q: Quaternion): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\t// a non-unit quaternion is not a turn: normalized, as Rapier needs\n\t\tconst n = q.clone().normalize();\n\t\tbody.setRotation({ x: n.x, y: n.y, z: n.z, w: n.w }, true);\n\t\tthis.writePose(renderable, body);\n\t}\n\n\t/**\n\t * Turn the body to `angle` about Z, the turn a 2D game knows, leaving out\n\t * any other.\n\t * @param renderable - the body's renderable\n\t * @param angle - in radians\n\t */\n\tsetAngle(renderable: Renderable, angle: number): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\t// an angle that is not a number leaves the body as it is, as\n\t\t// `Quaternion#rotate` and `Matrix3d#rotate` do\n\t\tif (!body || !Number.isFinite(angle)) return;\n\t\tbody.setRotation(_turn.identity().rotate(angle), true);\n\t\tthis.writePose(renderable, body);\n\t}\n\n\t/**\n\t * The body's turn about Z: the angle +X is turned through, seen down Z.\n\t * @param renderable - the body's renderable\n\t * @returns in radians; `0` for a renderable with no body here\n\t */\n\tgetAngle(renderable: Renderable): number {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return 0;\n\t\t// where the turn takes +X, its x and y: the first column of the\n\t\t// quaternion's matrix, which is all of `apply` this needs\n\t\tconst { x, y, z, w } = body.rotation();\n\t\tconst tx = 1 - 2 * (y * y + z * z);\n\t\tconst ty = 2 * (x * y + w * z);\n\t\treturn tx * tx + ty * ty < 1e-12 ? 0 : Math.atan2(ty, tx);\n\t}\n\n\t/**\n\t * Set the body's spin, in radians per second: a {@link Vector3d} about\n\t * each axis, a number about Z, keeping the spin about X and Y.\n\t * @param renderable - the body's renderable\n\t * @param omega - the spin\n\t */\n\tsetAngularVelocity(renderable: Renderable, omega: number | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tif (typeof omega === \"number\") {\n\t\t\tconst w = body.angvel();\n\t\t\tbody.setAngvel({ x: w.x, y: w.y, z: omega }, true);\n\t\t} else {\n\t\t\tbody.setAngvel({ x: omega.x, y: omega.y, z: omega.z }, true);\n\t\t}\n\t}\n\n\tgetAngularVelocity(renderable: Renderable): number {\n\t\treturn this.sim.bodies.get(renderable)?.angvel().z ?? 0;\n\t}\n\n\t/**\n\t * The body's spin about each axis, in radians per second.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the vector to write into\n\t * @returns the spin; zero for a renderable with no body here\n\t */\n\tgetAngularVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d {\n\t\tconst target = out ?? new Vector3d();\n\t\tconst w = this.sim.bodies.get(renderable)?.angvel();\n\t\treturn w ? target.set(w.x, w.y, w.z) : target.set(0, 0, 0);\n\t}\n\n\t/**\n\t * Twist the body for this frame: a number about Z, a {@link Vector3d}\n\t * about each axis. In Rapier's own unit (N\u00B7m, not scaled by\n\t * `pixelsPerMeter`), as on the 2D Rapier adapter.\n\t * @param renderable - the body's renderable\n\t * @param torque - the torque\n\t */\n\tapplyTorque(renderable: Renderable, torque: number | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.addTorque(body, torque);\n\t\t}\n\t}\n\n\t// \u2500\u2500 what a body is \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tsetStatic(renderable: Renderable, isStatic: boolean): void {\n\t\tconst { RigidBodyType } = this.rapier;\n\t\tthis.sim.bodies\n\t\t\t.get(renderable)\n\t\t\t?.setBodyType(\n\t\t\t\tisStatic ? RigidBodyType.Fixed : RigidBodyType.Dynamic,\n\t\t\t\ttrue,\n\t\t\t);\n\t}\n\n\tsetGravityScale(renderable: Renderable, scale: number): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\t// Rapier's own method, not the portable helper spliced over it\n\t\t\tthis.rapier.RigidBody.prototype.setGravityScale.call(body, scale, true);\n\t\t}\n\t}\n\n\tsetSensor(renderable: Renderable, isSensor: boolean): void {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) return;\n\t\tthis.overrides.of(renderable).sensor = isSensor;\n\t\tfor (const collider of colliders) {\n\t\t\tcollider.setSensor(isSensor);\n\t\t}\n\t}\n\n\tsetFrictionAir(\n\t\trenderable: Renderable,\n\t\tfriction: number | { x: number; y: number },\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tconst damping = averageOf(friction) ?? 0;\n\t\tbody.setLinearDamping(damping);\n\t\tbody.setAngularDamping(damping);\n\t}\n\n\t/**\n\t * Cap the body's speed on each axis, in pixels per second. A `z` caps\n\t * the depth axis too; left out, that axis has no cap.\n\t * @param renderable - the body's renderable\n\t * @param limit - the cap\n\t */\n\tsetMaxVelocity(renderable: Renderable, limit: Vector3Like): void {\n\t\t// nothing to cap, and nothing to keep, for a renderable with no body\n\t\tif (!this.sim.bodies.has(renderable)) return;\n\t\tthis.motion.limits.set(renderable, {\n\t\t\tx: limit.x,\n\t\t\ty: limit.y,\n\t\t\tz: limit.z,\n\t\t});\n\t}\n\n\tgetMaxVelocity(renderable: Renderable): {\n\t\tx: number;\n\t\ty: number;\n\t\tz: number;\n\t} {\n\t\t// a copy, so changing it does not change the cap; no cap reads as\n\t\t// Infinity\n\t\tconst limit = this.motion.limits.get(renderable);\n\t\treturn {\n\t\t\tx: limit?.x ?? Infinity,\n\t\t\ty: limit?.y ?? Infinity,\n\t\t\tz: limit?.z ?? Infinity,\n\t\t};\n\t}\n\n\tsetCollisionType(renderable: Renderable, type: number): void {\n\t\tthis.setFilter(renderable, type, undefined);\n\t}\n\n\tsetCollisionMask(renderable: Renderable, mask: number): void {\n\t\tthis.setFilter(renderable, undefined, mask);\n\t}\n\n\t// \u2500\u2500 reading bodies, and querying the world \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The body's XY bounds in renderable-local pixels, relative to `pos`: the\n\t * footprint of its colliders as the body is turned now. Exact for a\n\t * box, a sphere and a capsule; for a hull or a triangle mesh, that of its\n\t * bounding box, turned.\n\t * @param renderable - the renderable whose body bounds to read\n\t * @param out - destination `Bounds` (filled in place, also returned)\n\t */\n\tgetBodyAABB(renderable: Renderable, out: Bounds): Bounds | undefined {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (body === undefined || colliders === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (colliders.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst q = body.rotation();\n\t\tconst box = emptyFootprint();\n\t\tfor (const collider of colliders) {\n\t\t\tconst entry = this.sim.colliders.get(collider.handle);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tgrowFootprint(entry, q, box);\n\t\t\t}\n\t\t}\n\t\tout.setMinMax(box[0], box[1], box[2], box[3]);\n\t\treturn out;\n\t}\n\n\t/**\n\t * The body's collision shapes, as given in its `bodyDef`, relative to\n\t * `pos` and before the body turns (the turn is\n\t * {@link Rapier3dAdapter.getRotation}). A shape with `isActive: false`\n\t * is left out.\n\t * @param renderable - the renderable whose body shapes to read\n\t */\n\tgetBodyShapes(renderable: Renderable): readonly BodyShape[] {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) {\n\t\t\treturn [];\n\t\t}\n\t\tlet cached = this.reportedShapes.get(renderable);\n\t\tif (cached === undefined) {\n\t\t\tcached = [];\n\t\t\tfor (const collider of colliders) {\n\t\t\t\tconst entry = this.sim.colliders.get(collider.handle);\n\t\t\t\tif (entry !== undefined) {\n\t\t\t\t\tcached.push(entry.shape);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.reportedShapes.set(renderable, cached);\n\t\t}\n\t\treturn cached;\n\t}\n\n\t/**\n\t * Whether Rapier has put the body to sleep: a dynamic body at rest, left\n\t * out of the step until a contact or a write to it (a velocity, a force,\n\t * an impulse, a position or a rotation, which all wake it) moves it\n\t * again. `false` for a fixed or kinematic body, and for a renderable this\n\t * adapter does not know, including every one once it is destroyed.\n\t * @param renderable - the renderable whose body to read\n\t * @returns `true` while the body sleeps\n\t * @example\n\t * // the shot is over once every block has come to rest\n\t * const settled = blocks.every((b) => adapter.isSleeping(b));\n\t */\n\tisSleeping(renderable: Renderable): boolean {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\t// Rapier reports a fixed or kinematic body at rest as asleep too\n\t\treturn body !== undefined && body.isDynamic() && body.isSleeping();\n\t}\n\n\tisGrounded(renderable: Renderable): boolean {\n\t\treturn queries.isGrounded(this.sim, renderable);\n\t}\n\n\t/**\n\t * The first collider a segment meets, from `from` to `to`, in world\n\t * pixels: the exact shape, not a bounding volume. A shape the ray starts\n\t * inside is skipped, so a body casting from its own centre does not hit\n\t * itself. Sensors are hit like any other body.\n\t * @param from - where the ray starts\n\t * @param to - where it ends\n\t * @returns the hit, or `null`\n\t */\n\traycast3d(from: Vector3d, to: Vector3d): RaycastHit3d | null {\n\t\treturn queries.raycast3d(this.sim, from, to);\n\t}\n\n\t/**\n\t * The renderables whose colliders' boxes overlap a rectangle in XY, at\n\t * any depth: the boxes {@link Rapier3dAdapter.getBodyAABB} reports.\n\t * @param rect - the rectangle, in world pixels\n\t * @returns the renderables, each once\n\t */\n\tqueryAABB(rect: Rect): Renderable[] {\n\t\treturn queries.queryAABB(this.sim, rect);\n\t}\n\n\t/**\n\t * The renderables whose colliders overlap a sphere: their exact shapes.\n\t * @param center - the centre in world pixels, or a {@link Sphere}\n\t * @param [radius] - the radius in pixels, with a centre; none, or less\n\t * than none, is a point\n\t * @returns the renderables, each once\n\t */\n\tquerySphere(center: Vector3d | Sphere, radius?: number): Renderable[] {\n\t\treturn queries.querySphere(this.sim, center, radius);\n\t}\n\n\t// \u2500\u2500 internals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The gravity in meters per second\u00B2, for Rapier.\n\t * @returns the gravity\n\t */\n\tprivate gravityInMeters() {\n\t\tconst { x, y, z } = this.gravity;\n\t\treturn this.sim.units.inMeters(x, y, z);\n\t}\n\n\t/**\n\t * Write a body's place and turn back onto its renderable.\n\t * @param renderable - the renderable\n\t * @param body - its body\n\t */\n\tprivate writePose(renderable: Renderable, body: RAPIER.RigidBody): void {\n\t\twritePose(renderable, body, this.poses.get(renderable), this.sim.units);\n\t}\n\n\t/**\n\t * Make a body's colliders, with the body definition's material and\n\t * filter, a shape's own settings over them, and what was set on the\n\t * whole body at run time over both.\n\t * @param renderable - the body's renderable\n\t * @param body - the body\n\t * @param def - its definition\n\t * @param parts - the colliders to make\n\t * @param colliders - the body's list of colliders, added to\n\t */\n\tprivate createColliders(\n\t\trenderable: Renderable,\n\t\tbody: RAPIER.RigidBody,\n\t\tdef: BodyDefinition,\n\t\tparts: ColliderPart[],\n\t\tcolliders: RAPIER.Collider[],\n\t): void {\n\t\tconst over = this.overrides.get(renderable);\n\t\tconst bodyType =\n\t\t\ttypeof def.collisionType === \"number\" ? def.collisionType : 0x0001;\n\t\tconst bodyMask =\n\t\t\ttypeof def.collisionMask === \"number\"\n\t\t\t\t? def.collisionMask\n\t\t\t\t: collision.types.ALL_OBJECT;\n\t\tfor (const { shape, index, desc, min, max, round } of parts) {\n\t\t\tconst shapeType = (shape as { collisionType?: number }).collisionType;\n\t\t\tconst shapeMask = (shape as { collisionMask?: number }).collisionMask;\n\t\t\tconst trigger = (shape as { isTrigger?: boolean }).isTrigger === true;\n\t\t\tdesc\n\t\t\t\t.setDensity(def.density ?? 1)\n\t\t\t\t.setFriction(def.friction ?? 0.2)\n\t\t\t\t.setRestitution(over?.restitution ?? def.restitution ?? 0)\n\t\t\t\t// a trigger shape is a sensor: it reports contacts and\n\t\t\t\t// contributes nothing to the solver\n\t\t\t\t.setSensor(over?.sensor ?? (def.isSensor === true || trigger))\n\t\t\t\t.setActiveEvents(this.rapier.ActiveEvents.COLLISION_EVENTS);\n\t\t\tconst collider = this.sim.world.createCollider(desc, body);\n\t\t\t// a shape's own collision settings override the body's\n\t\t\tthis.filters.apply(\n\t\t\t\tcollider,\n\t\t\t\tover?.category ??\n\t\t\t\t\t(typeof shapeType === \"number\" ? shapeType : bodyType),\n\t\t\t\tover?.mask ?? (typeof shapeMask === \"number\" ? shapeMask : bodyMask),\n\t\t\t);\n\t\t\tconst entry: ColliderEntry = { renderable, shape, index, min, max };\n\t\t\tif (round !== undefined) {\n\t\t\t\tentry.round = round;\n\t\t\t}\n\t\t\tthis.sim.colliders.set(collider.handle, entry);\n\t\t\tcolliders.push(collider);\n\t\t}\n\t}\n\n\t/**\n\t * Tell the pairs touching colliders that are about to go that their\n\t * contact ended, then forget the colliders.\n\t * @param colliders - the colliders leaving the world\n\t */\n\tprivate forgetColliders(colliders: RAPIER.Collider[]): void {\n\t\tthis.contacts.endContacts(colliders);\n\t\tfor (const collider of colliders) {\n\t\t\tthis.sim.colliders.delete(collider.handle);\n\t\t\tthis.filters.forget(collider.handle);\n\t\t}\n\t}\n\n\t/**\n\t * Change the collision type and/or mask of every collider of a body, and\n\t * keep it for the colliders `updateShape()` makes.\n\t * @param renderable - the body's renderable\n\t * @param category - the new type, or undefined to keep each collider's\n\t * @param mask - the new mask, or undefined to keep each collider's\n\t */\n\tprivate setFilter(\n\t\trenderable: Renderable,\n\t\tcategory: number | undefined,\n\t\tmask: number | undefined,\n\t): void {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) return;\n\t\tconst over = this.overrides.of(renderable);\n\t\tif (category !== undefined) over.category = category;\n\t\tif (mask !== undefined) over.mask = mask;\n\t\tthis.filters.update(colliders, category, mask);\n\t}\n\n\t/**\n\t * What the helpers spliced onto a body act through.\n\t * @returns the context\n\t */\n\tprivate helperContext() {\n\t\treturn {\n\t\t\tadapter: this,\n\t\t\tsim: this.sim,\n\t\t\tmotion: this.motion,\n\t\t\tfilters: this.filters,\n\t\t\toverrides: this.overrides,\n\t\t};\n\t}\n}\n\n/**\n * One damping rate from a `frictionAir`: Rapier damping is one value, so an\n * `{x, y}` is averaged.\n * @param v - the setting\n * @returns the rate, or undefined when none is set\n */\nfunction averageOf(\n\tv: number | { x: number; y: number } | undefined,\n): number | undefined {\n\tif (v === undefined) return undefined;\n\tif (typeof v === \"number\") return v;\n\treturn (v.x + v.y) / 2;\n}\n\n/**\n * Namespace-merged with the {@link Rapier3dAdapter} class to expose\n * adapter-owned types alongside the runtime API.\n */\n// biome-ignore lint/style/useNamingConvention: namespace must match the class it merges with\n// eslint-disable-next-line @typescript-eslint/no-namespace -- intentional class+namespace declaration merge so adapter-owned types (`Rapier3dAdapter.Body`) are reachable alongside the runtime class\nexport namespace Rapier3dAdapter {\n\t/**\n\t * The body handle attached to `renderable.body` under\n\t * {@link Rapier3dAdapter}: the Rapier `RigidBody` (with all its native\n\t * methods: `enableCcd`, `linvel`, `mass`, `sleep`, \u2026) and the portable\n\t * melonJS helpers spliced onto it.\n\t *\n\t * ```ts\n\t * (this.body as Rapier3dAdapter.Body).enableCcd(true);\n\t * ```\n\t */\n\texport type Body = RAPIER.RigidBody & PhysicsBody;\n}\n", "/**\n * The portable `PhysicsBody` helpers, spliced onto a Rapier body so that\n * `renderable.body.setVelocity(x, y, z)` works as on every adapter. The body\n * stays a real `RAPIER.RigidBody`, with all its own methods.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { PhysicsBody, Renderable, Vector2d, Vector3d } from \"melonjs\";\nimport type { CollisionFilters } from \"../colliders/CollisionFilters\";\nimport type { Rapier3dAdapter } from \"../Rapier3dAdapter\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Motion } from \"./Motion\";\nimport type { RuntimeOverrides } from \"./RuntimeOverrides\";\n\n/** what the helpers act through */\nexport interface HelperContext {\n\tadapter: Rapier3dAdapter;\n\tsim: Simulation;\n\tmotion: Motion;\n\tfilters: CollisionFilters;\n\toverrides: RuntimeOverrides;\n}\n\n/**\n * Splice the helpers onto a body.\n * @param ctx - what they act through\n * @param renderable - the body's renderable\n * @param body - the Rapier body\n * @param colliders - its colliders: the live list, which `updateShape()`\n * refills in place\n */\nexport function spliceHelpers(\n\tctx: HelperContext,\n\trenderable: Renderable,\n\tbody: RAPIER.RigidBody,\n\tcolliders: RAPIER.Collider[],\n): void {\n\tconst { adapter, sim, motion, filters, overrides } = ctx;\n\tconst proto = sim.rapier.RigidBody.prototype;\n\tconst helpers: Omit<PhysicsBody, \"collisionType\" | \"collisionMask\"> = {\n\t\tsetVelocity: (x: number, y: number, z?: number) => {\n\t\t\tmotion.setVelocity(body, x, y, z);\n\t\t},\n\t\tgetVelocity: (out?: Vector2d): Vector2d => {\n\t\t\treturn adapter.getVelocity(renderable, out);\n\t\t},\n\t\tgetVelocity3d: (out?: Vector3d): Vector3d => {\n\t\t\treturn adapter.getVelocity3d(renderable, out);\n\t\t},\n\t\tapplyForce: (x: number, y: number, pointX?: number, pointY?: number) => {\n\t\t\tmotion.addForce(\n\t\t\t\tbody,\n\t\t\t\t{ x, y },\n\t\t\t\ttypeof pointX === \"number\" && typeof pointY === \"number\"\n\t\t\t\t\t? { x: pointX, y: pointY }\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t},\n\t\tapplyImpulse: (x: number, y: number, z?: number) => {\n\t\t\t// Rapier's own method, which this helper is spliced over\n\t\t\tproto.applyImpulse.call(body, sim.units.inMeters(x, y, z ?? 0), true);\n\t\t},\n\t\tsetSensor: (isSensor = true) => {\n\t\t\tadapter.setSensor(renderable, isSensor);\n\t\t},\n\t\tsetStatic: (isStatic = true) => {\n\t\t\tadapter.setStatic(renderable, isStatic);\n\t\t},\n\t\tsetCollisionMask: (mask: number) => {\n\t\t\tadapter.setCollisionMask(renderable, mask);\n\t\t},\n\t\tsetCollisionType: (type: number) => {\n\t\t\tadapter.setCollisionType(renderable, type);\n\t\t},\n\t\t/**\n\t\t * Set the body's mass, keeping how it is spread over its shapes: every\n\t\t * collider's density is scaled by the same factor.\n\t\t * @param m - the new mass, in kilograms\n\t\t */\n\t\tsetMass: (m: number) => {\n\t\t\tconst current = body.mass();\n\t\t\tif (current > 0) {\n\t\t\t\tconst k = m / current;\n\t\t\t\tfor (const collider of colliders) {\n\t\t\t\t\tcollider.setDensity(collider.density() * k);\n\t\t\t\t}\n\t\t\t\tbody.recomputeMassPropertiesFromColliders();\n\t\t\t}\n\t\t},\n\t\tsetBounce: (r: number) => {\n\t\t\toverrides.of(renderable).restitution = r;\n\t\t\tfor (const collider of colliders) {\n\t\t\t\tcollider.setRestitution(r);\n\t\t\t}\n\t\t},\n\t\tsetGravityScale: (scale: number) => {\n\t\t\tadapter.setGravityScale(renderable, scale);\n\t\t},\n\t\tsetAngle: (rad: number) => {\n\t\t\tadapter.setAngle(renderable, rad);\n\t\t},\n\t\tgetAngle: () => {\n\t\t\treturn adapter.getAngle(renderable);\n\t\t},\n\t\tsetAngularVelocity: (omega: number) => {\n\t\t\tadapter.setAngularVelocity(renderable, omega);\n\t\t},\n\t\tgetAngularVelocity: () => {\n\t\t\treturn adapter.getAngularVelocity(renderable);\n\t\t},\n\t\tapplyTorque: (torque: number) => {\n\t\t\tadapter.applyTorque(renderable, torque);\n\t\t},\n\t};\n\tObject.assign(body, helpers);\n\n\t// `collisionType` / `collisionMask` read the first collider's values and\n\t// write every collider's, as on the 2D adapters\n\tconst first = () => {\n\t\treturn colliders[0] as RAPIER.Collider | undefined;\n\t};\n\tObject.defineProperties(body, {\n\t\tcollisionType: {\n\t\t\tget: () => {\n\t\t\t\tconst c = first();\n\t\t\t\treturn c ? (filters.get(c.handle)?.category ?? 0) : 0;\n\t\t\t},\n\t\t\tset: (v: number) => {\n\t\t\t\tadapter.setCollisionType(renderable, v);\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t},\n\t\tcollisionMask: {\n\t\t\tget: () => {\n\t\t\t\tconst c = first();\n\t\t\t\treturn c ? (filters.get(c.handle)?.mask ?? 0) : 0;\n\t\t\t},\n\t\t\tset: (v: number) => {\n\t\t\t\tadapter.setCollisionMask(renderable, v);\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t},\n\t});\n}\n", "/**\n * Pixels and meters. melonJS works in pixels; Rapier is tuned for objects\n * about a meter across, so the adapter converts at every boundary.\n */\nimport type { Vector3Like } from \"../types\";\n\n/** A point or a vector in three dimensions, in pixels or meters. */\nexport type XYZ = { x: number; y: number; z: number };\n\n/**\n * The `z` of a vector that may not have one.\n * @param v - the vector\n * @returns its `z`, or `undefined`\n */\nexport function zOf(v: Vector3Like): number | undefined {\n\treturn typeof v.z === \"number\" ? v.z : undefined;\n}\n\n/** The scale between melonJS pixels and Rapier meters. */\nexport class Units {\n\treadonly pixelsPerMeter: number;\n\n\t/**\n\t * @param pixelsPerMeter - how many pixels make a meter\n\t */\n\tconstructor(pixelsPerMeter: number) {\n\t\tthis.pixelsPerMeter = pixelsPerMeter;\n\t}\n\n\t/**\n\t * @param px - a length in pixels\n\t * @returns the same length in meters\n\t */\n\ttoMeters(px: number): number {\n\t\treturn px / this.pixelsPerMeter;\n\t}\n\n\t/**\n\t * @param m - a length in meters\n\t * @returns the same length in pixels\n\t */\n\ttoPixels(m: number): number {\n\t\treturn m * this.pixelsPerMeter;\n\t}\n\n\t/**\n\t * A point or a vector in pixels, in meters.\n\t * @param x - along X, in pixels\n\t * @param y - along Y, in pixels\n\t * @param z - along Z, in pixels\n\t * @returns a new point in meters\n\t */\n\tinMeters(x: number, y: number, z: number): XYZ {\n\t\treturn { x: this.toMeters(x), y: this.toMeters(y), z: this.toMeters(z) };\n\t}\n}\n", "/**\n * Moving bodies in pixels: velocities, forces and torques for the frame, and\n * the speed caps (`maxVelocity`) Rapier has no notion of.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport { type XYZ, zOf } from \"../math/units\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Vector3Like } from \"../types\";\n\nexport class Motion {\n\t/** each body's speed cap, per axis, in pixels per second */\n\treadonly limits = new Map<Renderable, Vector3Like>();\n\tprivate readonly sim: Simulation;\n\t/** bodies with a force or torque to clear once the frame is stepped */\n\tprivate readonly forced = new Set<RAPIER.RigidBody>();\n\n\t/**\n\t * @param sim - the simulation whose bodies it moves\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * Set a body's velocity in pixels per second; a `z` left out keeps the\n\t * depth velocity.\n\t * @param body - the body\n\t * @param x - along X\n\t * @param y - along Y\n\t * @param [z] - along Z\n\t */\n\tsetVelocity(body: RAPIER.RigidBody, x: number, y: number, z?: number): void {\n\t\tconst { units } = this.sim;\n\t\tbody.setLinvel(\n\t\t\t{\n\t\t\t\tx: units.toMeters(x),\n\t\t\t\ty: units.toMeters(y),\n\t\t\t\tz: typeof z === \"number\" ? units.toMeters(z) : body.linvel().z,\n\t\t\t},\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/**\n\t * Add a force for this frame, in pixels: at a world point, it also turns\n\t * the body. A force or a point with no `z` acts in the plane of the body.\n\t * @param body - the body\n\t * @param force - the force\n\t * @param [point] - where it pushes, in world pixels\n\t */\n\taddForce(body: RAPIER.RigidBody, force: Vector3Like, point?: Vector3Like) {\n\t\tconst f = this.sim.units.inMeters(force.x, force.y, zOf(force) ?? 0);\n\t\tif (point) {\n\t\t\tbody.addForceAtPoint(f, this.pointInMeters(body, point), true);\n\t\t} else {\n\t\t\tbody.addForce(f, true);\n\t\t}\n\t\tthis.forced.add(body);\n\t}\n\n\t/**\n\t * Add a torque for this frame: a number about Z, a vector about each axis.\n\t * In Rapier's own unit (N\u00B7m), not scaled.\n\t * @param body - the body\n\t * @param torque - the torque\n\t */\n\taddTorque(body: RAPIER.RigidBody, torque: number | Vector3Like): void {\n\t\tbody.addTorque(\n\t\t\ttypeof torque === \"number\"\n\t\t\t\t? { x: 0, y: 0, z: torque }\n\t\t\t\t: { x: torque.x, y: torque.y, z: torque.z ?? 0 },\n\t\t\ttrue,\n\t\t);\n\t\tthis.forced.add(body);\n\t}\n\n\t/**\n\t * A world point in meters; one with no depth is in the plane of the body.\n\t * @param body - the body it acts on\n\t * @param point - the point in world pixels\n\t * @returns the point in meters\n\t */\n\tpointInMeters(body: RAPIER.RigidBody, point: Vector3Like): XYZ {\n\t\tconst { units } = this.sim;\n\t\tconst z = point.z;\n\t\treturn {\n\t\t\tx: units.toMeters(point.x),\n\t\t\ty: units.toMeters(point.y),\n\t\t\tz: typeof z === \"number\" ? units.toMeters(z) : body.translation().z,\n\t\t};\n\t}\n\n\t/** A force is for one frame, across every sub-step: clear them all. */\n\tclearForces(): void {\n\t\tfor (const body of this.forced) {\n\t\t\tif (body.isValid()) {\n\t\t\t\tbody.resetForces(false);\n\t\t\t\tbody.resetTorques(false);\n\t\t\t}\n\t\t}\n\t\tthis.forced.clear();\n\t}\n\n\t/** Hold every capped body to its cap. */\n\tclampVelocities(): void {\n\t\tconst { units, bodies } = this.sim;\n\t\tfor (const [renderable, limit] of this.limits) {\n\t\t\tconst body = bodies.get(renderable);\n\t\t\tif (!body) continue;\n\t\t\tconst v = body.linvel();\n\t\t\tconst clamp = (value: number, px: number | undefined) => {\n\t\t\t\t// no cap on this axis; one that is not a number caps nothing\n\t\t\t\t// (it would turn the velocity itself into NaN)\n\t\t\t\tif (typeof px !== \"number\" || Number.isNaN(px)) return value;\n\t\t\t\tconst m = units.toMeters(Math.abs(px));\n\t\t\t\treturn Math.max(-m, Math.min(m, value));\n\t\t\t};\n\t\t\tconst vx = clamp(v.x, limit.x);\n\t\t\tconst vy = clamp(v.y, limit.y);\n\t\t\tconst vz = clamp(v.z, limit.z);\n\t\t\tif (vx !== v.x || vy !== v.y || vz !== v.z) {\n\t\t\t\tbody.setLinvel({ x: vx, y: vy, z: vz }, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Forget a body that left the world.\n\t * @param renderable - its renderable\n\t * @param body - the body\n\t */\n\tforget(renderable: Renderable, body: RAPIER.RigidBody): void {\n\t\tthis.forced.delete(body);\n\t\tthis.limits.delete(renderable);\n\t}\n\n\t/** Forget every body. */\n\tclear(): void {\n\t\tthis.forced.clear();\n\t\tthis.limits.clear();\n\t}\n}\n", "/**\n * Writing a body's place and turn back onto its renderable: its position to\n * `pos` / `depth`, its turn onto `currentTransform`, from the transform the\n * renderable had when the body was made.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { type Matrix3d, Mesh, Quaternion, type Renderable } from \"melonjs\";\nimport type { Units } from \"../math/units\";\n\n/**\n * How a renderable draws its `currentTransform`, so the body's turn can be\n * written onto it: `bridge` is the sign of each axis between the space the\n * transform turns in and the engine's (a {@link Mesh} turns in its source's\n * Y-up space), and `base` the transform it had when the body was made.\n */\nexport interface Pose {\n\tbase: Matrix3d;\n\tbridge: [number, number, number];\n}\n\n// the body's turn, carried into the space the renderable turns in\nconst _turn = new Quaternion();\n\n/**\n * A renderable's pose as it stands, to turn from.\n * @param renderable - the renderable a body is made for\n * @returns its pose\n */\nexport function poseOf(renderable: Renderable): Pose {\n\treturn {\n\t\tbase: renderable.currentTransform.clone(),\n\t\tbridge:\n\t\t\trenderable instanceof Mesh\n\t\t\t\t? // a mesh turns in its source's Y-up space (see Mesh)\n\t\t\t\t\t[1, -1, renderable.rightHanded ? -1 : 1]\n\t\t\t\t: [1, 1, 1],\n\t};\n}\n\n/**\n * Write a body's position onto its renderable's `pos` / `depth` and, given a\n * pose, its turn onto its `currentTransform`.\n * @param renderable - the renderable\n * @param body - its body\n * @param pose - its pose, or undefined to write the position only\n * @param units - the scale between pixels and meters\n */\nexport function writePose(\n\trenderable: Renderable,\n\tbody: RAPIER.RigidBody,\n\tpose: Pose | undefined,\n\tunits: Units,\n): void {\n\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: pos is typed non-null but the pool releases it on recycle\n\tif (!renderable.pos) {\n\t\treturn;\n\t}\n\tconst p = body.translation();\n\t// one batched write: the position's change callback (a bounds update)\n\t// runs once, where assigning `pos.x`, `pos.y` and `depth` ran it three\n\t// times\n\trenderable.setPosition(\n\t\tunits.toPixels(p.x),\n\t\tunits.toPixels(p.y),\n\t\tunits.toPixels(p.z),\n\t);\n\trenderable.isDirty = true;\n\tif (pose === undefined) {\n\t\treturn;\n\t}\n\tconst { x, y, z, w } = body.rotation();\n\t// carried into the space the transform turns in: D \u00B7 R \u00B7 D, with the\n\t// bridge D its own inverse. On a quaternion, each axis part takes its\n\t// axis's sign, and the sign of det(D) when D mirrors the space\n\tconst [d0, d1, d2] = pose.bridge;\n\tconst det = d0 * d1 * d2;\n\t_turn.set(det * d0 * x, det * d1 * y, det * d2 * z, w);\n\t// currentTransform = R' \u00B7 base\n\trenderable.currentTransform.identity().rotate(_turn).multiply(pose.base);\n\trenderable.isDirty = true;\n}\n", "/**\n * What was set on every collider of a body at run time (`setSensor`,\n * `setCollisionType`, `setCollisionMask`, `setBounce`), so that the colliders\n * `updateShape()` makes get it too.\n */\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderOverrides } from \"../colliders/types\";\n\nexport class RuntimeOverrides extends Map<Renderable, ColliderOverrides> {\n\t/**\n\t * A body's record, to write to.\n\t * @param renderable - the body's renderable\n\t * @returns its record, made when there is none\n\t */\n\tof(renderable: Renderable): ColliderOverrides {\n\t\tlet over = this.get(renderable);\n\t\tif (over === undefined) {\n\t\t\tover = {};\n\t\t\tthis.set(renderable, over);\n\t\t}\n\t\treturn over;\n\t}\n}\n", "/**\n * melonJS collision types and masks on Rapier colliders.\n *\n * Rapier's own collision groups hold 16 bits of membership and 16 of filter,\n * where melonJS types and masks are 32 bits: a collider whose values do not\n * fit is filtered by Rapier's `filterContactPair` / `filterIntersectionPair`\n * hooks instead, on the full 32 bits.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { collision } from \"melonjs\";\n\n/** a collider's melonJS collision type and mask */\nexport interface Filter {\n\tcategory: number;\n\tmask: number;\n}\n\n// what a collider with no type or mask of its own has\nconst DEFAULT_CATEGORY = 0x0001;\n\nexport class CollisionFilters {\n\t/** The hooks Rapier calls for a pair that needs the full 32 bits. */\n\treadonly hooks: RAPIER.PhysicsHooks;\n\tprivate readonly rapier: typeof RAPIER;\n\t/** collider handle -> its type and mask */\n\tprivate readonly filters = new Map<number, Filter>();\n\n\t/**\n\t * @param rapier - the Rapier module\n\t */\n\tconstructor(rapier: typeof RAPIER) {\n\t\tthis.rapier = rapier;\n\t\tconst computeImpulse = rapier.SolverFlags.COMPUTE_IMPULSE;\n\t\tthis.hooks = {\n\t\t\tfilterContactPair: (c1, c2) => {\n\t\t\t\treturn this.passes(c1, c2) ? computeImpulse : null;\n\t\t\t},\n\t\t\tfilterIntersectionPair: (c1, c2) => {\n\t\t\t\treturn this.passes(c1, c2);\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * A collider's type and mask.\n\t * @param handle - the collider handle\n\t * @returns its filter, if it has one\n\t */\n\tget(handle: number): Filter | undefined {\n\t\treturn this.filters.get(handle);\n\t}\n\n\t/**\n\t * Give a collider its melonJS collision type and mask.\n\t * @param collider - the collider to configure\n\t * @param category - its collision type\n\t * @param mask - the collision types it collides with\n\t */\n\tapply(collider: RAPIER.Collider, category: number, mask: number): void {\n\t\tthis.filters.set(collider.handle, { category, mask });\n\t\tconst { ActiveHooks } = this.rapier;\n\t\tconst needsHooks =\n\t\t\tcategory >>> 16 !== 0 || (mask >>> 16 !== 0 && (mask & 0xffff) === 0);\n\t\tif (needsHooks) {\n\t\t\tcollider.setCollisionGroups(0xffffffff);\n\t\t\tcollider.setActiveHooks(\n\t\t\t\tActiveHooks.FILTER_CONTACT_PAIRS |\n\t\t\t\t\tActiveHooks.FILTER_INTERSECTION_PAIRS,\n\t\t\t);\n\t\t} else {\n\t\t\tcollider.setCollisionGroups(\n\t\t\t\t(((category & 0xffff) << 16) | (mask & 0xffff)) >>> 0,\n\t\t\t);\n\t\t\tcollider.setActiveHooks(ActiveHooks.NONE);\n\t\t}\n\t}\n\n\t/**\n\t * Change the type and/or the mask of several colliders.\n\t * @param colliders - the colliders\n\t * @param category - the new type, or undefined to keep each collider's\n\t * @param mask - the new mask, or undefined to keep each collider's\n\t */\n\tupdate(\n\t\tcolliders: RAPIER.Collider[],\n\t\tcategory: number | undefined,\n\t\tmask: number | undefined,\n\t): void {\n\t\tfor (const collider of colliders) {\n\t\t\tconst current = this.filters.get(collider.handle);\n\t\t\tthis.apply(\n\t\t\t\tcollider,\n\t\t\t\tcategory ?? current?.category ?? DEFAULT_CATEGORY,\n\t\t\t\tmask ?? current?.mask ?? collision.types.ALL_OBJECT,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Forget a collider that left the world.\n\t * @param handle - its handle\n\t */\n\tforget(handle: number): void {\n\t\tthis.filters.delete(handle);\n\t}\n\n\t/** Forget every collider. */\n\tclear(): void {\n\t\tthis.filters.clear();\n\t}\n\n\t/**\n\t * Whether two colliders collide, by their full 32-bit types and masks.\n\t * @param c1 - a collider handle\n\t * @param c2 - the other\n\t * @returns true when each one's mask includes the other's type\n\t */\n\tprivate passes(c1: number, c2: number): boolean {\n\t\tconst f1 = this.filters.get(c1);\n\t\tconst f2 = this.filters.get(c2);\n\t\tif (f1 === undefined || f2 === undefined) {\n\t\t\treturn true;\n\t\t}\n\t\treturn (f1.mask & f2.category) !== 0 && (f2.mask & f1.category) !== 0;\n\t}\n}\n", "/**\n * A collider's footprint in XY, as its body is turned: what `getBodyAABB`\n * reports and `queryAABB` tests against.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { ColliderEntry } from \"./types\";\n\n/** A box in XY: min x, min y, max x, max y. */\nexport type Footprint = [number, number, number, number];\n\n/**\n * An empty footprint, ready to grow.\n * @returns a box that contains nothing\n */\nexport function emptyFootprint(): Footprint {\n\treturn [Infinity, Infinity, -Infinity, -Infinity];\n}\n\n/**\n * Grow a box in XY by a collider's footprint as its body is turned, in\n * pixels, relative to the body's origin.\n * @param entry - the collider's entry\n * @param q - its body's turn\n * @param box - the box to grow\n */\nexport function growFootprint(\n\tentry: ColliderEntry,\n\tq: RAPIER.Rotation,\n\tbox: Footprint,\n): void {\n\tconst { min, max, round } = entry;\n\t// a sphere or a capsule: the two ends of its segment, turned with the\n\t// body, a radius wider. Any other: the eight corners of its box, turned\n\t// with the body\n\tconst r = round?.r ?? 0;\n\tconst { x, y, z, w } = q;\n\t// the X and Y rows of the turn's matrix, once for every corner: a\n\t// footprint is in XY, so the turned point's z is never needed. Written\n\t// out rather than through `Quaternion#apply` on a shared vector, which\n\t// measured slower: a query runs this for every corner of every collider\n\tconst r00 = 1 - 2 * (y * y + z * z);\n\tconst r01 = 2 * (x * y - w * z);\n\tconst r02 = 2 * (x * z + w * y);\n\tconst r10 = 2 * (x * y + w * z);\n\tconst r11 = 1 - 2 * (x * x + z * z);\n\tconst r12 = 2 * (y * z - w * x);\n\tfor (let i = 0; i < (round ? 2 : 8); i++) {\n\t\tlet px: number;\n\t\tlet py: number;\n\t\tlet pz: number;\n\t\tif (round) {\n\t\t\tconst end = i === 0 ? round.a : round.b;\n\t\t\tpx = end.x;\n\t\t\tpy = end.y;\n\t\t\tpz = end.z;\n\t\t} else {\n\t\t\tpx = i & 1 ? max.x : min.x;\n\t\t\tpy = i & 2 ? max.y : min.y;\n\t\t\tpz = i & 4 ? max.z : min.z;\n\t\t}\n\t\tconst tx = r00 * px + r01 * py + r02 * pz;\n\t\tconst ty = r10 * px + r11 * py + r12 * pz;\n\t\tif (tx - r < box[0]) box[0] = tx - r;\n\t\tif (ty - r < box[1]) box[1] = ty - r;\n\t\tif (tx + r > box[2]) box[2] = tx + r;\n\t\tif (ty + r > box[3]) box[3] = ty + r;\n\t}\n}\n", "/**\n * The Rapier colliders melonJS's 3D shapes become.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype BodyShape,\n\tBox3d,\n\tCapsule3d,\n\tConvexHull3d,\n\tSphere,\n\tTriangleMesh3d,\n} from \"melonjs\";\nimport type { Units, XYZ } from \"../math/units\";\nimport type { ColliderPart } from \"./types\";\n\n/**\n * The message for a shape this adapter cannot build a collider from.\n * @param shape - the shape that was refused\n * @returns the message to throw\n */\nfunction unsupportedShapeMessage(shape: BodyShape): string {\n\t// `type` rather than `constructor.name`: the class name is mangled by a\n\t// minifier and this string is most useful in a production build.\n\tconst name =\n\t\t(shape as { type?: string }).type ??\n\t\t(shape as { constructor: { name: string } }).constructor.name;\n\treturn `Rapier3dAdapter: unsupported shape type ${name}. A 3D world needs a shape with depth: this adapter builds colliders from Box3d, Sphere, Capsule3d, ConvexHull3d and TriangleMesh3d. A Rect becomes a Box3d of the same footprint, an Ellipse a Sphere.`;\n}\n\n/**\n * The colliders a list of shapes becomes, not yet in the world. A shape with\n * `isActive: false` makes none.\n * @param rapier - the Rapier module\n * @param units - the scale between pixels and meters\n * @param shapes - the shapes of a body definition\n * @returns one part per active shape\n * @throws {Error} for a shape this adapter cannot build\n */\nexport function buildColliderParts(\n\trapier: typeof RAPIER,\n\tunits: Units,\n\tshapes: BodyShape[],\n): ColliderPart[] {\n\tconst parts: ColliderPart[] = [];\n\tfor (const [index, shape] of shapes.entries()) {\n\t\t// `isActive === false` keeps a shape out of the simulation\n\t\tif ((shape as { isActive?: boolean }).isActive === false) {\n\t\t\tcontinue;\n\t\t}\n\t\tparts.push({ shape, index, ...shapeToCollider(rapier, units, shape) });\n\t}\n\treturn parts;\n}\n\n/**\n * The Rapier collider a melonJS 3D shape becomes, with its box in body space,\n * in pixels.\n * @param rapier - the Rapier module\n * @param units - the scale between pixels and meters\n * @param shape - the shape\n * @returns its collider description and box\n * @throws {Error} for a 2D shape, or anything else this adapter cannot build\n */\nfunction shapeToCollider(\n\trapier: typeof RAPIER,\n\tunits: Units,\n\tshape: BodyShape,\n): Omit<ColliderPart, \"shape\" | \"index\"> {\n\tconst { ColliderDesc } = rapier;\n\tconst m = (px: number) => {\n\t\treturn units.toMeters(px);\n\t};\n\t// the box around a centre, by its half sizes, in pixels\n\tconst box = (c: XYZ, hx: number, hy: number, hz: number) => {\n\t\treturn {\n\t\t\tmin: { x: c.x - hx, y: c.y - hy, z: c.z - hz },\n\t\t\tmax: { x: c.x + hx, y: c.y + hy, z: c.z + hz },\n\t\t};\n\t};\n\t// a collider placed at a centre given in pixels\n\tconst at = (desc: RAPIER.ColliderDesc, c: XYZ) => {\n\t\treturn desc.setTranslation(m(c.x), m(c.y), m(c.z));\n\t};\n\n\tif (shape instanceof Box3d) {\n\t\tconst h = shape.halfExtents;\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.cuboid(m(h.x), m(h.y), m(h.z)), shape.pos),\n\t\t\t...box(shape.pos, h.x, h.y, h.z),\n\t\t};\n\t}\n\n\tif (shape instanceof Sphere) {\n\t\tconst r = shape.radius;\n\t\tconst { x, y, z } = shape.pos;\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.ball(m(r)), shape.pos),\n\t\t\t...box(shape.pos, r, r, r),\n\t\t\tround: { a: { x, y, z }, b: { x, y, z }, r },\n\t\t};\n\t}\n\n\tif (shape instanceof Capsule3d) {\n\t\tconst r = shape.radius;\n\t\tconst half = shape.halfSegment;\n\t\tconst { x, y, z } = shape.pos;\n\t\t// along Y, as Rapier's own capsule\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.capsule(m(half), m(r)), shape.pos),\n\t\t\t...box(shape.pos, r, half + r, r),\n\t\t\tround: { a: { x, y: y - half, z }, b: { x, y: y + half, z }, r },\n\t\t};\n\t}\n\n\tif (shape instanceof TriangleMesh3d || shape instanceof ConvexHull3d) {\n\t\tconst source =\n\t\t\tshape instanceof TriangleMesh3d ? shape.vertices : shape.points;\n\t\tconst meters = new Float32Array(source.length);\n\t\tconst { x: ox, y: oy, z: oz } = shape.pos;\n\t\tfor (let i = 0; i < source.length; i += 3) {\n\t\t\tmeters[i] = m(source[i] + ox);\n\t\t\tmeters[i + 1] = m(source[i + 1] + oy);\n\t\t\tmeters[i + 2] = m(source[i + 2] + oz);\n\t\t}\n\t\tconst b = shape.getBounds3d();\n\t\tconst bounds = {\n\t\t\tmin: { x: b.min.x, y: b.min.y, z: b.min.z },\n\t\t\tmax: { x: b.max.x, y: b.max.y, z: b.max.z },\n\t\t};\n\t\tif (shape instanceof TriangleMesh3d) {\n\t\t\treturn { desc: ColliderDesc.trimesh(meters, shape.indices), ...bounds };\n\t\t}\n\t\tconst hull = ColliderDesc.convexHull(meters);\n\t\tif (hull !== null) {\n\t\t\treturn { desc: hull, ...bounds };\n\t\t}\n\t\t// points all in one plane have no hull: their bounding box\n\t\tconst c = {\n\t\t\tx: (bounds.min.x + bounds.max.x) / 2,\n\t\t\ty: (bounds.min.y + bounds.max.y) / 2,\n\t\t\tz: (bounds.min.z + bounds.max.z) / 2,\n\t\t};\n\t\tconst half = (lo: number, hi: number) => {\n\t\t\treturn Math.max((hi - lo) / 2, 0.5);\n\t\t};\n\t\tconst hx = half(bounds.min.x, bounds.max.x);\n\t\tconst hy = half(bounds.min.y, bounds.max.y);\n\t\tconst hz = half(bounds.min.z, bounds.max.z);\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.cuboid(m(hx), m(hy), m(hz)), c),\n\t\t\t...box(c, hx, hy, hz),\n\t\t};\n\t}\n\n\t// refused loudly rather than skipped, as on the other adapters\n\tthrow new Error(unsupportedShapeMessage(shape));\n}\n", "/**\n * Collision events: Rapier's start and end events, and every pair still\n * touching once a frame, turned into melonJS's collision hooks.\n *\n * On each renderable of a pair it fires the shape-level hook\n * (`onShapeCollisionStart`, `\u2026Active`, `\u2026End`), then the body-level one\n * (`onCollisionStart`, `onCollisionActive` or the legacy `onCollision`,\n * `onCollisionEnd`). A hook may take a body out of the world, even one of the\n * pair it is told about: the bookkeeping here makes sure no one hears of an\n * end before its start, nor of anything once its body is gone.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderEntry } from \"../colliders/types\";\nimport type { Simulation } from \"../Simulation\";\n\ntype Phase = \"start\" | \"active\" | \"end\";\n\n/** Which hooks of a pair a dispatch reaches: one bit per side and level. */\nconst SIDE_A = 1;\nconst SIDE_B = 2;\nconst SHAPE_A = 4;\nconst SHAPE_B = 8;\nconst EVERY_SIDE = SIDE_A | SIDE_B | SHAPE_A | SHAPE_B;\n\n/**\n * A pair whose start or active hooks are running. When one of them takes a\n * body of the pair out, the contact's end is told in the order a hook can\n * rely on: to the side going out at once, while it is whole, and to the other\n * once the hooks are done; and only to a side that heard the start.\n */\ninterface Dispatch {\n\tkey: string;\n\th1: number;\n\th2: number;\n\te1: ColliderEntry;\n\te2: ColliderEntry;\n\t/** the sides that may hear the end: those the start reached */\n\treached: number;\n\t/** the sides already told the end */\n\ttold: number;\n\t/** true once a body of the pair was taken out */\n\tended: boolean;\n}\n\n/**\n * A key for an unordered pair of colliders.\n * @param h1 - one collider handle\n * @param h2 - the other\n * @returns the same key for (h1, h2) and (h2, h1)\n */\nfunction pairKey(h1: number, h2: number): string {\n\treturn h1 < h2 ? `${h1}:${h2}` : `${h2}:${h1}`;\n}\n\nexport class ContactDispatcher {\n\t/** touching pairs, from Rapier's start events until their end */\n\treadonly activePairs = new Map<string, [number, number]>();\n\tprivate readonly sim: Simulation;\n\tprivate eventQueue!: RAPIER.EventQueue;\n\t/** a step's events, collected before any is dispatched */\n\tprivate readonly pendingEvents: number[] = [];\n\t/** the pairs whose start or active hooks are running, innermost last */\n\tprivate readonly dispatching: Dispatch[] = [];\n\n\t/**\n\t * @param sim - the simulation it reports on\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * The queue Rapier writes a step's start and end events to.\n\t * @returns the event queue to pass to `world.step`\n\t */\n\tget queue(): RAPIER.EventQueue {\n\t\treturn this.eventQueue;\n\t}\n\n\t/** Make the event queue, with the Rapier world. */\n\topen(): void {\n\t\tthis.eventQueue = new this.sim.rapier.EventQueue(true);\n\t}\n\n\t/** Free the event queue, and forget every pair. */\n\tclose(): void {\n\t\tthis.eventQueue.free();\n\t\tthis.activePairs.clear();\n\t\tthis.pendingEvents.length = 0;\n\t\tthis.dispatching.length = 0;\n\t}\n\n\t/**\n\t * Dispatch the start and end events Rapier queued during the last step.\n\t * They are all read before any is dispatched, so a handler that removes a\n\t * body cannot disturb the queue.\n\t */\n\tdispatchQueuedEvents(): void {\n\t\tconst events = this.pendingEvents;\n\t\tevents.length = 0;\n\t\tthis.eventQueue.drainCollisionEvents((h1, h2, started) => {\n\t\t\tevents.push(h1, h2, started ? 1 : 0);\n\t\t});\n\t\tfor (let i = 0; i < events.length; i += 3) {\n\t\t\tconst h1 = events[i];\n\t\t\tconst h2 = events[i + 1];\n\t\t\tconst key = pairKey(h1, h2);\n\t\t\tif (events[i + 2] === 1) {\n\t\t\t\t// a hook earlier in this step may have taken one of them out\n\t\t\t\tif (this.sim.colliders.has(h1) && this.sim.colliders.has(h2)) {\n\t\t\t\t\tthis.activePairs.set(key, [h1, h2]);\n\t\t\t\t\tthis.dispatchPair(h1, h2, \"start\");\n\t\t\t\t}\n\t\t\t} else if (this.activePairs.delete(key)) {\n\t\t\t\t// a pair already ended (one of its bodies was removed) is not\n\t\t\t\t// ended twice\n\t\t\t\tthis.dispatchPair(h1, h2, \"end\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Once per frame: the active hooks of every pair still touching. */\n\tdispatchActiveContacts(): void {\n\t\tfor (const [h1, h2] of this.activePairs.values()) {\n\t\t\tthis.dispatchPair(h1, h2, \"active\");\n\t\t}\n\t}\n\n\t/**\n\t * Tell the pairs touching colliders that are about to go that their\n\t * contact ended. The colliders must still be known: forget them after.\n\t * @param colliders - the colliders leaving the world\n\t */\n\tendContacts(colliders: RAPIER.Collider[]): void {\n\t\tconst handles = new Set(\n\t\t\tcolliders.map((c) => {\n\t\t\t\treturn c.handle;\n\t\t\t}),\n\t\t);\n\t\t// a pair whose start or active hooks are running: the side going out\n\t\t// hears the end now, the other once those hooks are done, so that no\n\t\t// one hears of an end before its start\n\t\tfor (const d of this.dispatching) {\n\t\t\tconst going =\n\t\t\t\t(handles.has(d.h1) ? SIDE_A | SHAPE_A : 0) |\n\t\t\t\t(handles.has(d.h2) ? SIDE_B | SHAPE_B : 0);\n\t\t\tif (going !== 0 && (this.activePairs.delete(d.key) || d.ended)) {\n\t\t\t\td.ended = true;\n\t\t\t\tconst sides = going & d.reached & ~d.told;\n\t\t\t\td.told |= sides;\n\t\t\t\tthis.dispatch(d.e1, d.e2, d.h1, d.h2, \"end\", sides);\n\t\t\t}\n\t\t}\n\t\tfor (const [key, [h1, h2]] of this.activePairs) {\n\t\t\tif (handles.has(h1) || handles.has(h2)) {\n\t\t\t\tthis.activePairs.delete(key);\n\t\t\t\tthis.dispatchPair(h1, h2, \"end\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Fire the hooks of one pair of colliders, on both renderables. A start or\n\t * active hook may take a body of the pair out: see {@link Dispatch}.\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @param phase - which lifecycle hook to fire\n\t */\n\tprivate dispatchPair(h1: number, h2: number, phase: Phase): void {\n\t\tconst e1 = this.sim.colliders.get(h1);\n\t\tconst e2 = this.sim.colliders.get(h2);\n\t\tif (e1 === undefined || e2 === undefined) return;\n\t\tif (phase === \"end\") {\n\t\t\tthis.dispatch(e1, e2, h1, h2, phase, EVERY_SIDE);\n\t\t\treturn;\n\t\t}\n\t\tconst current: Dispatch = {\n\t\t\tkey: pairKey(h1, h2),\n\t\t\th1,\n\t\t\th2,\n\t\t\te1,\n\t\t\te2,\n\t\t\t// a pair already active had its start on every side\n\t\t\treached: phase === \"start\" ? 0 : EVERY_SIDE,\n\t\t\ttold: 0,\n\t\t\tended: false,\n\t\t};\n\t\tthis.dispatching.push(current);\n\t\ttry {\n\t\t\tthis.dispatch(\n\t\t\t\te1,\n\t\t\t\te2,\n\t\t\t\th1,\n\t\t\t\th2,\n\t\t\t\tphase,\n\t\t\t\tEVERY_SIDE,\n\t\t\t\tphase === \"start\" ? current : undefined,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.dispatching.splice(this.dispatching.indexOf(current), 1);\n\t\t}\n\t\tif (current.ended) {\n\t\t\tthis.dispatch(e1, e2, h1, h2, \"end\", current.reached & ~current.told);\n\t\t}\n\t}\n\n\t/**\n\t * Fire one phase of a pair's hooks: the shape-level ones, then the\n\t * renderables' own. A renderable whose body is gone hears nothing.\n\t * @param e1 - the first collider's entry\n\t * @param e2 - the second collider's entry\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @param phase - which lifecycle hook to fire\n\t * @param sides - the sides and levels to fire it on, as bits\n\t * @param [record] - where to note each side reached, before its hook runs\n\t */\n\tprivate dispatch(\n\t\te1: ColliderEntry,\n\t\te2: ColliderEntry,\n\t\th1: number,\n\t\th2: number,\n\t\tphase: Phase,\n\t\tsides: number,\n\t\trecord?: Dispatch,\n\t): void {\n\t\tconst rA = e1.renderable;\n\t\tconst rB = e2.renderable;\n\t\t// skip start/active when either side has left the world; an end still\n\t\t// reaches the side that remains\n\t\tconst ancA = (rA as Renderable & { ancestor?: object | null }).ancestor;\n\t\tconst ancB = (rB as Renderable & { ancestor?: object | null }).ancestor;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: ancestor is set to null by Container on removeChild\n\t\tconst aDetached = ancA === null;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: ancestor is set to null by Container on removeChild\n\t\tconst bDetached = ancB === null;\n\t\tif (phase === \"end\") {\n\t\t\tif (aDetached && bDetached) return;\n\t\t} else if (aDetached || bDetached) {\n\t\t\treturn;\n\t\t}\n\t\t// a hook earlier in this dispatch may have removed a body: its\n\t\t// renderable hears nothing from then on\n\t\tconst reaches = (side: number, receiver: Renderable, detached: boolean) => {\n\t\t\tif ((sides & side) === 0 || detached || !this.sim.bodies.has(receiver)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (record !== undefined) {\n\t\t\t\trecord.reached |= side;\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\t// a separated pair has no contact: identity only\n\t\tconst { nx, ny, nz, depth } =\n\t\t\tphase === \"end\"\n\t\t\t\t? { nx: 0, ny: 0, nz: 0, depth: 0 }\n\t\t\t\t: this.contact(h1, h2);\n\n\t\t// each melonJS shape is one collider, so Rapier's events name the\n\t\t// shapes: the shape-level hooks first\n\t\tconst shapeMethod =\n\t\t\tphase === \"start\"\n\t\t\t\t? \"onShapeCollisionStart\"\n\t\t\t\t: phase === \"end\"\n\t\t\t\t\t? \"onShapeCollisionEnd\"\n\t\t\t\t\t: \"onShapeCollisionActive\";\n\t\tconst isTrigger =\n\t\t\t(e1.shape as { isTrigger?: boolean }).isTrigger === true ||\n\t\t\t(e2.shape as { isTrigger?: boolean }).isTrigger === true;\n\t\tconst emitShape = (\n\t\t\town: ColliderEntry,\n\t\t\tother: ColliderEntry,\n\t\t\tsign: number,\n\t\t): void => {\n\t\t\tconst receiver = own.renderable;\n\t\t\tconst fn = (receiver as Renderable & Record<string, unknown>)[\n\t\t\t\tshapeMethod\n\t\t\t];\n\t\t\tif (typeof fn !== \"function\") return;\n\t\t\t// (`+ 0` keeps a zero normal from reading as -0)\n\t\t\tconst ownNx = sign * nx + 0;\n\t\t\tconst ownNy = sign * ny + 0;\n\t\t\tconst ownNz = sign * nz + 0;\n\t\t\t(fn as (contact: unknown, other: Renderable) => unknown).call(\n\t\t\t\treceiver,\n\t\t\t\t{\n\t\t\t\t\ta: receiver,\n\t\t\t\t\tb: other.renderable,\n\t\t\t\t\tshapeA: own.shape,\n\t\t\t\t\tshapeB: other.shape,\n\t\t\t\t\tindexShapeA: own.index,\n\t\t\t\t\tindexShapeB: other.index,\n\t\t\t\t\tisTrigger,\n\t\t\t\t\tdepth,\n\t\t\t\t\toverlap: depth,\n\t\t\t\t\tnormal: { x: ownNx, y: ownNy },\n\t\t\t\t\tnormalZ: ownNz,\n\t\t\t\t\t// the SAT fields, in the builtin's convention\n\t\t\t\t\toverlapN: { x: -ownNx + 0, y: -ownNy + 0 },\n\t\t\t\t\toverlapNZ: -ownNz + 0,\n\t\t\t\t\toverlapV: { x: -ownNx * depth + 0, y: -ownNy * depth + 0 },\n\t\t\t\t\toverlapZ: -ownNz * depth + 0,\n\t\t\t\t},\n\t\t\t\tother.renderable,\n\t\t\t);\n\t\t};\n\t\t// the normal points from A to B: A escapes along its opposite, B\n\t\t// along it\n\t\tif (reaches(SHAPE_A, rA, aDetached)) {\n\t\t\temitShape(e1, e2, -1);\n\t\t}\n\t\tif (reaches(SHAPE_B, rB, bDetached)) {\n\t\t\temitShape(e2, e1, 1);\n\t\t}\n\n\t\t// then the renderables' own hooks\n\t\tconst bodyMethod = (receiver: Renderable): string => {\n\t\t\tif (phase === \"start\") return \"onCollisionStart\";\n\t\t\tif (phase === \"end\") return \"onCollisionEnd\";\n\t\t\treturn typeof (receiver as Renderable & { onCollisionActive?: unknown })\n\t\t\t\t.onCollisionActive === \"function\"\n\t\t\t\t? \"onCollisionActive\"\n\t\t\t\t: \"onCollision\";\n\t\t};\n\t\tconst pair = { collider1: h1, collider2: h2 };\n\t\tconst emit = (receiver: Renderable, other: Renderable, sign: number) => {\n\t\t\tconst fn = (receiver as Renderable & Record<string, unknown>)[\n\t\t\t\tbodyMethod(receiver)\n\t\t\t];\n\t\t\tif (typeof fn !== \"function\") return;\n\t\t\t(fn as (response: unknown, other: Renderable) => unknown).call(\n\t\t\t\treceiver,\n\t\t\t\t{\n\t\t\t\t\ta: receiver,\n\t\t\t\t\tb: other,\n\t\t\t\t\tnormal: { x: sign * nx + 0, y: sign * ny + 0, z: sign * nz + 0 },\n\t\t\t\t\tdepth,\n\t\t\t\t\tpair,\n\t\t\t\t},\n\t\t\t\tother,\n\t\t\t);\n\t\t};\n\t\tif (reaches(SIDE_A, rA, aDetached)) {\n\t\t\temit(rA, rB, -1);\n\t\t}\n\t\tif (reaches(SIDE_B, rB, bDetached)) {\n\t\t\temit(rB, rA, 1);\n\t\t}\n\t}\n\n\t/**\n\t * The contact between two colliders: the normal from the first to the\n\t * second, and how deep they overlap, in pixels. Zero for a sensor pair,\n\t * which Rapier computes no contact for.\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @returns the normal and the depth\n\t */\n\tprivate contact(\n\t\th1: number,\n\t\th2: number,\n\t): { nx: number; ny: number; nz: number; depth: number } {\n\t\tconst { world, units } = this.sim;\n\t\tconst c1 = world.getCollider(h1);\n\t\tconst c2 = world.getCollider(h2);\n\t\tlet nx = 0;\n\t\tlet ny = 0;\n\t\tlet nz = 0;\n\t\tlet depth = 0;\n\t\tif (c1.isSensor() || c2.isSensor()) {\n\t\t\treturn { nx, ny, nz, depth };\n\t\t}\n\t\tworld.contactPair(c1, c2, (manifold, flipped) => {\n\t\t\tconst count = manifold.numContacts();\n\t\t\tif (count === 0) return;\n\t\t\tconst n = manifold.normal();\n\t\t\tlet deepest = 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tconst d = -manifold.contactDist(i);\n\t\t\t\tif (d > deepest) deepest = d;\n\t\t\t}\n\t\t\tif (deepest >= depth) {\n\t\t\t\tdepth = deepest;\n\t\t\t\tconst s = flipped ? -1 : 1;\n\t\t\t\tnx = s * n.x;\n\t\t\t\tny = s * n.y;\n\t\t\t\tnz = s * n.z;\n\t\t\t}\n\t\t});\n\t\treturn { nx, ny, nz, depth: units.toPixels(depth) };\n\t}\n}\n", "/**\n * The joints `world.addJoint()` makes between bodies.\n *\n * A `\"hinge\"` is a Rapier revolute joint about `axis` (default Z), a `\"rope\"`\n * a rope joint, a `\"weld\"` a fixed joint and a `\"slider\"` a prismatic joint\n * along `axis` (default X). The bodies are joined as they stand, however each\n * is turned: a weld and a slider keep the turn between them, and a hinge\n * leaves them only the turn about its axis.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { Quaternion, Vector3d } from \"melonjs\";\nimport type { XYZ } from \"../math/units\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Rapier3dJointDefinition, Vector3Like } from \"../types\";\n\nconst NO_TURN = { x: 0, y: 0, z: 0, w: 1 };\n\nexport class Joints {\n\tprivate readonly sim: Simulation;\n\t/** the joints made here that are still alive */\n\tprivate readonly made = new Set<RAPIER.ImpulseJoint>();\n\n\t/**\n\t * @param sim - the simulation whose bodies it joins\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * Make a joint between two bodies. Anchors are in each renderable's own\n\t * space, relative to its `pos`, in pixels, and the axis in `a`'s; a `z`\n\t * left out is `0`.\n\t * @param def - what to join, and how, in pixels and radians\n\t * @returns the Rapier joint\n\t */\n\tadd(def: Rapier3dJointDefinition): RAPIER.ImpulseJoint {\n\t\tconst { bodies, rapier, units, world } = this.sim;\n\t\tconst bodyA = bodies.get(def.a);\n\t\tconst bodyB = bodies.get(def.b);\n\t\tif (bodyA === undefined || bodyB === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: addJoint() needs both renderables to have a body in the world; add them with addChild() first.\",\n\t\t\t);\n\t\t}\n\t\tconst { JointData } = rapier;\n\t\tconst anchorB = this.localAnchor(def.anchorB);\n\t\t// no anchor on `a`: the point of `a` under b's anchor, so nothing moves\n\t\t// when the joint is made; a rope joins the two centres\n\t\tconst anchorA =\n\t\t\tdef.anchorA === undefined && def.type !== \"rope\"\n\t\t\t\t? localPoint(bodyA, worldPoint(bodyB, anchorB))\n\t\t\t\t: this.localAnchor(def.anchorA);\n\t\t// the defaults resolved here are written back, so the same joint is\n\t\t// made again when the world rebuilds it\n\t\tdef.anchorA ??= {\n\t\t\tx: units.toPixels(anchorA.x),\n\t\t\ty: units.toPixels(anchorA.y),\n\t\t\tz: units.toPixels(anchorA.z),\n\t\t};\n\t\tdef.anchorB ??= { x: 0, y: 0, z: 0 };\n\t\t// the turn that brings b's space onto a's, as the two stand\n\t\tconst aInB = turnOf(bodyB).invert().multiply(turnOf(bodyA));\n\n\t\tlet data: RAPIER.JointData;\n\t\tswitch (def.type) {\n\t\t\tcase \"hinge\": {\n\t\t\t\t// the same axis in the world, in each body's own space: the same\n\t\t\t\t// vector in both when they are turned alike, or apart about the\n\t\t\t\t// axis only, as a 2D hinge is\n\t\t\t\tconst axis = unitAxis(def.axis, { x: 0, y: 0, z: 1 });\n\t\t\t\tdata = JointData.revoluteWithAxes(\n\t\t\t\t\tanchorA,\n\t\t\t\t\tanchorB,\n\t\t\t\t\taxis,\n\t\t\t\t\taInB.apply(new Vector3d(axis.x, axis.y, axis.z)),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"rope\": {\n\t\t\t\tif (def.maxLength === undefined) {\n\t\t\t\t\tconst pa = worldPoint(bodyA, anchorA);\n\t\t\t\t\tconst pb = worldPoint(bodyB, anchorB);\n\t\t\t\t\tdef.maxLength = units.toPixels(\n\t\t\t\t\t\tMath.hypot(pb.x - pa.x, pb.y - pa.y, pb.z - pa.z),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdata = JointData.rope(units.toMeters(def.maxLength), anchorA, anchorB);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"weld\":\n\t\t\t\t// welded as they stand: A's frame is A, B's frame is the turn\n\t\t\t\t// that brings B onto A\n\t\t\t\tdata = JointData.fixed(anchorA, NO_TURN, anchorB, aInB);\n\t\t\t\tbreak;\n\t\t\tcase \"slider\":\n\t\t\t\tdata = JointData.prismatic(\n\t\t\t\t\tanchorA,\n\t\t\t\t\tanchorB,\n\t\t\t\t\tunitAxis(def.axis, { x: 1, y: 0, z: 0 }),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@melonjs/rapier3d-adapter: unknown joint type \"${String((def as { type: unknown }).type)}\"; use \"hinge\", \"rope\", \"weld\" or \"slider\".`,\n\t\t\t\t);\n\t\t}\n\n\t\tconst joint = world.createImpulseJoint(data, bodyA, bodyB, true);\n\t\tif (def.type === \"slider\") {\n\t\t\t// Rapier gives both bodies the same frame, which would turn b onto\n\t\t\t// a: b's frame is a's as b sees it, so b keeps its turn\n\t\t\tconst frame = joint.frameX1();\n\t\t\tjoint.setFrameX2(\n\t\t\t\taInB\n\t\t\t\t\t.clone()\n\t\t\t\t\t.multiply(new Quaternion(frame.x, frame.y, frame.z, frame.w)),\n\t\t\t);\n\t\t}\n\t\tjoint.setContactsEnabled(def.collideConnected === true);\n\t\tif (\n\t\t\tdef.limits !== undefined &&\n\t\t\t(def.type === \"hinge\" || def.type === \"slider\")\n\t\t) {\n\t\t\t// radians for a hinge, meters along the axis for a slider\n\t\t\tconst scale = def.type === \"slider\" ? 1 / units.pixelsPerMeter : 1;\n\t\t\t(joint as RAPIER.UnitImpulseJoint).setLimits(\n\t\t\t\tdef.limits.min * scale,\n\t\t\t\tdef.limits.max * scale,\n\t\t\t);\n\t\t}\n\t\tthis.made.add(joint);\n\t\treturn joint;\n\t}\n\n\t/**\n\t * Remove a joint made here. A joint already gone, with one of its bodies,\n\t * is ignored.\n\t * @param joint - the Rapier joint\n\t */\n\tremove(joint: RAPIER.ImpulseJoint): void {\n\t\tif (this.made.delete(joint) && joint.isValid()) {\n\t\t\tthis.sim.world.removeImpulseJoint(joint, true);\n\t\t}\n\t}\n\n\t/**\n\t * Forget the joints of a body about to be removed: Rapier removes them\n\t * with it.\n\t * @param body - the body\n\t */\n\tforgetJointsOf(body: RAPIER.RigidBody): void {\n\t\tfor (const joint of this.made) {\n\t\t\tif (\n\t\t\t\t!joint.isValid() ||\n\t\t\t\tjoint.body1().handle === body.handle ||\n\t\t\t\tjoint.body2().handle === body.handle\n\t\t\t) {\n\t\t\t\tthis.made.delete(joint);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Forget every joint. */\n\tclear(): void {\n\t\tthis.made.clear();\n\t}\n\n\t/**\n\t * A joint anchor in pixels as a point on its body in meters. No anchor is\n\t * the body's origin, its renderable's `pos`.\n\t * @param anchor - the anchor in pixels, or undefined\n\t * @returns the body-local anchor\n\t */\n\tprivate localAnchor(anchor?: Vector3Like): XYZ {\n\t\tif (anchor === undefined) {\n\t\t\treturn { x: 0, y: 0, z: 0 };\n\t\t}\n\t\treturn this.sim.units.inMeters(anchor.x, anchor.y, anchor.z ?? 0);\n\t}\n}\n\n/**\n * A joint axis as a unit vector, or the default for a missing one.\n * @param axis - the axis given, if any\n * @param fallback - the default\n * @returns a unit vector\n * @throws {Error} for a zero or non-finite axis\n */\nfunction unitAxis(axis: Vector3Like | undefined, fallback: XYZ): XYZ {\n\tif (axis === undefined) {\n\t\treturn fallback;\n\t}\n\tconst z = axis.z ?? 0;\n\tconst length = Math.hypot(axis.x, axis.y, z);\n\tif (!(length > 0) || !Number.isFinite(length)) {\n\t\tthrow new Error(\n\t\t\t\"@melonjs/rapier3d-adapter: a joint axis needs a length; got a zero or non-finite vector.\",\n\t\t);\n\t}\n\treturn { x: axis.x / length, y: axis.y / length, z: z / length };\n}\n\n/**\n * A world point as a point on a body, both in meters.\n * @param body - the body\n * @param world - the point in the world\n * @returns the point on the body\n */\nfunction localPoint(body: RAPIER.RigidBody, world: XYZ): XYZ {\n\tconst t = body.translation();\n\treturn turnOf(body).applyInverse(\n\t\tnew Vector3d(world.x - t.x, world.y - t.y, world.z - t.z),\n\t);\n}\n\n/**\n * A body-local point in world space, both in meters.\n * @param body - the body\n * @param local - the point on the body\n * @returns the point in the world\n */\nfunction worldPoint(body: RAPIER.RigidBody, local: XYZ): XYZ {\n\tconst t = body.translation();\n\tconst p = turnOf(body).apply(new Vector3d(local.x, local.y, local.z));\n\treturn { x: t.x + p.x, y: t.y + p.y, z: t.z + p.z };\n}\n\n/**\n * A body's turn, as a quaternion of its own.\n * @param body - the body\n * @returns a new quaternion\n */\nfunction turnOf(body: RAPIER.RigidBody): Quaternion {\n\tconst q = body.rotation();\n\treturn new Quaternion(q.x, q.y, q.z, q.w);\n}\n", "/**\n * Loading Rapier: its WebAssembly is downloaded and compiled once, and every\n * adapter shares the result.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\n\n/** The Rapier module, once {@link loadRapier} has compiled it. */\nlet rapier: typeof RAPIER | undefined;\n/** The load in progress or done, shared by every caller. */\nlet loading: Promise<void> | undefined;\n\n/**\n * Download and compile Rapier's WebAssembly. Every call returns the same\n * promise; a failed load rejects, and a later call tries again.\n *\n * Rapier is imported with `import()`, so bundlers put it in a chunk of its\n * own, downloaded only when this is called.\n * @returns a promise that resolves once Rapier is ready\n */\nexport function loadRapier(): Promise<void> {\n\tloading ??= import(\"@dimforge/rapier3d-compat\")\n\t\t.then(async (module) => {\n\t\t\t// decode the embedded bytes and compile the WebAssembly\n\t\t\tawait module.init();\n\t\t\trapier = module;\n\t\t})\n\t\t.catch((error: unknown) => {\n\t\t\tloading = undefined;\n\t\t\tthrow error;\n\t\t});\n\treturn loading;\n}\n\n/**\n * The Rapier module, if it has been loaded.\n * @returns the module, or `undefined` before {@link loadRapier} finishes\n */\nexport function loadedRapier(): typeof RAPIER | undefined {\n\treturn rapier;\n}\n", "/**\n * Asking the world what is where: the ray cast, the box and sphere queries,\n * and whether a body stands on something.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype RaycastHit3d,\n\ttype Rect,\n\ttype Renderable,\n\tSphere,\n\tVector3d,\n} from \"melonjs\";\nimport { emptyFootprint, growFootprint } from \"../colliders/footprint\";\nimport type { Simulation } from \"../Simulation\";\n\n/**\n * How far UP a contact normal must point for {@link isGrounded} to count the\n * contact as ground, as on the 2D adapters: the upward component (`-y`, the\n * engine being Y-down) of the unit normal the body is pushed along.\n */\nconst GROUND_NORMAL_Y = 0.1;\n\n/**\n * Half the depth `queryAABB` searches through, in meters: a 2D rectangle\n * query in a 3D world finds what lies over that rectangle at any depth.\n */\nconst QUERY_HALF_DEPTH = 1e7;\n\n/**\n * The first collider a segment meets, from `from` to `to`, in world pixels:\n * the exact shape, not a bounding volume. A shape the ray starts inside is\n * skipped, so a body casting from its own centre does not hit itself.\n * Sensors are hit like any other body.\n * @param sim - the simulation\n * @param from - where the ray starts\n * @param to - where it ends\n * @returns the hit, or `null`\n */\nexport function raycast3d(\n\tsim: Simulation,\n\tfrom: Vector3d,\n\tto: Vector3d,\n): RaycastHit3d | null {\n\t// nothing to hit once the Rapier world is freed\n\tif (!sim.alive) return null;\n\tconst { units, world } = sim;\n\tconst origin = units.inMeters(from.x, from.y, from.z);\n\tconst dir = units.inMeters(to.x - from.x, to.y - from.y, to.z - from.z);\n\tif (dir.x === 0 && dir.y === 0 && dir.z === 0) return null;\n\tconst ray = new sim.rapier.Ray(origin, dir);\n\tconst hit = world.castRayAndGetNormal(\n\t\tray,\n\t\t1,\n\t\ttrue,\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\t(collider) => {\n\t\t\treturn !collider.containsPoint(origin);\n\t\t},\n\t);\n\tif (hit === null) return null;\n\tconst entry = sim.colliders.get(hit.collider.handle);\n\tif (entry === undefined) return null;\n\tconst toi = hit.timeOfImpact;\n\treturn {\n\t\trenderable: entry.renderable,\n\t\tpoint: new Vector3d(\n\t\t\tunits.toPixels(origin.x + dir.x * toi),\n\t\t\tunits.toPixels(origin.y + dir.y * toi),\n\t\t\tunits.toPixels(origin.z + dir.z * toi),\n\t\t),\n\t\tnormal: new Vector3d(hit.normal.x, hit.normal.y, hit.normal.z),\n\t\tfraction: toi,\n\t};\n}\n\n/**\n * The renderables whose colliders' boxes overlap a rectangle in XY, at any\n * depth: the boxes `getBodyAABB` reports.\n * @param sim - the simulation\n * @param rect - the rectangle, in world pixels\n * @returns the renderables, each once\n */\nexport function queryAABB(sim: Simulation, rect: Rect): Renderable[] {\n\tconst { units, world } = sim;\n\tconst { x, y } = rect.pos;\n\treturn collect(sim, (visit) => {\n\t\tworld.collidersWithAabbIntersectingAabb(\n\t\t\t{\n\t\t\t\tx: units.toMeters(x + rect.width / 2),\n\t\t\t\ty: units.toMeters(y + rect.height / 2),\n\t\t\t\tz: 0,\n\t\t\t},\n\t\t\t{\n\t\t\t\tx: units.toMeters(rect.width / 2),\n\t\t\t\ty: units.toMeters(rect.height / 2),\n\t\t\t\tz: QUERY_HALF_DEPTH,\n\t\t\t},\n\t\t\t(collider) => {\n\t\t\t\t// Rapier keeps its own boxes loose, more so around a body that\n\t\t\t\t// moves: those are the candidates, tested here\n\t\t\t\tconst entry = sim.colliders.get(collider.handle);\n\t\t\t\tconst body = collider.parent();\n\t\t\t\tif (entry === undefined || body === null) return true;\n\t\t\t\tconst box = emptyFootprint();\n\t\t\t\tgrowFootprint(entry, body.rotation(), box);\n\t\t\t\tconst t = body.translation();\n\t\t\t\tconst bx = units.toPixels(t.x);\n\t\t\t\tconst by = units.toPixels(t.y);\n\t\t\t\treturn bx + box[0] <= x + rect.width &&\n\t\t\t\t\tbx + box[2] >= x &&\n\t\t\t\t\tby + box[1] <= y + rect.height &&\n\t\t\t\t\tby + box[3] >= y\n\t\t\t\t\t? visit(collider)\n\t\t\t\t\t: true;\n\t\t\t},\n\t\t);\n\t});\n}\n\n/**\n * The renderables whose colliders overlap a sphere: their exact shapes.\n * @param sim - the simulation\n * @param center - the centre in world pixels, or a {@link Sphere}\n * @param [radius] - the radius in pixels, with a centre; none, or less than\n * none, is a point\n * @returns the renderables, each once\n */\nexport function querySphere(\n\tsim: Simulation,\n\tcenter: Vector3d | Sphere,\n\tradius?: number,\n): Renderable[] {\n\tconst { units } = sim;\n\tconst isSphere = center instanceof Sphere;\n\tconst c = isSphere ? center.pos : center;\n\tconst r = isSphere ? center.radius : (radius ?? 0);\n\tconst ball = new sim.rapier.Ball(units.toMeters(Math.max(r, 0)));\n\treturn collect(sim, (visit) => {\n\t\tsim.world.intersectionsWithShape(\n\t\t\tunits.inMeters(c.x, c.y, c.z),\n\t\t\t{ x: 0, y: 0, z: 0, w: 1 },\n\t\t\tball,\n\t\t\tvisit,\n\t\t);\n\t});\n}\n\n/**\n * Whether a body stands on something: a touching contact that pushes it UP,\n * as on the 2D adapters. A sensor pushes nothing, so a sensor contact counts\n * when the other body's centre is below this one's.\n * @param sim - the simulation\n * @param renderable - the body's renderable\n * @returns true while it is grounded\n */\nexport function isGrounded(sim: Simulation, renderable: Renderable): boolean {\n\tconst body = sim.bodies.get(renderable);\n\tif (!body) return false;\n\tconst { world } = sim;\n\tconst bodyY = body.translation().y;\n\tfor (const collider of sim.collidersOf.get(renderable) ?? []) {\n\t\tlet grounded = false;\n\t\tworld.intersectionPairsWith(collider, (other) => {\n\t\t\tconst parent = other.parent();\n\t\t\tif (\n\t\t\t\t!grounded &&\n\t\t\t\tparent !== null &&\n\t\t\t\tworld.intersectionPair(collider, other) &&\n\t\t\t\tparent.translation().y > bodyY\n\t\t\t) {\n\t\t\t\tgrounded = true;\n\t\t\t}\n\t\t});\n\t\tworld.contactPairsWith(collider, (other) => {\n\t\t\tif (grounded) return;\n\t\t\tworld.contactPair(collider, other, (manifold, flipped) => {\n\t\t\t\tif (manifold.numContacts() === 0) return;\n\t\t\t\tconst ny = flipped ? -manifold.normal().y : manifold.normal().y;\n\t\t\t\t// this body is pushed along the opposite of the normal\n\t\t\t\tif (-ny < -GROUND_NORMAL_Y) {\n\t\t\t\t\tgrounded = true;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\tif (grounded) return true;\n\t}\n\treturn false;\n}\n\n/**\n * The renderables a Rapier query visits, each once.\n * @param sim - the simulation\n * @param query - runs the query with the visitor\n * @returns the renderables\n */\nfunction collect(\n\tsim: Simulation,\n\tquery: (visit: (collider: RAPIER.Collider) => boolean) => void,\n): Renderable[] {\n\tconst result: Renderable[] = [];\n\t// nothing to find once the Rapier world is freed\n\tif (!sim.alive) return result;\n\tconst seen = new Set<Renderable>();\n\tquery((collider) => {\n\t\tconst entry = sim.colliders.get(collider.handle);\n\t\tif (entry !== undefined && !seen.has(entry.renderable)) {\n\t\t\tseen.add(entry.renderable);\n\t\t\tresult.push(entry.renderable);\n\t\t}\n\t\treturn true;\n\t});\n\treturn result;\n}\n", "/**\n * What every part of the adapter shares: the Rapier module, the units, the\n * Rapier world, and which body and colliders each renderable has.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderEntry } from \"./colliders/types\";\nimport type { Units } from \"./math/units\";\n\nexport class Simulation {\n\treadonly rapier: typeof RAPIER;\n\treadonly units: Units;\n\t/** The Rapier world: made by {@link open}, freed by {@link close}. */\n\tworld!: RAPIER.World;\n\t/** true between {@link open} and {@link close}: the Rapier world exists */\n\talive = false;\n\n\t/** each renderable's body */\n\treadonly bodies = new Map<Renderable, RAPIER.RigidBody>();\n\t/** each renderable's colliders, one per active shape */\n\treadonly collidersOf = new Map<Renderable, RAPIER.Collider[]>();\n\t/** collider handle -> its renderable, shape and box */\n\treadonly colliders = new Map<number, ColliderEntry>();\n\n\t/**\n\t * @param rapier - the loaded Rapier module\n\t * @param units - the scale between pixels and meters\n\t */\n\tconstructor(rapier: typeof RAPIER, units: Units) {\n\t\tthis.rapier = rapier;\n\t\tthis.units = units;\n\t}\n\n\t/**\n\t * Make the Rapier world.\n\t * @param gravity - its gravity, in meters per second\u00B2\n\t */\n\topen(gravity: RAPIER.Vector) {\n\t\tthis.world = new this.rapier.World(gravity);\n\t\tthis.alive = true;\n\t}\n\n\t/** Free the Rapier world, and forget every body and collider. */\n\tclose() {\n\t\tthis.alive = false;\n\t\t// Rapier's objects live in WebAssembly memory, which the garbage\n\t\t// collector does not reclaim: they are freed here\n\t\tthis.world.free();\n\t\tthis.bodies.clear();\n\t\tthis.collidersOf.clear();\n\t\tthis.colliders.clear();\n\t}\n}\n", "/**\n * The adapter's public types: its options, the joints it makes, and the\n * vectors it takes.\n */\nimport type { Renderable } from \"melonjs\";\n\n/**\n * Minimum melonJS version this adapter requires: the lower bound of its\n * `melonjs` peer dependency range, so the two cannot disagree. 20.16 is the\n * first with the 3D shapes and the 3D adapter interface.\n * @hidden\n */\nexport const REQUIRED_MELONJS_VERSION = \"20.16.0\";\n\n/**\n * A point or a vector in pixels whose `z` may be left out: a\n * {@link Vector3d}, a {@link Vector2d} or a plain object. What a missing `z`\n * means is said where it is taken.\n */\nexport interface Vector3Like {\n\tx: number;\n\ty: number;\n\tz?: number | undefined;\n}\n\n/**\n * What `world.addJoint()` passes to {@link Rapier3dAdapter.addJoint}: melonJS's\n * `JointDefinition`, whose anchors and axis may also carry a `z`.\n */\nexport interface Rapier3dJointDefinition {\n\ttype: \"hinge\" | \"rope\" | \"weld\" | \"slider\";\n\ta: Renderable;\n\tb: Renderable;\n\t/** in `a`'s own space, relative to its `pos`; `z` defaults to `0` */\n\tanchorA?: Vector3Like;\n\t/** in `b`'s own space, relative to its `pos`; `z` defaults to `0` */\n\tanchorB?: Vector3Like;\n\tcollideConnected?: boolean;\n\tlimits?: { min: number; max: number };\n\tmaxLength?: number;\n\t/**\n\t * `\"hinge\"`: the axis the bodies turn about, default Z, so a hinge turns\n\t * as it does in 2D. `\"slider\"`: the direction `b` slides in, default X.\n\t * In `a`'s own space; `z` defaults to `0`.\n\t */\n\taxis?: Vector3Like;\n}\n\n/**\n * Options accepted by the {@link Rapier3dAdapter} constructor and by\n * {@link Rapier3dAdapter.create}.\n */\nexport interface Rapier3dAdapterOptions {\n\t/**\n\t * World gravity in **pixels per second\u00B2**. Default `{x: 0, y: 320, z: 0}`,\n\t * about 10 m/s\u00B2 at the default `pixelsPerMeter` of 32, pulling down: the\n\t * engine's 3D convention is Y-down (see `Camera3d`). Converted to meters\n\t * for Rapier.\n\t */\n\tgravity?: Vector3Like;\n\t/**\n\t * Rapier is tuned for objects about a meter across, so the adapter works\n\t * in meters and converts at every boundary (positions, velocities,\n\t * gravity, forces, queries). Default `32`: a 32-pixel cube is one meter.\n\t * Raising it makes every body smaller in meters, so lighter, and the same\n\t * force moves it further; motion under gravity alone looks the same in\n\t * pixels. Must be a positive number.\n\t */\n\tpixelsPerMeter?: number;\n\t/**\n\t * Rapier steps per engine frame, each of `dt / N` seconds. More sub-steps\n\t * make fast contacts and tall stacks more accurate, at about `N` times\n\t * the physics cost. Default `1`; values below 1 are clamped to 1. A\n\t * force applied once in a frame acts across all of them.\n\t */\n\tsubSteps?: number;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAiBA;AAAA,EAKC,aAAAA;AAAA,EACA,WAAW;AAAA,EAGX,cAAAC;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,OAEM;;;ACNA,SAAS,cACf,KACA,YACA,MACA,WACO;AACP,QAAM,EAAE,SAAS,KAAK,QAAQ,SAAS,UAAU,IAAI;AACrD,QAAM,QAAQ,IAAI,OAAO,UAAU;AACnC,QAAM,UAAgE;AAAA,IACrE,aAAa,CAAC,GAAW,GAAW,MAAe;AAClD,aAAO,YAAY,MAAM,GAAG,GAAG,CAAC;AAAA,IACjC;AAAA,IACA,aAAa,CAAC,QAA6B;AAC1C,aAAO,QAAQ,YAAY,YAAY,GAAG;AAAA,IAC3C;AAAA,IACA,eAAe,CAAC,QAA6B;AAC5C,aAAO,QAAQ,cAAc,YAAY,GAAG;AAAA,IAC7C;AAAA,IACA,YAAY,CAAC,GAAW,GAAW,QAAiB,WAAoB;AACvE,aAAO;AAAA,QACN;AAAA,QACA,EAAE,GAAG,EAAE;AAAA,QACP,OAAO,WAAW,YAAY,OAAO,WAAW,WAC7C,EAAE,GAAG,QAAQ,GAAG,OAAO,IACvB;AAAA,MACJ;AAAA,IACD;AAAA,IACA,cAAc,CAAC,GAAW,GAAW,MAAe;AAEnD,YAAM,a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ACvB,WAAO;AAAA,MACN,SAAS;AAAA,MACT,KAAK,KAAK;AAAA,MACV,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,IACjB;AAAA,EACD;AACD;AAQA,SAAS,UACR,GACqB;AACrB,MAAI,MAAM,OAAW,QAAO;AAC5B,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,UAAQ,EAAE,IAAI,EAAE,KAAK;AACtB;",
|
|
4
|
+
"sourcesContent": ["/**\n * The adapter: the melonJS `PhysicsAdapter` interface on Rapier 3D.\n *\n * It owns the lifecycle (making and freeing the Rapier world, stepping it)\n * and the bodies (making them from a `bodyDef`, removing them), and answers\n * the portable API. The work itself is done by:\n *\n * - `Simulation`: the Rapier world and which body and colliders each\n * renderable has, shared by every part below\n * - `colliders/`: the colliders the 3D shapes become, their collision types\n * and masks, and their footprints\n * - `contacts/`: the collision hooks\n * - `bodies/`: the body's pose on its renderable, its motion, what was set on\n * it at run time, and the helpers on `renderable.body`\n * - `joints/` and `queries/`\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype AdapterCapabilities,\n\ttype BodyDefinition,\n\ttype BodyShape,\n\ttype Bounds,\n\tcollision,\n\tversion as melonjsVersion,\n\ttype PhysicsAdapter,\n\ttype PhysicsBody,\n\tQuaternion,\n\ttype RaycastHit3d,\n\ttype Rect,\n\ttype Renderable,\n\ttype Sphere,\n\tstate,\n\tutils,\n\tVector2d,\n\tVector3d,\n\ttype World,\n} from \"melonjs\";\nimport { spliceHelpers } from \"./bodies/helpers\";\nimport { Motion } from \"./bodies/Motion\";\nimport { type Pose, poseOf, writePose } from \"./bodies/pose\";\nimport { RuntimeOverrides } from \"./bodies/RuntimeOverrides\";\nimport { CollisionFilters } from \"./colliders/CollisionFilters\";\nimport { emptyFootprint, growFootprint } from \"./colliders/footprint\";\nimport { buildColliderParts } from \"./colliders/shapes\";\nimport type { ColliderEntry, ColliderPart } from \"./colliders/types\";\nimport { ContactDispatcher } from \"./contacts/ContactDispatcher\";\nimport { Joints } from \"./joints/Joints\";\nimport { loadedRapier, loadRapier } from \"./loader\";\nimport { Units, zOf } from \"./math/units\";\nimport * as queries from \"./queries/queries\";\nimport { Simulation } from \"./Simulation\";\nimport {\n\ttype Rapier3dAdapterOptions,\n\ttype Rapier3dJointDefinition,\n\tREQUIRED_MELONJS_VERSION,\n\ttype Vector3Like,\n} from \"./types\";\n\n// a body's turn about Z, set by `setAngle`\nconst _turn = new Quaternion();\n\ndeclare const __VERSION__: string;\n\n/**\n * melonJS physics adapter for Rapier 3D (https://rapier.rs), compiled to\n * WebAssembly: rigid bodies that move and turn in three dimensions, for a\n * game drawn with `Camera3d`.\n *\n * Bodies are declared as on every adapter, with a `bodyDef`, from the 3D\n * shapes: {@link Box3d}, {@link Sphere}, {@link Capsule3d},\n * {@link ConvexHull3d} and {@link TriangleMesh3d}. Shapes are in the\n * renderable's space, relative to its `pos` (and `depth`), which is where the\n * body sits; each frame the body's position is written back to `pos` /\n * `depth`, and its turn onto `currentTransform`, so a {@link Mesh}, a\n * `Sprite3d` or a `GLTFModel` tumbles as it is simulated.\n *\n * The adapter takes the 3D form of the portable API: `setVelocity`,\n * `applyForce`, `applyImpulse` and `setPosition` take a {@link Vector3d},\n * and `getVelocity3d`, `getRotation` / `setRotation` and\n * `getAngularVelocity3d` read the rest. The 2D calls still work, in the\n * plane of the body: a `Vector2d` leaves the depth as it was.\n *\n * Rapier's WebAssembly has to be compiled before an adapter can be\n * constructed: {@link Rapier3dAdapter.create} does both.\n * @example\n * import { Application, Camera3d } from \"melonjs\";\n * import { Rapier3dAdapter } from \"@melonjs/rapier3d-adapter\";\n *\n * const app = new Application(800, 600, {\n * parent: \"screen\",\n * cameraClass: Camera3d,\n * physic: await Rapier3dAdapter.create(),\n * });\n * @category Plugins\n * @document ../README.md\n */\nexport class Rapier3dAdapter implements PhysicsAdapter {\n\treadonly physicLabel = \"rapier3d\";\n\treadonly name = \"@melonjs/rapier3d-adapter\";\n\treadonly version = __VERSION__;\n\treadonly url = \"https://www.npmjs.com/package/@melonjs/rapier3d-adapter\";\n\n\treadonly capabilities: AdapterCapabilities = {\n\t\tconstraints: true,\n\t\t// opt-in per body: `(body as Rapier3dAdapter.Body).enableCcd(true)`\n\t\tcontinuousCollisionDetection: true,\n\t\tsleepingBodies: true,\n\t\t// a 3D world is queried with `raycast3d`\n\t\traycasts: false,\n\t\traycasts3d: true,\n\t\tvelocityLimit: true,\n\t\tisGrounded: true,\n\t\tbodies3d: true,\n\t};\n\n\t/**\n\t * World gravity, in pixels per second\u00B2. Change it at any time; read at\n\t * every step.\n\t */\n\tgravity: Vector3d;\n\n\t/**\n\t * The Rapier module: an escape hatch for what the portable\n\t * {@link PhysicsAdapter} interface does not cover (other joints, the\n\t * character controller, native queries). See the README.\n\t * @see {@link https://rapier.rs/docs/user_guides/javascript/getting_started_js Rapier JavaScript user guide}\n\t */\n\treadonly rapier: typeof RAPIER;\n\n\t/** Spatial conversion factor between melonJS pixels and Rapier meters. */\n\treadonly pixelsPerMeter: number;\n\n\t/** Back-reference to the owning melonJS world (set in {@link init}). */\n\tmelonWorld!: World;\n\n\tprivate readonly subSteps: number;\n\tprivate readonly sim: Simulation;\n\tprivate readonly filters: CollisionFilters;\n\tprivate readonly contacts: ContactDispatcher;\n\tprivate readonly motion: Motion;\n\tprivate readonly joints: Joints;\n\t/** what was set on every collider of a body at run time */\n\tprivate readonly overrides = new RuntimeOverrides();\n\t/** each body's definition, which `updateShape()` builds from again */\n\tprivate readonly defs = new Map<Renderable, BodyDefinition>();\n\t/** each renderable's transform when its body was made, and its bridge */\n\tprivate readonly poses = new Map<Renderable, Pose>();\n\t/** the shapes {@link Rapier3dAdapter.getBodyShapes} reports */\n\tprivate readonly reportedShapes = new Map<Renderable, BodyShape[]>();\n\n\t/**\n\t * Download and compile Rapier's WebAssembly. Every call returns the same\n\t * promise, so it can be started early and awaited wherever it is needed;\n\t * a failed load rejects, and a later call tries again.\n\t *\n\t * Rapier is imported with `import()`, so bundlers put it in a chunk of its\n\t * own, downloaded only when this is called.\n\t * @returns a promise that resolves once the adapter can be constructed\n\t * @example\n\t * const rapierReady = Rapier3dAdapter.load();\n\t * await loader.preload(assets);\n\t * await rapierReady;\n\t * app.world.setAdapter(new Rapier3dAdapter());\n\t */\n\tstatic load(): Promise<void> {\n\t\treturn loadRapier();\n\t}\n\n\t/**\n\t * Whether {@link Rapier3dAdapter.load} has finished, so that\n\t * `new Rapier3dAdapter()` can be called.\n\t * @returns true once Rapier is compiled\n\t */\n\tstatic get loaded(): boolean {\n\t\treturn loadedRapier() !== undefined;\n\t}\n\n\t/**\n\t * Create an adapter, the same way for every adapter: wait for\n\t * {@link Rapier3dAdapter.load}, then construct it.\n\t * @param options - the constructor's options\n\t * @returns the new adapter, an instance of the class `create` is called on\n\t */\n\tstatic async create<T extends PhysicsAdapter>(\n\t\tthis: Pick<typeof Rapier3dAdapter, \"load\"> &\n\t\t\t(new (\n\t\t\t\toptions?: Rapier3dAdapterOptions,\n\t\t\t) => T),\n\t\toptions?: Rapier3dAdapterOptions,\n\t): Promise<T> {\n\t\tawait this.load();\n\t\treturn new this(options);\n\t}\n\n\t/**\n\t * Construct an adapter. Rapier must be loaded first: use\n\t * {@link Rapier3dAdapter.create}, or await {@link Rapier3dAdapter.load}.\n\t * @param options - see {@link Rapier3dAdapterOptions}\n\t */\n\tconstructor(options: Rapier3dAdapterOptions = {}) {\n\t\tif (utils.checkVersion(REQUIRED_MELONJS_VERSION, melonjsVersion) > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`@melonjs/rapier3d-adapter requires melonJS >= ${REQUIRED_MELONJS_VERSION}, ` +\n\t\t\t\t\t`but the loaded melonJS is ${melonjsVersion}.`,\n\t\t\t);\n\t\t}\n\t\tconst rapier = loadedRapier();\n\t\tif (rapier === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: Rapier is not loaded yet. Use \" +\n\t\t\t\t\t\"`await Rapier3dAdapter.create(options)`, or `await Rapier3dAdapter.load()` \" +\n\t\t\t\t\t\"before `new Rapier3dAdapter(options)`.\",\n\t\t\t);\n\t\t}\n\t\tthis.rapier = rapier;\n\t\tconst ppm = options.pixelsPerMeter ?? 32;\n\t\tif (!(ppm > 0) || !Number.isFinite(ppm)) {\n\t\t\tthrow new Error(\n\t\t\t\t`@melonjs/rapier3d-adapter: pixelsPerMeter must be a positive number (got ${ppm}).`,\n\t\t\t);\n\t\t}\n\t\tthis.pixelsPerMeter = ppm;\n\t\tthis.subSteps = Math.max(1, Math.floor(options.subSteps ?? 1));\n\t\tconst g = options.gravity ?? { x: 0, y: 320, z: 0 };\n\t\tthis.gravity = new Vector3d(g.x, g.y, g.z ?? 0);\n\n\t\tthis.sim = new Simulation(rapier, new Units(ppm));\n\t\tthis.filters = new CollisionFilters(rapier);\n\t\tthis.contacts = new ContactDispatcher(this.sim);\n\t\tthis.motion = new Motion(this.sim);\n\t\tthis.joints = new Joints(this.sim);\n\t}\n\n\t/** The Rapier world; exposed for advanced use. Made in {@link init}. */\n\tget world(): RAPIER.World {\n\t\treturn this.sim.world;\n\t}\n\n\t// \u2500\u2500 lifecycle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tinit(world: World): void {\n\t\tthis.melonWorld = world;\n\t\tthis.sim.open(this.gravityInMeters());\n\t\tthis.contacts.open();\n\t}\n\n\tdestroy(): void {\n\t\t// nothing to free before `init()`, or a second time\n\t\tif (!this.sim.alive) {\n\t\t\treturn;\n\t\t}\n\t\tthis.contacts.close();\n\t\tthis.sim.close();\n\t\tthis.filters.clear();\n\t\tthis.motion.clear();\n\t\tthis.joints.clear();\n\t\tthis.overrides.clear();\n\t\tthis.defs.clear();\n\t\tthis.poses.clear();\n\t\tthis.reportedShapes.clear();\n\t}\n\n\tstep(dt: number): void {\n\t\tif (!this.sim.alive) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: step() on an adapter with no Rapier world: it was destroyed, or never installed with `world.setAdapter()`.\",\n\t\t\t);\n\t\t}\n\t\t// as the other adapters: no simulation while the game is paused\n\t\tif (state.isPaused()) {\n\t\t\treturn;\n\t\t}\n\t\t// a step of no length simulates nothing, and one that is not a number\n\t\t// would leave every body it touched stuck for good\n\t\tif (!(dt > 0) || !Number.isFinite(dt)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { world } = this.sim;\n\t\t// read every step, so `adapter.gravity` can change while the game runs\n\t\tworld.gravity = this.gravityInMeters();\n\t\t// melonJS passes dt in ms; Rapier wants seconds\n\t\tworld.timestep = dt / 1000 / this.subSteps;\n\t\tfor (let i = 0; i < this.subSteps; i++) {\n\t\t\tworld.step(this.contacts.queue, this.filters.hooks);\n\t\t\tthis.contacts.dispatchQueuedEvents();\n\t\t}\n\t\t// a force is for this frame, across every sub-step\n\t\tthis.motion.clearForces();\n\t\tthis.motion.clampVelocities();\n\t\tthis.contacts.dispatchActiveContacts();\n\t}\n\n\tsyncFromPhysics(): void {\n\t\tfor (const [renderable, body] of this.sim.bodies) {\n\t\t\t// a body at rest, or that never moves, has nothing new to write;\n\t\t\t// `setPosition` / `setRotation` write a moved one themselves\n\t\t\tif (body.isFixed() || body.isSleeping()) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.writePose(renderable, body);\n\t\t}\n\t}\n\n\t// \u2500\u2500 bodies \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\taddBody(renderable: Renderable, def: BodyDefinition): Rapier3dAdapter.Body {\n\t\tconst { rapier, units, world } = this.sim;\n\t\t// build every collider first, so a refused shape leaves no body behind,\n\t\t// nor takes away the one the renderable had\n\t\tconst parts = buildColliderParts(rapier, units, def.shapes);\n\t\t// a renderable has one body: a second one replaces the first\n\t\tthis.removeBody(renderable);\n\t\tconst { RigidBodyDesc } = rapier;\n\t\tconst desc =\n\t\t\tdef.type === \"static\"\n\t\t\t\t? RigidBodyDesc.fixed()\n\t\t\t\t: def.type === \"kinematic\"\n\t\t\t\t\t? // moved by its velocity, as on the other adapters\n\t\t\t\t\t\tRigidBodyDesc.kinematicVelocityBased()\n\t\t\t\t\t: RigidBodyDesc.dynamic();\n\t\t// the body sits where the renderable is: shapes are relative to it\n\t\tdesc.setTranslation(\n\t\t\tunits.toMeters(renderable.pos.x),\n\t\t\tunits.toMeters(renderable.pos.y),\n\t\t\tunits.toMeters(renderable.depth),\n\t\t);\n\t\t// `frictionAir` damps rotation as well as movement, as on the 2D\n\t\t// adapter: Rapier damping, a rate per second\n\t\tconst damping = averageOf(def.frictionAir) ?? 0;\n\t\tdesc.setLinearDamping(damping);\n\t\tdesc.setAngularDamping(damping);\n\t\tdesc.setGravityScale(def.gravityScale ?? 1);\n\t\t// unset means a rigid body turns\n\t\tif (def.fixedRotation === true) {\n\t\t\tdesc.lockRotations();\n\t\t}\n\t\tconst body = world.createRigidBody(desc);\n\t\tconst colliders: RAPIER.Collider[] = [];\n\t\tthis.sim.bodies.set(renderable, body);\n\t\tthis.sim.collidersOf.set(renderable, colliders);\n\t\tthis.defs.set(renderable, def);\n\t\tthis.createColliders(renderable, body, def, parts, colliders);\n\n\t\tif (def.maxVelocity) {\n\t\t\tthis.setMaxVelocity(renderable, def.maxVelocity);\n\t\t}\n\t\tthis.poses.set(renderable, poseOf(renderable));\n\n\t\tspliceHelpers(this.helperContext(), renderable, body, colliders);\n\t\tconst adapterBody = body as Rapier3dAdapter.Body;\n\t\trenderable.body = adapterBody;\n\t\t// as the builtin `Body` constructor does: a renderable with a body\n\t\t// takes part in physics and receives pointer events\n\t\trenderable.isKinematic = false;\n\t\treturn adapterBody;\n\t}\n\n\tremoveBody(renderable: Renderable): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body === undefined) {\n\t\t\treturn;\n\t\t}\n\t\t// a partner still touching this body learns the contact ended\n\t\tthis.forgetColliders(this.sim.collidersOf.get(renderable) ?? []);\n\t\t// one of their hooks may have taken this body out already\n\t\tif (this.sim.bodies.get(renderable) !== body) {\n\t\t\treturn;\n\t\t}\n\t\t// Rapier removes the body's joints and colliders with it\n\t\tthis.joints.forgetJointsOf(body);\n\t\tthis.sim.world.removeRigidBody(body);\n\t\tthis.motion.forget(renderable, body);\n\t\tthis.sim.bodies.delete(renderable);\n\t\tthis.sim.collidersOf.delete(renderable);\n\t\tthis.defs.delete(renderable);\n\t\tthis.poses.delete(renderable);\n\t\tthis.reportedShapes.delete(renderable);\n\t\tthis.overrides.delete(renderable);\n\t}\n\n\t/**\n\t * Give a body new shapes. The body itself stays: its position, turn and\n\t * velocities, its joints, what was changed on it at run time (static or\n\t * not, gravity scale, damping, sensor, collision type and mask, bounce,\n\t * speed cap, Rapier's own settings such as CCD) and the handle on\n\t * `renderable.body`. Its colliders are replaced, so the pairs touching\n\t * it end and start again, and its mass is that of the new shapes.\n\t *\n\t * A shape this adapter cannot build throws before anything is changed.\n\t * @param renderable - the body's renderable\n\t * @param shapes - the new shapes, relative to `pos`\n\t */\n\tupdateShape(renderable: Renderable, shapes: BodyShape[]): void {\n\t\tconst def = this.defs.get(renderable);\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (!def || !body || !colliders) {\n\t\t\treturn;\n\t\t}\n\t\t// every new collider is built before an old one goes\n\t\tconst parts = buildColliderParts(this.sim.rapier, this.sim.units, shapes);\n\t\tthis.forgetColliders(colliders);\n\t\t// one of the hooks told so may have taken this body out\n\t\tif (this.sim.bodies.get(renderable) !== body) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const collider of colliders) {\n\t\t\tthis.sim.world.removeCollider(collider, false);\n\t\t}\n\t\t// emptied in place: the body's helpers hold this array\n\t\tcolliders.length = 0;\n\t\tconst next = { ...def, shapes };\n\t\tthis.defs.set(renderable, next);\n\t\tthis.reportedShapes.delete(renderable);\n\t\tthis.createColliders(renderable, body, next, parts, colliders);\n\t\t// the mass and the inertia of the new shapes, from now\n\t\tbody.recomputeMassPropertiesFromColliders();\n\t\tbody.wakeUp();\n\t}\n\n\t// \u2500\u2500 joints \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * Make a joint between two bodies: what `world.addJoint()` calls, which\n\t * game code uses instead. A `\"hinge\"` is a Rapier revolute joint about\n\t * `axis` (default Z), a `\"rope\"` a rope joint, a `\"weld\"` a fixed joint\n\t * and a `\"slider\"` a prismatic joint along `axis` (default X). Anchors\n\t * are in each renderable's own space, relative to its `pos`, in pixels,\n\t * and the axis in `a`'s; a `z` left out is `0`.\n\t *\n\t * The bodies are joined as they stand, however each is turned: a weld\n\t * and a slider keep the turn between them, and a hinge leaves them only\n\t * the turn about its axis.\n\t * @param def - what to join, and how, in pixels and radians\n\t * @returns the Rapier joint\n\t */\n\taddJoint(def: Rapier3dJointDefinition): RAPIER.ImpulseJoint {\n\t\treturn this.joints.add(def);\n\t}\n\n\t/**\n\t * Remove a joint {@link Rapier3dAdapter.addJoint} made: what\n\t * `world.removeJoint()` calls. A joint already gone, with one of its\n\t * bodies, is ignored.\n\t * @param joint - the Rapier joint\n\t */\n\tremoveJoint(joint: RAPIER.ImpulseJoint): void {\n\t\tthis.joints.remove(joint);\n\t}\n\n\t// \u2500\u2500 velocity, forces and position \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tgetVelocity(renderable: Renderable, out?: Vector2d): Vector2d {\n\t\tconst target = out ?? new Vector2d();\n\t\tconst v = this.sim.bodies.get(renderable)?.linvel();\n\t\tconst { units } = this.sim;\n\t\treturn v\n\t\t\t? target.set(units.toPixels(v.x), units.toPixels(v.y))\n\t\t\t: target.set(0, 0);\n\t}\n\n\t/**\n\t * The body's velocity on all three axes, in pixels per second.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the vector to write into\n\t * @returns the velocity; zero for a renderable with no body here\n\t */\n\tgetVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d {\n\t\tconst target = out ?? new Vector3d();\n\t\tconst v = this.sim.bodies.get(renderable)?.linvel();\n\t\tconst { units } = this.sim;\n\t\treturn v\n\t\t\t? target.set(\n\t\t\t\t\tunits.toPixels(v.x),\n\t\t\t\t\tunits.toPixels(v.y),\n\t\t\t\t\tunits.toPixels(v.z),\n\t\t\t\t)\n\t\t\t: target.set(0, 0, 0);\n\t}\n\n\t/**\n\t * Set the body's velocity, in pixels per second. A {@link Vector3d} sets\n\t * all three axes; a {@link Vector2d} sets x and y and keeps the depth\n\t * velocity as it was.\n\t * @param renderable - the body's renderable\n\t * @param v - the velocity\n\t */\n\tsetVelocity(renderable: Renderable, v: Vector2d | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.setVelocity(body, v.x, v.y, zOf(v));\n\t\t}\n\t}\n\n\t/**\n\t * Push the body for this frame, across every sub-step: it accelerates by\n\t * `force / mass` pixels per second\u00B2. A force at `point` (in world pixels)\n\t * also turns it. A force or point given as a {@link Vector2d} acts in\n\t * the plane of the body.\n\t * @param renderable - the body's renderable\n\t * @param force - the force\n\t * @param [point] - where it pushes, in world space\n\t */\n\tapplyForce(\n\t\trenderable: Renderable,\n\t\tforce: Vector2d | Vector3d,\n\t\tpoint?: Vector2d | Vector3d,\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.addForce(body, force, point);\n\t\t}\n\t}\n\n\t/**\n\t * Strike the body once: its velocity changes by `impulse / mass` pixels\n\t * per second, at once. An impulse at `point` (in world pixels) also turns\n\t * it. A {@link Vector2d} strikes in the plane of the body.\n\t * @param renderable - the body's renderable\n\t * @param impulse - the impulse\n\t * @param [point] - where it strikes, in world space\n\t */\n\tapplyImpulse(\n\t\trenderable: Renderable,\n\t\timpulse: Vector2d | Vector3d,\n\t\tpoint?: Vector2d | Vector3d,\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tconst j = this.sim.units.inMeters(impulse.x, impulse.y, zOf(impulse) ?? 0);\n\t\tif (point) {\n\t\t\tbody.applyImpulseAtPoint(j, this.motion.pointInMeters(body, point), true);\n\t\t} else {\n\t\t\t// Rapier's own method, not the portable helper spliced over it\n\t\t\tthis.rapier.RigidBody.prototype.applyImpulse.call(body, j, true);\n\t\t}\n\t}\n\n\t/**\n\t * Move the body and its renderable, at once. A {@link Vector3d} sets the\n\t * depth too; a {@link Vector2d} keeps it. A renderable with no body here\n\t * is moved all the same, as on every adapter. A coordinate that is not a\n\t * finite number leaves the body and its renderable where they are.\n\t * @param renderable - the body's renderable\n\t * @param p - the new position, in `renderable.pos` space\n\t */\n\tsetPosition(renderable: Renderable, p: Vector2d | Vector3d): void {\n\t\tconst depth = zOf(p) ?? renderable.depth;\n\t\t// a coordinate that is not a number leaves the body where it is, as\n\t\t// `setAngle` does: Rapier would keep the body there, at NaN, until\n\t\t// the next position, and the renderable's depth with it\n\t\tif (\n\t\t\t!Number.isFinite(p.x) ||\n\t\t\t!Number.isFinite(p.y) ||\n\t\t\t!Number.isFinite(depth)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// one batched write, as the pose is written each frame\n\t\trenderable.setPosition(p.x, p.y, depth);\n\t\trenderable.isDirty = true;\n\t\tthis.sim.bodies\n\t\t\t.get(renderable)\n\t\t\t?.setTranslation(this.sim.units.inMeters(p.x, p.y, depth), true);\n\t}\n\n\t// \u2500\u2500 turn and spin \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The body's orientation, from the one it had when it was made.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the quaternion to write into\n\t * @returns the orientation; identity for a renderable with no body here\n\t */\n\tgetRotation(renderable: Renderable, out?: Quaternion): Quaternion {\n\t\tconst target = out ?? new Quaternion();\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) {\n\t\t\treturn target.identity();\n\t\t}\n\t\tconst q = body.rotation();\n\t\treturn target.set(q.x, q.y, q.z, q.w);\n\t}\n\n\t/**\n\t * Turn the body, and its renderable with it, to an orientation, from the\n\t * one it had when it was made.\n\t * @param renderable - the body's renderable\n\t * @param q - the orientation\n\t */\n\tsetRotation(renderable: Renderable, q: Quaternion): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\t// a non-unit quaternion is not a turn: normalized, as Rapier needs\n\t\tconst n = q.clone().normalize();\n\t\tbody.setRotation({ x: n.x, y: n.y, z: n.z, w: n.w }, true);\n\t\tthis.writePose(renderable, body);\n\t}\n\n\t/**\n\t * Turn the body to `angle` about Z, the turn a 2D game knows, leaving out\n\t * any other.\n\t * @param renderable - the body's renderable\n\t * @param angle - in radians\n\t */\n\tsetAngle(renderable: Renderable, angle: number): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\t// an angle that is not a number leaves the body as it is, as\n\t\t// `Quaternion#rotate` and `Matrix3d#rotate` do\n\t\tif (!body || !Number.isFinite(angle)) return;\n\t\tbody.setRotation(_turn.identity().rotate(angle), true);\n\t\tthis.writePose(renderable, body);\n\t}\n\n\t/**\n\t * The body's turn about Z: the angle +X is turned through, seen down Z.\n\t * @param renderable - the body's renderable\n\t * @returns in radians; `0` for a renderable with no body here\n\t */\n\tgetAngle(renderable: Renderable): number {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return 0;\n\t\t// where the turn takes +X, its x and y: the first column of the\n\t\t// quaternion's matrix, which is all of `apply` this needs\n\t\tconst { x, y, z, w } = body.rotation();\n\t\tconst tx = 1 - 2 * (y * y + z * z);\n\t\tconst ty = 2 * (x * y + w * z);\n\t\treturn tx * tx + ty * ty < 1e-12 ? 0 : Math.atan2(ty, tx);\n\t}\n\n\t/**\n\t * Set the body's spin, in radians per second: a {@link Vector3d} about\n\t * each axis, a number about Z, keeping the spin about X and Y.\n\t * @param renderable - the body's renderable\n\t * @param omega - the spin\n\t */\n\tsetAngularVelocity(renderable: Renderable, omega: number | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tif (typeof omega === \"number\") {\n\t\t\tconst w = body.angvel();\n\t\t\tbody.setAngvel({ x: w.x, y: w.y, z: omega }, true);\n\t\t} else {\n\t\t\tbody.setAngvel({ x: omega.x, y: omega.y, z: omega.z }, true);\n\t\t}\n\t}\n\n\tgetAngularVelocity(renderable: Renderable): number {\n\t\treturn this.sim.bodies.get(renderable)?.angvel().z ?? 0;\n\t}\n\n\t/**\n\t * The body's spin about each axis, in radians per second.\n\t * @param renderable - the body's renderable\n\t * @param [out] - the vector to write into\n\t * @returns the spin; zero for a renderable with no body here\n\t */\n\tgetAngularVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d {\n\t\tconst target = out ?? new Vector3d();\n\t\tconst w = this.sim.bodies.get(renderable)?.angvel();\n\t\treturn w ? target.set(w.x, w.y, w.z) : target.set(0, 0, 0);\n\t}\n\n\t/**\n\t * Twist the body for this frame: a number about Z, a {@link Vector3d}\n\t * about each axis. In Rapier's own unit (N\u00B7m, not scaled by\n\t * `pixelsPerMeter`), as on the 2D Rapier adapter.\n\t * @param renderable - the body's renderable\n\t * @param torque - the torque\n\t */\n\tapplyTorque(renderable: Renderable, torque: number | Vector3d): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\tthis.motion.addTorque(body, torque);\n\t\t}\n\t}\n\n\t// \u2500\u2500 what a body is \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tsetStatic(renderable: Renderable, isStatic: boolean): void {\n\t\tconst { RigidBodyType } = this.rapier;\n\t\tthis.sim.bodies\n\t\t\t.get(renderable)\n\t\t\t?.setBodyType(\n\t\t\t\tisStatic ? RigidBodyType.Fixed : RigidBodyType.Dynamic,\n\t\t\t\ttrue,\n\t\t\t);\n\t}\n\n\tsetGravityScale(renderable: Renderable, scale: number): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (body) {\n\t\t\t// Rapier's own method, not the portable helper spliced over it\n\t\t\tthis.rapier.RigidBody.prototype.setGravityScale.call(body, scale, true);\n\t\t}\n\t}\n\n\tsetSensor(renderable: Renderable, isSensor: boolean): void {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) return;\n\t\tthis.overrides.of(renderable).sensor = isSensor;\n\t\tfor (const collider of colliders) {\n\t\t\tcollider.setSensor(isSensor);\n\t\t}\n\t}\n\n\tsetFrictionAir(\n\t\trenderable: Renderable,\n\t\tfriction: number | { x: number; y: number },\n\t): void {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tif (!body) return;\n\t\tconst damping = averageOf(friction) ?? 0;\n\t\tbody.setLinearDamping(damping);\n\t\tbody.setAngularDamping(damping);\n\t}\n\n\t/**\n\t * Cap the body's speed on each axis, in pixels per second. A `z` caps\n\t * the depth axis too; left out, that axis has no cap.\n\t * @param renderable - the body's renderable\n\t * @param limit - the cap\n\t */\n\tsetMaxVelocity(renderable: Renderable, limit: Vector3Like): void {\n\t\t// nothing to cap, and nothing to keep, for a renderable with no body\n\t\tif (!this.sim.bodies.has(renderable)) return;\n\t\tthis.motion.limits.set(renderable, {\n\t\t\tx: limit.x,\n\t\t\ty: limit.y,\n\t\t\tz: limit.z,\n\t\t});\n\t}\n\n\tgetMaxVelocity(renderable: Renderable): {\n\t\tx: number;\n\t\ty: number;\n\t\tz: number;\n\t} {\n\t\t// a copy, so changing it does not change the cap; no cap reads as\n\t\t// Infinity\n\t\tconst limit = this.motion.limits.get(renderable);\n\t\treturn {\n\t\t\tx: limit?.x ?? Infinity,\n\t\t\ty: limit?.y ?? Infinity,\n\t\t\tz: limit?.z ?? Infinity,\n\t\t};\n\t}\n\n\tsetCollisionType(renderable: Renderable, type: number): void {\n\t\tthis.setFilter(renderable, type, undefined);\n\t}\n\n\tsetCollisionMask(renderable: Renderable, mask: number): void {\n\t\tthis.setFilter(renderable, undefined, mask);\n\t}\n\n\t// \u2500\u2500 reading bodies, and querying the world \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The body's XY bounds in renderable-local pixels, relative to `pos`: the\n\t * footprint of its colliders as the body is turned now. Exact for a\n\t * box, a sphere and a capsule; for a hull or a triangle mesh, that of its\n\t * bounding box, turned.\n\t * @param renderable - the renderable whose body bounds to read\n\t * @param out - destination `Bounds` (filled in place, also returned)\n\t */\n\tgetBodyAABB(renderable: Renderable, out: Bounds): Bounds | undefined {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (body === undefined || colliders === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (colliders.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst q = body.rotation();\n\t\tconst box = emptyFootprint();\n\t\tfor (const collider of colliders) {\n\t\t\tconst entry = this.sim.colliders.get(collider.handle);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tgrowFootprint(entry, q, box);\n\t\t\t}\n\t\t}\n\t\tout.setMinMax(box[0], box[1], box[2], box[3]);\n\t\treturn out;\n\t}\n\n\t/**\n\t * The body's collision shapes, as given in its `bodyDef`, relative to\n\t * `pos` and before the body turns (the turn is\n\t * {@link Rapier3dAdapter.getRotation}). A shape with `isActive: false`\n\t * is left out.\n\t * @param renderable - the renderable whose body shapes to read\n\t */\n\tgetBodyShapes(renderable: Renderable): readonly BodyShape[] {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) {\n\t\t\treturn [];\n\t\t}\n\t\tlet cached = this.reportedShapes.get(renderable);\n\t\tif (cached === undefined) {\n\t\t\tcached = [];\n\t\t\tfor (const collider of colliders) {\n\t\t\t\tconst entry = this.sim.colliders.get(collider.handle);\n\t\t\t\tif (entry !== undefined) {\n\t\t\t\t\tcached.push(entry.shape);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.reportedShapes.set(renderable, cached);\n\t\t}\n\t\treturn cached;\n\t}\n\n\t/**\n\t * Whether Rapier has put the body to sleep: a dynamic body at rest, left\n\t * out of the step until a contact or a write to it (a velocity, a force,\n\t * an impulse, a position or a rotation, which all wake it) moves it\n\t * again. `false` for a fixed or kinematic body, and for a renderable this\n\t * adapter does not know, including every one once it is destroyed.\n\t * @param renderable - the renderable whose body to read\n\t * @returns `true` while the body sleeps\n\t * @example\n\t * // the shot is over once every block has come to rest\n\t * const settled = blocks.every((b) => adapter.isSleeping(b));\n\t */\n\tisSleeping(renderable: Renderable): boolean {\n\t\tconst body = this.sim.bodies.get(renderable);\n\t\t// Rapier reports a fixed or kinematic body at rest as asleep too\n\t\treturn body !== undefined && body.isDynamic() && body.isSleeping();\n\t}\n\n\tisGrounded(renderable: Renderable): boolean {\n\t\treturn queries.isGrounded(this.sim, renderable);\n\t}\n\n\t/**\n\t * The first collider a segment meets, from `from` to `to`, in world\n\t * pixels: the exact shape, not a bounding volume. A shape the ray starts\n\t * inside is skipped, so a body casting from its own centre does not hit\n\t * itself. Sensors are hit like any other body.\n\t * @param from - where the ray starts\n\t * @param to - where it ends\n\t * @returns the hit, or `null`\n\t */\n\traycast3d(from: Vector3d, to: Vector3d): RaycastHit3d | null {\n\t\treturn queries.raycast3d(this.sim, from, to);\n\t}\n\n\t/**\n\t * The renderables whose colliders' boxes overlap a rectangle in XY, at\n\t * any depth: the boxes {@link Rapier3dAdapter.getBodyAABB} reports.\n\t * @param rect - the rectangle, in world pixels\n\t * @returns the renderables, each once\n\t */\n\tqueryAABB(rect: Rect): Renderable[] {\n\t\treturn queries.queryAABB(this.sim, rect);\n\t}\n\n\t/**\n\t * The renderables whose colliders overlap a sphere: their exact shapes.\n\t * @param center - the centre in world pixels, or a {@link Sphere}\n\t * @param [radius] - the radius in pixels, with a centre; none, or less\n\t * than none, is a point\n\t * @returns the renderables, each once\n\t */\n\tquerySphere(center: Vector3d | Sphere, radius?: number): Renderable[] {\n\t\treturn queries.querySphere(this.sim, center, radius);\n\t}\n\n\t// \u2500\u2500 internals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/**\n\t * The gravity in meters per second\u00B2, for Rapier.\n\t * @returns the gravity\n\t */\n\tprivate gravityInMeters() {\n\t\tconst { x, y, z } = this.gravity;\n\t\treturn this.sim.units.inMeters(x, y, z);\n\t}\n\n\t/**\n\t * Write a body's place and turn back onto its renderable.\n\t * @param renderable - the renderable\n\t * @param body - its body\n\t */\n\tprivate writePose(renderable: Renderable, body: RAPIER.RigidBody): void {\n\t\twritePose(renderable, body, this.poses.get(renderable), this.sim.units);\n\t}\n\n\t/**\n\t * Make a body's colliders, with the body definition's material and\n\t * filter, a shape's own settings over them, and what was set on the\n\t * whole body at run time over both.\n\t * @param renderable - the body's renderable\n\t * @param body - the body\n\t * @param def - its definition\n\t * @param parts - the colliders to make\n\t * @param colliders - the body's list of colliders, added to\n\t */\n\tprivate createColliders(\n\t\trenderable: Renderable,\n\t\tbody: RAPIER.RigidBody,\n\t\tdef: BodyDefinition,\n\t\tparts: ColliderPart[],\n\t\tcolliders: RAPIER.Collider[],\n\t): void {\n\t\tconst over = this.overrides.get(renderable);\n\t\tconst bodyType =\n\t\t\ttypeof def.collisionType === \"number\" ? def.collisionType : 0x0001;\n\t\tconst bodyMask =\n\t\t\ttypeof def.collisionMask === \"number\"\n\t\t\t\t? def.collisionMask\n\t\t\t\t: collision.types.ALL_OBJECT;\n\t\tfor (const { shape, index, desc, min, max, round } of parts) {\n\t\t\tconst shapeType = (shape as { collisionType?: number }).collisionType;\n\t\t\tconst shapeMask = (shape as { collisionMask?: number }).collisionMask;\n\t\t\tconst trigger = (shape as { isTrigger?: boolean }).isTrigger === true;\n\t\t\tdesc\n\t\t\t\t.setDensity(def.density ?? 1)\n\t\t\t\t.setFriction(def.friction ?? 0.2)\n\t\t\t\t.setRestitution(over?.restitution ?? def.restitution ?? 0)\n\t\t\t\t// a trigger shape is a sensor: it reports contacts and\n\t\t\t\t// contributes nothing to the solver\n\t\t\t\t.setSensor(over?.sensor ?? (def.isSensor === true || trigger))\n\t\t\t\t.setActiveEvents(this.rapier.ActiveEvents.COLLISION_EVENTS);\n\t\t\tconst collider = this.sim.world.createCollider(desc, body);\n\t\t\t// a shape's own collision settings override the body's\n\t\t\tthis.filters.apply(\n\t\t\t\tcollider,\n\t\t\t\tover?.category ??\n\t\t\t\t\t(typeof shapeType === \"number\" ? shapeType : bodyType),\n\t\t\t\tover?.mask ?? (typeof shapeMask === \"number\" ? shapeMask : bodyMask),\n\t\t\t);\n\t\t\tconst entry: ColliderEntry = { renderable, shape, index, min, max };\n\t\t\tif (round !== undefined) {\n\t\t\t\tentry.round = round;\n\t\t\t}\n\t\t\tthis.sim.colliders.set(collider.handle, entry);\n\t\t\tcolliders.push(collider);\n\t\t}\n\t}\n\n\t/**\n\t * Tell the pairs touching colliders that are about to go that their\n\t * contact ended, then forget the colliders.\n\t * @param colliders - the colliders leaving the world\n\t */\n\tprivate forgetColliders(colliders: RAPIER.Collider[]): void {\n\t\tthis.contacts.endContacts(colliders);\n\t\tfor (const collider of colliders) {\n\t\t\tthis.sim.colliders.delete(collider.handle);\n\t\t\tthis.filters.forget(collider.handle);\n\t\t}\n\t}\n\n\t/**\n\t * Change the collision type and/or mask of every collider of a body, and\n\t * keep it for the colliders `updateShape()` makes.\n\t * @param renderable - the body's renderable\n\t * @param category - the new type, or undefined to keep each collider's\n\t * @param mask - the new mask, or undefined to keep each collider's\n\t */\n\tprivate setFilter(\n\t\trenderable: Renderable,\n\t\tcategory: number | undefined,\n\t\tmask: number | undefined,\n\t): void {\n\t\tconst colliders = this.sim.collidersOf.get(renderable);\n\t\tif (colliders === undefined) return;\n\t\tconst over = this.overrides.of(renderable);\n\t\tif (category !== undefined) over.category = category;\n\t\tif (mask !== undefined) over.mask = mask;\n\t\tthis.filters.update(colliders, category, mask);\n\t}\n\n\t/**\n\t * What the helpers spliced onto a body act through.\n\t * @returns the context\n\t */\n\tprivate helperContext() {\n\t\treturn {\n\t\t\tadapter: this,\n\t\t\tsim: this.sim,\n\t\t\tmotion: this.motion,\n\t\t\tfilters: this.filters,\n\t\t\toverrides: this.overrides,\n\t\t};\n\t}\n}\n\n/**\n * One damping rate from a `frictionAir`: Rapier damping is one value, so an\n * `{x, y}` is averaged.\n * @param v - the setting\n * @returns the rate, or undefined when none is set\n */\nfunction averageOf(\n\tv: number | { x: number; y: number } | undefined,\n): number | undefined {\n\tif (v === undefined) return undefined;\n\tif (typeof v === \"number\") return v;\n\treturn (v.x + v.y) / 2;\n}\n\n/**\n * Namespace-merged with the {@link Rapier3dAdapter} class to expose\n * adapter-owned types alongside the runtime API.\n */\n// biome-ignore lint/style/useNamingConvention: namespace must match the class it merges with\n// eslint-disable-next-line @typescript-eslint/no-namespace -- intentional class+namespace declaration merge so adapter-owned types (`Rapier3dAdapter.Body`) are reachable alongside the runtime class\nexport namespace Rapier3dAdapter {\n\t/**\n\t * The body handle attached to `renderable.body` under\n\t * {@link Rapier3dAdapter}: the Rapier `RigidBody` (with all its native\n\t * methods: `enableCcd`, `linvel`, `mass`, `sleep`, \u2026) and the portable\n\t * melonJS helpers spliced onto it.\n\t *\n\t * ```ts\n\t * (this.body as Rapier3dAdapter.Body).enableCcd(true);\n\t * ```\n\t */\n\texport type Body = RAPIER.RigidBody & PhysicsBody;\n}\n", "/**\n * The portable `PhysicsBody` helpers, spliced onto a Rapier body so that\n * `renderable.body.setVelocity(x, y, z)` works as on every adapter. The body\n * stays a real `RAPIER.RigidBody`, with all its own methods.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { PhysicsBody, Renderable, Vector2d, Vector3d } from \"melonjs\";\nimport type { CollisionFilters } from \"../colliders/CollisionFilters\";\nimport type { Rapier3dAdapter } from \"../Rapier3dAdapter\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Motion } from \"./Motion\";\nimport type { RuntimeOverrides } from \"./RuntimeOverrides\";\n\n/** what the helpers act through */\nexport interface HelperContext {\n\tadapter: Rapier3dAdapter;\n\tsim: Simulation;\n\tmotion: Motion;\n\tfilters: CollisionFilters;\n\toverrides: RuntimeOverrides;\n}\n\n/**\n * Splice the helpers onto a body.\n * @param ctx - what they act through\n * @param renderable - the body's renderable\n * @param body - the Rapier body\n * @param colliders - its colliders: the live list, which `updateShape()`\n * refills in place\n */\nexport function spliceHelpers(\n\tctx: HelperContext,\n\trenderable: Renderable,\n\tbody: RAPIER.RigidBody,\n\tcolliders: RAPIER.Collider[],\n): void {\n\tconst { adapter, sim, motion, filters, overrides } = ctx;\n\tconst proto = sim.rapier.RigidBody.prototype;\n\tconst helpers: Omit<PhysicsBody, \"collisionType\" | \"collisionMask\"> = {\n\t\tsetVelocity: (x: number, y: number, z?: number) => {\n\t\t\tmotion.setVelocity(body, x, y, z);\n\t\t},\n\t\tgetVelocity: (out?: Vector2d): Vector2d => {\n\t\t\treturn adapter.getVelocity(renderable, out);\n\t\t},\n\t\tgetVelocity3d: (out?: Vector3d): Vector3d => {\n\t\t\treturn adapter.getVelocity3d(renderable, out);\n\t\t},\n\t\tapplyForce: (x: number, y: number, pointX?: number, pointY?: number) => {\n\t\t\tmotion.addForce(\n\t\t\t\tbody,\n\t\t\t\t{ x, y },\n\t\t\t\ttypeof pointX === \"number\" && typeof pointY === \"number\"\n\t\t\t\t\t? { x: pointX, y: pointY }\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t},\n\t\tapplyImpulse: (x: number, y: number, z?: number) => {\n\t\t\t// Rapier's own method, which this helper is spliced over\n\t\t\tproto.applyImpulse.call(body, sim.units.inMeters(x, y, z ?? 0), true);\n\t\t},\n\t\tsetSensor: (isSensor = true) => {\n\t\t\tadapter.setSensor(renderable, isSensor);\n\t\t},\n\t\tsetStatic: (isStatic = true) => {\n\t\t\tadapter.setStatic(renderable, isStatic);\n\t\t},\n\t\tsetCollisionMask: (mask: number) => {\n\t\t\tadapter.setCollisionMask(renderable, mask);\n\t\t},\n\t\tsetCollisionType: (type: number) => {\n\t\t\tadapter.setCollisionType(renderable, type);\n\t\t},\n\t\t/**\n\t\t * Set the body's mass, keeping how it is spread over its shapes: every\n\t\t * collider's density is scaled by the same factor.\n\t\t * @param m - the new mass, in kilograms\n\t\t */\n\t\tsetMass: (m: number) => {\n\t\t\tconst current = body.mass();\n\t\t\tif (current > 0) {\n\t\t\t\tconst k = m / current;\n\t\t\t\tfor (const collider of colliders) {\n\t\t\t\t\tcollider.setDensity(collider.density() * k);\n\t\t\t\t}\n\t\t\t\tbody.recomputeMassPropertiesFromColliders();\n\t\t\t}\n\t\t},\n\t\tsetBounce: (r: number) => {\n\t\t\toverrides.of(renderable).restitution = r;\n\t\t\tfor (const collider of colliders) {\n\t\t\t\tcollider.setRestitution(r);\n\t\t\t}\n\t\t},\n\t\tsetGravityScale: (scale: number) => {\n\t\t\tadapter.setGravityScale(renderable, scale);\n\t\t},\n\t\tsetAngle: (rad: number) => {\n\t\t\tadapter.setAngle(renderable, rad);\n\t\t},\n\t\tgetAngle: () => {\n\t\t\treturn adapter.getAngle(renderable);\n\t\t},\n\t\tsetAngularVelocity: (omega: number) => {\n\t\t\tadapter.setAngularVelocity(renderable, omega);\n\t\t},\n\t\tgetAngularVelocity: () => {\n\t\t\treturn adapter.getAngularVelocity(renderable);\n\t\t},\n\t\tapplyTorque: (torque: number) => {\n\t\t\tadapter.applyTorque(renderable, torque);\n\t\t},\n\t};\n\tObject.assign(body, helpers);\n\n\t// `collisionType` / `collisionMask` read the first collider's values and\n\t// write every collider's, as on the 2D adapters\n\tconst first = () => {\n\t\treturn colliders[0] as RAPIER.Collider | undefined;\n\t};\n\tObject.defineProperties(body, {\n\t\tcollisionType: {\n\t\t\tget: () => {\n\t\t\t\tconst c = first();\n\t\t\t\treturn c ? (filters.get(c.handle)?.category ?? 0) : 0;\n\t\t\t},\n\t\t\tset: (v: number) => {\n\t\t\t\tadapter.setCollisionType(renderable, v);\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t},\n\t\tcollisionMask: {\n\t\t\tget: () => {\n\t\t\t\tconst c = first();\n\t\t\t\treturn c ? (filters.get(c.handle)?.mask ?? 0) : 0;\n\t\t\t},\n\t\t\tset: (v: number) => {\n\t\t\t\tadapter.setCollisionMask(renderable, v);\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t},\n\t});\n}\n", "/**\n * Pixels and meters. melonJS works in pixels; Rapier is tuned for objects\n * about a meter across, so the adapter converts at every boundary.\n */\nimport type { Vector3Like } from \"../types\";\n\n/** A point or a vector in three dimensions, in pixels or meters. */\nexport type XYZ = { x: number; y: number; z: number };\n\n/**\n * The `z` of a vector that may not have one.\n * @param v - the vector\n * @returns its `z`, or `undefined`\n */\nexport function zOf(v: Vector3Like): number | undefined {\n\treturn typeof v.z === \"number\" ? v.z : undefined;\n}\n\n/** The scale between melonJS pixels and Rapier meters. */\nexport class Units {\n\treadonly pixelsPerMeter: number;\n\n\t/**\n\t * @param pixelsPerMeter - how many pixels make a meter\n\t */\n\tconstructor(pixelsPerMeter: number) {\n\t\tthis.pixelsPerMeter = pixelsPerMeter;\n\t}\n\n\t/**\n\t * @param px - a length in pixels\n\t * @returns the same length in meters\n\t */\n\ttoMeters(px: number): number {\n\t\treturn px / this.pixelsPerMeter;\n\t}\n\n\t/**\n\t * @param m - a length in meters\n\t * @returns the same length in pixels\n\t */\n\ttoPixels(m: number): number {\n\t\treturn m * this.pixelsPerMeter;\n\t}\n\n\t/**\n\t * A point or a vector in pixels, in meters.\n\t * @param x - along X, in pixels\n\t * @param y - along Y, in pixels\n\t * @param z - along Z, in pixels\n\t * @returns a new point in meters\n\t */\n\tinMeters(x: number, y: number, z: number): XYZ {\n\t\treturn { x: this.toMeters(x), y: this.toMeters(y), z: this.toMeters(z) };\n\t}\n}\n", "/**\n * Moving bodies in pixels: velocities, forces and torques for the frame, and\n * the speed caps (`maxVelocity`) Rapier has no notion of.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport { type XYZ, zOf } from \"../math/units\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Vector3Like } from \"../types\";\n\nexport class Motion {\n\t/** each body's speed cap, per axis, in pixels per second */\n\treadonly limits = new Map<Renderable, Vector3Like>();\n\tprivate readonly sim: Simulation;\n\t/** bodies with a force or torque to clear once the frame is stepped */\n\tprivate readonly forced = new Set<RAPIER.RigidBody>();\n\n\t/**\n\t * @param sim - the simulation whose bodies it moves\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * Set a body's velocity in pixels per second; a `z` left out keeps the\n\t * depth velocity.\n\t * @param body - the body\n\t * @param x - along X\n\t * @param y - along Y\n\t * @param [z] - along Z\n\t */\n\tsetVelocity(body: RAPIER.RigidBody, x: number, y: number, z?: number): void {\n\t\tconst { units } = this.sim;\n\t\tbody.setLinvel(\n\t\t\t{\n\t\t\t\tx: units.toMeters(x),\n\t\t\t\ty: units.toMeters(y),\n\t\t\t\tz: typeof z === \"number\" ? units.toMeters(z) : body.linvel().z,\n\t\t\t},\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/**\n\t * Add a force for this frame, in pixels: at a world point, it also turns\n\t * the body. A force or a point with no `z` acts in the plane of the body.\n\t * @param body - the body\n\t * @param force - the force\n\t * @param [point] - where it pushes, in world pixels\n\t */\n\taddForce(body: RAPIER.RigidBody, force: Vector3Like, point?: Vector3Like) {\n\t\tconst f = this.sim.units.inMeters(force.x, force.y, zOf(force) ?? 0);\n\t\tif (point) {\n\t\t\tbody.addForceAtPoint(f, this.pointInMeters(body, point), true);\n\t\t} else {\n\t\t\tbody.addForce(f, true);\n\t\t}\n\t\tthis.forced.add(body);\n\t}\n\n\t/**\n\t * Add a torque for this frame: a number about Z, a vector about each axis.\n\t * In Rapier's own unit (N\u00B7m), not scaled.\n\t * @param body - the body\n\t * @param torque - the torque\n\t */\n\taddTorque(body: RAPIER.RigidBody, torque: number | Vector3Like): void {\n\t\tbody.addTorque(\n\t\t\ttypeof torque === \"number\"\n\t\t\t\t? { x: 0, y: 0, z: torque }\n\t\t\t\t: { x: torque.x, y: torque.y, z: torque.z ?? 0 },\n\t\t\ttrue,\n\t\t);\n\t\tthis.forced.add(body);\n\t}\n\n\t/**\n\t * A world point in meters; one with no depth is in the plane of the body.\n\t * @param body - the body it acts on\n\t * @param point - the point in world pixels\n\t * @returns the point in meters\n\t */\n\tpointInMeters(body: RAPIER.RigidBody, point: Vector3Like): XYZ {\n\t\tconst { units } = this.sim;\n\t\tconst z = point.z;\n\t\treturn {\n\t\t\tx: units.toMeters(point.x),\n\t\t\ty: units.toMeters(point.y),\n\t\t\tz: typeof z === \"number\" ? units.toMeters(z) : body.translation().z,\n\t\t};\n\t}\n\n\t/** A force is for one frame, across every sub-step: clear them all. */\n\tclearForces(): void {\n\t\tfor (const body of this.forced) {\n\t\t\tif (body.isValid()) {\n\t\t\t\tbody.resetForces(false);\n\t\t\t\tbody.resetTorques(false);\n\t\t\t}\n\t\t}\n\t\tthis.forced.clear();\n\t}\n\n\t/** Hold every capped body to its cap. */\n\tclampVelocities(): void {\n\t\tconst { units, bodies } = this.sim;\n\t\tfor (const [renderable, limit] of this.limits) {\n\t\t\tconst body = bodies.get(renderable);\n\t\t\tif (!body) continue;\n\t\t\tconst v = body.linvel();\n\t\t\tconst clamp = (value: number, px: number | undefined) => {\n\t\t\t\t// no cap on this axis; one that is not a number caps nothing\n\t\t\t\t// (it would turn the velocity itself into NaN)\n\t\t\t\tif (typeof px !== \"number\" || Number.isNaN(px)) return value;\n\t\t\t\tconst m = units.toMeters(Math.abs(px));\n\t\t\t\treturn Math.max(-m, Math.min(m, value));\n\t\t\t};\n\t\t\tconst vx = clamp(v.x, limit.x);\n\t\t\tconst vy = clamp(v.y, limit.y);\n\t\t\tconst vz = clamp(v.z, limit.z);\n\t\t\tif (vx !== v.x || vy !== v.y || vz !== v.z) {\n\t\t\t\tbody.setLinvel({ x: vx, y: vy, z: vz }, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Forget a body that left the world.\n\t * @param renderable - its renderable\n\t * @param body - the body\n\t */\n\tforget(renderable: Renderable, body: RAPIER.RigidBody): void {\n\t\tthis.forced.delete(body);\n\t\tthis.limits.delete(renderable);\n\t}\n\n\t/** Forget every body. */\n\tclear(): void {\n\t\tthis.forced.clear();\n\t\tthis.limits.clear();\n\t}\n}\n", "/**\n * Writing a body's place and turn back onto its renderable: its position to\n * `pos` / `depth`, its turn onto `currentTransform`, from the transform the\n * renderable had when the body was made.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { type Matrix3d, Mesh, Quaternion, type Renderable } from \"melonjs\";\nimport type { Units } from \"../math/units\";\n\n/**\n * How a renderable draws its `currentTransform`, so the body's turn can be\n * written onto it: `bridge` is the sign of each axis between the space the\n * transform turns in and the engine's (a {@link Mesh} turns in its source's\n * Y-up space), and `base` the transform it had when the body was made.\n */\nexport interface Pose {\n\tbase: Matrix3d;\n\tbridge: [number, number, number];\n}\n\n// the body's turn, carried into the space the renderable turns in\nconst _turn = new Quaternion();\n\n/**\n * A renderable's pose as it stands, to turn from.\n * @param renderable - the renderable a body is made for\n * @returns its pose\n */\nexport function poseOf(renderable: Renderable): Pose {\n\treturn {\n\t\tbase: renderable.currentTransform.clone(),\n\t\tbridge:\n\t\t\trenderable instanceof Mesh\n\t\t\t\t? // a mesh turns in its source's Y-up space (see Mesh)\n\t\t\t\t\t[1, -1, renderable.rightHanded ? -1 : 1]\n\t\t\t\t: [1, 1, 1],\n\t};\n}\n\n/**\n * Write a body's position onto its renderable's `pos` / `depth` and, given a\n * pose, its turn onto its `currentTransform`.\n * @param renderable - the renderable\n * @param body - its body\n * @param pose - its pose, or undefined to write the position only\n * @param units - the scale between pixels and meters\n */\nexport function writePose(\n\trenderable: Renderable,\n\tbody: RAPIER.RigidBody,\n\tpose: Pose | undefined,\n\tunits: Units,\n): void {\n\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: pos is typed non-null but the pool releases it on recycle\n\tif (!renderable.pos) {\n\t\treturn;\n\t}\n\tconst p = body.translation();\n\t// one batched write: the position's change callback (a bounds update)\n\t// runs once, where assigning `pos.x`, `pos.y` and `depth` ran it three\n\t// times\n\trenderable.setPosition(\n\t\tunits.toPixels(p.x),\n\t\tunits.toPixels(p.y),\n\t\tunits.toPixels(p.z),\n\t);\n\trenderable.isDirty = true;\n\tif (pose === undefined) {\n\t\treturn;\n\t}\n\tconst { x, y, z, w } = body.rotation();\n\t// carried into the space the transform turns in: D \u00B7 R \u00B7 D, with the\n\t// bridge D its own inverse. On a quaternion, each axis part takes its\n\t// axis's sign, and the sign of det(D) when D mirrors the space\n\tconst [d0, d1, d2] = pose.bridge;\n\tconst det = d0 * d1 * d2;\n\t_turn.set(det * d0 * x, det * d1 * y, det * d2 * z, w);\n\t// currentTransform = R' \u00B7 base\n\trenderable.currentTransform.identity().rotate(_turn).multiply(pose.base);\n\trenderable.isDirty = true;\n}\n", "/**\n * What was set on every collider of a body at run time (`setSensor`,\n * `setCollisionType`, `setCollisionMask`, `setBounce`), so that the colliders\n * `updateShape()` makes get it too.\n */\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderOverrides } from \"../colliders/types\";\n\nexport class RuntimeOverrides extends Map<Renderable, ColliderOverrides> {\n\t/**\n\t * A body's record, to write to.\n\t * @param renderable - the body's renderable\n\t * @returns its record, made when there is none\n\t */\n\tof(renderable: Renderable): ColliderOverrides {\n\t\tlet over = this.get(renderable);\n\t\tif (over === undefined) {\n\t\t\tover = {};\n\t\t\tthis.set(renderable, over);\n\t\t}\n\t\treturn over;\n\t}\n}\n", "/**\n * melonJS collision types and masks on Rapier colliders.\n *\n * Rapier's own collision groups hold 16 bits of membership and 16 of filter,\n * where melonJS types and masks are 32 bits: a collider whose values do not\n * fit is filtered by Rapier's `filterContactPair` / `filterIntersectionPair`\n * hooks instead, on the full 32 bits.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { collision } from \"melonjs\";\n\n/** a collider's melonJS collision type and mask */\nexport interface Filter {\n\tcategory: number;\n\tmask: number;\n}\n\n// what a collider with no type or mask of its own has\nconst DEFAULT_CATEGORY = 0x0001;\n\nexport class CollisionFilters {\n\t/** The hooks Rapier calls for a pair that needs the full 32 bits. */\n\treadonly hooks: RAPIER.PhysicsHooks;\n\tprivate readonly rapier: typeof RAPIER;\n\t/** collider handle -> its type and mask */\n\tprivate readonly filters = new Map<number, Filter>();\n\n\t/**\n\t * @param rapier - the Rapier module\n\t */\n\tconstructor(rapier: typeof RAPIER) {\n\t\tthis.rapier = rapier;\n\t\tconst computeImpulse = rapier.SolverFlags.COMPUTE_IMPULSE;\n\t\tthis.hooks = {\n\t\t\tfilterContactPair: (c1, c2) => {\n\t\t\t\treturn this.passes(c1, c2) ? computeImpulse : null;\n\t\t\t},\n\t\t\tfilterIntersectionPair: (c1, c2) => {\n\t\t\t\treturn this.passes(c1, c2);\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * A collider's type and mask.\n\t * @param handle - the collider handle\n\t * @returns its filter, if it has one\n\t */\n\tget(handle: number): Filter | undefined {\n\t\treturn this.filters.get(handle);\n\t}\n\n\t/**\n\t * Give a collider its melonJS collision type and mask.\n\t * @param collider - the collider to configure\n\t * @param category - its collision type\n\t * @param mask - the collision types it collides with\n\t */\n\tapply(collider: RAPIER.Collider, category: number, mask: number): void {\n\t\tthis.filters.set(collider.handle, { category, mask });\n\t\tconst { ActiveHooks } = this.rapier;\n\t\tconst needsHooks =\n\t\t\tcategory >>> 16 !== 0 || (mask >>> 16 !== 0 && (mask & 0xffff) === 0);\n\t\tif (needsHooks) {\n\t\t\tcollider.setCollisionGroups(0xffffffff);\n\t\t\tcollider.setActiveHooks(\n\t\t\t\tActiveHooks.FILTER_CONTACT_PAIRS |\n\t\t\t\t\tActiveHooks.FILTER_INTERSECTION_PAIRS,\n\t\t\t);\n\t\t} else {\n\t\t\tcollider.setCollisionGroups(\n\t\t\t\t(((category & 0xffff) << 16) | (mask & 0xffff)) >>> 0,\n\t\t\t);\n\t\t\tcollider.setActiveHooks(ActiveHooks.NONE);\n\t\t}\n\t}\n\n\t/**\n\t * Change the type and/or the mask of several colliders.\n\t * @param colliders - the colliders\n\t * @param category - the new type, or undefined to keep each collider's\n\t * @param mask - the new mask, or undefined to keep each collider's\n\t */\n\tupdate(\n\t\tcolliders: RAPIER.Collider[],\n\t\tcategory: number | undefined,\n\t\tmask: number | undefined,\n\t): void {\n\t\tfor (const collider of colliders) {\n\t\t\tconst current = this.filters.get(collider.handle);\n\t\t\tthis.apply(\n\t\t\t\tcollider,\n\t\t\t\tcategory ?? current?.category ?? DEFAULT_CATEGORY,\n\t\t\t\tmask ?? current?.mask ?? collision.types.ALL_OBJECT,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Forget a collider that left the world.\n\t * @param handle - its handle\n\t */\n\tforget(handle: number): void {\n\t\tthis.filters.delete(handle);\n\t}\n\n\t/** Forget every collider. */\n\tclear(): void {\n\t\tthis.filters.clear();\n\t}\n\n\t/**\n\t * Whether two colliders collide, by their full 32-bit types and masks.\n\t * @param c1 - a collider handle\n\t * @param c2 - the other\n\t * @returns true when each one's mask includes the other's type\n\t */\n\tprivate passes(c1: number, c2: number): boolean {\n\t\tconst f1 = this.filters.get(c1);\n\t\tconst f2 = this.filters.get(c2);\n\t\tif (f1 === undefined || f2 === undefined) {\n\t\t\treturn true;\n\t\t}\n\t\treturn (f1.mask & f2.category) !== 0 && (f2.mask & f1.category) !== 0;\n\t}\n}\n", "/**\n * A collider's footprint in XY, as its body is turned: what `getBodyAABB`\n * reports and `queryAABB` tests against.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { ColliderEntry } from \"./types\";\n\n/** A box in XY: min x, min y, max x, max y. */\nexport type Footprint = [number, number, number, number];\n\n/**\n * An empty footprint, ready to grow.\n * @returns a box that contains nothing\n */\nexport function emptyFootprint(): Footprint {\n\treturn [Infinity, Infinity, -Infinity, -Infinity];\n}\n\n/**\n * Grow a box in XY by a collider's footprint as its body is turned, in\n * pixels, relative to the body's origin.\n * @param entry - the collider's entry\n * @param q - its body's turn\n * @param box - the box to grow\n */\nexport function growFootprint(\n\tentry: ColliderEntry,\n\tq: RAPIER.Rotation,\n\tbox: Footprint,\n): void {\n\tconst { min, max, round } = entry;\n\t// a sphere or a capsule: the two ends of its segment, turned with the\n\t// body, a radius wider. Any other: the eight corners of its box, turned\n\t// with the body\n\tconst r = round?.r ?? 0;\n\tconst { x, y, z, w } = q;\n\t// the X and Y rows of the turn's matrix, once for every corner: a\n\t// footprint is in XY, so the turned point's z is never needed. Written\n\t// out rather than through `Quaternion#apply` on a shared vector, which\n\t// measured slower: a query runs this for every corner of every collider\n\tconst r00 = 1 - 2 * (y * y + z * z);\n\tconst r01 = 2 * (x * y - w * z);\n\tconst r02 = 2 * (x * z + w * y);\n\tconst r10 = 2 * (x * y + w * z);\n\tconst r11 = 1 - 2 * (x * x + z * z);\n\tconst r12 = 2 * (y * z - w * x);\n\tfor (let i = 0; i < (round ? 2 : 8); i++) {\n\t\tlet px: number;\n\t\tlet py: number;\n\t\tlet pz: number;\n\t\tif (round) {\n\t\t\tconst end = i === 0 ? round.a : round.b;\n\t\t\tpx = end.x;\n\t\t\tpy = end.y;\n\t\t\tpz = end.z;\n\t\t} else {\n\t\t\tpx = i & 1 ? max.x : min.x;\n\t\t\tpy = i & 2 ? max.y : min.y;\n\t\t\tpz = i & 4 ? max.z : min.z;\n\t\t}\n\t\tconst tx = r00 * px + r01 * py + r02 * pz;\n\t\tconst ty = r10 * px + r11 * py + r12 * pz;\n\t\tif (tx - r < box[0]) box[0] = tx - r;\n\t\tif (ty - r < box[1]) box[1] = ty - r;\n\t\tif (tx + r > box[2]) box[2] = tx + r;\n\t\tif (ty + r > box[3]) box[3] = ty + r;\n\t}\n}\n", "/**\n * The Rapier colliders melonJS's 3D shapes become.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype BodyShape,\n\tBox3d,\n\tCapsule3d,\n\tConvexHull3d,\n\tSphere,\n\tTriangleMesh3d,\n} from \"melonjs\";\nimport type { Units, XYZ } from \"../math/units\";\nimport type { ColliderPart } from \"./types\";\n\n/**\n * The message for a shape this adapter cannot build a collider from.\n * @param shape - the shape that was refused\n * @returns the message to throw\n */\nfunction unsupportedShapeMessage(shape: BodyShape): string {\n\t// `type` rather than `constructor.name`: the class name is mangled by a\n\t// minifier and this string is most useful in a production build.\n\tconst name =\n\t\t(shape as { type?: string }).type ??\n\t\t(shape as { constructor: { name: string } }).constructor.name;\n\treturn `Rapier3dAdapter: unsupported shape type ${name}. A 3D world needs a shape with depth: this adapter builds colliders from Box3d, Sphere, Capsule3d, ConvexHull3d and TriangleMesh3d. A Rect becomes a Box3d of the same footprint, an Ellipse a Sphere.`;\n}\n\n/**\n * The colliders a list of shapes becomes, not yet in the world. A shape with\n * `isActive: false` makes none.\n * @param rapier - the Rapier module\n * @param units - the scale between pixels and meters\n * @param shapes - the shapes of a body definition\n * @returns one part per active shape\n * @throws {Error} for a shape this adapter cannot build\n */\nexport function buildColliderParts(\n\trapier: typeof RAPIER,\n\tunits: Units,\n\tshapes: BodyShape[],\n): ColliderPart[] {\n\tconst parts: ColliderPart[] = [];\n\tfor (const [index, shape] of shapes.entries()) {\n\t\t// `isActive === false` keeps a shape out of the simulation\n\t\tif ((shape as { isActive?: boolean }).isActive === false) {\n\t\t\tcontinue;\n\t\t}\n\t\tparts.push({ shape, index, ...shapeToCollider(rapier, units, shape) });\n\t}\n\treturn parts;\n}\n\n/**\n * The Rapier collider a melonJS 3D shape becomes, with its box in body space,\n * in pixels.\n * @param rapier - the Rapier module\n * @param units - the scale between pixels and meters\n * @param shape - the shape\n * @returns its collider description and box\n * @throws {Error} for a 2D shape, or anything else this adapter cannot build\n */\nfunction shapeToCollider(\n\trapier: typeof RAPIER,\n\tunits: Units,\n\tshape: BodyShape,\n): Omit<ColliderPart, \"shape\" | \"index\"> {\n\tconst { ColliderDesc } = rapier;\n\tconst m = (px: number) => {\n\t\treturn units.toMeters(px);\n\t};\n\t// the box around a centre, by its half sizes, in pixels\n\tconst box = (c: XYZ, hx: number, hy: number, hz: number) => {\n\t\treturn {\n\t\t\tmin: { x: c.x - hx, y: c.y - hy, z: c.z - hz },\n\t\t\tmax: { x: c.x + hx, y: c.y + hy, z: c.z + hz },\n\t\t};\n\t};\n\t// a collider placed at a centre given in pixels\n\tconst at = (desc: RAPIER.ColliderDesc, c: XYZ) => {\n\t\treturn desc.setTranslation(m(c.x), m(c.y), m(c.z));\n\t};\n\n\tif (shape instanceof Box3d) {\n\t\tconst h = shape.halfExtents;\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.cuboid(m(h.x), m(h.y), m(h.z)), shape.pos),\n\t\t\t...box(shape.pos, h.x, h.y, h.z),\n\t\t};\n\t}\n\n\tif (shape instanceof Sphere) {\n\t\tconst r = shape.radius;\n\t\tconst { x, y, z } = shape.pos;\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.ball(m(r)), shape.pos),\n\t\t\t...box(shape.pos, r, r, r),\n\t\t\tround: { a: { x, y, z }, b: { x, y, z }, r },\n\t\t};\n\t}\n\n\tif (shape instanceof Capsule3d) {\n\t\tconst r = shape.radius;\n\t\tconst half = shape.halfSegment;\n\t\tconst { x, y, z } = shape.pos;\n\t\t// along Y, as Rapier's own capsule\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.capsule(m(half), m(r)), shape.pos),\n\t\t\t...box(shape.pos, r, half + r, r),\n\t\t\tround: { a: { x, y: y - half, z }, b: { x, y: y + half, z }, r },\n\t\t};\n\t}\n\n\tif (shape instanceof TriangleMesh3d || shape instanceof ConvexHull3d) {\n\t\tconst source =\n\t\t\tshape instanceof TriangleMesh3d ? shape.vertices : shape.points;\n\t\tconst meters = new Float32Array(source.length);\n\t\tconst { x: ox, y: oy, z: oz } = shape.pos;\n\t\tfor (let i = 0; i < source.length; i += 3) {\n\t\t\tmeters[i] = m(source[i] + ox);\n\t\t\tmeters[i + 1] = m(source[i + 1] + oy);\n\t\t\tmeters[i + 2] = m(source[i + 2] + oz);\n\t\t}\n\t\tconst b = shape.getBounds3d();\n\t\tconst bounds = {\n\t\t\tmin: { x: b.min.x, y: b.min.y, z: b.min.z },\n\t\t\tmax: { x: b.max.x, y: b.max.y, z: b.max.z },\n\t\t};\n\t\tif (shape instanceof TriangleMesh3d) {\n\t\t\treturn { desc: ColliderDesc.trimesh(meters, shape.indices), ...bounds };\n\t\t}\n\t\tconst hull = ColliderDesc.convexHull(meters);\n\t\tif (hull !== null) {\n\t\t\treturn { desc: hull, ...bounds };\n\t\t}\n\t\t// points all in one plane have no hull: their bounding box\n\t\tconst c = {\n\t\t\tx: (bounds.min.x + bounds.max.x) / 2,\n\t\t\ty: (bounds.min.y + bounds.max.y) / 2,\n\t\t\tz: (bounds.min.z + bounds.max.z) / 2,\n\t\t};\n\t\tconst half = (lo: number, hi: number) => {\n\t\t\treturn Math.max((hi - lo) / 2, 0.5);\n\t\t};\n\t\tconst hx = half(bounds.min.x, bounds.max.x);\n\t\tconst hy = half(bounds.min.y, bounds.max.y);\n\t\tconst hz = half(bounds.min.z, bounds.max.z);\n\t\treturn {\n\t\t\tdesc: at(ColliderDesc.cuboid(m(hx), m(hy), m(hz)), c),\n\t\t\t...box(c, hx, hy, hz),\n\t\t};\n\t}\n\n\t// refused loudly rather than skipped, as on the other adapters\n\tthrow new Error(unsupportedShapeMessage(shape));\n}\n", "/**\n * Collision events: Rapier's start and end events, and every pair still\n * touching once a frame, turned into melonJS's collision hooks.\n *\n * On each renderable of a pair it fires the shape-level hook\n * (`onShapeCollisionStart`, `\u2026Active`, `\u2026End`), then the body-level one\n * (`onCollisionStart`, `onCollisionActive` or the legacy `onCollision`,\n * `onCollisionEnd`). A hook may take a body out of the world, even one of the\n * pair it is told about: the bookkeeping here makes sure no one hears of an\n * end before its start, nor of anything once its body is gone.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderEntry } from \"../colliders/types\";\nimport type { Simulation } from \"../Simulation\";\n\ntype Phase = \"start\" | \"active\" | \"end\";\n\n/** Which hooks of a pair a dispatch reaches: one bit per side and level. */\nconst SIDE_A = 1;\nconst SIDE_B = 2;\nconst SHAPE_A = 4;\nconst SHAPE_B = 8;\nconst EVERY_SIDE = SIDE_A | SIDE_B | SHAPE_A | SHAPE_B;\n\n/**\n * A pair whose start or active hooks are running. When one of them takes a\n * body of the pair out, the contact's end is told in the order a hook can\n * rely on: to the side going out at once, while it is whole, and to the other\n * once the hooks are done; and only to a side that heard the start.\n */\ninterface Dispatch {\n\tkey: string;\n\th1: number;\n\th2: number;\n\te1: ColliderEntry;\n\te2: ColliderEntry;\n\t/** the sides that may hear the end: those the start reached */\n\treached: number;\n\t/** the sides already told the end */\n\ttold: number;\n\t/** true once a body of the pair was taken out */\n\tended: boolean;\n}\n\n/**\n * A key for an unordered pair of colliders.\n * @param h1 - one collider handle\n * @param h2 - the other\n * @returns the same key for (h1, h2) and (h2, h1)\n */\nfunction pairKey(h1: number, h2: number): string {\n\treturn h1 < h2 ? `${h1}:${h2}` : `${h2}:${h1}`;\n}\n\nexport class ContactDispatcher {\n\t/** touching pairs, from Rapier's start events until their end */\n\treadonly activePairs = new Map<string, [number, number]>();\n\tprivate readonly sim: Simulation;\n\tprivate eventQueue!: RAPIER.EventQueue;\n\t/** a step's events, collected before any is dispatched */\n\tprivate readonly pendingEvents: number[] = [];\n\t/** the pairs whose start or active hooks are running, innermost last */\n\tprivate readonly dispatching: Dispatch[] = [];\n\n\t/**\n\t * @param sim - the simulation it reports on\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * The queue Rapier writes a step's start and end events to.\n\t * @returns the event queue to pass to `world.step`\n\t */\n\tget queue(): RAPIER.EventQueue {\n\t\treturn this.eventQueue;\n\t}\n\n\t/** Make the event queue, with the Rapier world. */\n\topen(): void {\n\t\tthis.eventQueue = new this.sim.rapier.EventQueue(true);\n\t}\n\n\t/** Free the event queue, and forget every pair. */\n\tclose(): void {\n\t\tthis.eventQueue.free();\n\t\tthis.activePairs.clear();\n\t\tthis.pendingEvents.length = 0;\n\t\tthis.dispatching.length = 0;\n\t}\n\n\t/**\n\t * Dispatch the start and end events Rapier queued during the last step.\n\t * They are all read before any is dispatched, so a handler that removes a\n\t * body cannot disturb the queue.\n\t */\n\tdispatchQueuedEvents(): void {\n\t\tconst events = this.pendingEvents;\n\t\tevents.length = 0;\n\t\tthis.eventQueue.drainCollisionEvents((h1, h2, started) => {\n\t\t\tevents.push(h1, h2, started ? 1 : 0);\n\t\t});\n\t\tfor (let i = 0; i < events.length; i += 3) {\n\t\t\tconst h1 = events[i];\n\t\t\tconst h2 = events[i + 1];\n\t\t\tconst key = pairKey(h1, h2);\n\t\t\tif (events[i + 2] === 1) {\n\t\t\t\t// a hook earlier in this step may have taken one of them out\n\t\t\t\tif (this.sim.colliders.has(h1) && this.sim.colliders.has(h2)) {\n\t\t\t\t\tthis.activePairs.set(key, [h1, h2]);\n\t\t\t\t\tthis.dispatchPair(h1, h2, \"start\");\n\t\t\t\t}\n\t\t\t} else if (this.activePairs.delete(key)) {\n\t\t\t\t// a pair already ended (one of its bodies was removed) is not\n\t\t\t\t// ended twice\n\t\t\t\tthis.dispatchPair(h1, h2, \"end\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Once per frame: the active hooks of every pair still touching. */\n\tdispatchActiveContacts(): void {\n\t\tfor (const [h1, h2] of this.activePairs.values()) {\n\t\t\tthis.dispatchPair(h1, h2, \"active\");\n\t\t}\n\t}\n\n\t/**\n\t * Tell the pairs touching colliders that are about to go that their\n\t * contact ended. The colliders must still be known: forget them after.\n\t * @param colliders - the colliders leaving the world\n\t */\n\tendContacts(colliders: RAPIER.Collider[]): void {\n\t\tconst handles = new Set(\n\t\t\tcolliders.map((c) => {\n\t\t\t\treturn c.handle;\n\t\t\t}),\n\t\t);\n\t\t// a pair whose start or active hooks are running: the side going out\n\t\t// hears the end now, the other once those hooks are done, so that no\n\t\t// one hears of an end before its start\n\t\tfor (const d of this.dispatching) {\n\t\t\tconst going =\n\t\t\t\t(handles.has(d.h1) ? SIDE_A | SHAPE_A : 0) |\n\t\t\t\t(handles.has(d.h2) ? SIDE_B | SHAPE_B : 0);\n\t\t\tif (going !== 0 && (this.activePairs.delete(d.key) || d.ended)) {\n\t\t\t\td.ended = true;\n\t\t\t\tconst sides = going & d.reached & ~d.told;\n\t\t\t\td.told |= sides;\n\t\t\t\tthis.dispatch(d.e1, d.e2, d.h1, d.h2, \"end\", sides);\n\t\t\t}\n\t\t}\n\t\tfor (const [key, [h1, h2]] of this.activePairs) {\n\t\t\tif (handles.has(h1) || handles.has(h2)) {\n\t\t\t\tthis.activePairs.delete(key);\n\t\t\t\tthis.dispatchPair(h1, h2, \"end\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Fire the hooks of one pair of colliders, on both renderables. A start or\n\t * active hook may take a body of the pair out: see {@link Dispatch}.\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @param phase - which lifecycle hook to fire\n\t */\n\tprivate dispatchPair(h1: number, h2: number, phase: Phase): void {\n\t\tconst e1 = this.sim.colliders.get(h1);\n\t\tconst e2 = this.sim.colliders.get(h2);\n\t\tif (e1 === undefined || e2 === undefined) return;\n\t\tif (phase === \"end\") {\n\t\t\tthis.dispatch(e1, e2, h1, h2, phase, EVERY_SIDE);\n\t\t\treturn;\n\t\t}\n\t\tconst current: Dispatch = {\n\t\t\tkey: pairKey(h1, h2),\n\t\t\th1,\n\t\t\th2,\n\t\t\te1,\n\t\t\te2,\n\t\t\t// a pair already active had its start on every side\n\t\t\treached: phase === \"start\" ? 0 : EVERY_SIDE,\n\t\t\ttold: 0,\n\t\t\tended: false,\n\t\t};\n\t\tthis.dispatching.push(current);\n\t\ttry {\n\t\t\tthis.dispatch(\n\t\t\t\te1,\n\t\t\t\te2,\n\t\t\t\th1,\n\t\t\t\th2,\n\t\t\t\tphase,\n\t\t\t\tEVERY_SIDE,\n\t\t\t\tphase === \"start\" ? current : undefined,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.dispatching.splice(this.dispatching.indexOf(current), 1);\n\t\t}\n\t\tif (current.ended) {\n\t\t\tthis.dispatch(e1, e2, h1, h2, \"end\", current.reached & ~current.told);\n\t\t}\n\t}\n\n\t/**\n\t * Fire one phase of a pair's hooks: the shape-level ones, then the\n\t * renderables' own. A renderable whose body is gone hears nothing.\n\t * @param e1 - the first collider's entry\n\t * @param e2 - the second collider's entry\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @param phase - which lifecycle hook to fire\n\t * @param sides - the sides and levels to fire it on, as bits\n\t * @param [record] - where to note each side reached, before its hook runs\n\t */\n\tprivate dispatch(\n\t\te1: ColliderEntry,\n\t\te2: ColliderEntry,\n\t\th1: number,\n\t\th2: number,\n\t\tphase: Phase,\n\t\tsides: number,\n\t\trecord?: Dispatch,\n\t): void {\n\t\tconst rA = e1.renderable;\n\t\tconst rB = e2.renderable;\n\t\t// skip start/active when either side has left the world; an end still\n\t\t// reaches the side that remains\n\t\tconst ancA = (rA as Renderable & { ancestor?: object | null }).ancestor;\n\t\tconst ancB = (rB as Renderable & { ancestor?: object | null }).ancestor;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: ancestor is set to null by Container on removeChild\n\t\tconst aDetached = ancA === null;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: ancestor is set to null by Container on removeChild\n\t\tconst bDetached = ancB === null;\n\t\tif (phase === \"end\") {\n\t\t\tif (aDetached && bDetached) return;\n\t\t} else if (aDetached || bDetached) {\n\t\t\treturn;\n\t\t}\n\t\t// a hook earlier in this dispatch may have removed a body: its\n\t\t// renderable hears nothing from then on\n\t\tconst reaches = (side: number, receiver: Renderable, detached: boolean) => {\n\t\t\tif ((sides & side) === 0 || detached || !this.sim.bodies.has(receiver)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (record !== undefined) {\n\t\t\t\trecord.reached |= side;\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\t// a separated pair has no contact: identity only\n\t\tconst { nx, ny, nz, depth } =\n\t\t\tphase === \"end\"\n\t\t\t\t? { nx: 0, ny: 0, nz: 0, depth: 0 }\n\t\t\t\t: this.contact(h1, h2);\n\n\t\t// each melonJS shape is one collider, so Rapier's events name the\n\t\t// shapes: the shape-level hooks first\n\t\tconst shapeMethod =\n\t\t\tphase === \"start\"\n\t\t\t\t? \"onShapeCollisionStart\"\n\t\t\t\t: phase === \"end\"\n\t\t\t\t\t? \"onShapeCollisionEnd\"\n\t\t\t\t\t: \"onShapeCollisionActive\";\n\t\tconst isTrigger =\n\t\t\t(e1.shape as { isTrigger?: boolean }).isTrigger === true ||\n\t\t\t(e2.shape as { isTrigger?: boolean }).isTrigger === true;\n\t\tconst emitShape = (\n\t\t\town: ColliderEntry,\n\t\t\tother: ColliderEntry,\n\t\t\tsign: number,\n\t\t): void => {\n\t\t\tconst receiver = own.renderable;\n\t\t\tconst fn = (receiver as Renderable & Record<string, unknown>)[\n\t\t\t\tshapeMethod\n\t\t\t];\n\t\t\tif (typeof fn !== \"function\") return;\n\t\t\t// (`+ 0` keeps a zero normal from reading as -0)\n\t\t\tconst ownNx = sign * nx + 0;\n\t\t\tconst ownNy = sign * ny + 0;\n\t\t\tconst ownNz = sign * nz + 0;\n\t\t\t(fn as (contact: unknown, other: Renderable) => unknown).call(\n\t\t\t\treceiver,\n\t\t\t\t{\n\t\t\t\t\ta: receiver,\n\t\t\t\t\tb: other.renderable,\n\t\t\t\t\tshapeA: own.shape,\n\t\t\t\t\tshapeB: other.shape,\n\t\t\t\t\tindexShapeA: own.index,\n\t\t\t\t\tindexShapeB: other.index,\n\t\t\t\t\tisTrigger,\n\t\t\t\t\tdepth,\n\t\t\t\t\toverlap: depth,\n\t\t\t\t\tnormal: { x: ownNx, y: ownNy },\n\t\t\t\t\tnormalZ: ownNz,\n\t\t\t\t\t// the SAT fields, in the builtin's convention\n\t\t\t\t\toverlapN: { x: -ownNx + 0, y: -ownNy + 0 },\n\t\t\t\t\toverlapNZ: -ownNz + 0,\n\t\t\t\t\toverlapV: { x: -ownNx * depth + 0, y: -ownNy * depth + 0 },\n\t\t\t\t\toverlapZ: -ownNz * depth + 0,\n\t\t\t\t},\n\t\t\t\tother.renderable,\n\t\t\t);\n\t\t};\n\t\t// the normal points from A to B: A escapes along its opposite, B\n\t\t// along it\n\t\tif (reaches(SHAPE_A, rA, aDetached)) {\n\t\t\temitShape(e1, e2, -1);\n\t\t}\n\t\tif (reaches(SHAPE_B, rB, bDetached)) {\n\t\t\temitShape(e2, e1, 1);\n\t\t}\n\n\t\t// then the renderables' own hooks\n\t\tconst bodyMethod = (receiver: Renderable): string => {\n\t\t\tif (phase === \"start\") return \"onCollisionStart\";\n\t\t\tif (phase === \"end\") return \"onCollisionEnd\";\n\t\t\treturn typeof (receiver as Renderable & { onCollisionActive?: unknown })\n\t\t\t\t.onCollisionActive === \"function\"\n\t\t\t\t? \"onCollisionActive\"\n\t\t\t\t: \"onCollision\";\n\t\t};\n\t\tconst pair = { collider1: h1, collider2: h2 };\n\t\tconst emit = (receiver: Renderable, other: Renderable, sign: number) => {\n\t\t\tconst fn = (receiver as Renderable & Record<string, unknown>)[\n\t\t\t\tbodyMethod(receiver)\n\t\t\t];\n\t\t\tif (typeof fn !== \"function\") return;\n\t\t\t(fn as (response: unknown, other: Renderable) => unknown).call(\n\t\t\t\treceiver,\n\t\t\t\t{\n\t\t\t\t\ta: receiver,\n\t\t\t\t\tb: other,\n\t\t\t\t\tnormal: { x: sign * nx + 0, y: sign * ny + 0, z: sign * nz + 0 },\n\t\t\t\t\tdepth,\n\t\t\t\t\tpair,\n\t\t\t\t},\n\t\t\t\tother,\n\t\t\t);\n\t\t};\n\t\tif (reaches(SIDE_A, rA, aDetached)) {\n\t\t\temit(rA, rB, -1);\n\t\t}\n\t\tif (reaches(SIDE_B, rB, bDetached)) {\n\t\t\temit(rB, rA, 1);\n\t\t}\n\t}\n\n\t/**\n\t * The contact between two colliders: the normal from the first to the\n\t * second, and how deep they overlap, in pixels. Zero for a sensor pair,\n\t * which Rapier computes no contact for.\n\t * @param h1 - the first collider handle\n\t * @param h2 - the second\n\t * @returns the normal and the depth\n\t */\n\tprivate contact(\n\t\th1: number,\n\t\th2: number,\n\t): { nx: number; ny: number; nz: number; depth: number } {\n\t\tconst { world, units } = this.sim;\n\t\tconst c1 = world.getCollider(h1);\n\t\tconst c2 = world.getCollider(h2);\n\t\tlet nx = 0;\n\t\tlet ny = 0;\n\t\tlet nz = 0;\n\t\tlet depth = 0;\n\t\tif (c1.isSensor() || c2.isSensor()) {\n\t\t\treturn { nx, ny, nz, depth };\n\t\t}\n\t\tworld.contactPair(c1, c2, (manifold, flipped) => {\n\t\t\tconst count = manifold.numContacts();\n\t\t\tif (count === 0) return;\n\t\t\tconst n = manifold.normal();\n\t\t\tlet deepest = 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tconst d = -manifold.contactDist(i);\n\t\t\t\tif (d > deepest) deepest = d;\n\t\t\t}\n\t\t\tif (deepest >= depth) {\n\t\t\t\tdepth = deepest;\n\t\t\t\tconst s = flipped ? -1 : 1;\n\t\t\t\tnx = s * n.x;\n\t\t\t\tny = s * n.y;\n\t\t\t\tnz = s * n.z;\n\t\t\t}\n\t\t});\n\t\treturn { nx, ny, nz, depth: units.toPixels(depth) };\n\t}\n}\n", "/**\n * The joints `world.addJoint()` makes between bodies.\n *\n * A `\"hinge\"` is a Rapier revolute joint about `axis` (default Z), a `\"rope\"`\n * a rope joint, a `\"weld\"` a fixed joint and a `\"slider\"` a prismatic joint\n * along `axis` (default X). The bodies are joined as they stand, however each\n * is turned: a weld and a slider keep the turn between them, and a hinge\n * leaves them only the turn about its axis.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport { Quaternion, Vector3d } from \"melonjs\";\nimport type { XYZ } from \"../math/units\";\nimport type { Simulation } from \"../Simulation\";\nimport type { Rapier3dJointDefinition, Vector3Like } from \"../types\";\n\nconst NO_TURN = { x: 0, y: 0, z: 0, w: 1 };\n\nexport class Joints {\n\tprivate readonly sim: Simulation;\n\t/** the joints made here that are still alive */\n\tprivate readonly made = new Set<RAPIER.ImpulseJoint>();\n\n\t/**\n\t * @param sim - the simulation whose bodies it joins\n\t */\n\tconstructor(sim: Simulation) {\n\t\tthis.sim = sim;\n\t}\n\n\t/**\n\t * Make a joint between two bodies. Anchors are in each renderable's own\n\t * space, relative to its `pos`, in pixels, and the axis in `a`'s; a `z`\n\t * left out is `0`.\n\t * @param def - what to join, and how, in pixels and radians\n\t * @returns the Rapier joint\n\t */\n\tadd(def: Rapier3dJointDefinition): RAPIER.ImpulseJoint {\n\t\tconst { bodies, rapier, units, world } = this.sim;\n\t\tconst bodyA = bodies.get(def.a);\n\t\tconst bodyB = bodies.get(def.b);\n\t\tif (bodyA === undefined || bodyB === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"@melonjs/rapier3d-adapter: addJoint() needs both renderables to have a body in the world; add them with addChild() first.\",\n\t\t\t);\n\t\t}\n\t\tconst { JointData } = rapier;\n\t\tconst anchorB = this.localAnchor(def.anchorB);\n\t\t// no anchor on `a`: the point of `a` under b's anchor, so nothing moves\n\t\t// when the joint is made; a rope joins the two centres\n\t\tconst anchorA =\n\t\t\tdef.anchorA === undefined && def.type !== \"rope\"\n\t\t\t\t? localPoint(bodyA, worldPoint(bodyB, anchorB))\n\t\t\t\t: this.localAnchor(def.anchorA);\n\t\t// the defaults resolved here are written back, so the same joint is\n\t\t// made again when the world rebuilds it\n\t\tdef.anchorA ??= {\n\t\t\tx: units.toPixels(anchorA.x),\n\t\t\ty: units.toPixels(anchorA.y),\n\t\t\tz: units.toPixels(anchorA.z),\n\t\t};\n\t\tdef.anchorB ??= { x: 0, y: 0, z: 0 };\n\t\t// the turn that brings b's space onto a's, as the two stand\n\t\tconst aInB = turnOf(bodyB).invert().multiply(turnOf(bodyA));\n\n\t\tlet data: RAPIER.JointData;\n\t\tswitch (def.type) {\n\t\t\tcase \"hinge\": {\n\t\t\t\t// the same axis in the world, in each body's own space: the same\n\t\t\t\t// vector in both when they are turned alike, or apart about the\n\t\t\t\t// axis only, as a 2D hinge is\n\t\t\t\tconst axis = unitAxis(def.axis, { x: 0, y: 0, z: 1 });\n\t\t\t\tdata = JointData.revoluteWithAxes(\n\t\t\t\t\tanchorA,\n\t\t\t\t\tanchorB,\n\t\t\t\t\taxis,\n\t\t\t\t\taInB.apply(new Vector3d(axis.x, axis.y, axis.z)),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"rope\": {\n\t\t\t\tif (def.maxLength === undefined) {\n\t\t\t\t\tconst pa = worldPoint(bodyA, anchorA);\n\t\t\t\t\tconst pb = worldPoint(bodyB, anchorB);\n\t\t\t\t\tdef.maxLength = units.toPixels(\n\t\t\t\t\t\tMath.hypot(pb.x - pa.x, pb.y - pa.y, pb.z - pa.z),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdata = JointData.rope(units.toMeters(def.maxLength), anchorA, anchorB);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"weld\":\n\t\t\t\t// welded as they stand: A's frame is A, B's frame is the turn\n\t\t\t\t// that brings B onto A\n\t\t\t\tdata = JointData.fixed(anchorA, NO_TURN, anchorB, aInB);\n\t\t\t\tbreak;\n\t\t\tcase \"slider\":\n\t\t\t\tdata = JointData.prismatic(\n\t\t\t\t\tanchorA,\n\t\t\t\t\tanchorB,\n\t\t\t\t\tunitAxis(def.axis, { x: 1, y: 0, z: 0 }),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@melonjs/rapier3d-adapter: unknown joint type \"${String((def as { type: unknown }).type)}\"; use \"hinge\", \"rope\", \"weld\" or \"slider\".`,\n\t\t\t\t);\n\t\t}\n\n\t\tconst joint = world.createImpulseJoint(data, bodyA, bodyB, true);\n\t\tif (def.type === \"slider\") {\n\t\t\t// Rapier gives both bodies the same frame, which would turn b onto\n\t\t\t// a: b's frame is a's as b sees it, so b keeps its turn\n\t\t\tconst frame = joint.frameX1();\n\t\t\tjoint.setFrameX2(\n\t\t\t\taInB\n\t\t\t\t\t.clone()\n\t\t\t\t\t.multiply(new Quaternion(frame.x, frame.y, frame.z, frame.w)),\n\t\t\t);\n\t\t}\n\t\tjoint.setContactsEnabled(def.collideConnected === true);\n\t\tif (\n\t\t\tdef.limits !== undefined &&\n\t\t\t(def.type === \"hinge\" || def.type === \"slider\")\n\t\t) {\n\t\t\t// radians for a hinge, meters along the axis for a slider\n\t\t\tconst scale = def.type === \"slider\" ? 1 / units.pixelsPerMeter : 1;\n\t\t\t(joint as RAPIER.UnitImpulseJoint).setLimits(\n\t\t\t\tdef.limits.min * scale,\n\t\t\t\tdef.limits.max * scale,\n\t\t\t);\n\t\t}\n\t\tthis.made.add(joint);\n\t\treturn joint;\n\t}\n\n\t/**\n\t * Remove a joint made here. A joint already gone, with one of its bodies,\n\t * is ignored.\n\t * @param joint - the Rapier joint\n\t */\n\tremove(joint: RAPIER.ImpulseJoint): void {\n\t\tif (this.made.delete(joint) && joint.isValid()) {\n\t\t\tthis.sim.world.removeImpulseJoint(joint, true);\n\t\t}\n\t}\n\n\t/**\n\t * Forget the joints of a body about to be removed: Rapier removes them\n\t * with it.\n\t * @param body - the body\n\t */\n\tforgetJointsOf(body: RAPIER.RigidBody): void {\n\t\tfor (const joint of this.made) {\n\t\t\tif (\n\t\t\t\t!joint.isValid() ||\n\t\t\t\tjoint.body1().handle === body.handle ||\n\t\t\t\tjoint.body2().handle === body.handle\n\t\t\t) {\n\t\t\t\tthis.made.delete(joint);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Forget every joint. */\n\tclear(): void {\n\t\tthis.made.clear();\n\t}\n\n\t/**\n\t * A joint anchor in pixels as a point on its body in meters. No anchor is\n\t * the body's origin, its renderable's `pos`.\n\t * @param anchor - the anchor in pixels, or undefined\n\t * @returns the body-local anchor\n\t */\n\tprivate localAnchor(anchor?: Vector3Like): XYZ {\n\t\tif (anchor === undefined) {\n\t\t\treturn { x: 0, y: 0, z: 0 };\n\t\t}\n\t\treturn this.sim.units.inMeters(anchor.x, anchor.y, anchor.z ?? 0);\n\t}\n}\n\n/**\n * A joint axis as a unit vector, or the default for a missing one.\n * @param axis - the axis given, if any\n * @param fallback - the default\n * @returns a unit vector\n * @throws {Error} for a zero or non-finite axis\n */\nfunction unitAxis(axis: Vector3Like | undefined, fallback: XYZ): XYZ {\n\tif (axis === undefined) {\n\t\treturn fallback;\n\t}\n\tconst z = axis.z ?? 0;\n\tconst length = Math.hypot(axis.x, axis.y, z);\n\tif (!(length > 0) || !Number.isFinite(length)) {\n\t\tthrow new Error(\n\t\t\t\"@melonjs/rapier3d-adapter: a joint axis needs a length; got a zero or non-finite vector.\",\n\t\t);\n\t}\n\treturn { x: axis.x / length, y: axis.y / length, z: z / length };\n}\n\n/**\n * A world point as a point on a body, both in meters.\n * @param body - the body\n * @param world - the point in the world\n * @returns the point on the body\n */\nfunction localPoint(body: RAPIER.RigidBody, world: XYZ): XYZ {\n\tconst t = body.translation();\n\treturn turnOf(body).applyInverse(\n\t\tnew Vector3d(world.x - t.x, world.y - t.y, world.z - t.z),\n\t);\n}\n\n/**\n * A body-local point in world space, both in meters.\n * @param body - the body\n * @param local - the point on the body\n * @returns the point in the world\n */\nfunction worldPoint(body: RAPIER.RigidBody, local: XYZ): XYZ {\n\tconst t = body.translation();\n\tconst p = turnOf(body).apply(new Vector3d(local.x, local.y, local.z));\n\treturn { x: t.x + p.x, y: t.y + p.y, z: t.z + p.z };\n}\n\n/**\n * A body's turn, as a quaternion of its own.\n * @param body - the body\n * @returns a new quaternion\n */\nfunction turnOf(body: RAPIER.RigidBody): Quaternion {\n\tconst q = body.rotation();\n\treturn new Quaternion(q.x, q.y, q.z, q.w);\n}\n", "/**\n * Loading Rapier: its WebAssembly is downloaded and compiled once, and every\n * adapter shares the result.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\n\n/** The Rapier module, once {@link loadRapier} has compiled it. */\nlet rapier: typeof RAPIER | undefined;\n/** The load in progress or done, shared by every caller. */\nlet loading: Promise<void> | undefined;\n\n/**\n * Download and compile Rapier's WebAssembly. Every call returns the same\n * promise; a failed load rejects, and a later call tries again.\n *\n * Rapier is imported with `import()`, so bundlers put it in a chunk of its\n * own, downloaded only when this is called.\n * @returns a promise that resolves once Rapier is ready\n */\nexport function loadRapier(): Promise<void> {\n\tloading ??= import(\"@dimforge/rapier3d-compat\")\n\t\t.then(async (module) => {\n\t\t\t// decode the embedded bytes and compile the WebAssembly\n\t\t\tawait module.init();\n\t\t\trapier = module;\n\t\t})\n\t\t.catch((error: unknown) => {\n\t\t\tloading = undefined;\n\t\t\tthrow error;\n\t\t});\n\treturn loading;\n}\n\n/**\n * The Rapier module, if it has been loaded.\n * @returns the module, or `undefined` before {@link loadRapier} finishes\n */\nexport function loadedRapier(): typeof RAPIER | undefined {\n\treturn rapier;\n}\n", "/**\n * Asking the world what is where: the ray cast, the box and sphere queries,\n * and whether a body stands on something.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport {\n\ttype RaycastHit3d,\n\ttype Rect,\n\ttype Renderable,\n\tSphere,\n\tVector3d,\n} from \"melonjs\";\nimport { emptyFootprint, growFootprint } from \"../colliders/footprint\";\nimport type { Simulation } from \"../Simulation\";\n\n/**\n * How far UP a contact normal must point for {@link isGrounded} to count the\n * contact as ground, as on the 2D adapters: the upward component (`-y`, the\n * engine being Y-down) of the unit normal the body is pushed along.\n */\nconst GROUND_NORMAL_Y = 0.1;\n\n/**\n * Half the depth `queryAABB` searches through, in meters: a 2D rectangle\n * query in a 3D world finds what lies over that rectangle at any depth.\n */\nconst QUERY_HALF_DEPTH = 1e7;\n\n/**\n * The first collider a segment meets, from `from` to `to`, in world pixels:\n * the exact shape, not a bounding volume. A shape the ray starts inside is\n * skipped, so a body casting from its own centre does not hit itself.\n * Sensors are hit like any other body.\n * @param sim - the simulation\n * @param from - where the ray starts\n * @param to - where it ends\n * @returns the hit, or `null`\n */\nexport function raycast3d(\n\tsim: Simulation,\n\tfrom: Vector3d,\n\tto: Vector3d,\n): RaycastHit3d | null {\n\t// nothing to hit once the Rapier world is freed\n\tif (!sim.alive) return null;\n\tconst { units, world } = sim;\n\tconst origin = units.inMeters(from.x, from.y, from.z);\n\tconst dir = units.inMeters(to.x - from.x, to.y - from.y, to.z - from.z);\n\tif (dir.x === 0 && dir.y === 0 && dir.z === 0) return null;\n\tconst ray = new sim.rapier.Ray(origin, dir);\n\tconst hit = world.castRayAndGetNormal(\n\t\tray,\n\t\t1,\n\t\ttrue,\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\tundefined,\n\t\t(collider) => {\n\t\t\treturn !collider.containsPoint(origin);\n\t\t},\n\t);\n\tif (hit === null) return null;\n\tconst entry = sim.colliders.get(hit.collider.handle);\n\tif (entry === undefined) return null;\n\tconst toi = hit.timeOfImpact;\n\treturn {\n\t\trenderable: entry.renderable,\n\t\tpoint: new Vector3d(\n\t\t\tunits.toPixels(origin.x + dir.x * toi),\n\t\t\tunits.toPixels(origin.y + dir.y * toi),\n\t\t\tunits.toPixels(origin.z + dir.z * toi),\n\t\t),\n\t\tnormal: new Vector3d(hit.normal.x, hit.normal.y, hit.normal.z),\n\t\tfraction: toi,\n\t};\n}\n\n/**\n * The renderables whose colliders' boxes overlap a rectangle in XY, at any\n * depth: the boxes `getBodyAABB` reports.\n * @param sim - the simulation\n * @param rect - the rectangle, in world pixels\n * @returns the renderables, each once\n */\nexport function queryAABB(sim: Simulation, rect: Rect): Renderable[] {\n\tconst { units, world } = sim;\n\tconst { x, y } = rect.pos;\n\treturn collect(sim, (visit) => {\n\t\tworld.collidersWithAabbIntersectingAabb(\n\t\t\t{\n\t\t\t\tx: units.toMeters(x + rect.width / 2),\n\t\t\t\ty: units.toMeters(y + rect.height / 2),\n\t\t\t\tz: 0,\n\t\t\t},\n\t\t\t{\n\t\t\t\tx: units.toMeters(rect.width / 2),\n\t\t\t\ty: units.toMeters(rect.height / 2),\n\t\t\t\tz: QUERY_HALF_DEPTH,\n\t\t\t},\n\t\t\t(collider) => {\n\t\t\t\t// Rapier keeps its own boxes loose, more so around a body that\n\t\t\t\t// moves: those are the candidates, tested here\n\t\t\t\tconst entry = sim.colliders.get(collider.handle);\n\t\t\t\tconst body = collider.parent();\n\t\t\t\tif (entry === undefined || body === null) return true;\n\t\t\t\tconst box = emptyFootprint();\n\t\t\t\tgrowFootprint(entry, body.rotation(), box);\n\t\t\t\tconst t = body.translation();\n\t\t\t\tconst bx = units.toPixels(t.x);\n\t\t\t\tconst by = units.toPixels(t.y);\n\t\t\t\treturn bx + box[0] <= x + rect.width &&\n\t\t\t\t\tbx + box[2] >= x &&\n\t\t\t\t\tby + box[1] <= y + rect.height &&\n\t\t\t\t\tby + box[3] >= y\n\t\t\t\t\t? visit(collider)\n\t\t\t\t\t: true;\n\t\t\t},\n\t\t);\n\t});\n}\n\n/**\n * The renderables whose colliders overlap a sphere: their exact shapes.\n * @param sim - the simulation\n * @param center - the centre in world pixels, or a {@link Sphere}\n * @param [radius] - the radius in pixels, with a centre; none, or less than\n * none, is a point\n * @returns the renderables, each once\n */\nexport function querySphere(\n\tsim: Simulation,\n\tcenter: Vector3d | Sphere,\n\tradius?: number,\n): Renderable[] {\n\tconst { units } = sim;\n\tconst isSphere = center instanceof Sphere;\n\tconst c = isSphere ? center.pos : center;\n\tconst r = isSphere ? center.radius : (radius ?? 0);\n\tconst ball = new sim.rapier.Ball(units.toMeters(Math.max(r, 0)));\n\treturn collect(sim, (visit) => {\n\t\tsim.world.intersectionsWithShape(\n\t\t\tunits.inMeters(c.x, c.y, c.z),\n\t\t\t{ x: 0, y: 0, z: 0, w: 1 },\n\t\t\tball,\n\t\t\tvisit,\n\t\t);\n\t});\n}\n\n/**\n * Whether a body stands on something: a touching contact that pushes it UP,\n * as on the 2D adapters. A sensor pushes nothing, so a sensor contact counts\n * when the other body's centre is below this one's.\n * @param sim - the simulation\n * @param renderable - the body's renderable\n * @returns true while it is grounded\n */\nexport function isGrounded(sim: Simulation, renderable: Renderable): boolean {\n\tconst body = sim.bodies.get(renderable);\n\tif (!body) return false;\n\tconst { world } = sim;\n\tconst bodyY = body.translation().y;\n\tfor (const collider of sim.collidersOf.get(renderable) ?? []) {\n\t\tlet grounded = false;\n\t\tworld.intersectionPairsWith(collider, (other) => {\n\t\t\tconst parent = other.parent();\n\t\t\tif (\n\t\t\t\t!grounded &&\n\t\t\t\tparent !== null &&\n\t\t\t\tworld.intersectionPair(collider, other) &&\n\t\t\t\tparent.translation().y > bodyY\n\t\t\t) {\n\t\t\t\tgrounded = true;\n\t\t\t}\n\t\t});\n\t\tworld.contactPairsWith(collider, (other) => {\n\t\t\tif (grounded) return;\n\t\t\tworld.contactPair(collider, other, (manifold, flipped) => {\n\t\t\t\tif (manifold.numContacts() === 0) return;\n\t\t\t\tconst ny = flipped ? -manifold.normal().y : manifold.normal().y;\n\t\t\t\t// this body is pushed along the opposite of the normal\n\t\t\t\tif (-ny < -GROUND_NORMAL_Y) {\n\t\t\t\t\tgrounded = true;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\tif (grounded) return true;\n\t}\n\treturn false;\n}\n\n/**\n * The renderables a Rapier query visits, each once.\n * @param sim - the simulation\n * @param query - runs the query with the visitor\n * @returns the renderables\n */\nfunction collect(\n\tsim: Simulation,\n\tquery: (visit: (collider: RAPIER.Collider) => boolean) => void,\n): Renderable[] {\n\tconst result: Renderable[] = [];\n\t// nothing to find once the Rapier world is freed\n\tif (!sim.alive) return result;\n\tconst seen = new Set<Renderable>();\n\tquery((collider) => {\n\t\tconst entry = sim.colliders.get(collider.handle);\n\t\tif (entry !== undefined && !seen.has(entry.renderable)) {\n\t\t\tseen.add(entry.renderable);\n\t\t\tresult.push(entry.renderable);\n\t\t}\n\t\treturn true;\n\t});\n\treturn result;\n}\n", "/**\n * What every part of the adapter shares: the Rapier module, the units, the\n * Rapier world, and which body and colliders each renderable has.\n */\nimport type * as RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { Renderable } from \"melonjs\";\nimport type { ColliderEntry } from \"./colliders/types\";\nimport type { Units } from \"./math/units\";\n\nexport class Simulation {\n\treadonly rapier: typeof RAPIER;\n\treadonly units: Units;\n\t/** The Rapier world: made by {@link open}, freed by {@link close}. */\n\tworld!: RAPIER.World;\n\t/** true between {@link open} and {@link close}: the Rapier world exists */\n\talive = false;\n\n\t/** each renderable's body */\n\treadonly bodies = new Map<Renderable, RAPIER.RigidBody>();\n\t/** each renderable's colliders, one per active shape */\n\treadonly collidersOf = new Map<Renderable, RAPIER.Collider[]>();\n\t/** collider handle -> its renderable, shape and box */\n\treadonly colliders = new Map<number, ColliderEntry>();\n\n\t/**\n\t * @param rapier - the loaded Rapier module\n\t * @param units - the scale between pixels and meters\n\t */\n\tconstructor(rapier: typeof RAPIER, units: Units) {\n\t\tthis.rapier = rapier;\n\t\tthis.units = units;\n\t}\n\n\t/**\n\t * Make the Rapier world.\n\t * @param gravity - its gravity, in meters per second\u00B2\n\t */\n\topen(gravity: RAPIER.Vector) {\n\t\tthis.world = new this.rapier.World(gravity);\n\t\tthis.alive = true;\n\t}\n\n\t/** Free the Rapier world, and forget every body and collider. */\n\tclose() {\n\t\tthis.alive = false;\n\t\t// Rapier's objects live in WebAssembly memory, which the garbage\n\t\t// collector does not reclaim: they are freed here\n\t\tthis.world.free();\n\t\tthis.bodies.clear();\n\t\tthis.collidersOf.clear();\n\t\tthis.colliders.clear();\n\t}\n}\n", "/**\n * The adapter's public types: its options, the joints it makes, and the\n * vectors it takes.\n */\nimport type { Renderable } from \"melonjs\";\n\n/**\n * Minimum melonJS version this adapter requires: the lower bound of its\n * `melonjs` peer dependency range, so the two cannot disagree. 20.16 is the\n * first with the 3D shapes and the 3D adapter interface.\n * @hidden\n */\nexport const REQUIRED_MELONJS_VERSION = \"20.16.0\";\n\n/**\n * A point or a vector in pixels whose `z` may be left out: a\n * {@link Vector3d}, a {@link Vector2d} or a plain object. What a missing `z`\n * means is said where it is taken.\n */\nexport interface Vector3Like {\n\tx: number;\n\ty: number;\n\tz?: number | undefined;\n}\n\n/**\n * What `world.addJoint()` passes to {@link Rapier3dAdapter.addJoint}: melonJS's\n * `JointDefinition`, whose anchors and axis may also carry a `z`.\n */\nexport interface Rapier3dJointDefinition {\n\ttype: \"hinge\" | \"rope\" | \"weld\" | \"slider\";\n\ta: Renderable;\n\tb: Renderable;\n\t/** in `a`'s own space, relative to its `pos`; `z` defaults to `0` */\n\tanchorA?: Vector3Like;\n\t/** in `b`'s own space, relative to its `pos`; `z` defaults to `0` */\n\tanchorB?: Vector3Like;\n\tcollideConnected?: boolean;\n\tlimits?: { min: number; max: number };\n\tmaxLength?: number;\n\t/**\n\t * `\"hinge\"`: the axis the bodies turn about, default Z, so a hinge turns\n\t * as it does in 2D. `\"slider\"`: the direction `b` slides in, default X.\n\t * In `a`'s own space; `z` defaults to `0`.\n\t */\n\taxis?: Vector3Like;\n}\n\n/**\n * Options accepted by the {@link Rapier3dAdapter} constructor and by\n * {@link Rapier3dAdapter.create}.\n */\nexport interface Rapier3dAdapterOptions {\n\t/**\n\t * World gravity in **pixels per second\u00B2**. Default `{x: 0, y: 320, z: 0}`,\n\t * about 10 m/s\u00B2 at the default `pixelsPerMeter` of 32, pulling down: the\n\t * engine's 3D convention is Y-down (see `Camera3d`). Converted to meters\n\t * for Rapier.\n\t */\n\tgravity?: Vector3Like;\n\t/**\n\t * Rapier is tuned for objects about a meter across, so the adapter works\n\t * in meters and converts at every boundary (positions, velocities,\n\t * gravity, forces, queries). Default `32`: a 32-pixel cube is one meter.\n\t * Raising it makes every body smaller in meters, so lighter, and the same\n\t * force moves it further; motion under gravity alone looks the same in\n\t * pixels. Must be a positive number.\n\t */\n\tpixelsPerMeter?: number;\n\t/**\n\t * Rapier steps per engine frame, each of `dt / N` seconds. More sub-steps\n\t * make fast contacts and tall stacks more accurate, at about `N` times\n\t * the physics cost. Default `1`; values below 1 are clamped to 1. A\n\t * force applied once in a frame acts across all of them.\n\t */\n\tsubSteps?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAiBA;AAAA,EAKC,aAAAA;AAAA,EACA,WAAW;AAAA,EAGX,cAAAC;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,OAEM;;;ACNA,SAAS,cACf,KACA,YACA,MACA,WACO;AACP,QAAM,EAAE,SAAS,KAAK,QAAQ,SAAS,UAAU,IAAI;AACrD,QAAM,QAAQ,IAAI,OAAO,UAAU;AACnC,QAAM,UAAgE;AAAA,IACrE,aAAa,CAAC,GAAW,GAAW,MAAe;AAClD,aAAO,YAAY,MAAM,GAAG,GAAG,CAAC;AAAA,IACjC;AAAA,IACA,aAAa,CAAC,QAA6B;AAC1C,aAAO,QAAQ,YAAY,YAAY,GAAG;AAAA,IAC3C;AAAA,IACA,eAAe,CAAC,QAA6B;AAC5C,aAAO,QAAQ,cAAc,YAAY,GAAG;AAAA,IAC7C;AAAA,IACA,YAAY,CAAC,GAAW,GAAW,QAAiB,WAAoB;AAC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;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,UACP,YACA,UACA,MACO;AACP,UAAM,YAAY,KAAK,IAAI,YAAY,IAAI,UAAU;AACrD,QAAI,cAAc,OAAW;AAC7B,UAAM,OAAO,KAAK,UAAU,GAAG,UAAU;AACzC,QAAI,aAAa,OAAW,MAAK,WAAW;AAC5C,QAAI,SAAS,OAAW,MAAK,OAAO;AACpC,SAAK,QAAQ,OAAO,WAAW,UAAU,IAAI;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,gBAAgB;AACvB,WAAO;AAAA,MACN,SAAS;AAAA,MACT,KAAK,KAAK;AAAA,MACV,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,IACjB;AAAA,EACD;AACD;AAQA,SAAS,UACR,GACqB;AACrB,MAAI,MAAM,OAAW,QAAO;AAC5B,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,UAAQ,EAAE,IAAI,EAAE,KAAK;AACtB;",
|
|
6
6
|
"names": ["collision", "Quaternion", "Vector3d", "rapier", "rapier", "Quaternion", "rapier", "Sphere", "Vector3d", "Vector3d", "Sphere", "rapier", "_turn", "Quaternion", "rapier", "Vector3d", "collision"]
|
|
7
7
|
}
|
package/package.json
CHANGED