melonjs 19.4.0 → 19.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/build/application/application.d.ts.map +1 -1
- package/build/application/settings.d.ts +25 -2
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +77 -253
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend.d.ts +121 -0
- package/build/audio/backend.d.ts.map +1 -0
- package/build/audio/playback.d.ts +157 -0
- package/build/audio/playback.d.ts.map +1 -0
- package/build/audio/procedural.d.ts +105 -0
- package/build/audio/procedural.d.ts.map +1 -0
- package/build/audio/types.d.ts +205 -0
- package/build/audio/types.d.ts.map +1 -0
- package/build/index.d.ts +6 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2273 -379
- package/build/index.js.map +4 -4
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts +12 -0
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/factories/shape.d.ts +1 -1
- package/build/level/tiled/factories/shape.d.ts.map +1 -1
- package/build/level/tiled/factories/tile.d.ts.map +1 -1
- package/build/loader/loader.d.ts +2 -2
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/aseprite.d.ts +37 -0
- package/build/loader/parsers/aseprite.d.ts.map +1 -0
- package/build/physics/adapter.d.ts +560 -0
- package/build/physics/adapter.d.ts.map +1 -0
- package/build/physics/bounds.d.ts +18 -5
- package/build/physics/bounds.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +605 -0
- package/build/physics/builtin/body.d.ts.map +1 -0
- package/build/physics/builtin/builtin-adapter.d.ts +91 -0
- package/build/physics/builtin/builtin-adapter.d.ts.map +1 -0
- package/build/physics/builtin/detector.d.ts +167 -0
- package/build/physics/builtin/detector.d.ts.map +1 -0
- package/build/physics/builtin/quadtree.d.ts +112 -0
- package/build/physics/builtin/quadtree.d.ts.map +1 -0
- package/build/physics/builtin/raycast.d.ts +4 -0
- package/build/physics/builtin/raycast.d.ts.map +1 -0
- package/build/physics/{sat.d.ts → builtin/sat.d.ts} +7 -7
- package/build/physics/builtin/sat.d.ts.map +1 -0
- package/build/physics/world.d.ts +61 -26
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/collectable.d.ts +7 -1
- package/build/renderable/collectable.d.ts.map +1 -1
- package/build/renderable/container.d.ts +0 -13
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +78 -17
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/trigger.d.ts +14 -1
- package/build/renderable/trigger.d.ts.map +1 -1
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/system/timer.d.ts +0 -5
- package/build/system/timer.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +0 -130
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +111 -0
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/effects/shine.d.ts +87 -0
- package/build/video/webgl/effects/shine.d.ts.map +1 -0
- package/build/video/webgl/webgl_renderer.d.ts +0 -106
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/physics/body.d.ts +0 -351
- package/build/physics/body.d.ts.map +0 -1
- package/build/physics/detector.d.ts +0 -72
- package/build/physics/detector.d.ts.map +0 -1
- package/build/physics/quadtree.d.ts +0 -69
- package/build/physics/quadtree.d.ts.map +0 -1
- package/build/physics/sat.d.ts.map +0 -1
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import type { Ellipse } from "../geometries/ellipse.ts";
|
|
2
|
+
import type { Polygon } from "../geometries/polygon.ts";
|
|
3
|
+
import type { Rect } from "../geometries/rectangle.ts";
|
|
4
|
+
import type { Vector2d } from "../math/vector2d.ts";
|
|
5
|
+
import type Renderable from "../renderable/renderable.js";
|
|
6
|
+
import type { Bounds } from "./bounds.ts";
|
|
7
|
+
import type World from "./world.js";
|
|
8
|
+
/**
|
|
9
|
+
* Body simulation kind. `static` bodies never move (terrain, walls);
|
|
10
|
+
* `dynamic` bodies are simulated (player, projectiles); `kinematic`
|
|
11
|
+
* bodies are user-positioned but participate in collision (moving
|
|
12
|
+
* platforms, elevators).
|
|
13
|
+
*/
|
|
14
|
+
export type BodyType = "static" | "dynamic" | "kinematic";
|
|
15
|
+
/** Collision shape that a physics body may be composed of. */
|
|
16
|
+
export type BodyShape = Rect | Ellipse | Polygon;
|
|
17
|
+
/**
|
|
18
|
+
* Collision response passed to the modern collision lifecycle hooks
|
|
19
|
+
* (`onCollisionStart`, `onCollisionActive`, `onCollisionEnd`) on every
|
|
20
|
+
* adapter.
|
|
21
|
+
*
|
|
22
|
+
* **Receiver-symmetric:** `a` is always the renderable whose handler is
|
|
23
|
+
* firing (`response.a === this`), `b` is always the partner (`response.b
|
|
24
|
+
* === other`). The same overlap is dispatched once to each side as a
|
|
25
|
+
* separate response with `a`/`b` swapped accordingly.
|
|
26
|
+
*
|
|
27
|
+
* **NOT the same contract as the legacy `onCollision`.** The legacy
|
|
28
|
+
* handler receives a different response shape (fixed `a`/`b` per pair,
|
|
29
|
+
* `overlapV` sign convention from b → a, fires 2× per frame for
|
|
30
|
+
* dynamic-dynamic pairs). See `Renderable.onCollision` JSDoc for that
|
|
31
|
+
* one.
|
|
32
|
+
* @example
|
|
33
|
+
* onCollisionActive(response, other) {
|
|
34
|
+
* if (response.normal.y < -0.7) {
|
|
35
|
+
* // push-me-up direction ⇒ I'm on top of `other` (stomp)
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
export interface CollisionResponse {
|
|
40
|
+
/** the renderable whose handler is firing — always `=== this`. */
|
|
41
|
+
a: Renderable;
|
|
42
|
+
/** the partner renderable — always `=== other`. */
|
|
43
|
+
b: Renderable;
|
|
44
|
+
/**
|
|
45
|
+
* Unit minimum-translation vector for the receiver: the direction `a`
|
|
46
|
+
* must move to separate from `b`. Same sign convention across every
|
|
47
|
+
* adapter — in canvas coordinates (y grows downward):
|
|
48
|
+
*
|
|
49
|
+
* - `normal.y < -0.7` → push me **up** ⇒ I'm on top of `b` (stomp / landed on)
|
|
50
|
+
* - `normal.y > 0.7` → push me **down** ⇒ I'm underneath `b`
|
|
51
|
+
* - `Math.abs(normal.x) > 0.7` → mostly horizontal contact (side hit)
|
|
52
|
+
*/
|
|
53
|
+
normal: {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
};
|
|
57
|
+
/** Penetration depth along the shortest-separation axis (always positive). */
|
|
58
|
+
depth: number;
|
|
59
|
+
/**
|
|
60
|
+
* Engine-native contact pair object. **Shape is adapter-specific** —
|
|
61
|
+
* `Matter.Pair` under `@melonjs/matter-adapter`, a `ContactPair`-shaped
|
|
62
|
+
* object under a future Rapier adapter, a `b2Contact` under a future
|
|
63
|
+
* Box2D adapter, etc. Reading this commits your code to a specific
|
|
64
|
+
* engine; use the portable `normal` / `depth` fields for
|
|
65
|
+
* adapter-portable handlers.
|
|
66
|
+
*
|
|
67
|
+
* Present only when the active adapter has a native pair concept;
|
|
68
|
+
* `undefined` under the built-in SAT adapter (which has no native
|
|
69
|
+
* pair representation — the SAT detector works pair-by-pair without
|
|
70
|
+
* persisting them).
|
|
71
|
+
*/
|
|
72
|
+
pair?: unknown;
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated Use `depth`. Built-in SAT legacy field; kept on modern
|
|
75
|
+
* handler dispatches for migration. `undefined` under
|
|
76
|
+
* `@melonjs/matter-adapter`.
|
|
77
|
+
*/
|
|
78
|
+
overlap?: number;
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `normal`. Built-in SAT legacy field; flipped per
|
|
81
|
+
* receiver so the sign convention aligns with `normal` on the modern
|
|
82
|
+
* dispatch. `undefined` under `@melonjs/matter-adapter`.
|
|
83
|
+
*/
|
|
84
|
+
overlapN?: {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Built-in SAT legacy field, equal to `normal × depth`.
|
|
90
|
+
* Flipped per receiver. `undefined` under `@melonjs/matter-adapter`.
|
|
91
|
+
*/
|
|
92
|
+
overlapV?: {
|
|
93
|
+
x: number;
|
|
94
|
+
y: number;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Portable physics body handle returned by {@link PhysicsAdapter.addBody}
|
|
99
|
+
* and stored on `renderable.body`. Every adapter guarantees these
|
|
100
|
+
* methods so engine-portable code can read and mutate body state
|
|
101
|
+
* without knowing which adapter is active.
|
|
102
|
+
*
|
|
103
|
+
* Each adapter exports a concrete `Body` type (e.g.
|
|
104
|
+
* `MatterAdapter.Body`, `BuiltinAdapter.Body`) that extends this
|
|
105
|
+
* interface with its native fields — cast to the adapter-specific type
|
|
106
|
+
* only when reaching for engine-specific state (Matter's `frictionAir`,
|
|
107
|
+
* BuiltinAdapter's `vel`/`force`, etc.).
|
|
108
|
+
*
|
|
109
|
+
* Methods marked optional are not implemented by every adapter; check
|
|
110
|
+
* the adapter docs or fall back to the equivalent on the adapter
|
|
111
|
+
* itself (e.g. `adapter.setVelocity(r, v)` always works).
|
|
112
|
+
*/
|
|
113
|
+
export interface PhysicsBody {
|
|
114
|
+
/** Set linear velocity in viewport pixels per frame. */
|
|
115
|
+
setVelocity(x: number, y: number): void;
|
|
116
|
+
/** Read linear velocity; writes into `out` if provided to avoid an alloc. */
|
|
117
|
+
getVelocity(out?: Vector2d): Vector2d;
|
|
118
|
+
/**
|
|
119
|
+
* Apply a continuous force (integrated over the next step). When the
|
|
120
|
+
* optional application point is provided and differs from the body's
|
|
121
|
+
* centroid, a corresponding torque is generated:
|
|
122
|
+
* `τ = r × F`, where `r = point - centroid`. BuiltinAdapter routes the
|
|
123
|
+
* torque into {@link applyTorque}; MatterAdapter passes the point
|
|
124
|
+
* directly to `Matter.Body.applyForce`.
|
|
125
|
+
* @example
|
|
126
|
+
* // pure linear thrust (existing 2-arg form, unchanged):
|
|
127
|
+
* ship.body.applyForce(0, -0.05);
|
|
128
|
+
*
|
|
129
|
+
* // off-centre kick: pushes the crate to the right AND tips it over,
|
|
130
|
+
* // because the contact point is at the top of the crate, away from
|
|
131
|
+
* // its centroid:
|
|
132
|
+
* const topX = crate.pos.x + crate.width / 2;
|
|
133
|
+
* const topY = crate.pos.y;
|
|
134
|
+
* crate.body.applyForce(1.5, 0, topX, topY);
|
|
135
|
+
* @param x - force X component
|
|
136
|
+
* @param y - force Y component
|
|
137
|
+
* @param pointX - world X of the application point (defaults to centroid)
|
|
138
|
+
* @param pointY - world Y of the application point (defaults to centroid)
|
|
139
|
+
*/
|
|
140
|
+
applyForce(x: number, y: number, pointX?: number, pointY?: number): void;
|
|
141
|
+
/** Apply an instantaneous impulse (`Δv = J / mass`). */
|
|
142
|
+
applyImpulse(x: number, y: number): void;
|
|
143
|
+
/**
|
|
144
|
+
* Toggle static (fixed-position, infinite-mass) state. Static bodies
|
|
145
|
+
* still participate in collisions; they just don't integrate.
|
|
146
|
+
*/
|
|
147
|
+
setStatic(isStatic?: boolean): void;
|
|
148
|
+
/**
|
|
149
|
+
* Set the bit mask of collision types this body collides with.
|
|
150
|
+
* @see collision.types
|
|
151
|
+
*/
|
|
152
|
+
setCollisionMask(mask: number): void;
|
|
153
|
+
/** Set the collision category bit for this body. */
|
|
154
|
+
setCollisionType?(type: number): void;
|
|
155
|
+
/** Toggle sensor mode (fires collision events without push-out). */
|
|
156
|
+
setSensor?(isSensor?: boolean): void;
|
|
157
|
+
/** Set mass directly (recomputes inertia where applicable). */
|
|
158
|
+
setMass?(m: number): void;
|
|
159
|
+
/** Set restitution / bounciness. */
|
|
160
|
+
setBounce?(r: number): void;
|
|
161
|
+
/** Set per-body gravity multiplier. */
|
|
162
|
+
setGravityScale?(scale: number): void;
|
|
163
|
+
/**
|
|
164
|
+
* Set angular velocity (rad / frame). BuiltinAdapter integrates this
|
|
165
|
+
* each step into the body's `angle` and updates the renderable's
|
|
166
|
+
* `currentTransform` (visual rotation only — SAT collisions remain
|
|
167
|
+
* axis-aligned). MatterAdapter routes to `Matter.Body.setAngularVelocity`,
|
|
168
|
+
* which participates fully in matter's rotational dynamics.
|
|
169
|
+
* @example
|
|
170
|
+
* // a coin sprite that spins continuously while sitting on the ground:
|
|
171
|
+
* coin.body.setAngularVelocity?.(0.05);
|
|
172
|
+
*/
|
|
173
|
+
setAngularVelocity?(omega: number): void;
|
|
174
|
+
/**
|
|
175
|
+
* Read angular velocity (rad / frame). Returns 0 if rotation isn't tracked.
|
|
176
|
+
* @example
|
|
177
|
+
* if ((spinner.body.getAngularVelocity?.() ?? 0) > 1) {
|
|
178
|
+
* spinner.body.setAngularVelocity?.(1); // cap spin
|
|
179
|
+
* }
|
|
180
|
+
*/
|
|
181
|
+
getAngularVelocity?(): number;
|
|
182
|
+
/**
|
|
183
|
+
* Set absolute rotation angle (radians). Re-syncs the renderable's
|
|
184
|
+
* `currentTransform` immediately — no need to wait for the next
|
|
185
|
+
* physics step. Useful when you want to point a body at a target.
|
|
186
|
+
* @example
|
|
187
|
+
* // turret tracks the player every frame:
|
|
188
|
+
* const dx = player.centerX - turret.centerX;
|
|
189
|
+
* const dy = player.centerY - turret.centerY;
|
|
190
|
+
* turret.body.setAngle?.(Math.atan2(dy, dx));
|
|
191
|
+
*/
|
|
192
|
+
setAngle?(rad: number): void;
|
|
193
|
+
/** Read absolute rotation angle (radians). */
|
|
194
|
+
getAngle?(): number;
|
|
195
|
+
/**
|
|
196
|
+
* Apply an angular impulse directly: `Δω = τ / pseudoInertia`. Bypasses
|
|
197
|
+
* the force/lever-arm computation in {@link applyForce} for the case
|
|
198
|
+
* where you want to spin something up without applying a linear force —
|
|
199
|
+
* a thruster, a power-up's intrinsic rotation, a knockback spin effect.
|
|
200
|
+
* @example
|
|
201
|
+
* // give a powerup a one-shot 360° spin-up burst on collection:
|
|
202
|
+
* powerup.body.applyTorque?.(50);
|
|
203
|
+
*/
|
|
204
|
+
applyTorque?(torque: number): void;
|
|
205
|
+
/** Live alias of the collision category bit. */
|
|
206
|
+
collisionType: number;
|
|
207
|
+
/** Live alias of the collision mask bits. */
|
|
208
|
+
collisionMask: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Engine-portable body description, passed to {@link PhysicsAdapter.addBody}.
|
|
212
|
+
* Adapter-native fields (Box2D meters, Matter collisionFilter bits, etc.)
|
|
213
|
+
* are derived from these portable fields by each adapter.
|
|
214
|
+
*/
|
|
215
|
+
export interface BodyDefinition {
|
|
216
|
+
/** simulation kind */
|
|
217
|
+
type: BodyType;
|
|
218
|
+
/** collision shapes (one or more — compound body support) */
|
|
219
|
+
shapes: BodyShape[];
|
|
220
|
+
/** mass per unit area; defaults are adapter-specific */
|
|
221
|
+
density?: number;
|
|
222
|
+
/**
|
|
223
|
+
* Per-step velocity damping (Matter's `frictionAir`). Bleeds velocity
|
|
224
|
+
* off every frame regardless of contact, creating terminal velocity.
|
|
225
|
+
* Number applies uniformly; `{x, y}` damps each axis independently
|
|
226
|
+
* (melonJS-specific — Matter only supports scalar and will average).
|
|
227
|
+
*/
|
|
228
|
+
frictionAir?: number | {
|
|
229
|
+
x: number;
|
|
230
|
+
y: number;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Bounciness (coefficient of restitution): `0` = inelastic (stops on
|
|
234
|
+
* contact), `1` = perfectly elastic (rebound speed equals impact speed).
|
|
235
|
+
* Typically in `[0, 1]`. Values `> 1` produce a super-elastic
|
|
236
|
+
* ("energy-gain") rebound — physically unrealistic but useful for
|
|
237
|
+
* arcade effects like pinball flippers, slingshot boosters, or
|
|
238
|
+
* trampoline pads. The value is not clamped at the interface level;
|
|
239
|
+
* how an adapter handles out-of-range values is adapter-specific.
|
|
240
|
+
*/
|
|
241
|
+
restitution?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Surface coefficient of friction during contact. Matter's
|
|
244
|
+
* `body.friction` — `0` = frictionless (objects slide past each
|
|
245
|
+
* other), `1` = high stick. Determines how much tangential velocity
|
|
246
|
+
* is transferred between contacting bodies. Combined with body
|
|
247
|
+
* rotation, this is what produces "throw" between colliding circles
|
|
248
|
+
* and "english" off a wall. Distinct from `frictionAir` (per-step
|
|
249
|
+
* drag with no contact required). Builtin SAT adapter ignores this.
|
|
250
|
+
*/
|
|
251
|
+
friction?: number;
|
|
252
|
+
/**
|
|
253
|
+
* Per-body gravity multiplier. `0` disables gravity for this body;
|
|
254
|
+
* negative inverts it. Matches Matter's `body.gravityScale`.
|
|
255
|
+
*/
|
|
256
|
+
gravityScale?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Hard cap on velocity magnitude per axis. melonJS extension —
|
|
259
|
+
* Matter has no direct equivalent and uses `frictionAir`-induced
|
|
260
|
+
* terminal velocity instead; MatterAdapter implements this by
|
|
261
|
+
* clamping velocity in an `afterUpdate` hook.
|
|
262
|
+
*/
|
|
263
|
+
maxVelocity?: {
|
|
264
|
+
x: number;
|
|
265
|
+
y: number;
|
|
266
|
+
};
|
|
267
|
+
/** disable rotation simulation; the body keeps its initial angle */
|
|
268
|
+
fixedRotation?: boolean;
|
|
269
|
+
/** the body generates collision events but no physical response */
|
|
270
|
+
isSensor?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Bit flag identifying this body's collision type. See
|
|
273
|
+
* {@link collision.types}. Adapters translate to their native filter
|
|
274
|
+
* system (Matter `collisionFilter.category`, Box2D `categoryBits`).
|
|
275
|
+
*/
|
|
276
|
+
collisionType?: number;
|
|
277
|
+
/**
|
|
278
|
+
* Bit mask of collision types this body can collide with. Defaults to
|
|
279
|
+
* `collision.types.ALL_OBJECT`.
|
|
280
|
+
*/
|
|
281
|
+
collisionMask?: number;
|
|
282
|
+
/** arbitrary user data attached to the body */
|
|
283
|
+
userData?: unknown;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Adapter feature flags. The engine reads these to negotiate optional
|
|
287
|
+
* capabilities; user code can branch on them to gracefully degrade when
|
|
288
|
+
* a feature isn't available under the active adapter.
|
|
289
|
+
*/
|
|
290
|
+
export interface AdapterCapabilities {
|
|
291
|
+
/** supports joints, springs, hinges, etc. */
|
|
292
|
+
constraints: boolean;
|
|
293
|
+
/** supports continuous collision detection for fast-moving bodies */
|
|
294
|
+
continuousCollisionDetection: boolean;
|
|
295
|
+
/** supports body sleeping to reduce simulation cost when idle */
|
|
296
|
+
sleepingBodies: boolean;
|
|
297
|
+
/** supports {@link PhysicsAdapter.raycast} */
|
|
298
|
+
raycasts: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* supports {@link BodyDefinition.maxVelocity} /
|
|
301
|
+
* {@link PhysicsAdapter.setMaxVelocity}. BuiltinAdapter does this
|
|
302
|
+
* via its kinematic integrator; MatterAdapter via an `afterUpdate`
|
|
303
|
+
* clamp. Adapters that can't enforce a hard cap report `false`.
|
|
304
|
+
*/
|
|
305
|
+
velocityLimit: boolean;
|
|
306
|
+
/**
|
|
307
|
+
* supports {@link PhysicsAdapter.isGrounded}. Adapters that can't
|
|
308
|
+
* cheaply derive ground contact (no contact iteration) report `false`.
|
|
309
|
+
*/
|
|
310
|
+
isGrounded: boolean;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Common adapter constructor options. Concrete adapters may extend this
|
|
314
|
+
* with their own engine-specific options.
|
|
315
|
+
*/
|
|
316
|
+
export interface AdapterOptions {
|
|
317
|
+
/** world gravity vector, default `(0, 0.98)` */
|
|
318
|
+
gravity?: Vector2d;
|
|
319
|
+
}
|
|
320
|
+
/** Result of a successful {@link PhysicsAdapter.raycast}. */
|
|
321
|
+
export interface RaycastHit {
|
|
322
|
+
/** the renderable whose body the ray hit */
|
|
323
|
+
renderable: Renderable;
|
|
324
|
+
/** world-space hit point */
|
|
325
|
+
point: Vector2d;
|
|
326
|
+
/** surface normal at the hit point */
|
|
327
|
+
normal: Vector2d;
|
|
328
|
+
/** position along the ray, `0..1` from `from` to `to` */
|
|
329
|
+
fraction: number;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Swappable physics engine integration. `BuiltinAdapter` ships with
|
|
333
|
+
* melonjs and wraps the engine's native SAT-based physics; third-party
|
|
334
|
+
* adapters (e.g. `@melonjs/matter-adapter`) implement this interface to
|
|
335
|
+
* plug a different engine in.
|
|
336
|
+
*
|
|
337
|
+
* **Lifecycle contract:** one adapter per {@link World}, instantiated and
|
|
338
|
+
* passed to `Application` at construction, never swapped at runtime.
|
|
339
|
+
* Adapter state (bodies, constraints, sleeping flags, etc.) does not
|
|
340
|
+
* migrate between adapters.
|
|
341
|
+
*
|
|
342
|
+
* **Body handle convention:** {@link PhysicsAdapter.addBody} returns an
|
|
343
|
+
* opaque handle that becomes `renderable.body`. Each adapter chooses its
|
|
344
|
+
* own concrete body type — `BuiltinAdapter` returns the legacy
|
|
345
|
+
* {@link Body} class so existing property-based code (`body.vel.x = 5`,
|
|
346
|
+
* `body.isStatic = true`) keeps working unchanged. Third-party adapters
|
|
347
|
+
* return their engine's native body type. For adapter-agnostic code, use
|
|
348
|
+
* the portable methods on the adapter itself ({@link setVelocity},
|
|
349
|
+
* {@link applyForce}, etc.) instead of mutating the handle directly.
|
|
350
|
+
*/
|
|
351
|
+
export interface PhysicsAdapter {
|
|
352
|
+
/** advertised capabilities; user code may branch on these */
|
|
353
|
+
readonly capabilities: AdapterCapabilities;
|
|
354
|
+
/**
|
|
355
|
+
* Short adapter identifier exposed as `world.physic`. User code uses
|
|
356
|
+
* it to branch on which physics implementation is active without
|
|
357
|
+
* importing the adapter class — e.g.
|
|
358
|
+
*
|
|
359
|
+
* ```ts
|
|
360
|
+
* if (app.world.physic === "matter") {
|
|
361
|
+
* // matter-only setup (constraints, etc.)
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* Convention: a single lowercase token. The first-party labels are
|
|
366
|
+
* `"builtin"` (default — `BuiltinAdapter`) and `"matter"`
|
|
367
|
+
* (`@melonjs/matter-adapter`). Third-party adapters should pick a
|
|
368
|
+
* concise identifier that won't collide with future official ones.
|
|
369
|
+
*
|
|
370
|
+
* The reserved value `"none"` is set on `world.physic` only when the
|
|
371
|
+
* user passes `physic: "none"` to `Application` to disable physics
|
|
372
|
+
* entirely; adapters should not use it.
|
|
373
|
+
*
|
|
374
|
+
* Defaults to `"builtin"` if an adapter doesn't declare its own — keeps
|
|
375
|
+
* legacy adapters wired in before this field was added still working.
|
|
376
|
+
*/
|
|
377
|
+
readonly physicLabel?: string;
|
|
378
|
+
/**
|
|
379
|
+
* Optional display name reported on the startup banner. Defaults to
|
|
380
|
+
* the adapter class name. Third-party packages typically set this to
|
|
381
|
+
* their npm package id (e.g. `"@melonjs/matter-adapter"`).
|
|
382
|
+
*/
|
|
383
|
+
readonly name?: string;
|
|
384
|
+
/**
|
|
385
|
+
* Optional package version reported on the startup banner. Set this
|
|
386
|
+
* when shipping the adapter as a separate npm package so users can
|
|
387
|
+
* tell which version is wired in at a glance.
|
|
388
|
+
*/
|
|
389
|
+
readonly version?: string;
|
|
390
|
+
/**
|
|
391
|
+
* Optional URL (npm / homepage / repo) reported on the startup banner.
|
|
392
|
+
* Convention matches the debug-plugin's startup line.
|
|
393
|
+
*/
|
|
394
|
+
readonly url?: string;
|
|
395
|
+
/** world gravity. Mutate to change at runtime. */
|
|
396
|
+
gravity: Vector2d;
|
|
397
|
+
/**
|
|
398
|
+
* Called once after the adapter is attached to a {@link World}.
|
|
399
|
+
* Adapters may register internal listeners, allocate native engine
|
|
400
|
+
* state, or read world bounds here.
|
|
401
|
+
*/
|
|
402
|
+
init?(world: World): void;
|
|
403
|
+
/** Called when the adapter is being torn down; release native resources. */
|
|
404
|
+
destroy?(): void;
|
|
405
|
+
/** Advance the simulation by one frame. Called from `World.update(dt)`. */
|
|
406
|
+
step(dt: number): void;
|
|
407
|
+
/**
|
|
408
|
+
* Copy physics-engine body positions back to `renderable.pos` and
|
|
409
|
+
* rotations to the renderable's transform. Called after {@link step}
|
|
410
|
+
* each frame. Adapters that mutate the renderable directly during
|
|
411
|
+
* step (e.g. `BuiltinAdapter`) may leave this a no-op.
|
|
412
|
+
*/
|
|
413
|
+
syncFromPhysics(): void;
|
|
414
|
+
/**
|
|
415
|
+
* Optional inverse of {@link syncFromPhysics} — push a single
|
|
416
|
+
* renderable's current pos/angle into the physics engine. Called by
|
|
417
|
+
* the engine when game code teleports a renderable. Adapters may
|
|
418
|
+
* also expose this via {@link setPosition} and skip implementing
|
|
419
|
+
* it directly.
|
|
420
|
+
*/
|
|
421
|
+
syncToPhysics?(renderable: Renderable): void;
|
|
422
|
+
/**
|
|
423
|
+
* Register a body with the simulation. Returns an opaque handle that
|
|
424
|
+
* becomes `renderable.body`. Each adapter chooses its own concrete
|
|
425
|
+
* body type — see the class doc for the convention.
|
|
426
|
+
*
|
|
427
|
+
* **Prefer the declarative path.** Set `renderable.bodyDef` and call
|
|
428
|
+
* `Container.addChild(renderable)` — the container auto-invokes
|
|
429
|
+
* `addBody` AND inserts the renderable into the world's broadphase
|
|
430
|
+
* (QuadTree) in one atomic step. Direct calls to `addBody` only
|
|
431
|
+
* register the body with this adapter; they do NOT add the renderable
|
|
432
|
+
* to the world's container hierarchy, so the broadphase won't return
|
|
433
|
+
* it as a collision candidate. A body registered via direct `addBody`
|
|
434
|
+
* without a matching `addChild` will integrate (velocity, forces) but
|
|
435
|
+
* never collide.
|
|
436
|
+
*/
|
|
437
|
+
addBody(renderable: Renderable, def: BodyDefinition): PhysicsBody;
|
|
438
|
+
/**
|
|
439
|
+
* Unregister a body. Called automatically when `Container.removeChild`
|
|
440
|
+
* detaches the renderable; direct calls are the inverse of a direct
|
|
441
|
+
* `addBody` (rare — use `removeChild` for the normal lifecycle).
|
|
442
|
+
*/
|
|
443
|
+
removeBody(renderable: Renderable): void;
|
|
444
|
+
/** Replace the body's collision geometry without re-creating the body. */
|
|
445
|
+
updateShape?(renderable: Renderable, shapes: BodyShape[]): void;
|
|
446
|
+
/**
|
|
447
|
+
* Portable velocity / force / position API. Every adapter implements
|
|
448
|
+
* these by routing to its native engine. Use these instead of
|
|
449
|
+
* mutating the body handle directly when writing adapter-agnostic
|
|
450
|
+
* code.
|
|
451
|
+
*/
|
|
452
|
+
getVelocity(renderable: Renderable, out?: Vector2d): Vector2d;
|
|
453
|
+
setVelocity(renderable: Renderable, v: Vector2d): void;
|
|
454
|
+
applyForce(renderable: Renderable, force: Vector2d, point?: Vector2d): void;
|
|
455
|
+
applyImpulse(renderable: Renderable, impulse: Vector2d, point?: Vector2d): void;
|
|
456
|
+
setPosition(renderable: Renderable, p: Vector2d): void;
|
|
457
|
+
setAngle?(renderable: Renderable, angle: number): void;
|
|
458
|
+
/** Read absolute rotation angle (radians). Returns 0 if not tracked. */
|
|
459
|
+
getAngle?(renderable: Renderable): number;
|
|
460
|
+
/** Set angular velocity (rad / frame). */
|
|
461
|
+
setAngularVelocity?(renderable: Renderable, omega: number): void;
|
|
462
|
+
/** Read angular velocity (rad / frame). Returns 0 if not tracked. */
|
|
463
|
+
getAngularVelocity?(renderable: Renderable): number;
|
|
464
|
+
/** Apply an angular impulse (`Δω = τ / inertia`). */
|
|
465
|
+
applyTorque?(renderable: Renderable, torque: number): void;
|
|
466
|
+
/**
|
|
467
|
+
* Runtime body-property mutators. Each maps to the corresponding
|
|
468
|
+
* {@link BodyDefinition} field and lets game code change a body's
|
|
469
|
+
* physical properties without re-creating it. Adapter implementations
|
|
470
|
+
* route to their native engine (BuiltinAdapter writes to the `Body`
|
|
471
|
+
* handle; MatterAdapter calls Matter's `Body.set*` helpers).
|
|
472
|
+
*/
|
|
473
|
+
setStatic(renderable: Renderable, isStatic: boolean): void;
|
|
474
|
+
setGravityScale(renderable: Renderable, scale: number): void;
|
|
475
|
+
setFrictionAir(renderable: Renderable, friction: number | {
|
|
476
|
+
x: number;
|
|
477
|
+
y: number;
|
|
478
|
+
}): void;
|
|
479
|
+
setMaxVelocity(renderable: Renderable, limit: {
|
|
480
|
+
x: number;
|
|
481
|
+
y: number;
|
|
482
|
+
}): void;
|
|
483
|
+
/**
|
|
484
|
+
* Read the body's current velocity cap (mirror of
|
|
485
|
+
* {@link setMaxVelocity}). Returns plain `{x, y}` so callers don't
|
|
486
|
+
* need to import a vector type. Optional — adapters that don't
|
|
487
|
+
* implement velocity caps omit this method.
|
|
488
|
+
*/
|
|
489
|
+
getMaxVelocity?(renderable: Renderable): {
|
|
490
|
+
x: number;
|
|
491
|
+
y: number;
|
|
492
|
+
};
|
|
493
|
+
setCollisionType(renderable: Renderable, type: number): void;
|
|
494
|
+
setCollisionMask(renderable: Renderable, mask: number): void;
|
|
495
|
+
/**
|
|
496
|
+
* Toggle a body between solid and sensor mode. A sensor still fires
|
|
497
|
+
* collision events (`onCollisionStart` / `onCollisionActive` /
|
|
498
|
+
* `onCollisionEnd`) but the engine does not push the bodies apart on
|
|
499
|
+
* contact — useful for one-way platforms, trigger zones, ground-snap
|
|
500
|
+
* ground assists, etc.
|
|
501
|
+
*
|
|
502
|
+
* Adapters without a native sensor flag emulate by toggling the
|
|
503
|
+
* collision mask between its previous value and `NO_OBJECT`.
|
|
504
|
+
*/
|
|
505
|
+
setSensor?(renderable: Renderable, isSensor: boolean): void;
|
|
506
|
+
/**
|
|
507
|
+
* Whether the body has at least one active contact with a surface
|
|
508
|
+
* below it (collision normal pointing up). Capability-gated by
|
|
509
|
+
* {@link AdapterCapabilities.isGrounded}. melonJS extension — Matter
|
|
510
|
+
* has no direct equivalent and the MatterAdapter implements it by
|
|
511
|
+
* scanning active pairs each call.
|
|
512
|
+
*/
|
|
513
|
+
isGrounded?(renderable: Renderable): boolean;
|
|
514
|
+
/**
|
|
515
|
+
* Spatial queries.
|
|
516
|
+
*
|
|
517
|
+
* `raycast` is capability-gated by {@link AdapterCapabilities.raycasts}.
|
|
518
|
+
* Adapters that don't support it may omit the method entirely
|
|
519
|
+
* (`typeof adapter.raycast === "function"`).
|
|
520
|
+
*
|
|
521
|
+
* `queryAABB` is mandatory — every adapter must support a region query
|
|
522
|
+
* (a broadphase walk is already needed for collision detection, so
|
|
523
|
+
* exposing it costs nothing).
|
|
524
|
+
*/
|
|
525
|
+
raycast?(from: Vector2d, to: Vector2d): RaycastHit | null;
|
|
526
|
+
queryAABB(rect: Rect): Renderable[];
|
|
527
|
+
/**
|
|
528
|
+
* Return the body's axis-aligned bounding box in **renderable-local**
|
|
529
|
+
* coordinates (relative to `renderable.pos`). Writes into the
|
|
530
|
+
* supplied `out` Bounds so callers can poll allocation-free each
|
|
531
|
+
* frame. Returns `undefined` if the renderable has no registered
|
|
532
|
+
* body.
|
|
533
|
+
*
|
|
534
|
+
* Used by ecosystem tooling — most notably `@melonjs/debug-plugin`
|
|
535
|
+
* — to visualize the body's effective collision extent. The adapter
|
|
536
|
+
* owns coordinate-system conversion: builtin Body already stores
|
|
537
|
+
* bounds in local space, matter stores them in world space and the
|
|
538
|
+
* adapter subtracts `renderable.pos` before writing.
|
|
539
|
+
*
|
|
540
|
+
* Required by the adapter contract: any adapter that registers
|
|
541
|
+
* bodies MUST implement this. The output is the canonical, local-
|
|
542
|
+
* space representation tools rely on regardless of which engine
|
|
543
|
+
* the adapter wraps.
|
|
544
|
+
*/
|
|
545
|
+
getBodyAABB(renderable: Renderable, out: Bounds): Bounds | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Return a snapshot of the body's collision shapes in
|
|
548
|
+
* **renderable-local** coordinates. The returned array is intended
|
|
549
|
+
* for read-only inspection (debug drawing, hit-region queries) —
|
|
550
|
+
* adapters may return a live reference for performance, so callers
|
|
551
|
+
* MUST NOT mutate it. Returns an empty array if no body.
|
|
552
|
+
*
|
|
553
|
+
* Pairs with {@link getBodyAABB} as the adapter-side debug surface;
|
|
554
|
+
* lets each adapter own its coordinate convention without polluting
|
|
555
|
+
* the underlying physics-engine body objects. Required by the
|
|
556
|
+
* adapter contract.
|
|
557
|
+
*/
|
|
558
|
+
getBodyShapes(renderable: Renderable): readonly BodyShape[];
|
|
559
|
+
}
|
|
560
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/physics/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;AAE1D,8DAA8D;AAC9D,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,iBAAiB;IACjC,kEAAkE;IAClE,CAAC,EAAE,UAAU,CAAC;IACd,mDAAmD;IACnD,CAAC,EAAE,UAAU,CAAC;IACd;;;;;;;;OAQG;IACH,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE;QAA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G,UAAU,GAAG,IAAI,CAAC;IAC1D,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE,CAAC;IAEpC;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAErE;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,SAAS,EAAE,CAAC;CAC5D"}
|
|
@@ -128,6 +128,24 @@ export declare class Bounds {
|
|
|
128
128
|
* @param [clear] - Whether to reset the bounds before adding the new bounds.
|
|
129
129
|
*/
|
|
130
130
|
addBounds(bounds: Bounds, clear?: boolean): void;
|
|
131
|
+
/**
|
|
132
|
+
* Expand this bounds to include every shape in `shapes`. Each shape
|
|
133
|
+
* contributes its own `.getBounds()` (so `Rect`, `Polygon`, `Ellipse`,
|
|
134
|
+
* `Bounds`, and anything else implementing the same getter all work);
|
|
135
|
+
* shapes without `.getBounds()` are silently ignored. Use `clear=true`
|
|
136
|
+
* to compute a fresh union (matches the `add` / `addBounds` shape).
|
|
137
|
+
*
|
|
138
|
+
* Useful for sizing a renderable from its `bodyDef.shapes` before
|
|
139
|
+
* the underlying physics body has been constructed — used by the
|
|
140
|
+
* TMX shape factory and {@link Trigger}.
|
|
141
|
+
* @param shapes - one shape or an iterable of shapes
|
|
142
|
+
* @param [clear] - reset the bounds before unioning
|
|
143
|
+
*/
|
|
144
|
+
addShapes(shapes: {
|
|
145
|
+
getBounds?: () => Bounds;
|
|
146
|
+
} | Iterable<{
|
|
147
|
+
getBounds?: () => Bounds;
|
|
148
|
+
}>, clear?: boolean): void;
|
|
131
149
|
/**
|
|
132
150
|
* Adds the given point to the bounds definition.
|
|
133
151
|
* @param point - The point to add to the bounds.
|
|
@@ -184,11 +202,6 @@ export declare class Bounds {
|
|
|
184
202
|
* @returns A new Bounds object that is a copy of this bounds.
|
|
185
203
|
*/
|
|
186
204
|
clone(): Bounds;
|
|
187
|
-
/**
|
|
188
|
-
* Returns a polygon whose edges are the same as this bounds.
|
|
189
|
-
* @returns A new Polygon that represents this bounds.
|
|
190
|
-
*/
|
|
191
|
-
toPolygon(): import("../index.ts").Polygon;
|
|
192
205
|
}
|
|
193
206
|
/**
|
|
194
207
|
* A pool for creating and reusing Bounds objects.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../src/physics/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../src/physics/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAS5C;;;GAGG;AACH,qBAAa,MAAM;IAClB,OAAO,EAAE,QAAQ,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IAEb;;;OAGG;gBACS,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE;IAUvD;;OAEG;IACH,KAAK;IAIL;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAQhE;;;OAGG;IACH,IAAI,CAAC,WAEJ;IAED;;;OAGG;IACH,IAAI,CAAC,CAAC,KAAK,QAAA,EAIV;IAED;;;OAGG;IACH,IAAI,CAAC,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