emeraldengine 3.0.0 → 3.1.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 +1498 -1659
- package/dist/types/index.d.ts +4 -1
- package/dist/types/src/Animator.d.ts +1 -1
- package/dist/types/src/CollisionLayers.d.ts +2 -2
- package/dist/types/src/Color.d.ts +1 -0
- package/dist/types/src/Drawable.d.ts +1 -1
- package/dist/types/src/EmeraldDB.d.ts +2 -2
- package/dist/types/src/InstancedTexture.d.ts +17 -2
- package/dist/types/src/Material.d.ts +2 -2
- package/dist/types/src/MathUtils.d.ts +2 -1
- package/dist/types/src/ParticleEmitter.d.ts +1 -1
- package/dist/types/src/Physics.d.ts +148 -18
- package/dist/types/src/Scene.d.ts +1 -1
- package/dist/types/src/Shaders.d.ts +2 -2
- package/dist/types/src/Tilemap.d.ts +1 -1
- package/dist/types/src/UI.d.ts +1 -1
- package/dist/types/src/components/Behaviour.d.ts +2 -2
- package/dist/types/src/components/Collider.d.ts +7 -1
- package/dist/types/src/components/GameObject.d.ts +2 -2
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +281 -8
- package/dist/types/src/importers/Aseprite.d.ts +2 -2
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
- package/dist/types/src/importers/TiledMap.d.ts +1 -1
- package/dist/types/src/managers/EventManager.d.ts +1 -1
- package/dist/types/src/managers/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/InputManager.d.ts +93 -2
- package/dist/types/src/managers/NetworkManager.d.ts +2 -2
- package/dist/types/src/managers/RenderStats.d.ts +1 -1
- package/dist/types/src/managers/TextureManager.d.ts +1 -1
- package/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +6 -0
- package/package.json +2 -3
- package/src/Animator.js +1 -1
- package/src/CollisionLayers.js +3 -3
- package/src/Color.js +8 -0
- package/src/Drawable.js +1 -1
- package/src/Emerald.js +1 -1
- package/src/EmeraldDB.js +2 -2
- package/src/InstancedTexture.js +57 -9
- package/src/Material.js +2 -2
- package/src/MathUtils.js +2 -1
- package/src/ParticleEmitter.js +1 -1
- package/src/Physics.js +270 -60
- package/src/Scene.js +1 -1
- package/src/Shaders.js +20 -20
- package/src/Tilemap.js +1 -1
- package/src/UI.js +1 -1
- package/src/components/Behaviour.js +2 -2
- package/src/components/BoxCollider.js +7 -9
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +7 -9
- package/src/components/CircleColliderDebug.js +3 -2
- package/src/components/Collider.js +13 -3
- package/src/components/GameObject.js +2 -2
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +441 -14
- package/src/importers/Aseprite.js +2 -2
- package/src/importers/ForgeLevel.js +581 -0
- package/src/importers/TiledMap.js +1 -1
- package/src/managers/EventManager.js +1 -1
- package/src/managers/Gamepad.js +126 -0
- package/src/managers/InputManager.js +129 -3
- package/src/managers/NetworkManager.js +2 -2
- package/src/managers/RenderStats.js +1 -1
- package/src/managers/TextureManager.js +1 -1
- package/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
|
@@ -5,10 +5,10 @@ export default InputManager;
|
|
|
5
5
|
* gamepad support (analog sticks/triggers, semantic button names, rumble,
|
|
6
6
|
* connect events, and per-controller mapping), with rebindable named actions.
|
|
7
7
|
* Call `update()` once per frame so `justPressed`/`justReleased` edge queries
|
|
8
|
-
* work for every device
|
|
8
|
+
* work for every device, including the gamepad.
|
|
9
9
|
*
|
|
10
10
|
* Gamepad tokens (usable anywhere a key token is, including in mapAction and
|
|
11
|
-
* justPressed)
|
|
11
|
+
* justPressed); `<i>` is the pad index:
|
|
12
12
|
* "pad:<i>:south" / "pad:<i>:a" - face buttons (also east/b, west/x, north/y)
|
|
13
13
|
* "pad:<i>:l1" / "pad:<i>:r2" ... - shoulders / triggers
|
|
14
14
|
* "pad:<i>:start" / "pad:<i>:select" - center buttons
|
|
@@ -21,6 +21,11 @@ export default InputManager;
|
|
|
21
21
|
* Names resolve through the active mapping, so "pad:0:south" is the bottom face
|
|
22
22
|
* button regardless of whether the pad reports Xbox or PlayStation ordering.
|
|
23
23
|
*
|
|
24
|
+
* Typing these by hand means remembering the exact spelling of every button
|
|
25
|
+
* name above; {@link Gamepad} builds the same strings from named constants
|
|
26
|
+
* instead (`Gamepad.get(0).key(Gamepad.SOUTH)` === "pad:0:south"), which most
|
|
27
|
+
* editors will autocomplete the way an enum's members would.
|
|
28
|
+
*
|
|
24
29
|
* @example
|
|
25
30
|
* const input = new InputManager();
|
|
26
31
|
* input.mapAction("jump", ["Space", " ", "pad:0:south"]);
|
|
@@ -65,6 +70,15 @@ declare class InputManager {
|
|
|
65
70
|
private _disconnectHandlers;
|
|
66
71
|
/** @private */
|
|
67
72
|
private _connected;
|
|
73
|
+
/**
|
|
74
|
+
* Which device last produced real input: "keyboard", "mouse",
|
|
75
|
+
* "gamepad", "touch", or null before anything has happened yet. See
|
|
76
|
+
* {@link getLastActiveDevice}.
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private _lastActiveDevice;
|
|
80
|
+
/** Pending {@link identifyButton} calls, resolved from `update()`. @private */
|
|
81
|
+
private _buttonWaiters;
|
|
68
82
|
/** @private */
|
|
69
83
|
private _onKeyDown;
|
|
70
84
|
/** @private */
|
|
@@ -251,6 +265,27 @@ declare class InputManager {
|
|
|
251
265
|
* @returns {boolean}
|
|
252
266
|
*/
|
|
253
267
|
isGamepadConnected(padIndex?: number): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* @method getLastActiveDevice
|
|
270
|
+
* @description Which device the player most recently *actually used*,
|
|
271
|
+
* not just "is a gamepad plugged in" (see `isGamepadConnected`, which stays
|
|
272
|
+
* true all game long once one is), but "did they just press a key, click,
|
|
273
|
+
* touch, or move a gamepad button/stick". A pad being connected doesn't
|
|
274
|
+
* mean it's what's driving the game right now; this is the signal for
|
|
275
|
+
* swapping on-screen prompts between keyboard and gamepad button icons as
|
|
276
|
+
* the player actually switches between them mid-session.
|
|
277
|
+
*
|
|
278
|
+
* Only counts deliberate input: keydown, mousedown, and touch, not
|
|
279
|
+
* incidental mouse movement, so idly nudging the mouse while playing on a
|
|
280
|
+
* pad won't flip prompts back to keyboard/mouse.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* // once per frame, after input.update():
|
|
284
|
+
* hud.setPromptStyle(input.getLastActiveDevice() === "gamepad" ? "pad" : "keyboard");
|
|
285
|
+
*
|
|
286
|
+
* @returns {"keyboard"|"mouse"|"gamepad"|"touch"|null} - null before any input at all
|
|
287
|
+
*/
|
|
288
|
+
getLastActiveDevice(): "keyboard" | "mouse" | "gamepad" | "touch" | null;
|
|
254
289
|
/**
|
|
255
290
|
* @method getPressedButtons
|
|
256
291
|
* @description Diagnostic: raw indices of all currently pressed buttons on a
|
|
@@ -259,6 +294,55 @@ declare class InputManager {
|
|
|
259
294
|
* @returns {number[]}
|
|
260
295
|
*/
|
|
261
296
|
getPressedButtons(padIndex?: number): number[];
|
|
297
|
+
/**
|
|
298
|
+
* @method identifyButton
|
|
299
|
+
* @description Resolves with the raw index of the next *new* button press
|
|
300
|
+
* on a pad: the reliable way to support a controller whose layout isn't
|
|
301
|
+
* already covered by the standard/registered mapping tables (a Steam
|
|
302
|
+
* Controller running outside Steam Input, an old flight stick, anything
|
|
303
|
+
* with a scrambled button order), instead of guessing indices: ask for one
|
|
304
|
+
* physical press and record wherever it actually lands on that specific
|
|
305
|
+
* device. Keep calling `update()` as normal while waiting; the promise
|
|
306
|
+
* resolves on the frame a button transitions from up to down. A button
|
|
307
|
+
* already held when this is called doesn't count; only a fresh press does.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* console.log("Press the button you want for Jump…");
|
|
311
|
+
* const index = await input.identifyButton(0);
|
|
312
|
+
* InputManager.registerGamepadMapping(input.getGamepadInfo(0).id, {
|
|
313
|
+
* buttons: { south: index },
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* @param {number} [padIndex=0]
|
|
317
|
+
* @returns {Promise<number>} - Never resolves if no new button is ever pressed
|
|
318
|
+
*/
|
|
319
|
+
identifyButton(padIndex?: number): Promise<number>;
|
|
320
|
+
/**
|
|
321
|
+
* @method calibrateGamepad
|
|
322
|
+
* @description Walks a list of semantic button names one at a time, asking
|
|
323
|
+
* for a physical press for each (see {@link identifyButton}), and resolves
|
|
324
|
+
* with a `{name: rawIndex}` map ready to hand straight to
|
|
325
|
+
* `InputManager.registerGamepadMapping`, a complete fix for an oddball
|
|
326
|
+
* controller in a few seconds, without knowing anything about its layout
|
|
327
|
+
* in advance.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* const mapping = await input.calibrateGamepad(
|
|
331
|
+
* 0,
|
|
332
|
+
* ["south", "east", "west", "north", "l1", "r1", "start"],
|
|
333
|
+
* (name, i, total) => showPrompt(`(${i + 1}/${total}) Press the button for "${name}"`)
|
|
334
|
+
* );
|
|
335
|
+
* InputManager.registerGamepadMapping(input.getGamepadInfo(0).id, { buttons: mapping });
|
|
336
|
+
*
|
|
337
|
+
* @param {number} padIndex
|
|
338
|
+
* @param {string[]} names - Semantic names to calibrate, e.g. ["south", "east", "start"]
|
|
339
|
+
* @param {(name: string, index: number, total: number) => void} [onPrompt] -
|
|
340
|
+
* Called right before waiting for each name, so you can show "press ___" UI
|
|
341
|
+
* @returns {Promise<Object.<string, number>>} - { [name]: rawButtonIndex }
|
|
342
|
+
*/
|
|
343
|
+
calibrateGamepad(padIndex: number, names: string[], onPrompt?: (name: string, index: number, total: number) => void): Promise<{
|
|
344
|
+
[x: string]: number;
|
|
345
|
+
}>;
|
|
262
346
|
/**
|
|
263
347
|
* @method _decodeHat
|
|
264
348
|
* @description Some non-standard pads report the d-pad as an 8-way "hat" on a
|
|
@@ -282,6 +366,13 @@ declare class InputManager {
|
|
|
282
366
|
* per frame after reading input.
|
|
283
367
|
*/
|
|
284
368
|
update(): void;
|
|
369
|
+
/**
|
|
370
|
+
* @method _resolveButtonWaiters
|
|
371
|
+
* @description Resolves any {@link identifyButton} calls whose pad just
|
|
372
|
+
* saw a button go from up to down.
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
private _resolveButtonWaiters;
|
|
285
376
|
/**
|
|
286
377
|
* @method destroy
|
|
287
378
|
* @description Removes all event listeners.
|
|
@@ -3,7 +3,7 @@ export default NetworkManager;
|
|
|
3
3
|
* @class NetworkManager
|
|
4
4
|
* @description A thin, optional multiplayer layer over Colyseus. `colyseus.js`
|
|
5
5
|
* is an optional peer dependency and is imported dynamically, so the engine has
|
|
6
|
-
* no hard dependency on it
|
|
6
|
+
* no hard dependency on it, so games that don't use networking never load it.
|
|
7
7
|
*
|
|
8
8
|
* It wraps connection/room lifecycle, exposes a small event API
|
|
9
9
|
* (onStateChange / onMessage / onAdd / onRemove / onLeave), and bundles an
|
|
@@ -74,7 +74,7 @@ declare class NetworkManager {
|
|
|
74
74
|
send(type: any, payload: any): this;
|
|
75
75
|
/**
|
|
76
76
|
* @method now
|
|
77
|
-
* @description Seconds since this manager was created
|
|
77
|
+
* @description Seconds since this manager was created, a convenient clock for
|
|
78
78
|
* feeding the interpolator.
|
|
79
79
|
* @returns {number}
|
|
80
80
|
*/
|
|
@@ -4,7 +4,7 @@ export default RenderStats;
|
|
|
4
4
|
* @description Frame-level render counters, incremented by every draw site in
|
|
5
5
|
* the engine (Drawable, InstancedTexture, SpriteBatch, post-processing) and
|
|
6
6
|
* reset at the start of each drawScene. Read the previous completed frame via
|
|
7
|
-
* `RenderStats.frame` or `emerald.getRenderStats()
|
|
7
|
+
* `RenderStats.frame` or `emerald.getRenderStats()`. DebugOverlay shows it
|
|
8
8
|
* automatically.
|
|
9
9
|
*
|
|
10
10
|
* - drawCalls: GPU draw commands issued (the batching win shows up here)
|
|
@@ -42,7 +42,7 @@ declare class TextureManager {
|
|
|
42
42
|
* @method restoreAll
|
|
43
43
|
* @description Re-uploads every cached texture after a WebGL context loss.
|
|
44
44
|
* The image cache survives the loss, so this is upload-only (no network).
|
|
45
|
-
* Reference counts are untouched
|
|
45
|
+
* Reference counts are untouched: they track logical ownership by
|
|
46
46
|
* drawables, which still exist.
|
|
47
47
|
*/
|
|
48
48
|
static restoreAll(): void;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export default AABB;
|
|
2
|
+
/**
|
|
3
|
+
* @class AABB
|
|
4
|
+
* @description An axis-aligned bounding box in physics space. Used by the
|
|
5
|
+
* broadphase to reject pairs long before any real collision maths runs.
|
|
6
|
+
*/
|
|
7
|
+
declare class AABB {
|
|
8
|
+
/**
|
|
9
|
+
* @method testOverlap
|
|
10
|
+
* @description True when two boxes overlap.
|
|
11
|
+
* @param {AABB} a
|
|
12
|
+
* @param {AABB} b
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
static testOverlap(a: AABB, b: AABB): boolean;
|
|
16
|
+
constructor(lowerX?: number, lowerY?: number, upperX?: number, upperY?: number);
|
|
17
|
+
lowerBound: Vec2;
|
|
18
|
+
upperBound: Vec2;
|
|
19
|
+
/**
|
|
20
|
+
* @method set
|
|
21
|
+
* @description Sets all four bounds in place.
|
|
22
|
+
* @param {number} lx
|
|
23
|
+
* @param {number} ly
|
|
24
|
+
* @param {number} ux
|
|
25
|
+
* @param {number} uy
|
|
26
|
+
* @returns {AABB} - this
|
|
27
|
+
*/
|
|
28
|
+
set(lx: number, ly: number, ux: number, uy: number): AABB;
|
|
29
|
+
/**
|
|
30
|
+
* @method copy
|
|
31
|
+
* @description Copies another AABB.
|
|
32
|
+
* @param {AABB} other
|
|
33
|
+
* @returns {AABB} - this
|
|
34
|
+
*/
|
|
35
|
+
copy(other: AABB): AABB;
|
|
36
|
+
/**
|
|
37
|
+
* @method getCenter
|
|
38
|
+
* @description Returns the box center.
|
|
39
|
+
* @returns {Vec2}
|
|
40
|
+
*/
|
|
41
|
+
getCenter(): Vec2;
|
|
42
|
+
/**
|
|
43
|
+
* @method getExtents
|
|
44
|
+
* @description Returns the box half-extents.
|
|
45
|
+
* @returns {Vec2}
|
|
46
|
+
*/
|
|
47
|
+
getExtents(): Vec2;
|
|
48
|
+
/**
|
|
49
|
+
* @method getPerimeter
|
|
50
|
+
* @description Perimeter of the box, the cost function the AABB tree
|
|
51
|
+
* minimizes when choosing where to insert a leaf.
|
|
52
|
+
* @returns {number}
|
|
53
|
+
*/
|
|
54
|
+
getPerimeter(): number;
|
|
55
|
+
/**
|
|
56
|
+
* @method combine
|
|
57
|
+
* @description Sets this box to the union of two others.
|
|
58
|
+
* @param {AABB} a
|
|
59
|
+
* @param {AABB} b
|
|
60
|
+
* @returns {AABB} - this
|
|
61
|
+
*/
|
|
62
|
+
combine(a: AABB, b: AABB): AABB;
|
|
63
|
+
/**
|
|
64
|
+
* @method extend
|
|
65
|
+
* @description Grows the box by `amount` on every side.
|
|
66
|
+
* @param {number} amount
|
|
67
|
+
* @returns {AABB} - this
|
|
68
|
+
*/
|
|
69
|
+
extend(amount: number): AABB;
|
|
70
|
+
/**
|
|
71
|
+
* @method contains
|
|
72
|
+
* @description True when `other` lies entirely inside this box.
|
|
73
|
+
* @param {AABB} other
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
contains(other: AABB): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @method containsPoint
|
|
79
|
+
* @description True when a point lies inside this box.
|
|
80
|
+
* @param {Object} p - `{ x, y }`
|
|
81
|
+
* @returns {boolean}
|
|
82
|
+
*/
|
|
83
|
+
containsPoint(p: any): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* @method rayCast
|
|
86
|
+
* @description Slab test of a ray against this box.
|
|
87
|
+
* @param {Object} input - `{ p1, p2, maxFraction }`
|
|
88
|
+
* @returns {boolean} - True if the ray hits the box within maxFraction
|
|
89
|
+
*/
|
|
90
|
+
rayCast(input: any): boolean;
|
|
91
|
+
}
|
|
92
|
+
import { Vec2 } from "./Math2D.js";
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Body
|
|
3
|
+
* @description A rigid body: a position, an orientation, and the velocity and
|
|
4
|
+
* mass that go with them. Collision geometry lives on its fixtures, added with
|
|
5
|
+
* {@link Body#createFixture}. Bodies are created through
|
|
6
|
+
* {@link World#createBody}, never with `new`.
|
|
7
|
+
*
|
|
8
|
+
* Everything here is in physics units (meters, radians, seconds). The engine's
|
|
9
|
+
* {@link RigidBody} component is the pixel-space wrapper around this class.
|
|
10
|
+
*
|
|
11
|
+
* @param {World} world - The owning world
|
|
12
|
+
* @param {Object} [def] - `{ type, position, angle, linearVelocity,
|
|
13
|
+
* angularVelocity, linearDamping, angularDamping, fixedRotation, bullet,
|
|
14
|
+
* allowSleep, awake, active, gravityScale, userData }`
|
|
15
|
+
*/
|
|
16
|
+
export class Body {
|
|
17
|
+
constructor(world: any, def?: {});
|
|
18
|
+
world: any;
|
|
19
|
+
type: any;
|
|
20
|
+
xf: Transform2;
|
|
21
|
+
sweep: Sweep;
|
|
22
|
+
linearVelocity: Vec2;
|
|
23
|
+
angularVelocity: any;
|
|
24
|
+
force: Vec2;
|
|
25
|
+
torque: number;
|
|
26
|
+
linearDamping: any;
|
|
27
|
+
angularDamping: any;
|
|
28
|
+
gravityScale: any;
|
|
29
|
+
mass: number;
|
|
30
|
+
invMass: number;
|
|
31
|
+
I: number;
|
|
32
|
+
invI: number;
|
|
33
|
+
fixedRotation: boolean;
|
|
34
|
+
bullet: boolean;
|
|
35
|
+
allowSleep: boolean;
|
|
36
|
+
awake: boolean;
|
|
37
|
+
active: boolean;
|
|
38
|
+
sleepTime: number;
|
|
39
|
+
userData: any;
|
|
40
|
+
/** Head of this body's fixture list. @private */
|
|
41
|
+
private fixtureList;
|
|
42
|
+
/** @private */
|
|
43
|
+
private fixtureCount;
|
|
44
|
+
/** Contacts this body currently takes part in. @private */
|
|
45
|
+
private contacts;
|
|
46
|
+
/** Joints this body currently takes part in. @private */
|
|
47
|
+
private joints;
|
|
48
|
+
/** @private */
|
|
49
|
+
private prev;
|
|
50
|
+
/** @private */
|
|
51
|
+
private next;
|
|
52
|
+
/** Scratch flag used while building solver islands. @private */
|
|
53
|
+
private islandFlag;
|
|
54
|
+
/** Index into the current island's body array. @private */
|
|
55
|
+
private islandIndex;
|
|
56
|
+
/**
|
|
57
|
+
* @method createFixture
|
|
58
|
+
* @description Attaches a shape to this body. The second argument may be a
|
|
59
|
+
* plain density number or a definition object.
|
|
60
|
+
* @param {Shape} shape - A CircleShape or PolygonShape
|
|
61
|
+
* @param {Object|number} [def] - `{ density, friction, restitution, isSensor,
|
|
62
|
+
* filterCategoryBits, filterMaskBits, filterGroupIndex, userData }`
|
|
63
|
+
* @returns {Fixture} - The new fixture
|
|
64
|
+
*/
|
|
65
|
+
createFixture(shape: Shape, def?: any | number): Fixture;
|
|
66
|
+
/**
|
|
67
|
+
* @method destroyFixture
|
|
68
|
+
* @description Removes a fixture and every contact it was part of.
|
|
69
|
+
* @param {Fixture} fixture
|
|
70
|
+
*/
|
|
71
|
+
destroyFixture(fixture: Fixture): void;
|
|
72
|
+
/**
|
|
73
|
+
* @method getFixtureList
|
|
74
|
+
* @description Returns the first fixture; walk the rest with
|
|
75
|
+
* {@link Fixture#getNext}.
|
|
76
|
+
* @returns {Fixture|null}
|
|
77
|
+
*/
|
|
78
|
+
getFixtureList(): Fixture | null;
|
|
79
|
+
/**
|
|
80
|
+
* @method getNext
|
|
81
|
+
* @description Returns the next body in the world's list.
|
|
82
|
+
* @returns {Body|null}
|
|
83
|
+
*/
|
|
84
|
+
getNext(): Body | null;
|
|
85
|
+
/**
|
|
86
|
+
* @method setUserData
|
|
87
|
+
* @description Attaches arbitrary data to the body. The engine stores the
|
|
88
|
+
* owning {@link RigidBody} here so contacts can be traced back to game
|
|
89
|
+
* objects.
|
|
90
|
+
* @param {*} data
|
|
91
|
+
*/
|
|
92
|
+
setUserData(data: any): void;
|
|
93
|
+
/**
|
|
94
|
+
* @method getUserData
|
|
95
|
+
* @description Returns the attached data.
|
|
96
|
+
* @returns {*}
|
|
97
|
+
*/
|
|
98
|
+
getUserData(): any;
|
|
99
|
+
/**
|
|
100
|
+
* @method getWorld
|
|
101
|
+
* @description Returns the owning world.
|
|
102
|
+
* @returns {World}
|
|
103
|
+
*/
|
|
104
|
+
getWorld(): World;
|
|
105
|
+
/**
|
|
106
|
+
* @method getType
|
|
107
|
+
* @description Returns "static", "kinematic" or "dynamic".
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
getType(): string;
|
|
111
|
+
/**
|
|
112
|
+
* @method setType
|
|
113
|
+
* @description Changes the body type at runtime, resetting velocities and
|
|
114
|
+
* re-deriving mass. Existing contacts are dropped so they rebuild against the
|
|
115
|
+
* new type.
|
|
116
|
+
* @param {string} type - "static", "kinematic" or "dynamic"
|
|
117
|
+
*/
|
|
118
|
+
setType(type: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* @method setTransform
|
|
121
|
+
* @description Teleports the body: sets position and angle directly, without
|
|
122
|
+
* any velocity implied by the move.
|
|
123
|
+
*
|
|
124
|
+
* A teleport wakes the body. Contacts are only re-evaluated for bodies that
|
|
125
|
+
* are awake, so a sleeping body dropped into a new spot would otherwise sit
|
|
126
|
+
* there without noticing what it now overlaps: respawning a player onto a
|
|
127
|
+
* pickup, for instance, would silently miss it.
|
|
128
|
+
*
|
|
129
|
+
* @param {Object} position - `{ x, y }` in physics units
|
|
130
|
+
* @param {number} angle - Radians
|
|
131
|
+
*/
|
|
132
|
+
setTransform(position: any, angle: number): void;
|
|
133
|
+
/**
|
|
134
|
+
* @method setPosition
|
|
135
|
+
* @description Moves the body, keeping its angle.
|
|
136
|
+
* @param {Object} position - `{ x, y }` in physics units
|
|
137
|
+
*/
|
|
138
|
+
setPosition(position: any): void;
|
|
139
|
+
/**
|
|
140
|
+
* @method setAngle
|
|
141
|
+
* @description Rotates the body, keeping its position.
|
|
142
|
+
* @param {number} angle - Radians
|
|
143
|
+
*/
|
|
144
|
+
setAngle(angle: number): void;
|
|
145
|
+
/**
|
|
146
|
+
* @method getTransform
|
|
147
|
+
* @description Returns the body's transform (live reference).
|
|
148
|
+
* @returns {Transform2}
|
|
149
|
+
*/
|
|
150
|
+
getTransform(): Transform2;
|
|
151
|
+
/**
|
|
152
|
+
* @method getPosition
|
|
153
|
+
* @description Returns the body origin in world space (live reference).
|
|
154
|
+
* @returns {Vec2}
|
|
155
|
+
*/
|
|
156
|
+
getPosition(): Vec2;
|
|
157
|
+
/**
|
|
158
|
+
* @method getAngle
|
|
159
|
+
* @description Returns the body's angle in radians.
|
|
160
|
+
* @returns {number}
|
|
161
|
+
*/
|
|
162
|
+
getAngle(): number;
|
|
163
|
+
/**
|
|
164
|
+
* @method getWorldCenter
|
|
165
|
+
* @description Returns the center of mass in world space.
|
|
166
|
+
* @returns {Vec2}
|
|
167
|
+
*/
|
|
168
|
+
getWorldCenter(): Vec2;
|
|
169
|
+
/**
|
|
170
|
+
* @method getLocalCenter
|
|
171
|
+
* @description Returns the center of mass in the body's frame.
|
|
172
|
+
* @returns {Vec2}
|
|
173
|
+
*/
|
|
174
|
+
getLocalCenter(): Vec2;
|
|
175
|
+
/**
|
|
176
|
+
* @method getWorldPoint
|
|
177
|
+
* @description Converts a local point to world space.
|
|
178
|
+
* @param {Object} localPoint
|
|
179
|
+
* @returns {Vec2}
|
|
180
|
+
*/
|
|
181
|
+
getWorldPoint(localPoint: any): Vec2;
|
|
182
|
+
/**
|
|
183
|
+
* @method getLocalPoint
|
|
184
|
+
* @description Converts a world point to the body's frame.
|
|
185
|
+
* @param {Object} worldPoint
|
|
186
|
+
* @returns {Vec2}
|
|
187
|
+
*/
|
|
188
|
+
getLocalPoint(worldPoint: any): Vec2;
|
|
189
|
+
/**
|
|
190
|
+
* @method getWorldVector
|
|
191
|
+
* @description Rotates a local direction into world space.
|
|
192
|
+
* @param {Object} localVector
|
|
193
|
+
* @returns {Vec2}
|
|
194
|
+
*/
|
|
195
|
+
getWorldVector(localVector: any): Vec2;
|
|
196
|
+
/**
|
|
197
|
+
* @method getLocalVector
|
|
198
|
+
* @description Rotates a world direction into the body's frame.
|
|
199
|
+
* @param {Object} worldVector
|
|
200
|
+
* @returns {Vec2}
|
|
201
|
+
*/
|
|
202
|
+
getLocalVector(worldVector: any): Vec2;
|
|
203
|
+
/**
|
|
204
|
+
* @method setLinearVelocity
|
|
205
|
+
* @description Sets the velocity of the center of mass.
|
|
206
|
+
* @param {Object} velocity - `{ x, y }` in physics units per second
|
|
207
|
+
*/
|
|
208
|
+
setLinearVelocity(velocity: any): void;
|
|
209
|
+
/**
|
|
210
|
+
* @method getLinearVelocity
|
|
211
|
+
* @description Returns the velocity of the center of mass (live reference).
|
|
212
|
+
* @returns {Vec2}
|
|
213
|
+
*/
|
|
214
|
+
getLinearVelocity(): Vec2;
|
|
215
|
+
/**
|
|
216
|
+
* @method getLinearVelocityFromWorldPoint
|
|
217
|
+
* @description Velocity of the material point of this body that currently
|
|
218
|
+
* coincides with a world point (linear plus the spin contribution).
|
|
219
|
+
* @param {Object} worldPoint
|
|
220
|
+
* @returns {Vec2}
|
|
221
|
+
*/
|
|
222
|
+
getLinearVelocityFromWorldPoint(worldPoint: any): Vec2;
|
|
223
|
+
/**
|
|
224
|
+
* @method setAngularVelocity
|
|
225
|
+
* @description Sets the spin in radians per second.
|
|
226
|
+
* @param {number} omega
|
|
227
|
+
*/
|
|
228
|
+
setAngularVelocity(omega: number): void;
|
|
229
|
+
/**
|
|
230
|
+
* @method getAngularVelocity
|
|
231
|
+
* @description Returns the spin in radians per second.
|
|
232
|
+
* @returns {number}
|
|
233
|
+
*/
|
|
234
|
+
getAngularVelocity(): number;
|
|
235
|
+
/**
|
|
236
|
+
* @method applyForce
|
|
237
|
+
* @description Applies a force at a world point. Forces are cleared at the
|
|
238
|
+
* end of every step, so this belongs in your update loop.
|
|
239
|
+
* @param {Object} force
|
|
240
|
+
* @param {Object} [point] - Defaults to the center of mass
|
|
241
|
+
* @param {boolean} [wake=true]
|
|
242
|
+
*/
|
|
243
|
+
applyForce(force: any, point?: any, wake?: boolean): void;
|
|
244
|
+
/**
|
|
245
|
+
* @method applyForceToCenter
|
|
246
|
+
* @description Applies a force at the center of mass (no torque).
|
|
247
|
+
* @param {Object} force
|
|
248
|
+
* @param {boolean} [wake=true]
|
|
249
|
+
*/
|
|
250
|
+
applyForceToCenter(force: any, wake?: boolean): void;
|
|
251
|
+
/**
|
|
252
|
+
* @method applyTorque
|
|
253
|
+
* @description Applies a torque about the center of mass.
|
|
254
|
+
* @param {number} torque
|
|
255
|
+
* @param {boolean} [wake=true]
|
|
256
|
+
*/
|
|
257
|
+
applyTorque(torque: number, wake?: boolean): void;
|
|
258
|
+
/**
|
|
259
|
+
* @method applyLinearImpulse
|
|
260
|
+
* @description Applies an instantaneous change in momentum at a world point.
|
|
261
|
+
* Unlike a force, an impulse takes effect immediately: this is what a jump
|
|
262
|
+
* or a knockback should use.
|
|
263
|
+
* @param {Object} impulse
|
|
264
|
+
* @param {Object} [point] - Defaults to the center of mass
|
|
265
|
+
* @param {boolean} [wake=true]
|
|
266
|
+
*/
|
|
267
|
+
applyLinearImpulse(impulse: any, point?: any, wake?: boolean): void;
|
|
268
|
+
/**
|
|
269
|
+
* @method applyAngularImpulse
|
|
270
|
+
* @description Applies an instantaneous change in angular momentum.
|
|
271
|
+
* @param {number} impulse
|
|
272
|
+
* @param {boolean} [wake=true]
|
|
273
|
+
*/
|
|
274
|
+
applyAngularImpulse(impulse: number, wake?: boolean): void;
|
|
275
|
+
/**
|
|
276
|
+
* @method getMass
|
|
277
|
+
* @description Returns the body's mass.
|
|
278
|
+
* @returns {number}
|
|
279
|
+
*/
|
|
280
|
+
getMass(): number;
|
|
281
|
+
/**
|
|
282
|
+
* @method getInertia
|
|
283
|
+
* @description Returns the rotational inertia about the center of mass.
|
|
284
|
+
* @returns {number}
|
|
285
|
+
*/
|
|
286
|
+
getInertia(): number;
|
|
287
|
+
/**
|
|
288
|
+
* @method resetMassData
|
|
289
|
+
* @description Recomputes mass, center of mass and inertia from the
|
|
290
|
+
* fixtures' densities. Called automatically when fixtures change.
|
|
291
|
+
*/
|
|
292
|
+
resetMassData(): void;
|
|
293
|
+
/**
|
|
294
|
+
* @method setMassData
|
|
295
|
+
* @description Overrides the computed mass properties.
|
|
296
|
+
* @param {Object} massData - `{ mass, center, I }`
|
|
297
|
+
*/
|
|
298
|
+
setMassData(massData: any): void;
|
|
299
|
+
/**
|
|
300
|
+
* @method setAwake
|
|
301
|
+
* @description Wakes the body or puts it to sleep. A sleeping body is skipped
|
|
302
|
+
* by the solver until something touches it, which is what keeps a settled
|
|
303
|
+
* pile of crates free.
|
|
304
|
+
* @param {boolean} flag
|
|
305
|
+
*/
|
|
306
|
+
setAwake(flag: boolean): void;
|
|
307
|
+
/**
|
|
308
|
+
* @method isAwake
|
|
309
|
+
* @description Whether the body is currently simulated.
|
|
310
|
+
* @returns {boolean}
|
|
311
|
+
*/
|
|
312
|
+
isAwake(): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* @method setSleepingAllowed
|
|
315
|
+
* @description Allows or forbids this body from ever sleeping.
|
|
316
|
+
* @param {boolean} flag
|
|
317
|
+
*/
|
|
318
|
+
setSleepingAllowed(flag: boolean): void;
|
|
319
|
+
/**
|
|
320
|
+
* @method isSleepingAllowed
|
|
321
|
+
* @description Whether this body may sleep.
|
|
322
|
+
* @returns {boolean}
|
|
323
|
+
*/
|
|
324
|
+
isSleepingAllowed(): boolean;
|
|
325
|
+
/**
|
|
326
|
+
* @method setActive
|
|
327
|
+
* @description Adds or removes the body from collision detection without
|
|
328
|
+
* destroying it.
|
|
329
|
+
* @param {boolean} flag
|
|
330
|
+
*/
|
|
331
|
+
setActive(flag: boolean): void;
|
|
332
|
+
/**
|
|
333
|
+
* @method isActive
|
|
334
|
+
* @description Whether the body takes part in collision detection.
|
|
335
|
+
* @returns {boolean}
|
|
336
|
+
*/
|
|
337
|
+
isActive(): boolean;
|
|
338
|
+
/**
|
|
339
|
+
* @method setFixedRotation
|
|
340
|
+
* @description Locks or unlocks the body's rotation. Locking is the usual
|
|
341
|
+
* choice for player characters, which should never topple over.
|
|
342
|
+
* @param {boolean} flag
|
|
343
|
+
*/
|
|
344
|
+
setFixedRotation(flag: boolean): void;
|
|
345
|
+
/**
|
|
346
|
+
* @method isFixedRotation
|
|
347
|
+
* @description Whether rotation is locked.
|
|
348
|
+
* @returns {boolean}
|
|
349
|
+
*/
|
|
350
|
+
isFixedRotation(): boolean;
|
|
351
|
+
/**
|
|
352
|
+
* @method setBullet
|
|
353
|
+
* @description Turns continuous collision detection on for this body, so it
|
|
354
|
+
* is swept against static geometry instead of teleporting between steps.
|
|
355
|
+
* @param {boolean} flag
|
|
356
|
+
*/
|
|
357
|
+
setBullet(flag: boolean): void;
|
|
358
|
+
/**
|
|
359
|
+
* @method isBullet
|
|
360
|
+
* @description Whether continuous collision detection is enabled.
|
|
361
|
+
* @returns {boolean}
|
|
362
|
+
*/
|
|
363
|
+
isBullet(): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* @method setLinearDamping
|
|
366
|
+
* @description Sets the drag applied to linear motion each step.
|
|
367
|
+
* @param {number} damping
|
|
368
|
+
*/
|
|
369
|
+
setLinearDamping(damping: number): void;
|
|
370
|
+
/**
|
|
371
|
+
* @method getLinearDamping
|
|
372
|
+
* @description Returns the linear damping.
|
|
373
|
+
* @returns {number}
|
|
374
|
+
*/
|
|
375
|
+
getLinearDamping(): number;
|
|
376
|
+
/**
|
|
377
|
+
* @method setAngularDamping
|
|
378
|
+
* @description Sets the drag applied to rotation each step.
|
|
379
|
+
* @param {number} damping
|
|
380
|
+
*/
|
|
381
|
+
setAngularDamping(damping: number): void;
|
|
382
|
+
/**
|
|
383
|
+
* @method getAngularDamping
|
|
384
|
+
* @description Returns the angular damping.
|
|
385
|
+
* @returns {number}
|
|
386
|
+
*/
|
|
387
|
+
getAngularDamping(): number;
|
|
388
|
+
/**
|
|
389
|
+
* @method setGravityScale
|
|
390
|
+
* @description Scales how strongly gravity pulls on this body (0 disables it,
|
|
391
|
+
* 2 makes it twice as heavy-feeling).
|
|
392
|
+
* @param {number} scale
|
|
393
|
+
*/
|
|
394
|
+
setGravityScale(scale: number): void;
|
|
395
|
+
/**
|
|
396
|
+
* @method getGravityScale
|
|
397
|
+
* @description Returns the gravity multiplier.
|
|
398
|
+
* @returns {number}
|
|
399
|
+
*/
|
|
400
|
+
getGravityScale(): number;
|
|
401
|
+
/**
|
|
402
|
+
* @method getContactList
|
|
403
|
+
* @description Returns the contacts this body is part of.
|
|
404
|
+
* @returns {Array<Contact>}
|
|
405
|
+
*/
|
|
406
|
+
getContactList(): Array<Contact>;
|
|
407
|
+
/**
|
|
408
|
+
* @method synchronizeTransform
|
|
409
|
+
* @description Rebuilds the body transform from the sweep's current state.
|
|
410
|
+
* @private
|
|
411
|
+
*/
|
|
412
|
+
private synchronizeTransform;
|
|
413
|
+
/**
|
|
414
|
+
* @method synchronizeFixtures
|
|
415
|
+
* @description Updates the broadphase proxies to span where the body was at
|
|
416
|
+
* the start of the step and where it is now.
|
|
417
|
+
* @param {Transform2} [xf1] - Optional explicit "before" transform
|
|
418
|
+
* @private
|
|
419
|
+
*/
|
|
420
|
+
private synchronizeFixtures;
|
|
421
|
+
/**
|
|
422
|
+
* @method advance
|
|
423
|
+
* @description Moves the body to a fraction of its sweep, used by continuous
|
|
424
|
+
* collision detection when an impact is found mid-step.
|
|
425
|
+
* @param {number} alpha
|
|
426
|
+
* @private
|
|
427
|
+
*/
|
|
428
|
+
private advance;
|
|
429
|
+
}
|
|
430
|
+
import { BodyType } from "./BodyType.js";
|
|
431
|
+
import { Transform2 } from "./Math2D.js";
|
|
432
|
+
import { Sweep } from "./Math2D.js";
|
|
433
|
+
import { Vec2 } from "./Math2D.js";
|
|
434
|
+
import { Fixture } from "./Fixture.js";
|
|
435
|
+
export { BodyType };
|