@melonjs/rapier3d-adapter 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +341 -2
- package/build/Rapier3dAdapter.d.ts +395 -0
- package/build/Rapier3dAdapter.d.ts.map +1 -0
- package/build/Simulation.d.ts +35 -0
- package/build/Simulation.d.ts.map +1 -0
- package/build/bodies/Motion.d.ts +64 -0
- package/build/bodies/Motion.d.ts.map +1 -0
- package/build/bodies/RuntimeOverrides.d.ts +16 -0
- package/build/bodies/RuntimeOverrides.d.ts.map +1 -0
- package/build/bodies/helpers.d.ts +30 -0
- package/build/bodies/helpers.d.ts.map +1 -0
- package/build/bodies/pose.d.ts +34 -0
- package/build/bodies/pose.d.ts.map +1 -0
- package/build/colliders/CollisionFilters.d.ts +60 -0
- package/build/colliders/CollisionFilters.d.ts.map +1 -0
- package/build/colliders/footprint.d.ts +22 -0
- package/build/colliders/footprint.d.ts.map +1 -0
- package/build/colliders/shapes.d.ts +18 -0
- package/build/colliders/shapes.d.ts.map +1 -0
- package/build/colliders/types.d.ts +48 -0
- package/build/colliders/types.d.ts.map +1 -0
- package/build/contacts/ContactDispatcher.d.ts +80 -0
- package/build/contacts/ContactDispatcher.d.ts.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1938 -0
- package/build/index.js.map +7 -0
- package/build/joints/Joints.d.ts +51 -0
- package/build/joints/Joints.d.ts.map +1 -0
- package/build/loader.d.ts +20 -0
- package/build/loader.d.ts.map +1 -0
- package/build/math/units.d.ts +44 -0
- package/build/math/units.d.ts.map +1 -0
- package/build/queries/queries.d.ts +40 -0
- package/build/queries/queries.d.ts.map +1 -0
- package/build/types.d.ts +77 -0
- package/build/types.d.ts.map +1 -0
- package/package.json +71 -5
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter: the melonJS `PhysicsAdapter` interface on Rapier 3D.
|
|
3
|
+
*
|
|
4
|
+
* It owns the lifecycle (making and freeing the Rapier world, stepping it)
|
|
5
|
+
* and the bodies (making them from a `bodyDef`, removing them), and answers
|
|
6
|
+
* the portable API. The work itself is done by:
|
|
7
|
+
*
|
|
8
|
+
* - `Simulation`: the Rapier world and which body and colliders each
|
|
9
|
+
* renderable has, shared by every part below
|
|
10
|
+
* - `colliders/`: the colliders the 3D shapes become, their collision types
|
|
11
|
+
* and masks, and their footprints
|
|
12
|
+
* - `contacts/`: the collision hooks
|
|
13
|
+
* - `bodies/`: the body's pose on its renderable, its motion, what was set on
|
|
14
|
+
* it at run time, and the helpers on `renderable.body`
|
|
15
|
+
* - `joints/` and `queries/`
|
|
16
|
+
*/
|
|
17
|
+
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
18
|
+
import { type AdapterCapabilities, type BodyDefinition, type BodyShape, type Bounds, type PhysicsAdapter, type PhysicsBody, Quaternion, type RaycastHit3d, type Rect, type Renderable, type Sphere, Vector2d, Vector3d, type World } from "melonjs";
|
|
19
|
+
import { type Rapier3dAdapterOptions, type Rapier3dJointDefinition, type Vector3Like } from "./types";
|
|
20
|
+
/**
|
|
21
|
+
* melonJS physics adapter for Rapier 3D (https://rapier.rs), compiled to
|
|
22
|
+
* WebAssembly: rigid bodies that move and turn in three dimensions, for a
|
|
23
|
+
* game drawn with `Camera3d`.
|
|
24
|
+
*
|
|
25
|
+
* Bodies are declared as on every adapter, with a `bodyDef`, from the 3D
|
|
26
|
+
* shapes: {@link Box3d}, {@link Sphere}, {@link Capsule3d},
|
|
27
|
+
* {@link ConvexHull3d} and {@link TriangleMesh3d}. Shapes are in the
|
|
28
|
+
* renderable's space, relative to its `pos` (and `depth`), which is where the
|
|
29
|
+
* body sits; each frame the body's position is written back to `pos` /
|
|
30
|
+
* `depth`, and its turn onto `currentTransform`, so a {@link Mesh}, a
|
|
31
|
+
* `Sprite3d` or a `GLTFModel` tumbles as it is simulated.
|
|
32
|
+
*
|
|
33
|
+
* The adapter takes the 3D form of the portable API: `setVelocity`,
|
|
34
|
+
* `applyForce`, `applyImpulse` and `setPosition` take a {@link Vector3d},
|
|
35
|
+
* and `getVelocity3d`, `getRotation` / `setRotation` and
|
|
36
|
+
* `getAngularVelocity3d` read the rest. The 2D calls still work, in the
|
|
37
|
+
* plane of the body: a `Vector2d` leaves the depth as it was.
|
|
38
|
+
*
|
|
39
|
+
* Rapier's WebAssembly has to be compiled before an adapter can be
|
|
40
|
+
* constructed: {@link Rapier3dAdapter.create} does both.
|
|
41
|
+
* @example
|
|
42
|
+
* import { Application, Camera3d } from "melonjs";
|
|
43
|
+
* import { Rapier3dAdapter } from "@melonjs/rapier3d-adapter";
|
|
44
|
+
*
|
|
45
|
+
* const app = new Application(800, 600, {
|
|
46
|
+
* parent: "screen",
|
|
47
|
+
* cameraClass: Camera3d,
|
|
48
|
+
* physic: await Rapier3dAdapter.create(),
|
|
49
|
+
* });
|
|
50
|
+
* @category Plugins
|
|
51
|
+
* @document ../README.md
|
|
52
|
+
*/
|
|
53
|
+
export declare class Rapier3dAdapter implements PhysicsAdapter {
|
|
54
|
+
readonly physicLabel = "rapier3d";
|
|
55
|
+
readonly name = "@melonjs/rapier3d-adapter";
|
|
56
|
+
readonly version: string;
|
|
57
|
+
readonly url = "https://www.npmjs.com/package/@melonjs/rapier3d-adapter";
|
|
58
|
+
readonly capabilities: AdapterCapabilities;
|
|
59
|
+
/**
|
|
60
|
+
* World gravity, in pixels per second². Change it at any time; read at
|
|
61
|
+
* every step.
|
|
62
|
+
*/
|
|
63
|
+
gravity: Vector3d;
|
|
64
|
+
/**
|
|
65
|
+
* The Rapier module: an escape hatch for what the portable
|
|
66
|
+
* {@link PhysicsAdapter} interface does not cover (other joints, the
|
|
67
|
+
* character controller, native queries). See the README.
|
|
68
|
+
* @see {@link https://rapier.rs/docs/user_guides/javascript/getting_started_js Rapier JavaScript user guide}
|
|
69
|
+
*/
|
|
70
|
+
readonly rapier: typeof RAPIER;
|
|
71
|
+
/** Spatial conversion factor between melonJS pixels and Rapier meters. */
|
|
72
|
+
readonly pixelsPerMeter: number;
|
|
73
|
+
/** Back-reference to the owning melonJS world (set in {@link init}). */
|
|
74
|
+
melonWorld: World;
|
|
75
|
+
private readonly subSteps;
|
|
76
|
+
private readonly sim;
|
|
77
|
+
private readonly filters;
|
|
78
|
+
private readonly contacts;
|
|
79
|
+
private readonly motion;
|
|
80
|
+
private readonly joints;
|
|
81
|
+
/** what was set on every collider of a body at run time */
|
|
82
|
+
private readonly overrides;
|
|
83
|
+
/** each body's definition, which `updateShape()` builds from again */
|
|
84
|
+
private readonly defs;
|
|
85
|
+
/** each renderable's transform when its body was made, and its bridge */
|
|
86
|
+
private readonly poses;
|
|
87
|
+
/** the shapes {@link Rapier3dAdapter.getBodyShapes} reports */
|
|
88
|
+
private readonly reportedShapes;
|
|
89
|
+
/**
|
|
90
|
+
* Download and compile Rapier's WebAssembly. Every call returns the same
|
|
91
|
+
* promise, so it can be started early and awaited wherever it is needed;
|
|
92
|
+
* a failed load rejects, and a later call tries again.
|
|
93
|
+
*
|
|
94
|
+
* Rapier is imported with `import()`, so bundlers put it in a chunk of its
|
|
95
|
+
* own, downloaded only when this is called.
|
|
96
|
+
* @returns a promise that resolves once the adapter can be constructed
|
|
97
|
+
* @example
|
|
98
|
+
* const rapierReady = Rapier3dAdapter.load();
|
|
99
|
+
* await loader.preload(assets);
|
|
100
|
+
* await rapierReady;
|
|
101
|
+
* app.world.setAdapter(new Rapier3dAdapter());
|
|
102
|
+
*/
|
|
103
|
+
static load(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Whether {@link Rapier3dAdapter.load} has finished, so that
|
|
106
|
+
* `new Rapier3dAdapter()` can be called.
|
|
107
|
+
* @returns true once Rapier is compiled
|
|
108
|
+
*/
|
|
109
|
+
static get loaded(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Create an adapter, the same way for every adapter: wait for
|
|
112
|
+
* {@link Rapier3dAdapter.load}, then construct it.
|
|
113
|
+
* @param options - the constructor's options
|
|
114
|
+
* @returns the new adapter, an instance of the class `create` is called on
|
|
115
|
+
*/
|
|
116
|
+
static create<T extends PhysicsAdapter>(this: Pick<typeof Rapier3dAdapter, "load"> & (new (options?: Rapier3dAdapterOptions) => T), options?: Rapier3dAdapterOptions): Promise<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Construct an adapter. Rapier must be loaded first: use
|
|
119
|
+
* {@link Rapier3dAdapter.create}, or await {@link Rapier3dAdapter.load}.
|
|
120
|
+
* @param options - see {@link Rapier3dAdapterOptions}
|
|
121
|
+
*/
|
|
122
|
+
constructor(options?: Rapier3dAdapterOptions);
|
|
123
|
+
/** The Rapier world; exposed for advanced use. Made in {@link init}. */
|
|
124
|
+
get world(): RAPIER.World;
|
|
125
|
+
init(world: World): void;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
step(dt: number): void;
|
|
128
|
+
syncFromPhysics(): void;
|
|
129
|
+
addBody(renderable: Renderable, def: BodyDefinition): Rapier3dAdapter.Body;
|
|
130
|
+
removeBody(renderable: Renderable): void;
|
|
131
|
+
/**
|
|
132
|
+
* Give a body new shapes. The body itself stays: its position, turn and
|
|
133
|
+
* velocities, its joints, what was changed on it at run time (static or
|
|
134
|
+
* not, gravity scale, damping, sensor, collision type and mask, bounce,
|
|
135
|
+
* speed cap, Rapier's own settings such as CCD) and the handle on
|
|
136
|
+
* `renderable.body`. Its colliders are replaced, so the pairs touching
|
|
137
|
+
* it end and start again, and its mass is that of the new shapes.
|
|
138
|
+
*
|
|
139
|
+
* A shape this adapter cannot build throws before anything is changed.
|
|
140
|
+
* @param renderable - the body's renderable
|
|
141
|
+
* @param shapes - the new shapes, relative to `pos`
|
|
142
|
+
*/
|
|
143
|
+
updateShape(renderable: Renderable, shapes: BodyShape[]): void;
|
|
144
|
+
/**
|
|
145
|
+
* Make a joint between two bodies: what `world.addJoint()` calls, which
|
|
146
|
+
* game code uses instead. A `"hinge"` is a Rapier revolute joint about
|
|
147
|
+
* `axis` (default Z), a `"rope"` a rope joint, a `"weld"` a fixed joint
|
|
148
|
+
* and a `"slider"` a prismatic joint along `axis` (default X). Anchors
|
|
149
|
+
* are in each renderable's own space, relative to its `pos`, in pixels,
|
|
150
|
+
* and the axis in `a`'s; a `z` left out is `0`.
|
|
151
|
+
*
|
|
152
|
+
* The bodies are joined as they stand, however each is turned: a weld
|
|
153
|
+
* and a slider keep the turn between them, and a hinge leaves them only
|
|
154
|
+
* the turn about its axis.
|
|
155
|
+
* @param def - what to join, and how, in pixels and radians
|
|
156
|
+
* @returns the Rapier joint
|
|
157
|
+
*/
|
|
158
|
+
addJoint(def: Rapier3dJointDefinition): RAPIER.ImpulseJoint;
|
|
159
|
+
/**
|
|
160
|
+
* Remove a joint {@link Rapier3dAdapter.addJoint} made: what
|
|
161
|
+
* `world.removeJoint()` calls. A joint already gone, with one of its
|
|
162
|
+
* bodies, is ignored.
|
|
163
|
+
* @param joint - the Rapier joint
|
|
164
|
+
*/
|
|
165
|
+
removeJoint(joint: RAPIER.ImpulseJoint): void;
|
|
166
|
+
getVelocity(renderable: Renderable, out?: Vector2d): Vector2d;
|
|
167
|
+
/**
|
|
168
|
+
* The body's velocity on all three axes, in pixels per second.
|
|
169
|
+
* @param renderable - the body's renderable
|
|
170
|
+
* @param [out] - the vector to write into
|
|
171
|
+
* @returns the velocity; zero for a renderable with no body here
|
|
172
|
+
*/
|
|
173
|
+
getVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d;
|
|
174
|
+
/**
|
|
175
|
+
* Set the body's velocity, in pixels per second. A {@link Vector3d} sets
|
|
176
|
+
* all three axes; a {@link Vector2d} sets x and y and keeps the depth
|
|
177
|
+
* velocity as it was.
|
|
178
|
+
* @param renderable - the body's renderable
|
|
179
|
+
* @param v - the velocity
|
|
180
|
+
*/
|
|
181
|
+
setVelocity(renderable: Renderable, v: Vector2d | Vector3d): void;
|
|
182
|
+
/**
|
|
183
|
+
* Push the body for this frame, across every sub-step: it accelerates by
|
|
184
|
+
* `force / mass` pixels per second². A force at `point` (in world pixels)
|
|
185
|
+
* also turns it. A force or point given as a {@link Vector2d} acts in
|
|
186
|
+
* the plane of the body.
|
|
187
|
+
* @param renderable - the body's renderable
|
|
188
|
+
* @param force - the force
|
|
189
|
+
* @param [point] - where it pushes, in world space
|
|
190
|
+
*/
|
|
191
|
+
applyForce(renderable: Renderable, force: Vector2d | Vector3d, point?: Vector2d | Vector3d): void;
|
|
192
|
+
/**
|
|
193
|
+
* Strike the body once: its velocity changes by `impulse / mass` pixels
|
|
194
|
+
* per second, at once. An impulse at `point` (in world pixels) also turns
|
|
195
|
+
* it. A {@link Vector2d} strikes in the plane of the body.
|
|
196
|
+
* @param renderable - the body's renderable
|
|
197
|
+
* @param impulse - the impulse
|
|
198
|
+
* @param [point] - where it strikes, in world space
|
|
199
|
+
*/
|
|
200
|
+
applyImpulse(renderable: Renderable, impulse: Vector2d | Vector3d, point?: Vector2d | Vector3d): void;
|
|
201
|
+
/**
|
|
202
|
+
* Move the body and its renderable, at once. A {@link Vector3d} sets the
|
|
203
|
+
* depth too; a {@link Vector2d} keeps it. A renderable with no body here
|
|
204
|
+
* is moved all the same, as on every adapter.
|
|
205
|
+
* @param renderable - the body's renderable
|
|
206
|
+
* @param p - the new position, in `renderable.pos` space
|
|
207
|
+
*/
|
|
208
|
+
setPosition(renderable: Renderable, p: Vector2d | Vector3d): void;
|
|
209
|
+
/**
|
|
210
|
+
* The body's orientation, from the one it had when it was made.
|
|
211
|
+
* @param renderable - the body's renderable
|
|
212
|
+
* @param [out] - the quaternion to write into
|
|
213
|
+
* @returns the orientation; identity for a renderable with no body here
|
|
214
|
+
*/
|
|
215
|
+
getRotation(renderable: Renderable, out?: Quaternion): Quaternion;
|
|
216
|
+
/**
|
|
217
|
+
* Turn the body, and its renderable with it, to an orientation, from the
|
|
218
|
+
* one it had when it was made.
|
|
219
|
+
* @param renderable - the body's renderable
|
|
220
|
+
* @param q - the orientation
|
|
221
|
+
*/
|
|
222
|
+
setRotation(renderable: Renderable, q: Quaternion): void;
|
|
223
|
+
/**
|
|
224
|
+
* Turn the body to `angle` about Z, the turn a 2D game knows, leaving out
|
|
225
|
+
* any other.
|
|
226
|
+
* @param renderable - the body's renderable
|
|
227
|
+
* @param angle - in radians
|
|
228
|
+
*/
|
|
229
|
+
setAngle(renderable: Renderable, angle: number): void;
|
|
230
|
+
/**
|
|
231
|
+
* The body's turn about Z: the angle +X is turned through, seen down Z.
|
|
232
|
+
* @param renderable - the body's renderable
|
|
233
|
+
* @returns in radians; `0` for a renderable with no body here
|
|
234
|
+
*/
|
|
235
|
+
getAngle(renderable: Renderable): number;
|
|
236
|
+
/**
|
|
237
|
+
* Set the body's spin, in radians per second: a {@link Vector3d} about
|
|
238
|
+
* each axis, a number about Z, keeping the spin about X and Y.
|
|
239
|
+
* @param renderable - the body's renderable
|
|
240
|
+
* @param omega - the spin
|
|
241
|
+
*/
|
|
242
|
+
setAngularVelocity(renderable: Renderable, omega: number | Vector3d): void;
|
|
243
|
+
getAngularVelocity(renderable: Renderable): number;
|
|
244
|
+
/**
|
|
245
|
+
* The body's spin about each axis, in radians per second.
|
|
246
|
+
* @param renderable - the body's renderable
|
|
247
|
+
* @param [out] - the vector to write into
|
|
248
|
+
* @returns the spin; zero for a renderable with no body here
|
|
249
|
+
*/
|
|
250
|
+
getAngularVelocity3d(renderable: Renderable, out?: Vector3d): Vector3d;
|
|
251
|
+
/**
|
|
252
|
+
* Twist the body for this frame: a number about Z, a {@link Vector3d}
|
|
253
|
+
* about each axis. In Rapier's own unit (N·m, not scaled by
|
|
254
|
+
* `pixelsPerMeter`), as on the 2D Rapier adapter.
|
|
255
|
+
* @param renderable - the body's renderable
|
|
256
|
+
* @param torque - the torque
|
|
257
|
+
*/
|
|
258
|
+
applyTorque(renderable: Renderable, torque: number | Vector3d): void;
|
|
259
|
+
setStatic(renderable: Renderable, isStatic: boolean): void;
|
|
260
|
+
setGravityScale(renderable: Renderable, scale: number): void;
|
|
261
|
+
setSensor(renderable: Renderable, isSensor: boolean): void;
|
|
262
|
+
setFrictionAir(renderable: Renderable, friction: number | {
|
|
263
|
+
x: number;
|
|
264
|
+
y: number;
|
|
265
|
+
}): void;
|
|
266
|
+
/**
|
|
267
|
+
* Cap the body's speed on each axis, in pixels per second. A `z` caps
|
|
268
|
+
* the depth axis too; left out, that axis has no cap.
|
|
269
|
+
* @param renderable - the body's renderable
|
|
270
|
+
* @param limit - the cap
|
|
271
|
+
*/
|
|
272
|
+
setMaxVelocity(renderable: Renderable, limit: Vector3Like): void;
|
|
273
|
+
getMaxVelocity(renderable: Renderable): {
|
|
274
|
+
x: number;
|
|
275
|
+
y: number;
|
|
276
|
+
z: number;
|
|
277
|
+
};
|
|
278
|
+
setCollisionType(renderable: Renderable, type: number): void;
|
|
279
|
+
setCollisionMask(renderable: Renderable, mask: number): void;
|
|
280
|
+
/**
|
|
281
|
+
* The body's XY bounds in renderable-local pixels, relative to `pos`: the
|
|
282
|
+
* footprint of its colliders as the body is turned now. Exact for a
|
|
283
|
+
* box, a sphere and a capsule; for a hull or a triangle mesh, that of its
|
|
284
|
+
* bounding box, turned.
|
|
285
|
+
* @param renderable - the renderable whose body bounds to read
|
|
286
|
+
* @param out - destination `Bounds` (filled in place, also returned)
|
|
287
|
+
*/
|
|
288
|
+
getBodyAABB(renderable: Renderable, out: Bounds): Bounds | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* The body's collision shapes, as given in its `bodyDef`, relative to
|
|
291
|
+
* `pos` and before the body turns (the turn is
|
|
292
|
+
* {@link Rapier3dAdapter.getRotation}). A shape with `isActive: false`
|
|
293
|
+
* is left out.
|
|
294
|
+
* @param renderable - the renderable whose body shapes to read
|
|
295
|
+
*/
|
|
296
|
+
getBodyShapes(renderable: Renderable): readonly BodyShape[];
|
|
297
|
+
/**
|
|
298
|
+
* Whether Rapier has put the body to sleep: a dynamic body at rest, left
|
|
299
|
+
* out of the step until a contact or a write to it (a velocity, a force,
|
|
300
|
+
* an impulse, a position or a rotation, which all wake it) moves it
|
|
301
|
+
* again. `false` for a fixed or kinematic body, and for a renderable this
|
|
302
|
+
* adapter does not know, including every one once it is destroyed.
|
|
303
|
+
* @param renderable - the renderable whose body to read
|
|
304
|
+
* @returns `true` while the body sleeps
|
|
305
|
+
* @example
|
|
306
|
+
* // the shot is over once every block has come to rest
|
|
307
|
+
* const settled = blocks.every((b) => adapter.isSleeping(b));
|
|
308
|
+
*/
|
|
309
|
+
isSleeping(renderable: Renderable): boolean;
|
|
310
|
+
isGrounded(renderable: Renderable): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* The first collider a segment meets, from `from` to `to`, in world
|
|
313
|
+
* pixels: the exact shape, not a bounding volume. A shape the ray starts
|
|
314
|
+
* inside is skipped, so a body casting from its own centre does not hit
|
|
315
|
+
* itself. Sensors are hit like any other body.
|
|
316
|
+
* @param from - where the ray starts
|
|
317
|
+
* @param to - where it ends
|
|
318
|
+
* @returns the hit, or `null`
|
|
319
|
+
*/
|
|
320
|
+
raycast3d(from: Vector3d, to: Vector3d): RaycastHit3d | null;
|
|
321
|
+
/**
|
|
322
|
+
* The renderables whose colliders' boxes overlap a rectangle in XY, at
|
|
323
|
+
* any depth: the boxes {@link Rapier3dAdapter.getBodyAABB} reports.
|
|
324
|
+
* @param rect - the rectangle, in world pixels
|
|
325
|
+
* @returns the renderables, each once
|
|
326
|
+
*/
|
|
327
|
+
queryAABB(rect: Rect): Renderable[];
|
|
328
|
+
/**
|
|
329
|
+
* The renderables whose colliders overlap a sphere: their exact shapes.
|
|
330
|
+
* @param center - the centre in world pixels, or a {@link Sphere}
|
|
331
|
+
* @param [radius] - the radius in pixels, with a centre; none, or less
|
|
332
|
+
* than none, is a point
|
|
333
|
+
* @returns the renderables, each once
|
|
334
|
+
*/
|
|
335
|
+
querySphere(center: Vector3d | Sphere, radius?: number): Renderable[];
|
|
336
|
+
/**
|
|
337
|
+
* The gravity in meters per second², for Rapier.
|
|
338
|
+
* @returns the gravity
|
|
339
|
+
*/
|
|
340
|
+
private gravityInMeters;
|
|
341
|
+
/**
|
|
342
|
+
* Write a body's place and turn back onto its renderable.
|
|
343
|
+
* @param renderable - the renderable
|
|
344
|
+
* @param body - its body
|
|
345
|
+
*/
|
|
346
|
+
private writePose;
|
|
347
|
+
/**
|
|
348
|
+
* Make a body's colliders, with the body definition's material and
|
|
349
|
+
* filter, a shape's own settings over them, and what was set on the
|
|
350
|
+
* whole body at run time over both.
|
|
351
|
+
* @param renderable - the body's renderable
|
|
352
|
+
* @param body - the body
|
|
353
|
+
* @param def - its definition
|
|
354
|
+
* @param parts - the colliders to make
|
|
355
|
+
* @param colliders - the body's list of colliders, added to
|
|
356
|
+
*/
|
|
357
|
+
private createColliders;
|
|
358
|
+
/**
|
|
359
|
+
* Tell the pairs touching colliders that are about to go that their
|
|
360
|
+
* contact ended, then forget the colliders.
|
|
361
|
+
* @param colliders - the colliders leaving the world
|
|
362
|
+
*/
|
|
363
|
+
private forgetColliders;
|
|
364
|
+
/**
|
|
365
|
+
* Change the collision type and/or mask of every collider of a body, and
|
|
366
|
+
* keep it for the colliders `updateShape()` makes.
|
|
367
|
+
* @param renderable - the body's renderable
|
|
368
|
+
* @param category - the new type, or undefined to keep each collider's
|
|
369
|
+
* @param mask - the new mask, or undefined to keep each collider's
|
|
370
|
+
*/
|
|
371
|
+
private setFilter;
|
|
372
|
+
/**
|
|
373
|
+
* What the helpers spliced onto a body act through.
|
|
374
|
+
* @returns the context
|
|
375
|
+
*/
|
|
376
|
+
private helperContext;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Namespace-merged with the {@link Rapier3dAdapter} class to expose
|
|
380
|
+
* adapter-owned types alongside the runtime API.
|
|
381
|
+
*/
|
|
382
|
+
export declare namespace Rapier3dAdapter {
|
|
383
|
+
/**
|
|
384
|
+
* The body handle attached to `renderable.body` under
|
|
385
|
+
* {@link Rapier3dAdapter}: the Rapier `RigidBody` (with all its native
|
|
386
|
+
* methods: `enableCcd`, `linvel`, `mass`, `sleep`, …) and the portable
|
|
387
|
+
* melonJS helpers spliced onto it.
|
|
388
|
+
*
|
|
389
|
+
* ```ts
|
|
390
|
+
* (this.body as Rapier3dAdapter.Body).enableCcd(true);
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
type Body = RAPIER.RigidBody & PhysicsBody;
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=Rapier3dAdapter.d.ts.map
|
|
@@ -0,0 +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,EACd,KAAK,MAAM,EAGX,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,MAAM,EAGX,QAAQ,EACR,QAAQ,EACR,KAAK,KAAK,EACV,MAAM,SAAS,CAAC;AAejB,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAE5B,KAAK,WAAW,EAChB,MAAM,SAAS,CAAC;AAOjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,eAAgB,YAAW,cAAc;IACrD,QAAQ,CAAC,WAAW,cAAc;IAClC,QAAQ,CAAC,IAAI,+BAA+B;IAC5C,QAAQ,CAAC,OAAO,SAAe;IAC/B,QAAQ,CAAC,GAAG,6DAA6D;IAEzE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAWxC;IAEF;;;OAGG;IACH,OAAO,EAAE,QAAQ,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,MAA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,GAAG,IAAI;IAI5D,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAM5D;;;;;;;OAOG;IACH,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAqBpE;;;;;;OAMG;IACH,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,SAAS,EAAE;IAmB3D;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAM3C,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAI3C;;;;;;;;OAQG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI;IAI5D;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE;IAInC;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IAMrE;;;OAGG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;IA2CvB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAQvB;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACH,OAAO,CAAC,aAAa;CASrB;AAgBD;;;GAGG;AAGH,yBAAiB,eAAe,CAAC;IAChC;;;;;;;;;OASG;IACH,KAAY,IAAI,GAAG,MAAM,CAAC,SAAS,GAAG,WAAW,CAAC;CAClD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every part of the adapter shares: the Rapier module, the units, the
|
|
3
|
+
* Rapier world, and which body and colliders each renderable has.
|
|
4
|
+
*/
|
|
5
|
+
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
6
|
+
import type { Renderable } from "melonjs";
|
|
7
|
+
import type { ColliderEntry } from "./colliders/types";
|
|
8
|
+
import type { Units } from "./math/units";
|
|
9
|
+
export declare class Simulation {
|
|
10
|
+
readonly rapier: typeof RAPIER;
|
|
11
|
+
readonly units: Units;
|
|
12
|
+
/** The Rapier world: made by {@link open}, freed by {@link close}. */
|
|
13
|
+
world: RAPIER.World;
|
|
14
|
+
/** true between {@link open} and {@link close}: the Rapier world exists */
|
|
15
|
+
alive: boolean;
|
|
16
|
+
/** each renderable's body */
|
|
17
|
+
readonly bodies: Map<Renderable, RAPIER.RigidBody>;
|
|
18
|
+
/** each renderable's colliders, one per active shape */
|
|
19
|
+
readonly collidersOf: Map<Renderable, RAPIER.Collider[]>;
|
|
20
|
+
/** collider handle -> its renderable, shape and box */
|
|
21
|
+
readonly colliders: Map<number, ColliderEntry>;
|
|
22
|
+
/**
|
|
23
|
+
* @param rapier - the loaded Rapier module
|
|
24
|
+
* @param units - the scale between pixels and meters
|
|
25
|
+
*/
|
|
26
|
+
constructor(rapier: typeof RAPIER, units: Units);
|
|
27
|
+
/**
|
|
28
|
+
* Make the Rapier world.
|
|
29
|
+
* @param gravity - its gravity, in meters per second²
|
|
30
|
+
*/
|
|
31
|
+
open(gravity: RAPIER.Vector): void;
|
|
32
|
+
/** Free the Rapier world, and forget every body and collider. */
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=Simulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Simulation.d.ts","sourceRoot":"","sources":["../src/Simulation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,sEAAsE;IACtE,KAAK,EAAG,MAAM,CAAC,KAAK,CAAC;IACrB,2EAA2E;IAC3E,KAAK,UAAS;IAEd,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,oCAA2C;IAC1D,wDAAwD;IACxD,QAAQ,CAAC,WAAW,qCAA4C;IAChE,uDAAuD;IACvD,QAAQ,CAAC,SAAS,6BAAoC;IAEtD;;;OAGG;gBACS,MAAM,EAAE,OAAO,MAAM,EAAE,KAAK,EAAE,KAAK;IAK/C;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM;IAK3B,iEAAiE;IACjE,KAAK;CASL"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving bodies in pixels: velocities, forces and torques for the frame, and
|
|
3
|
+
* the speed caps (`maxVelocity`) Rapier has no notion of.
|
|
4
|
+
*/
|
|
5
|
+
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
6
|
+
import type { Renderable } from "melonjs";
|
|
7
|
+
import { type XYZ } from "../math/units";
|
|
8
|
+
import type { Simulation } from "../Simulation";
|
|
9
|
+
import type { Vector3Like } from "../types";
|
|
10
|
+
export declare class Motion {
|
|
11
|
+
/** each body's speed cap, per axis, in pixels per second */
|
|
12
|
+
readonly limits: Map<Renderable, Vector3Like>;
|
|
13
|
+
private readonly sim;
|
|
14
|
+
/** bodies with a force or torque to clear once the frame is stepped */
|
|
15
|
+
private readonly forced;
|
|
16
|
+
/**
|
|
17
|
+
* @param sim - the simulation whose bodies it moves
|
|
18
|
+
*/
|
|
19
|
+
constructor(sim: Simulation);
|
|
20
|
+
/**
|
|
21
|
+
* Set a body's velocity in pixels per second; a `z` left out keeps the
|
|
22
|
+
* depth velocity.
|
|
23
|
+
* @param body - the body
|
|
24
|
+
* @param x - along X
|
|
25
|
+
* @param y - along Y
|
|
26
|
+
* @param [z] - along Z
|
|
27
|
+
*/
|
|
28
|
+
setVelocity(body: RAPIER.RigidBody, x: number, y: number, z?: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Add a force for this frame, in pixels: at a world point, it also turns
|
|
31
|
+
* the body. A force or a point with no `z` acts in the plane of the body.
|
|
32
|
+
* @param body - the body
|
|
33
|
+
* @param force - the force
|
|
34
|
+
* @param [point] - where it pushes, in world pixels
|
|
35
|
+
*/
|
|
36
|
+
addForce(body: RAPIER.RigidBody, force: Vector3Like, point?: Vector3Like): void;
|
|
37
|
+
/**
|
|
38
|
+
* Add a torque for this frame: a number about Z, a vector about each axis.
|
|
39
|
+
* In Rapier's own unit (N·m), not scaled.
|
|
40
|
+
* @param body - the body
|
|
41
|
+
* @param torque - the torque
|
|
42
|
+
*/
|
|
43
|
+
addTorque(body: RAPIER.RigidBody, torque: number | Vector3Like): void;
|
|
44
|
+
/**
|
|
45
|
+
* A world point in meters; one with no depth is in the plane of the body.
|
|
46
|
+
* @param body - the body it acts on
|
|
47
|
+
* @param point - the point in world pixels
|
|
48
|
+
* @returns the point in meters
|
|
49
|
+
*/
|
|
50
|
+
pointInMeters(body: RAPIER.RigidBody, point: Vector3Like): XYZ;
|
|
51
|
+
/** A force is for one frame, across every sub-step: clear them all. */
|
|
52
|
+
clearForces(): void;
|
|
53
|
+
/** Hold every capped body to its cap. */
|
|
54
|
+
clampVelocities(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Forget a body that left the world.
|
|
57
|
+
* @param renderable - its renderable
|
|
58
|
+
* @param body - the body
|
|
59
|
+
*/
|
|
60
|
+
forget(renderable: Renderable, body: RAPIER.RigidBody): void;
|
|
61
|
+
/** Forget every body. */
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=Motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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,IAAI;IAK5D,yBAAyB;IACzB,KAAK,IAAI,IAAI;CAIb"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What was set on every collider of a body at run time (`setSensor`,
|
|
3
|
+
* `setCollisionType`, `setCollisionMask`, `setBounce`), so that the colliders
|
|
4
|
+
* `updateShape()` makes get it too.
|
|
5
|
+
*/
|
|
6
|
+
import type { Renderable } from "melonjs";
|
|
7
|
+
import type { ColliderOverrides } from "../colliders/types";
|
|
8
|
+
export declare class RuntimeOverrides extends Map<Renderable, ColliderOverrides> {
|
|
9
|
+
/**
|
|
10
|
+
* A body's record, to write to.
|
|
11
|
+
* @param renderable - the body's renderable
|
|
12
|
+
* @returns its record, made when there is none
|
|
13
|
+
*/
|
|
14
|
+
of(renderable: Renderable): ColliderOverrides;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=RuntimeOverrides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeOverrides.d.ts","sourceRoot":"","sources":["../../src/bodies/RuntimeOverrides.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,qBAAa,gBAAiB,SAAQ,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC;IACvE;;;;OAIG;IACH,EAAE,CAAC,UAAU,EAAE,UAAU,GAAG,iBAAiB;CAQ7C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The portable `PhysicsBody` helpers, spliced onto a Rapier body so that
|
|
3
|
+
* `renderable.body.setVelocity(x, y, z)` works as on every adapter. The body
|
|
4
|
+
* stays a real `RAPIER.RigidBody`, with all its own methods.
|
|
5
|
+
*/
|
|
6
|
+
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
7
|
+
import type { Renderable } from "melonjs";
|
|
8
|
+
import type { CollisionFilters } from "../colliders/CollisionFilters";
|
|
9
|
+
import type { Rapier3dAdapter } from "../Rapier3dAdapter";
|
|
10
|
+
import type { Simulation } from "../Simulation";
|
|
11
|
+
import type { Motion } from "./Motion";
|
|
12
|
+
import type { RuntimeOverrides } from "./RuntimeOverrides";
|
|
13
|
+
/** what the helpers act through */
|
|
14
|
+
export interface HelperContext {
|
|
15
|
+
adapter: Rapier3dAdapter;
|
|
16
|
+
sim: Simulation;
|
|
17
|
+
motion: Motion;
|
|
18
|
+
filters: CollisionFilters;
|
|
19
|
+
overrides: RuntimeOverrides;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Splice the helpers onto a body.
|
|
23
|
+
* @param ctx - what they act through
|
|
24
|
+
* @param renderable - the body's renderable
|
|
25
|
+
* @param body - the Rapier body
|
|
26
|
+
* @param colliders - its colliders: the live list, which `updateShape()`
|
|
27
|
+
* refills in place
|
|
28
|
+
*/
|
|
29
|
+
export declare function spliceHelpers(ctx: HelperContext, renderable: Renderable, body: RAPIER.RigidBody, colliders: RAPIER.Collider[]): void;
|
|
30
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/bodies/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAe,UAAU,EAAsB,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,eAAe,CAAC;IACzB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,CAAC;IAC1B,SAAS,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,CAAC,SAAS,EACtB,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,GAC1B,IAAI,CA6GN"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a body's place and turn back onto its renderable: its position to
|
|
3
|
+
* `pos` / `depth`, its turn onto `currentTransform`, from the transform the
|
|
4
|
+
* renderable had when the body was made.
|
|
5
|
+
*/
|
|
6
|
+
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
7
|
+
import { type Matrix3d, type Renderable } from "melonjs";
|
|
8
|
+
import type { Units } from "../math/units";
|
|
9
|
+
/**
|
|
10
|
+
* How a renderable draws its `currentTransform`, so the body's turn can be
|
|
11
|
+
* written onto it: `bridge` is the sign of each axis between the space the
|
|
12
|
+
* transform turns in and the engine's (a {@link Mesh} turns in its source's
|
|
13
|
+
* Y-up space), and `base` the transform it had when the body was made.
|
|
14
|
+
*/
|
|
15
|
+
export interface Pose {
|
|
16
|
+
base: Matrix3d;
|
|
17
|
+
bridge: [number, number, number];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A renderable's pose as it stands, to turn from.
|
|
21
|
+
* @param renderable - the renderable a body is made for
|
|
22
|
+
* @returns its pose
|
|
23
|
+
*/
|
|
24
|
+
export declare function poseOf(renderable: Renderable): Pose;
|
|
25
|
+
/**
|
|
26
|
+
* Write a body's position onto its renderable's `pos` / `depth` and, given a
|
|
27
|
+
* pose, its turn onto its `currentTransform`.
|
|
28
|
+
* @param renderable - the renderable
|
|
29
|
+
* @param body - its body
|
|
30
|
+
* @param pose - its pose, or undefined to write the position only
|
|
31
|
+
* @param units - the scale between pixels and meters
|
|
32
|
+
*/
|
|
33
|
+
export declare function writePose(renderable: Renderable, body: RAPIER.RigidBody, pose: Pose | undefined, units: Units): void;
|
|
34
|
+
//# sourceMappingURL=pose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pose.d.ts","sourceRoot":"","sources":["../../src/bodies/pose.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAoB,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,IAAI;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAKD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CASnD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACxB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,CAAC,SAAS,EACtB,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,KAAK,EAAE,KAAK,GACV,IAAI,CA4BN"}
|