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.
Files changed (103) hide show
  1. package/README.md +1498 -1659
  2. package/dist/types/index.d.ts +4 -1
  3. package/dist/types/src/Animator.d.ts +1 -1
  4. package/dist/types/src/CollisionLayers.d.ts +2 -2
  5. package/dist/types/src/Color.d.ts +1 -0
  6. package/dist/types/src/Drawable.d.ts +1 -1
  7. package/dist/types/src/EmeraldDB.d.ts +2 -2
  8. package/dist/types/src/InstancedTexture.d.ts +17 -2
  9. package/dist/types/src/Material.d.ts +2 -2
  10. package/dist/types/src/MathUtils.d.ts +2 -1
  11. package/dist/types/src/ParticleEmitter.d.ts +1 -1
  12. package/dist/types/src/Physics.d.ts +148 -18
  13. package/dist/types/src/Scene.d.ts +1 -1
  14. package/dist/types/src/Shaders.d.ts +2 -2
  15. package/dist/types/src/Tilemap.d.ts +1 -1
  16. package/dist/types/src/UI.d.ts +1 -1
  17. package/dist/types/src/components/Behaviour.d.ts +2 -2
  18. package/dist/types/src/components/Collider.d.ts +7 -1
  19. package/dist/types/src/components/GameObject.d.ts +2 -2
  20. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  21. package/dist/types/src/components/RigidBody.d.ts +281 -8
  22. package/dist/types/src/importers/Aseprite.d.ts +2 -2
  23. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  24. package/dist/types/src/importers/TiledMap.d.ts +1 -1
  25. package/dist/types/src/managers/EventManager.d.ts +1 -1
  26. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  27. package/dist/types/src/managers/InputManager.d.ts +93 -2
  28. package/dist/types/src/managers/NetworkManager.d.ts +2 -2
  29. package/dist/types/src/managers/RenderStats.d.ts +1 -1
  30. package/dist/types/src/managers/TextureManager.d.ts +1 -1
  31. package/dist/types/src/physics/AABB.d.ts +92 -0
  32. package/dist/types/src/physics/Body.d.ts +435 -0
  33. package/dist/types/src/physics/BodyType.d.ts +6 -0
  34. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  35. package/dist/types/src/physics/Collision.d.ts +102 -0
  36. package/dist/types/src/physics/Contact.d.ts +206 -0
  37. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  38. package/dist/types/src/physics/Distance.d.ts +54 -0
  39. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  40. package/dist/types/src/physics/Fixture.d.ts +221 -0
  41. package/dist/types/src/physics/Island.d.ts +52 -0
  42. package/dist/types/src/physics/Joint.d.ts +59 -0
  43. package/dist/types/src/physics/Math2D.d.ts +371 -0
  44. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  45. package/dist/types/src/physics/Settings.d.ts +22 -0
  46. package/dist/types/src/physics/Shapes.d.ts +207 -0
  47. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  48. package/dist/types/src/physics/World.d.ts +274 -0
  49. package/dist/types/src/physics/index.d.ts +34 -0
  50. package/index.js +6 -0
  51. package/package.json +2 -3
  52. package/src/Animator.js +1 -1
  53. package/src/CollisionLayers.js +3 -3
  54. package/src/Color.js +8 -0
  55. package/src/Drawable.js +1 -1
  56. package/src/Emerald.js +1 -1
  57. package/src/EmeraldDB.js +2 -2
  58. package/src/InstancedTexture.js +57 -9
  59. package/src/Material.js +2 -2
  60. package/src/MathUtils.js +2 -1
  61. package/src/ParticleEmitter.js +1 -1
  62. package/src/Physics.js +270 -60
  63. package/src/Scene.js +1 -1
  64. package/src/Shaders.js +20 -20
  65. package/src/Tilemap.js +1 -1
  66. package/src/UI.js +1 -1
  67. package/src/components/Behaviour.js +2 -2
  68. package/src/components/BoxCollider.js +7 -9
  69. package/src/components/BoxColliderDebug.js +3 -4
  70. package/src/components/CircleCollider.js +7 -9
  71. package/src/components/CircleColliderDebug.js +3 -2
  72. package/src/components/Collider.js +13 -3
  73. package/src/components/GameObject.js +2 -2
  74. package/src/components/PolygonCollider.js +55 -0
  75. package/src/components/RigidBody.js +441 -14
  76. package/src/importers/Aseprite.js +2 -2
  77. package/src/importers/ForgeLevel.js +581 -0
  78. package/src/importers/TiledMap.js +1 -1
  79. package/src/managers/EventManager.js +1 -1
  80. package/src/managers/Gamepad.js +126 -0
  81. package/src/managers/InputManager.js +129 -3
  82. package/src/managers/NetworkManager.js +2 -2
  83. package/src/managers/RenderStats.js +1 -1
  84. package/src/managers/TextureManager.js +1 -1
  85. package/src/physics/AABB.js +207 -0
  86. package/src/physics/Body.js +862 -0
  87. package/src/physics/BodyType.js +16 -0
  88. package/src/physics/BroadPhase.js +641 -0
  89. package/src/physics/Collision.js +534 -0
  90. package/src/physics/Contact.js +500 -0
  91. package/src/physics/ContactSolver.js +526 -0
  92. package/src/physics/Distance.js +403 -0
  93. package/src/physics/DistanceJoint.js +227 -0
  94. package/src/physics/Fixture.js +346 -0
  95. package/src/physics/Island.js +203 -0
  96. package/src/physics/Joint.js +78 -0
  97. package/src/physics/Math2D.js +573 -0
  98. package/src/physics/RevoluteJoint.js +278 -0
  99. package/src/physics/Settings.js +78 -0
  100. package/src/physics/Shapes.js +549 -0
  101. package/src/physics/TimeOfImpact.js +87 -0
  102. package/src/physics/World.js +731 -0
  103. package/src/physics/index.js +79 -0
@@ -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";
@@ -0,0 +1,221 @@
1
+ /**
2
+ * @class Fixture
3
+ * @description A shape bound to a body, together with the material properties
4
+ * that decide how contacts behave: density (which feeds the body's mass),
5
+ * friction, restitution (bounciness), the sensor flag, and the collision
6
+ * filter. A body can carry any number of fixtures.
7
+ *
8
+ * Fixtures are created through {@link Body#createFixture}, never directly.
9
+ */
10
+ export class Fixture {
11
+ constructor(body: any, shape: any, def?: {});
12
+ body: any;
13
+ shape: any;
14
+ density: any;
15
+ friction: any;
16
+ restitution: any;
17
+ sensor: boolean;
18
+ userData: any;
19
+ filter: {
20
+ categoryBits: any;
21
+ maskBits: any;
22
+ groupIndex: any;
23
+ };
24
+ /** @private */
25
+ private proxies;
26
+ /** @private */
27
+ private next;
28
+ /**
29
+ * @method getType
30
+ * @description Returns the underlying shape type ("circle" or "polygon").
31
+ * @returns {string}
32
+ */
33
+ getType(): string;
34
+ /**
35
+ * @method getShape
36
+ * @description Returns the fixture's shape.
37
+ * @returns {Shape}
38
+ */
39
+ getShape(): Shape;
40
+ /**
41
+ * @method getBody
42
+ * @description Returns the body this fixture is attached to.
43
+ * @returns {Body}
44
+ */
45
+ getBody(): Body;
46
+ /**
47
+ * @method getNext
48
+ * @description Returns the next fixture on the same body, or null.
49
+ * @returns {Fixture|null}
50
+ */
51
+ getNext(): Fixture | null;
52
+ /**
53
+ * @method setUserData
54
+ * @description Attaches arbitrary data to the fixture.
55
+ * @param {*} data
56
+ */
57
+ setUserData(data: any): void;
58
+ /**
59
+ * @method getUserData
60
+ * @description Returns the attached data.
61
+ * @returns {*}
62
+ */
63
+ getUserData(): any;
64
+ /**
65
+ * @method setSensor
66
+ * @description A sensor still reports contacts but never generates a
67
+ * collision response: the classic trigger volume.
68
+ * @param {boolean} value
69
+ */
70
+ setSensor(value: boolean): void;
71
+ /**
72
+ * @method isSensor
73
+ * @description Whether this fixture is a sensor.
74
+ * @returns {boolean}
75
+ */
76
+ isSensor(): boolean;
77
+ /**
78
+ * @method setFilterData
79
+ * @description Replaces the collision filter. Two fixtures collide only when
80
+ * each one's category bit appears in the other's mask (or they share a
81
+ * positive group index).
82
+ * @param {Object} filter - `{ categoryBits, maskBits, groupIndex }`
83
+ */
84
+ setFilterData(filter?: any): void;
85
+ /**
86
+ * @method getFilterData
87
+ * @description Returns the current collision filter.
88
+ * @returns {Object}
89
+ */
90
+ getFilterData(): any;
91
+ /**
92
+ * @method getFilterCategoryBits
93
+ * @description Returns the category bits.
94
+ * @returns {number}
95
+ */
96
+ getFilterCategoryBits(): number;
97
+ /**
98
+ * @method getFilterMaskBits
99
+ * @description Returns the mask bits.
100
+ * @returns {number}
101
+ */
102
+ getFilterMaskBits(): number;
103
+ /**
104
+ * @method getFilterGroupIndex
105
+ * @description Returns the group index.
106
+ * @returns {number}
107
+ */
108
+ getFilterGroupIndex(): number;
109
+ /**
110
+ * @method refilter
111
+ * @description Re-evaluates existing contacts after a filter change, so a
112
+ * fixture that just stopped colliding with a layer separates immediately
113
+ * instead of on its next move.
114
+ */
115
+ refilter(): void;
116
+ /**
117
+ * @method setDensity
118
+ * @description Sets the density. Call {@link Body#resetMassData} afterwards
119
+ * for it to take effect on the body's mass.
120
+ * @param {number} density
121
+ */
122
+ setDensity(density: number): void;
123
+ /**
124
+ * @method getDensity
125
+ * @description Returns the density.
126
+ * @returns {number}
127
+ */
128
+ getDensity(): number;
129
+ /**
130
+ * @method setFriction
131
+ * @description Sets the friction coefficient (0 = ice).
132
+ * @param {number} friction
133
+ */
134
+ setFriction(friction: number): void;
135
+ /**
136
+ * @method getFriction
137
+ * @description Returns the friction coefficient.
138
+ * @returns {number}
139
+ */
140
+ getFriction(): number;
141
+ /**
142
+ * @method setRestitution
143
+ * @description Sets the bounciness (0 = no bounce, 1 = perfectly elastic).
144
+ * @param {number} restitution
145
+ */
146
+ setRestitution(restitution: number): void;
147
+ /**
148
+ * @method getRestitution
149
+ * @description Returns the bounciness.
150
+ * @returns {number}
151
+ */
152
+ getRestitution(): number;
153
+ /**
154
+ * @method testPoint
155
+ * @description True when a world-space point is inside this fixture.
156
+ * @param {Object} p - `{ x, y }` in physics units
157
+ * @returns {boolean}
158
+ */
159
+ testPoint(p: any): boolean;
160
+ /**
161
+ * @method rayCast
162
+ * @description Casts a ray against this fixture's shape.
163
+ * @param {Object} output - Written as `{ fraction, normal }` on a hit
164
+ * @param {Object} input - `{ p1, p2, maxFraction }`
165
+ * @returns {boolean}
166
+ */
167
+ rayCast(output: any, input: any): boolean;
168
+ /**
169
+ * @method getMassData
170
+ * @description Computes this fixture's contribution to the body's mass.
171
+ * @param {Object} [massData]
172
+ * @returns {Object} - `{ mass, center, I }`
173
+ */
174
+ getMassData(massData?: any): any;
175
+ /**
176
+ * @method getAABB
177
+ * @description Returns the fixture's current world AABB.
178
+ * @param {number} [childIndex=0]
179
+ * @returns {AABB}
180
+ */
181
+ getAABB(childIndex?: number): AABB;
182
+ /**
183
+ * @method createProxies
184
+ * @description Registers this fixture with the broadphase.
185
+ * @param {BroadPhase} broadPhase
186
+ * @param {Transform2} xf
187
+ * @private
188
+ */
189
+ private createProxies;
190
+ /**
191
+ * @method destroyProxies
192
+ * @description Removes this fixture from the broadphase.
193
+ * @param {BroadPhase} broadPhase
194
+ * @private
195
+ */
196
+ private destroyProxies;
197
+ /**
198
+ * @method synchronize
199
+ * @description Re-fits the broadphase proxies after the body moved. The AABB
200
+ * spans both the old and the new transform so a fast body's proxy still
201
+ * covers the ground it swept over.
202
+ * @param {BroadPhase} broadPhase
203
+ * @param {Transform2} xf1
204
+ * @param {Transform2} xf2
205
+ * @private
206
+ */
207
+ private synchronize;
208
+ }
209
+ /**
210
+ * @class FixtureProxy
211
+ * @description The link between a fixture and its entry in the broadphase tree.
212
+ * @private
213
+ */
214
+ export class FixtureProxy {
215
+ constructor(fixture: any, childIndex: any);
216
+ aabb: AABB;
217
+ fixture: any;
218
+ childIndex: any;
219
+ proxyId: number;
220
+ }
221
+ import AABB from "./AABB.js";
@@ -0,0 +1,52 @@
1
+ export default Island;
2
+ /**
3
+ * @class Island
4
+ * @description A connected group of bodies, everything reachable through
5
+ * touching contacts, solved together. Islands are what make sleeping work:
6
+ * a pile of crates only goes to sleep once *every* body in it has settled, so
7
+ * one crate still rolling keeps the whole pile simulated.
8
+ */
9
+ declare class Island {
10
+ bodies: any[];
11
+ contacts: any[];
12
+ joints: any[];
13
+ /** @private */
14
+ private positions;
15
+ /** @private */
16
+ private velocities;
17
+ /**
18
+ * @method clear
19
+ * @description Empties the island for reuse on the next seed body.
20
+ */
21
+ clear(): void;
22
+ /**
23
+ * @method addBody
24
+ * @description Adds a body and records its index for the solver.
25
+ * @param {Body} body
26
+ */
27
+ addBody(body: Body): void;
28
+ /**
29
+ * @method addContact
30
+ * @description Adds a touching contact to be solved with this island.
31
+ * @param {Contact} contact
32
+ */
33
+ addContact(contact: Contact): void;
34
+ /**
35
+ * @method addJoint
36
+ * @description Adds a joint to be solved with this island.
37
+ * @param {Joint} joint
38
+ */
39
+ addJoint(joint: Joint): void;
40
+ /**
41
+ * @method solve
42
+ * @description Advances the island by one step: integrate velocities, solve
43
+ * contacts, integrate positions, fix leftover overlap, then decide whether
44
+ * the island can go to sleep.
45
+ * @param {Object} step - `{ dt, velocityIterations, positionIterations,
46
+ * warmStarting, velocityThreshold }`
47
+ * @param {Vec2} gravity - World gravity in physics units
48
+ * @param {boolean} allowSleep - Whether sleeping is enabled world-wide
49
+ */
50
+ solve(step: any, gravity: Vec2, allowSleep: boolean): void;
51
+ }
52
+ import { Vec2 } from "./Math2D.js";
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @class Joint
3
+ * @description Base class for a constraint between two bodies. A joint is
4
+ * solved by the same island that solves contacts (see {@link Island}), right
5
+ * alongside them, so a body linked only by a joint (no touching fixtures)
6
+ * still wakes, sleeps and moves together with whatever it is jointed to.
7
+ *
8
+ * Concrete joints ({@link DistanceJoint}, {@link RevoluteJoint}) implement
9
+ * `initVelocityConstraints`, `solveVelocityConstraints` and
10
+ * `solvePositionConstraints`, matching {@link ContactSolver}'s per-step
11
+ * lifecycle.
12
+ * @param {Object} def - `{ type, bodyA, bodyB, collideConnected, userData }`
13
+ */
14
+ export class Joint {
15
+ constructor(def: any);
16
+ type: any;
17
+ bodyA: any;
18
+ bodyB: any;
19
+ collideConnected: any;
20
+ userData: any;
21
+ /** @private */
22
+ private islandFlag;
23
+ /** @private */
24
+ private prev;
25
+ /** @private */
26
+ private next;
27
+ /**
28
+ * @method getType
29
+ * @returns {string}
30
+ */
31
+ getType(): string;
32
+ /**
33
+ * @method getBodyA
34
+ * @returns {Body}
35
+ */
36
+ getBodyA(): Body;
37
+ /**
38
+ * @method getBodyB
39
+ * @returns {Body}
40
+ */
41
+ getBodyB(): Body;
42
+ /**
43
+ * @method getUserData
44
+ * @returns {*}
45
+ */
46
+ getUserData(): any;
47
+ /**
48
+ * @method setUserData
49
+ * @param {*} data
50
+ */
51
+ setUserData(data: any): void;
52
+ }
53
+ /**
54
+ * @description Identifies a concrete {@link Joint} subclass.
55
+ */
56
+ export const JointType: Readonly<{
57
+ DISTANCE: "distance";
58
+ REVOLUTE: "revolute";
59
+ }>;