emeraldengine 2.2.1 → 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.
Files changed (208) hide show
  1. package/README.md +2198 -968
  2. package/dist/types/index.d.ts +75 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +81 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/src/Physics.d.ts +337 -0
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +102 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  54. package/dist/types/src/components/RigidBody.d.ts +456 -0
  55. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  56. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  57. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  58. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  59. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  60. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  61. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  62. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  63. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  64. package/dist/types/src/managers/GLManager.d.ts +84 -0
  65. package/dist/types/src/managers/GLState.d.ts +37 -0
  66. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  67. package/dist/types/src/managers/IDManager.d.ts +31 -0
  68. package/dist/types/src/managers/InputManager.d.ts +381 -0
  69. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  70. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  71. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  72. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  73. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  74. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  75. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  76. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  77. package/dist/types/src/physics/AABB.d.ts +92 -0
  78. package/dist/types/src/physics/Body.d.ts +435 -0
  79. package/dist/types/src/physics/BodyType.d.ts +6 -0
  80. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  81. package/dist/types/src/physics/Collision.d.ts +102 -0
  82. package/dist/types/src/physics/Contact.d.ts +206 -0
  83. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  84. package/dist/types/src/physics/Distance.d.ts +54 -0
  85. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  86. package/dist/types/src/physics/Fixture.d.ts +221 -0
  87. package/dist/types/src/physics/Island.d.ts +52 -0
  88. package/dist/types/src/physics/Joint.d.ts +59 -0
  89. package/dist/types/src/physics/Math2D.d.ts +371 -0
  90. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  91. package/dist/types/src/physics/Settings.d.ts +22 -0
  92. package/dist/types/src/physics/Shapes.d.ts +207 -0
  93. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  94. package/dist/types/src/physics/World.d.ts +274 -0
  95. package/dist/types/src/physics/index.d.ts +34 -0
  96. package/index.js +78 -0
  97. package/package.json +73 -60
  98. package/src/Animator.js +95 -0
  99. package/src/BitmapText.js +6 -5
  100. package/src/Camera.js +183 -0
  101. package/src/CameraController.js +192 -0
  102. package/src/CanvasText.js +281 -0
  103. package/src/CollisionLayers.js +86 -0
  104. package/src/Color.js +26 -18
  105. package/src/Coroutine.js +259 -0
  106. package/src/DebugOverlay.js +246 -0
  107. package/src/Drawable.js +842 -582
  108. package/src/Easing.js +57 -0
  109. package/src/Emerald.js +1150 -459
  110. package/src/EmeraldDB.js +328 -0
  111. package/src/FPSCounter.js +43 -43
  112. package/src/GLUtils.js +60 -67
  113. package/src/Instance.js +41 -5
  114. package/src/InstancedTexture.js +308 -127
  115. package/src/Interpolator.js +124 -0
  116. package/src/Material.js +202 -0
  117. package/src/MathUtils.js +134 -0
  118. package/src/ParticleEmitter.js +284 -0
  119. package/src/Physics.js +431 -40
  120. package/src/Pool.js +85 -0
  121. package/src/PostEffects.js +296 -0
  122. package/src/PostProcessor.js +304 -0
  123. package/src/RenderTarget.js +134 -0
  124. package/src/Scene.js +115 -83
  125. package/src/ScreenEffects.js +266 -0
  126. package/src/Serializer.js +131 -0
  127. package/src/Shaders.js +150 -165
  128. package/src/Shapes.js +118 -129
  129. package/src/SpatialGrid.js +111 -0
  130. package/src/SpriteBatch.js +299 -0
  131. package/src/StateMachine.js +82 -0
  132. package/src/Storage.js +175 -47
  133. package/src/Texture.js +58 -67
  134. package/src/TextureAtlas.js +96 -0
  135. package/src/Tilemap.js +274 -0
  136. package/src/Time.js +51 -6
  137. package/src/Timer.js +99 -0
  138. package/src/Transform.js +100 -7
  139. package/src/Tween.js +160 -0
  140. package/src/UI.js +394 -0
  141. package/src/components/Behaviour.js +90 -0
  142. package/src/components/BoxCollider.js +29 -12
  143. package/src/components/BoxColliderDebug.js +3 -4
  144. package/src/components/CircleCollider.js +26 -12
  145. package/src/components/CircleColliderDebug.js +25 -24
  146. package/src/components/Collider.js +150 -34
  147. package/src/components/GameObject.js +130 -21
  148. package/src/components/PolygonCollider.js +55 -0
  149. package/src/components/RigidBody.js +556 -8
  150. package/src/importers/Aseprite.js +142 -0
  151. package/src/importers/ForgeLevel.js +581 -0
  152. package/src/importers/TiledMap.js +158 -0
  153. package/src/lights/DirectionalLight.js +6 -15
  154. package/src/lights/PointLight.js +4 -4
  155. package/src/managers/AssetManager.js +239 -0
  156. package/src/managers/AudioManager.js +565 -146
  157. package/src/managers/EventManager.js +488 -477
  158. package/src/managers/GLManager.js +57 -0
  159. package/src/managers/GLState.js +70 -0
  160. package/src/managers/Gamepad.js +126 -0
  161. package/src/managers/IDManager.js +24 -2
  162. package/src/managers/InputManager.js +905 -0
  163. package/src/managers/NetworkManager.js +178 -0
  164. package/src/managers/RenderStats.js +34 -0
  165. package/src/managers/SceneManager.js +30 -0
  166. package/src/managers/ShaderManager.js +0 -2
  167. package/src/managers/TextureManager.js +218 -0
  168. package/src/particlesystem/Particle.js +82 -7
  169. package/src/particlesystem/ParticleSettings.js +21 -3
  170. package/src/particlesystem/Particles.js +80 -31
  171. package/src/physics/AABB.js +207 -0
  172. package/src/physics/Body.js +862 -0
  173. package/src/physics/BodyType.js +16 -0
  174. package/src/physics/BroadPhase.js +641 -0
  175. package/src/physics/Collision.js +534 -0
  176. package/src/physics/Contact.js +500 -0
  177. package/src/physics/ContactSolver.js +526 -0
  178. package/src/physics/Distance.js +403 -0
  179. package/src/physics/DistanceJoint.js +227 -0
  180. package/src/physics/Fixture.js +346 -0
  181. package/src/physics/Island.js +203 -0
  182. package/src/physics/Joint.js +78 -0
  183. package/src/physics/Math2D.js +573 -0
  184. package/src/physics/RevoluteJoint.js +278 -0
  185. package/src/physics/Settings.js +78 -0
  186. package/src/physics/Shapes.js +549 -0
  187. package/src/physics/TimeOfImpact.js +87 -0
  188. package/src/physics/World.js +731 -0
  189. package/src/physics/index.js +79 -0
  190. package/dist/types/Drawable.d.ts +0 -157
  191. package/dist/types/Emerald.d.ts +0 -73
  192. package/dist/types/GLUtils.d.ts +0 -6
  193. package/dist/types/Physics.d.ts +0 -139
  194. package/dist/types/Scene.d.ts +0 -39
  195. package/dist/types/Shaders.d.ts +0 -4
  196. package/dist/types/Storage.d.ts +0 -46
  197. package/dist/types/Time.d.ts +0 -22
  198. package/dist/types/Transform.d.ts +0 -41
  199. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  200. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  201. package/dist/types/components/Collider.d.ts +0 -53
  202. package/dist/types/components/GameObject.d.ts +0 -72
  203. package/dist/types/components/RigidBody.d.ts +0 -104
  204. package/dist/types/managers/AudioManager.d.ts +0 -60
  205. package/dist/types/managers/GLManager.d.ts +0 -47
  206. package/dist/types/managers/IDManager.d.ts +0 -21
  207. package/dist/types/managers/SceneManager.d.ts +0 -22
  208. package/dist/types/particlesystem/Particle.d.ts +0 -42
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @class Manifold
3
+ * @description Up to two contact points plus the frame they are expressed in.
4
+ * Two points is all a 2D convex-convex overlap can produce, and it is exactly
5
+ * what a stable resting contact (a box on the ground) needs.
6
+ */
7
+ export class Manifold {
8
+ type: number;
9
+ localNormal: Vec2;
10
+ localPoint: Vec2;
11
+ points: ManifoldPoint[];
12
+ pointCount: number;
13
+ /**
14
+ * @method reset
15
+ * @description Empties the manifold.
16
+ */
17
+ reset(): void;
18
+ }
19
+ /**
20
+ * @class ManifoldPoint
21
+ * @description A single contact point, stored in the reference body's local
22
+ * frame so it stays valid as the bodies move within a step.
23
+ */
24
+ export class ManifoldPoint {
25
+ localPoint: Vec2;
26
+ normalImpulse: number;
27
+ tangentImpulse: number;
28
+ id: number;
29
+ }
30
+ export type ManifoldType = ManifoldType;
31
+ export namespace ManifoldType {
32
+ let CIRCLES: number;
33
+ let FACE_A: number;
34
+ let FACE_B: number;
35
+ }
36
+ /**
37
+ * @class WorldManifold
38
+ * @description A manifold converted into world space: the collision normal
39
+ * (always pointing from body A to body B), the contact points, and how deeply
40
+ * each one is penetrating (negative means overlapping).
41
+ */
42
+ export class WorldManifold {
43
+ normal: Vec2;
44
+ points: Vec2[];
45
+ separations: number[];
46
+ pointCount: number;
47
+ /**
48
+ * @method initialize
49
+ * @description Fills this world manifold from a local manifold.
50
+ * @param {Manifold} manifold
51
+ * @param {Transform2} xfA
52
+ * @param {number} radiusA
53
+ * @param {Transform2} xfB
54
+ * @param {number} radiusB
55
+ * @returns {WorldManifold} - this
56
+ */
57
+ initialize(manifold: Manifold, xfA: Transform2, radiusA: number, xfB: Transform2, radiusB: number): WorldManifold;
58
+ }
59
+ /**
60
+ * @function collideCircles
61
+ * @description Builds the manifold for two circles.
62
+ * @param {Manifold} manifold - Output manifold
63
+ * @param {CircleShape} circleA
64
+ * @param {Transform2} xfA
65
+ * @param {CircleShape} circleB
66
+ * @param {Transform2} xfB
67
+ */
68
+ export function collideCircles(manifold: Manifold, circleA: CircleShape, xfA: Transform2, circleB: CircleShape, xfB: Transform2): void;
69
+ /**
70
+ * @function collidePolygonAndCircle
71
+ * @description Builds the manifold for a polygon against a circle. The circle
72
+ * is pushed into the polygon's frame, then tested against the closest face,
73
+ * falling back to the nearest corner when it sits past the face's edge.
74
+ * @param {Manifold} manifold - Output manifold
75
+ * @param {PolygonShape} polygonA
76
+ * @param {Transform2} xfA
77
+ * @param {CircleShape} circleB
78
+ * @param {Transform2} xfB
79
+ */
80
+ export function collidePolygonAndCircle(manifold: Manifold, polygonA: PolygonShape, xfA: Transform2, circleB: CircleShape, xfB: Transform2): void;
81
+ /**
82
+ * @function collidePolygons
83
+ * @description Builds the manifold for two convex polygons using the
84
+ * separating-axis test to pick a reference face, then clipping the opposing
85
+ * (incident) edge against it. The result is the one- or two-point contact patch
86
+ * that makes boxes rest flat instead of rocking.
87
+ * @param {Manifold} manifold - Output manifold
88
+ * @param {PolygonShape} polyA
89
+ * @param {Transform2} xfA
90
+ * @param {PolygonShape} polyB
91
+ * @param {Transform2} xfB
92
+ */
93
+ export function collidePolygons(manifold: Manifold, polyA: PolygonShape, xfA: Transform2, polyB: PolygonShape, xfB: Transform2): void;
94
+ /**
95
+ * @function mulTXf
96
+ * @description Composes transforms: returns the transform of `B` expressed in
97
+ * `A`'s frame.
98
+ * @private
99
+ */
100
+ export function mulTXf(A: any, B: any): Transform2;
101
+ import { Vec2 } from "./Math2D.js";
102
+ import { Transform2 } from "./Math2D.js";
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @class Contact
3
+ * @description A potential or actual touch between two fixtures. The broadphase
4
+ * creates one as soon as two AABBs overlap; `touching` only becomes true once
5
+ * the narrowphase finds real contact points. Contacts persist across steps,
6
+ * which is what lets the solver warm-start from last frame's impulses.
7
+ */
8
+ export class Contact {
9
+ /**
10
+ * @method create
11
+ * @description Builds a contact for a fixture pair, normalizing the order so
12
+ * mixed polygon/circle pairs always arrive as (polygon, circle): the one
13
+ * ordering the narrowphase implements.
14
+ * @param {Fixture} fixtureA
15
+ * @param {Fixture} fixtureB
16
+ * @returns {Contact}
17
+ */
18
+ static create(fixtureA: Fixture, fixtureB: Fixture): Contact;
19
+ constructor(fixtureA: any, fixtureB: any);
20
+ fixtureA: any;
21
+ fixtureB: any;
22
+ manifold: Manifold;
23
+ friction: number;
24
+ restitution: any;
25
+ tangentSpeed: number;
26
+ /** @private */
27
+ private touching;
28
+ /** @private */
29
+ private enabled;
30
+ /** @private */
31
+ private filterFlag;
32
+ /** @private */
33
+ private islandFlag;
34
+ /** @private */
35
+ private toiFlag;
36
+ /** @private */
37
+ private toi;
38
+ /** @private */
39
+ private _index;
40
+ /**
41
+ * @method getManifold
42
+ * @description Returns the local-space manifold.
43
+ * @returns {Manifold}
44
+ */
45
+ getManifold(): Manifold;
46
+ /**
47
+ * @method getWorldManifold
48
+ * @description Returns the contact in world space: the normal (pointing from
49
+ * fixture A's body towards fixture B's), the contact points, and the
50
+ * separation at each point.
51
+ * @param {WorldManifold} [worldManifold] - Optional object to fill
52
+ * @returns {WorldManifold}
53
+ */
54
+ getWorldManifold(worldManifold?: WorldManifold): WorldManifold;
55
+ /**
56
+ * @method isTouching
57
+ * @description Whether the fixtures are actually in contact this step.
58
+ * @returns {boolean}
59
+ */
60
+ isTouching(): boolean;
61
+ /**
62
+ * @method setEnabled
63
+ * @description Enables or disables the collision response for this contact.
64
+ * Disabling only lasts for the current step (useful from a pre-solve
65
+ * callback to build one-way platforms).
66
+ * @param {boolean} value
67
+ */
68
+ setEnabled(value: boolean): void;
69
+ /**
70
+ * @method isEnabled
71
+ * @description Whether the collision response is enabled.
72
+ * @returns {boolean}
73
+ */
74
+ isEnabled(): boolean;
75
+ /**
76
+ * @method getFixtureA
77
+ * @description Returns the first fixture.
78
+ * @returns {Fixture}
79
+ */
80
+ getFixtureA(): Fixture;
81
+ /**
82
+ * @method getFixtureB
83
+ * @description Returns the second fixture.
84
+ * @returns {Fixture}
85
+ */
86
+ getFixtureB(): Fixture;
87
+ /**
88
+ * @method getFriction
89
+ * @description Returns the mixed friction used by the solver.
90
+ * @returns {number}
91
+ */
92
+ getFriction(): number;
93
+ /**
94
+ * @method setFriction
95
+ * @description Overrides the mixed friction for this contact.
96
+ * @param {number} friction
97
+ */
98
+ setFriction(friction: number): void;
99
+ /**
100
+ * @method resetFriction
101
+ * @description Restores the friction mixed from the two fixtures.
102
+ */
103
+ resetFriction(): void;
104
+ /**
105
+ * @method getRestitution
106
+ * @description Returns the mixed restitution used by the solver.
107
+ * @returns {number}
108
+ */
109
+ getRestitution(): number;
110
+ /**
111
+ * @method setRestitution
112
+ * @description Overrides the mixed restitution for this contact.
113
+ * @param {number} restitution
114
+ */
115
+ setRestitution(restitution: number): void;
116
+ /**
117
+ * @method resetRestitution
118
+ * @description Restores the restitution mixed from the two fixtures.
119
+ */
120
+ resetRestitution(): void;
121
+ /**
122
+ * @method flagForFiltering
123
+ * @description Marks the contact so the next step re-checks whether these two
124
+ * fixtures are still allowed to collide.
125
+ */
126
+ flagForFiltering(): void;
127
+ /**
128
+ * @method evaluate
129
+ * @description Runs the narrowphase for this fixture pair into `manifold`.
130
+ * @param {Manifold} manifold
131
+ * @param {Transform2} xfA
132
+ * @param {Transform2} xfB
133
+ * @private
134
+ */
135
+ private evaluate;
136
+ /**
137
+ * @method update
138
+ * @description Re-runs the narrowphase, carries last step's impulses over to
139
+ * matching contact points (warm starting), and fires begin/end contact
140
+ * events on the world when the touching state flips.
141
+ * @param {World} world - The owning world, used to dispatch events
142
+ */
143
+ update(world: World): void;
144
+ }
145
+ /**
146
+ * @class ContactManager
147
+ * @description Owns the world's contact list: creates contacts from broadphase
148
+ * pairs, drops them once the AABBs stop overlapping, and refreshes the ones
149
+ * that remain each step.
150
+ */
151
+ export class ContactManager {
152
+ constructor(world: any);
153
+ world: any;
154
+ contacts: any[];
155
+ /**
156
+ * @method addPair
157
+ * @description Creates a contact for a new broadphase pair, unless the two
158
+ * fixtures share a body, already have a contact, or the filter rejects them.
159
+ * @param {FixtureProxy} proxyA
160
+ * @param {FixtureProxy} proxyB
161
+ */
162
+ addPair(proxyA: FixtureProxy, proxyB: FixtureProxy): void;
163
+ /**
164
+ * @method findNewContacts
165
+ * @description Turns this step's broadphase movement into new contacts.
166
+ */
167
+ findNewContacts(): void;
168
+ /**
169
+ * @method destroy
170
+ * @description Removes a contact, firing end-contact if it was touching.
171
+ * @param {Contact} contact
172
+ */
173
+ destroy(contact: Contact): void;
174
+ /**
175
+ * @method collide
176
+ * @description Refreshes every contact: drops the ones whose AABBs no longer
177
+ * overlap or whose filters changed, and re-runs the narrowphase on the rest.
178
+ */
179
+ collide(): void;
180
+ }
181
+ /**
182
+ * @function shouldCollide
183
+ * @description Applies the collision filter to a fixture pair. A positive
184
+ * shared group index always collides, a negative one never does; otherwise each
185
+ * fixture's category must appear in the other's mask.
186
+ * @param {Fixture} fixtureA
187
+ * @param {Fixture} fixtureB
188
+ * @returns {boolean}
189
+ */
190
+ export function shouldCollide(fixtureA: Fixture, fixtureB: Fixture): boolean;
191
+ /**
192
+ * @function mixFriction
193
+ * @description Combines two friction coefficients (geometric mean), so a slick
194
+ * body sliding on a rough one lands somewhere in between.
195
+ * @private
196
+ */
197
+ export function mixFriction(a: any, b: any): number;
198
+ /**
199
+ * @function mixRestitution
200
+ * @description Combines two restitutions: the bouncier surface wins, which is
201
+ * what players expect from a trampoline on concrete.
202
+ * @private
203
+ */
204
+ export function mixRestitution(a: any, b: any): any;
205
+ import { Manifold } from "./Collision.js";
206
+ import { WorldManifold } from "./Collision.js";
@@ -0,0 +1,108 @@
1
+ export default ContactSolver;
2
+ /**
3
+ * @class ContactSolver
4
+ * @description Resolves every contact in an island with sequential impulses:
5
+ * for each contact point it works out the impulse that removes the approaching
6
+ * velocity (plus any bounce), applies it, and repeats over all points for a
7
+ * fixed number of iterations. Impulses are accumulated and clamped so they can
8
+ * only ever push, never pull, and they carry over between steps (warm starting)
9
+ * so stacks settle instead of sinking.
10
+ *
11
+ * Position error left over after the velocity pass is fixed separately, by
12
+ * nudging the bodies apart without injecting energy.
13
+ *
14
+ * @param {Object} def - `{ contacts, positions, velocities, dt, velocityThreshold }`
15
+ */
16
+ declare class ContactSolver {
17
+ constructor(def: any);
18
+ positions: any;
19
+ velocities: any;
20
+ contacts: any;
21
+ dt: any;
22
+ velocityThreshold: any;
23
+ velocityConstraints: {
24
+ friction: any;
25
+ restitution: any;
26
+ tangentSpeed: any;
27
+ indexA: any;
28
+ indexB: any;
29
+ invMassA: any;
30
+ invMassB: any;
31
+ invIA: any;
32
+ invIB: any;
33
+ contactIndex: number;
34
+ pointCount: any;
35
+ normal: Vec2;
36
+ tangent: Vec2;
37
+ K: {
38
+ k11: number;
39
+ k12: number;
40
+ k22: number;
41
+ };
42
+ normalMass: {
43
+ k11: number;
44
+ k12: number;
45
+ k22: number;
46
+ };
47
+ points: any[];
48
+ }[];
49
+ positionConstraints: {
50
+ indexA: any;
51
+ indexB: any;
52
+ invMassA: any;
53
+ invMassB: any;
54
+ invIA: any;
55
+ invIB: any;
56
+ localCenterA: any;
57
+ localCenterB: any;
58
+ radiusA: any;
59
+ radiusB: any;
60
+ type: any;
61
+ localNormal: any;
62
+ localPoint: any;
63
+ localPoints: any[];
64
+ pointCount: any;
65
+ }[];
66
+ /**
67
+ * @method initializeVelocityConstraints
68
+ * @description Computes the effective mass at every contact point and the
69
+ * bounce target, from the state at the start of the step.
70
+ */
71
+ initializeVelocityConstraints(): void;
72
+ /**
73
+ * @method warmStart
74
+ * @description Re-applies last step's impulses before solving, which gets the
75
+ * solver most of the way to the answer immediately.
76
+ */
77
+ warmStart(): void;
78
+ /**
79
+ * @method solveVelocityConstraints
80
+ * @description One relaxation pass over every contact point: friction first,
81
+ * then the normal impulses that stop the bodies interpenetrating.
82
+ */
83
+ solveVelocityConstraints(): void;
84
+ /**
85
+ * @method _solveBlock
86
+ * @description Two-point block solve. Solving both points of a manifold
87
+ * together (rather than one after the other) is what keeps a box resting on
88
+ * the ground from rocking between its corners. Four candidate solutions are
89
+ * tried in turn: both points pushing, either one alone, or neither.
90
+ * @private
91
+ */
92
+ private _solveBlock;
93
+ /**
94
+ * @method storeImpulses
95
+ * @description Writes the accumulated impulses back onto the manifold so the
96
+ * next step can warm-start from them.
97
+ */
98
+ storeImpulses(): void;
99
+ /**
100
+ * @method solvePositionConstraints
101
+ * @description Pushes overlapping bodies apart geometrically. This runs on
102
+ * positions only, no velocity is added, so separating a deep overlap can't
103
+ * fling bodies across the level.
104
+ * @returns {boolean} - True once every overlap is within tolerance
105
+ */
106
+ solvePositionConstraints(): boolean;
107
+ }
108
+ import { Vec2 } from "./Math2D.js";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @class DistanceProxy
3
+ * @description A convex shape reduced to what GJK needs: a point cloud plus a
4
+ * skin radius. Circles collapse to a single point with a large radius; polygons
5
+ * keep their corners and carry the small polygon skin.
6
+ */
7
+ export class DistanceProxy {
8
+ vertices: any[];
9
+ radius: number;
10
+ /**
11
+ * @method set
12
+ * @description Fills this proxy from a shape.
13
+ * @param {Shape} shape - A CircleShape or PolygonShape
14
+ * @returns {DistanceProxy} - this
15
+ */
16
+ set(shape: Shape): DistanceProxy;
17
+ /**
18
+ * @method getSupport
19
+ * @description Index of the vertex furthest along a direction.
20
+ * @param {Object} d - Direction in the proxy's local frame
21
+ * @returns {number}
22
+ */
23
+ getSupport(d: any): number;
24
+ /**
25
+ * @method getMaxExtent
26
+ * @description Distance from the local origin to the furthest vertex, plus
27
+ * the skin. Continuous collision uses it to bound how fast a rotating body's
28
+ * surface can approach another.
29
+ * @returns {number}
30
+ */
31
+ getMaxExtent(): number;
32
+ }
33
+ /**
34
+ * @function distance
35
+ * @description GJK: computes the distance and the closest points between two
36
+ * convex proxies. This is the primitive continuous collision and overlap tests
37
+ * are built on.
38
+ * @param {Object} output - Written as `{ distance, pointA, pointB, iterations }`
39
+ * @param {Object} input - `{ proxyA, proxyB, transformA, transformB, useRadii }`
40
+ * @returns {Object} - The same output object
41
+ */
42
+ export function distance(output: any, input: any): any;
43
+ /**
44
+ * @function testOverlap
45
+ * @description True when two shapes overlap under their transforms. Sensors use
46
+ * this instead of building a manifold, since they never need contact points.
47
+ * @param {Shape} shapeA
48
+ * @param {Transform2} xfA
49
+ * @param {Shape} shapeB
50
+ * @param {Transform2} xfB
51
+ * @returns {boolean}
52
+ */
53
+ export function testOverlap(shapeA: Shape, xfA: Transform2, shapeB: Shape, xfB: Transform2): boolean;
54
+ import { Transform2 } from "./Math2D.js";
@@ -0,0 +1,90 @@
1
+ export default DistanceJoint;
2
+ /**
3
+ * @class DistanceJoint
4
+ * @extends Joint
5
+ * @description Holds two anchor points at a fixed distance apart, like a
6
+ * rigid rod. Passing `frequencyHz` turns it into a damped spring pulling the
7
+ * anchors toward that distance instead of holding it exactly, for tethers
8
+ * and camera rigs that should have some give.
9
+ * @param {Object} def - `{ bodyA, bodyB, localAnchorA, localAnchorB, length,
10
+ * frequencyHz, dampingRatio, collideConnected, userData }`
11
+ */
12
+ declare class DistanceJoint extends Joint {
13
+ localAnchorA: Vec2;
14
+ localAnchorB: Vec2;
15
+ length: any;
16
+ frequencyHz: any;
17
+ dampingRatio: any;
18
+ impulse: number;
19
+ gamma: number;
20
+ bias: number;
21
+ u: Vec2;
22
+ rA: Vec2;
23
+ rB: Vec2;
24
+ mass: number;
25
+ /** @private */
26
+ private indexA;
27
+ /** @private */
28
+ private indexB;
29
+ /**
30
+ * @method getAnchorA
31
+ * @returns {Vec2}
32
+ */
33
+ getAnchorA(): Vec2;
34
+ /**
35
+ * @method getAnchorB
36
+ * @returns {Vec2}
37
+ */
38
+ getAnchorB(): Vec2;
39
+ /**
40
+ * @method getReactionForce
41
+ * @param {number} invDt
42
+ * @returns {Vec2}
43
+ */
44
+ getReactionForce(invDt: number): Vec2;
45
+ /**
46
+ * @method getReactionTorque
47
+ * @returns {number}
48
+ */
49
+ getReactionTorque(): number;
50
+ /**
51
+ * @method setLength
52
+ * @param {number} length
53
+ */
54
+ setLength(length: number): void;
55
+ /**
56
+ * @method getLength
57
+ * @returns {number}
58
+ */
59
+ getLength(): number;
60
+ /**
61
+ * @method initVelocityConstraints
62
+ * @description Effective mass at the current anchor separation, plus (for
63
+ * a soft joint) the spring-damper bias for this step.
64
+ * @param {Object} step - `{ dt, warmStarting }`
65
+ * @param {Array<Object>} positions
66
+ * @param {Array<Object>} velocities
67
+ */
68
+ initVelocityConstraints(step: any, positions: Array<any>, velocities: Array<any>): void;
69
+ invMassA: any;
70
+ invMassB: any;
71
+ invIA: any;
72
+ invIB: any;
73
+ /**
74
+ * @method solveVelocityConstraints
75
+ * @param {Object} step - `{ dt }` (unused here, kept for a uniform joint interface)
76
+ * @param {Array<Object>} velocities
77
+ */
78
+ solveVelocityConstraints(step: any, velocities: Array<any>): void;
79
+ /**
80
+ * @method solvePositionConstraints
81
+ * @description Skipped for a soft (spring) joint: the bias already pulled
82
+ * it toward rest length during the velocity pass, and correcting position
83
+ * on top of that would fight the spring.
84
+ * @param {Array<Object>} positions
85
+ * @returns {boolean}
86
+ */
87
+ solvePositionConstraints(positions: Array<any>): boolean;
88
+ }
89
+ import { Joint } from "./Joint.js";
90
+ import { Vec2 } from "./Math2D.js";