excalibur 0.28.2 → 0.28.3

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 (43) hide show
  1. package/CHANGELOG.md +73 -4
  2. package/build/dist/Collision/BodyComponent.js +374 -0
  3. package/build/dist/Collision/BodyComponent.js.map +1 -0
  4. package/build/dist/Collision/Colliders/CompositeCollider.js +222 -0
  5. package/build/dist/Collision/Colliders/CompositeCollider.js.map +1 -0
  6. package/build/dist/Collision/CollisionSystem.js +127 -0
  7. package/build/dist/Collision/CollisionSystem.js.map +1 -0
  8. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.d.ts +5 -1
  9. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js +244 -0
  10. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js.map +1 -0
  11. package/build/dist/Collision/Group/CollisionGroup.d.ts +3 -0
  12. package/build/dist/Collision/Group/CollisionGroup.js +128 -0
  13. package/build/dist/Collision/Group/CollisionGroup.js.map +1 -0
  14. package/build/dist/Collision/Group/CollisionGroupManager.js +56 -0
  15. package/build/dist/Collision/Group/CollisionGroupManager.js.map +1 -0
  16. package/build/dist/Collision/Index.js +31 -0
  17. package/build/dist/Collision/Index.js.map +1 -0
  18. package/build/dist/Graphics/Context/material-renderer/material-renderer.js +147 -0
  19. package/build/dist/Graphics/Context/material-renderer/material-renderer.js.map +1 -0
  20. package/build/dist/Graphics/Context/shader.js +353 -0
  21. package/build/dist/Graphics/Context/shader.js.map +1 -0
  22. package/build/dist/Graphics/Context/vertex-layout.js +109 -0
  23. package/build/dist/Graphics/Context/vertex-layout.js.map +1 -0
  24. package/build/dist/excalibur.js +91 -62
  25. package/build/dist/excalibur.js.map +1 -1
  26. package/build/dist/excalibur.min.js +1 -1
  27. package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
  28. package/build/dist/excalibur.min.js.map +1 -1
  29. package/build/esm/Collision/Detection/DynamicTreeCollisionProcessor.d.ts +5 -1
  30. package/build/esm/Collision/Group/CollisionGroup.d.ts +3 -0
  31. package/build/esm/excalibur.js +91 -62
  32. package/build/esm/excalibur.js.map +1 -1
  33. package/build/esm/excalibur.min.js +1 -1
  34. package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
  35. package/build/esm/excalibur.min.js.map +1 -1
  36. package/build/nuget/Excalibur.0.28.3.nupkg +0 -0
  37. package/build/v0.28.3.zip +0 -0
  38. package/excalibur-0.28.3.tgz +0 -0
  39. package/package.json +2 -2
  40. package/build/dist-v0.28.2.zip +0 -0
  41. package/build/nuget/Excalibur.0.28.2.nupkg +0 -0
  42. package/docker/Dockerfile +0 -20
  43. package/site/build/api/namespace/Provides support for mice, keyboards, and controllers./index.html +0 -49
package/CHANGELOG.md CHANGED
@@ -15,6 +15,79 @@ This project adheres to [Semantic Versioning](http://semver.org/).
15
15
 
16
16
  ### Added
17
17
 
18
+ -
19
+
20
+
21
+ ### Fixed
22
+
23
+ -
24
+
25
+ ### Updates
26
+
27
+ -
28
+
29
+ ### Changed
30
+
31
+ -
32
+
33
+ <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
34
+ <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
35
+ <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
36
+
37
+
38
+ ## [v0.28.2]
39
+
40
+ ### Breaking Changes
41
+
42
+ -
43
+
44
+ ### Deprecated
45
+
46
+ -
47
+
48
+ ### Added
49
+
50
+ - Added new feature to collision group raycasting, directly provide a `collisionMask` that you want to search for.
51
+
52
+ ```typescript
53
+ const playerGroup = ex.CollisionGroupManager.create('playerGroup');
54
+ const notPlayersMask = ~playersGroup.category;
55
+ const hits = engine.currentScene.physics.rayCast(
56
+ new ex.Ray(player.pos, playerDir),
57
+ {
58
+ maxDistance: playerSightDistance,
59
+ // Search for all categories that match the mask
60
+ collisionMask: notPlayers,
61
+ searchAllColliders: false
62
+ });
63
+ ```
64
+
65
+
66
+ ### Fixed
67
+
68
+ - Fixed issue where rendering multiple materials at once would crash the renderer
69
+ - Fixed issue where raycasting with more complex collision groups was not working as expected
70
+
71
+ ### Updates
72
+
73
+ -
74
+
75
+ ### Changed
76
+
77
+ -
78
+
79
+ ## [v0.28.2]
80
+
81
+ ### Breaking Changes
82
+
83
+ -
84
+
85
+ ### Deprecated
86
+
87
+ -
88
+
89
+ ### Added
90
+
18
91
  - Added `ex.Engine.version` to report the current excalibur version build string
19
92
  - Added new `ex.Screen.events`
20
93
  - `screen.events.on('resize', (evt) => )` Will emit when the screen is resized
@@ -47,10 +120,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
47
120
  - Changed the canvas 2d fallback default, no longer is enabled by default. Developers must opt in.
48
121
  - Allow entity names to be set after construction! Entities will now default to a name "Entity#1234" followed by an id.
49
122
 
50
- <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
51
- <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
52
- <!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
53
-
54
123
  ## [v0.28.0]
55
124
 
56
125
  ### Breaking Changes
@@ -0,0 +1,374 @@
1
+ import { Vector } from '../Math/vector';
2
+ import { CollisionType } from './CollisionType';
3
+ import { Physics } from './Physics';
4
+ import { TransformComponent } from '../EntityComponentSystem/Components/TransformComponent';
5
+ import { MotionComponent } from '../EntityComponentSystem/Components/MotionComponent';
6
+ import { Component } from '../EntityComponentSystem/Component';
7
+ import { CollisionGroup } from './Group/CollisionGroup';
8
+ import { createId } from '../Id';
9
+ import { clamp } from '../Math/util';
10
+ import { ColliderComponent } from './ColliderComponent';
11
+ import { Transform } from '../Math/transform';
12
+ import { EventEmitter } from '../EventEmitter';
13
+ export var DegreeOfFreedom;
14
+ (function (DegreeOfFreedom) {
15
+ DegreeOfFreedom["Rotation"] = "rotation";
16
+ DegreeOfFreedom["X"] = "x";
17
+ DegreeOfFreedom["Y"] = "y";
18
+ })(DegreeOfFreedom || (DegreeOfFreedom = {}));
19
+ /**
20
+ * Body describes all the physical properties pos, vel, acc, rotation, angular velocity for the purpose of
21
+ * of physics simulation.
22
+ */
23
+ export class BodyComponent extends Component {
24
+ constructor(options) {
25
+ var _a, _b, _c;
26
+ super();
27
+ this.type = 'ex.body';
28
+ this.dependencies = [TransformComponent, MotionComponent];
29
+ this.id = createId('body', BodyComponent._ID++);
30
+ this.events = new EventEmitter();
31
+ this._oldTransform = new Transform();
32
+ /**
33
+ * Indicates whether the old transform has been captured at least once for interpolation
34
+ * @internal
35
+ */
36
+ this.__oldTransformCaptured = false;
37
+ /**
38
+ * Enable or disabled the fixed update interpolation, by default interpolation is on.
39
+ */
40
+ this.enableFixedUpdateInterpolate = true;
41
+ /**
42
+ * Collision type for the rigidbody physics simulation, by default [[CollisionType.PreventCollision]]
43
+ */
44
+ this.collisionType = CollisionType.PreventCollision;
45
+ /**
46
+ * The collision group for the body's colliders, by default body colliders collide with everything
47
+ */
48
+ this.group = CollisionGroup.All;
49
+ /**
50
+ * The amount of mass the body has
51
+ */
52
+ this._mass = Physics.defaultMass;
53
+ /**
54
+ * Amount of "motion" the body has before sleeping. If below [[Physics.sleepEpsilon]] it goes to "sleep"
55
+ */
56
+ this.sleepMotion = Physics.sleepEpsilon * 5;
57
+ /**
58
+ * Can this body sleep, by default bodies do not sleep
59
+ */
60
+ this.canSleep = Physics.bodiesCanSleepByDefault;
61
+ this._sleeping = false;
62
+ /**
63
+ * The also known as coefficient of restitution of this actor, represents the amount of energy preserved after collision or the
64
+ * bounciness. If 1, it is 100% bouncy, 0 it completely absorbs.
65
+ */
66
+ this.bounciness = 0.2;
67
+ /**
68
+ * The coefficient of friction on this actor
69
+ */
70
+ this.friction = 0.99;
71
+ /**
72
+ * Should use global gravity [[Physics.gravity]] in it's physics simulation, default is true
73
+ */
74
+ this.useGravity = true;
75
+ /**
76
+ * Degrees of freedom to limit
77
+ *
78
+ * Note: this only limits responses in the realistic solver, if velocity/angularVelocity is set the actor will still respond
79
+ */
80
+ this.limitDegreeOfFreedom = [];
81
+ /**
82
+ * The velocity of the actor last frame (vx, vy) in pixels/second
83
+ */
84
+ this.oldVel = new Vector(0, 0);
85
+ /**
86
+ * Gets/sets the acceleration of the actor from the last frame. This does not include the global acc [[Physics.acc]].
87
+ */
88
+ this.oldAcc = Vector.Zero;
89
+ if (options) {
90
+ this.collisionType = (_a = options.type) !== null && _a !== void 0 ? _a : this.collisionType;
91
+ this.group = (_b = options.group) !== null && _b !== void 0 ? _b : this.group;
92
+ this.useGravity = (_c = options.useGravity) !== null && _c !== void 0 ? _c : this.useGravity;
93
+ }
94
+ }
95
+ get matrix() {
96
+ return this.transform.get().matrix;
97
+ }
98
+ get mass() {
99
+ return this._mass;
100
+ }
101
+ set mass(newMass) {
102
+ this._mass = newMass;
103
+ this._cachedInertia = undefined;
104
+ this._cachedInverseInertia = undefined;
105
+ }
106
+ /**
107
+ * The inverse mass (1/mass) of the body. If [[CollisionType.Fixed]] this is 0, meaning "infinite" mass
108
+ */
109
+ get inverseMass() {
110
+ return this.collisionType === CollisionType.Fixed ? 0 : 1 / this.mass;
111
+ }
112
+ /**
113
+ * Whether this body is sleeping or not
114
+ */
115
+ get sleeping() {
116
+ return this._sleeping;
117
+ }
118
+ /**
119
+ * Set the sleep state of the body
120
+ * @param sleeping
121
+ */
122
+ setSleeping(sleeping) {
123
+ this._sleeping = sleeping;
124
+ if (!sleeping) {
125
+ // Give it a kick to keep it from falling asleep immediately
126
+ this.sleepMotion = Physics.sleepEpsilon * 5;
127
+ }
128
+ else {
129
+ this.vel = Vector.Zero;
130
+ this.acc = Vector.Zero;
131
+ this.angularVelocity = 0;
132
+ this.sleepMotion = 0;
133
+ }
134
+ }
135
+ /**
136
+ * Update body's [[BodyComponent.sleepMotion]] for the purpose of sleeping
137
+ */
138
+ updateMotion() {
139
+ if (this._sleeping) {
140
+ this.setSleeping(true);
141
+ }
142
+ const currentMotion = this.vel.size * this.vel.size + Math.abs(this.angularVelocity * this.angularVelocity);
143
+ const bias = Physics.sleepBias;
144
+ this.sleepMotion = bias * this.sleepMotion + (1 - bias) * currentMotion;
145
+ this.sleepMotion = clamp(this.sleepMotion, 0, 10 * Physics.sleepEpsilon);
146
+ if (this.canSleep && this.sleepMotion < Physics.sleepEpsilon) {
147
+ this.setSleeping(true);
148
+ }
149
+ }
150
+ /**
151
+ * Get the moment of inertia from the [[ColliderComponent]]
152
+ */
153
+ get inertia() {
154
+ if (this._cachedInertia) {
155
+ return this._cachedInertia;
156
+ }
157
+ // Inertia is a property of the geometry, so this is a little goofy but seems to be okay?
158
+ const collider = this.owner.get(ColliderComponent);
159
+ if (collider) {
160
+ collider.$colliderAdded.subscribe(() => {
161
+ this._cachedInertia = null;
162
+ });
163
+ collider.$colliderRemoved.subscribe(() => {
164
+ this._cachedInertia = null;
165
+ });
166
+ const maybeCollider = collider.get();
167
+ if (maybeCollider) {
168
+ return this._cachedInertia = maybeCollider.getInertia(this.mass);
169
+ }
170
+ }
171
+ return 0;
172
+ }
173
+ /**
174
+ * Get the inverse moment of inertial from the [[ColliderComponent]]. If [[CollisionType.Fixed]] this is 0, meaning "infinite" mass
175
+ */
176
+ get inverseInertia() {
177
+ if (this._cachedInverseInertia) {
178
+ return this._cachedInverseInertia;
179
+ }
180
+ return this._cachedInverseInertia = this.collisionType === CollisionType.Fixed ? 0 : 1 / this.inertia;
181
+ }
182
+ /**
183
+ * Returns if the owner is active
184
+ */
185
+ get active() {
186
+ var _a;
187
+ return !!((_a = this.owner) === null || _a === void 0 ? void 0 : _a.active);
188
+ }
189
+ /**
190
+ * @deprecated Use globalP0s
191
+ */
192
+ get center() {
193
+ return this.globalPos;
194
+ }
195
+ get transform() {
196
+ var _a;
197
+ return (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get(TransformComponent);
198
+ }
199
+ get motion() {
200
+ var _a;
201
+ return (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get(MotionComponent);
202
+ }
203
+ get pos() {
204
+ return this.transform.pos;
205
+ }
206
+ set pos(val) {
207
+ this.transform.pos = val;
208
+ }
209
+ /**
210
+ * The (x, y) position of the actor this will be in the middle of the actor if the
211
+ * [[Actor.anchor]] is set to (0.5, 0.5) which is default.
212
+ * If you want the (x, y) position to be the top left of the actor specify an anchor of (0, 0).
213
+ */
214
+ get globalPos() {
215
+ return this.transform.globalPos;
216
+ }
217
+ set globalPos(val) {
218
+ this.transform.globalPos = val;
219
+ }
220
+ /**
221
+ * The position of the actor last frame (x, y) in pixels
222
+ */
223
+ get oldPos() {
224
+ return this._oldTransform.pos;
225
+ }
226
+ /**
227
+ * The current velocity vector (vx, vy) of the actor in pixels/second
228
+ */
229
+ get vel() {
230
+ return this.motion.vel;
231
+ }
232
+ set vel(val) {
233
+ this.motion.vel = val;
234
+ }
235
+ /**
236
+ * The current acceleration vector (ax, ay) of the actor in pixels/second/second. An acceleration pointing down such as (0, 100) may
237
+ * be useful to simulate a gravitational effect.
238
+ */
239
+ get acc() {
240
+ return this.motion.acc;
241
+ }
242
+ set acc(val) {
243
+ this.motion.acc = val;
244
+ }
245
+ /**
246
+ * The current torque applied to the actor
247
+ */
248
+ get torque() {
249
+ return this.motion.torque;
250
+ }
251
+ set torque(val) {
252
+ this.motion.torque = val;
253
+ }
254
+ /**
255
+ * Gets/sets the rotation of the body from the last frame.
256
+ */
257
+ get oldRotation() {
258
+ return this._oldTransform.rotation;
259
+ }
260
+ /**
261
+ * The rotation of the body in radians
262
+ */
263
+ get rotation() {
264
+ return this.transform.globalRotation;
265
+ }
266
+ set rotation(val) {
267
+ this.transform.globalRotation = val;
268
+ }
269
+ /**
270
+ * The scale vector of the actor
271
+ */
272
+ get scale() {
273
+ return this.transform.globalScale;
274
+ }
275
+ set scale(val) {
276
+ this.transform.globalScale = val;
277
+ }
278
+ /**
279
+ * The scale of the actor last frame
280
+ */
281
+ get oldScale() {
282
+ return this._oldTransform.scale;
283
+ }
284
+ /**
285
+ * The scale rate of change of the actor in scale/second
286
+ */
287
+ get scaleFactor() {
288
+ return this.motion.scaleFactor;
289
+ }
290
+ set scaleFactor(scaleFactor) {
291
+ this.motion.scaleFactor = scaleFactor;
292
+ }
293
+ /**
294
+ * Get the angular velocity in radians/second
295
+ */
296
+ get angularVelocity() {
297
+ return this.motion.angularVelocity;
298
+ }
299
+ /**
300
+ * Set the angular velocity in radians/second
301
+ */
302
+ set angularVelocity(value) {
303
+ this.motion.angularVelocity = value;
304
+ }
305
+ /**
306
+ * Apply a specific impulse to the body
307
+ * @param point
308
+ * @param impulse
309
+ */
310
+ applyImpulse(point, impulse) {
311
+ if (this.collisionType !== CollisionType.Active) {
312
+ return; // only active objects participate in the simulation
313
+ }
314
+ const finalImpulse = impulse.scale(this.inverseMass);
315
+ if (this.limitDegreeOfFreedom.includes(DegreeOfFreedom.X)) {
316
+ finalImpulse.x = 0;
317
+ }
318
+ if (this.limitDegreeOfFreedom.includes(DegreeOfFreedom.Y)) {
319
+ finalImpulse.y = 0;
320
+ }
321
+ this.vel.addEqual(finalImpulse);
322
+ if (!this.limitDegreeOfFreedom.includes(DegreeOfFreedom.Rotation)) {
323
+ const distanceFromCenter = point.sub(this.globalPos);
324
+ this.angularVelocity += this.inverseInertia * distanceFromCenter.cross(impulse);
325
+ }
326
+ }
327
+ /**
328
+ * Apply only linear impulse to the body
329
+ * @param impulse
330
+ */
331
+ applyLinearImpulse(impulse) {
332
+ if (this.collisionType !== CollisionType.Active) {
333
+ return; // only active objects participate in the simulation
334
+ }
335
+ const finalImpulse = impulse.scale(this.inverseMass);
336
+ if (this.limitDegreeOfFreedom.includes(DegreeOfFreedom.X)) {
337
+ finalImpulse.x = 0;
338
+ }
339
+ if (this.limitDegreeOfFreedom.includes(DegreeOfFreedom.Y)) {
340
+ finalImpulse.y = 0;
341
+ }
342
+ this.vel = this.vel.add(finalImpulse);
343
+ }
344
+ /**
345
+ * Apply only angular impulse to the body
346
+ * @param point
347
+ * @param impulse
348
+ */
349
+ applyAngularImpulse(point, impulse) {
350
+ if (this.collisionType !== CollisionType.Active) {
351
+ return; // only active objects participate in the simulation
352
+ }
353
+ if (!this.limitDegreeOfFreedom.includes(DegreeOfFreedom.Rotation)) {
354
+ const distanceFromCenter = point.sub(this.globalPos);
355
+ this.angularVelocity += this.inverseInertia * distanceFromCenter.cross(impulse);
356
+ }
357
+ }
358
+ /**
359
+ * Sets the old versions of pos, vel, acc, and scale.
360
+ */
361
+ captureOldTransform() {
362
+ // Capture old values before integration step updates them
363
+ this.__oldTransformCaptured = true;
364
+ this.transform.get().clone(this._oldTransform);
365
+ this.oldVel.setTo(this.vel.x, this.vel.y);
366
+ this.oldAcc.setTo(this.acc.x, this.acc.y);
367
+ }
368
+ clone() {
369
+ const component = super.clone();
370
+ return component;
371
+ }
372
+ }
373
+ BodyComponent._ID = 0;
374
+ //# sourceMappingURL=BodyComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyComponent.js","sourceRoot":"","sources":["../../../src/engine/Collision/BodyComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,MAAM,CAAN,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IACI,mBAAmB;QACxB,0DAA0D;QAC1D,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK;QACV,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,EAAmB,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;;AApZa,iBAAG,GAAG,CAAC,AAAJ,CAAK"}
@@ -0,0 +1,222 @@
1
+ import { Util } from '../..';
2
+ import { Pair } from '../Detection/Pair';
3
+ import { Projection } from '../../Math/projection';
4
+ import { Vector } from '../../Math/vector';
5
+ import { BoundingBox } from '../BoundingBox';
6
+ import { DynamicTree } from '../Detection/DynamicTree';
7
+ import { DynamicTreeCollisionProcessor } from '../Detection/DynamicTreeCollisionProcessor';
8
+ import { Collider } from './Collider';
9
+ export class CompositeCollider extends Collider {
10
+ constructor(colliders) {
11
+ super();
12
+ this._collisionProcessor = new DynamicTreeCollisionProcessor();
13
+ this._dynamicAABBTree = new DynamicTree();
14
+ this._colliders = [];
15
+ for (const c of colliders) {
16
+ this.addCollider(c);
17
+ }
18
+ }
19
+ clearColliders() {
20
+ this._colliders = [];
21
+ }
22
+ addCollider(collider) {
23
+ collider.events.pipe(this.events);
24
+ collider.__compositeColliderId = this.id;
25
+ this._colliders.push(collider);
26
+ this._collisionProcessor.track(collider);
27
+ this._dynamicAABBTree.trackCollider(collider);
28
+ }
29
+ removeCollider(collider) {
30
+ collider.events.pipe(this.events);
31
+ collider.__compositeColliderId = null;
32
+ Util.removeItemFromArray(collider, this._colliders);
33
+ this._collisionProcessor.untrack(collider);
34
+ this._dynamicAABBTree.untrackCollider(collider);
35
+ }
36
+ getColliders() {
37
+ return this._colliders;
38
+ }
39
+ get worldPos() {
40
+ var _a, _b;
41
+ // TODO transform component world pos
42
+ return (_b = (_a = this._transform) === null || _a === void 0 ? void 0 : _a.pos) !== null && _b !== void 0 ? _b : Vector.Zero;
43
+ }
44
+ get center() {
45
+ var _a, _b;
46
+ return (_b = (_a = this._transform) === null || _a === void 0 ? void 0 : _a.pos) !== null && _b !== void 0 ? _b : Vector.Zero;
47
+ }
48
+ get bounds() {
49
+ var _a, _b;
50
+ // TODO cache this
51
+ const colliders = this.getColliders();
52
+ const results = colliders.reduce((acc, collider) => acc.combine(collider.bounds), (_b = (_a = colliders[0]) === null || _a === void 0 ? void 0 : _a.bounds) !== null && _b !== void 0 ? _b : new BoundingBox().translate(this.worldPos));
53
+ return results;
54
+ }
55
+ get localBounds() {
56
+ var _a, _b;
57
+ // TODO cache this
58
+ const colliders = this.getColliders();
59
+ const results = colliders.reduce((acc, collider) => acc.combine(collider.localBounds), (_b = (_a = colliders[0]) === null || _a === void 0 ? void 0 : _a.localBounds) !== null && _b !== void 0 ? _b : new BoundingBox());
60
+ return results;
61
+ }
62
+ get axes() {
63
+ // TODO cache this
64
+ const colliders = this.getColliders();
65
+ let axes = [];
66
+ for (const collider of colliders) {
67
+ axes = axes.concat(collider.axes);
68
+ }
69
+ return axes;
70
+ }
71
+ getFurthestPoint(direction) {
72
+ const colliders = this.getColliders();
73
+ const furthestPoints = [];
74
+ for (const collider of colliders) {
75
+ furthestPoints.push(collider.getFurthestPoint(direction));
76
+ }
77
+ // Pick best point from all colliders
78
+ let bestPoint = furthestPoints[0];
79
+ let maxDistance = -Number.MAX_VALUE;
80
+ for (const point of furthestPoints) {
81
+ const distance = point.dot(direction);
82
+ if (distance > maxDistance) {
83
+ bestPoint = point;
84
+ maxDistance = distance;
85
+ }
86
+ }
87
+ return bestPoint;
88
+ }
89
+ getInertia(mass) {
90
+ const colliders = this.getColliders();
91
+ let totalInertia = 0;
92
+ for (const collider of colliders) {
93
+ totalInertia += collider.getInertia(mass);
94
+ }
95
+ return totalInertia;
96
+ }
97
+ collide(other) {
98
+ let otherColliders = [other];
99
+ if (other instanceof CompositeCollider) {
100
+ otherColliders = other.getColliders();
101
+ }
102
+ const pairs = [];
103
+ for (const c of otherColliders) {
104
+ this._dynamicAABBTree.query(c, (potentialCollider) => {
105
+ pairs.push(new Pair(c, potentialCollider));
106
+ return false;
107
+ });
108
+ }
109
+ let contacts = [];
110
+ for (const p of pairs) {
111
+ contacts = contacts.concat(p.collide());
112
+ }
113
+ return contacts;
114
+ }
115
+ getClosestLineBetween(other) {
116
+ const colliders = this.getColliders();
117
+ const lines = [];
118
+ if (other instanceof CompositeCollider) {
119
+ const otherColliders = other.getColliders();
120
+ for (const colliderA of colliders) {
121
+ for (const colliderB of otherColliders) {
122
+ const maybeLine = colliderA.getClosestLineBetween(colliderB);
123
+ if (maybeLine) {
124
+ lines.push(maybeLine);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ else {
130
+ for (const collider of colliders) {
131
+ const maybeLine = other.getClosestLineBetween(collider);
132
+ if (maybeLine) {
133
+ lines.push(maybeLine);
134
+ }
135
+ }
136
+ }
137
+ if (lines.length) {
138
+ let minLength = lines[0].getLength();
139
+ let minLine = lines[0];
140
+ for (const line of lines) {
141
+ const length = line.getLength();
142
+ if (length < minLength) {
143
+ minLength = length;
144
+ minLine = line;
145
+ }
146
+ }
147
+ return minLine;
148
+ }
149
+ return null;
150
+ }
151
+ contains(point) {
152
+ const colliders = this.getColliders();
153
+ for (const collider of colliders) {
154
+ if (collider.contains(point)) {
155
+ return true;
156
+ }
157
+ }
158
+ return false;
159
+ }
160
+ rayCast(ray, max) {
161
+ const colliders = this.getColliders();
162
+ const points = [];
163
+ for (const collider of colliders) {
164
+ const vec = collider.rayCast(ray, max);
165
+ if (vec) {
166
+ points.push(vec);
167
+ }
168
+ }
169
+ if (points.length) {
170
+ let minPoint = points[0];
171
+ let minDistance = minPoint.dot(ray.dir);
172
+ for (const point of points) {
173
+ const distance = ray.dir.dot(point);
174
+ if (distance < minDistance) {
175
+ minPoint = point;
176
+ minDistance = distance;
177
+ }
178
+ }
179
+ return minPoint;
180
+ }
181
+ return null;
182
+ }
183
+ project(axis) {
184
+ const colliders = this.getColliders();
185
+ const projs = [];
186
+ for (const collider of colliders) {
187
+ const proj = collider.project(axis);
188
+ if (proj) {
189
+ projs.push(proj);
190
+ }
191
+ }
192
+ // Merge all proj's on the same axis
193
+ if (projs.length) {
194
+ const newProjection = new Projection(projs[0].min, projs[0].max);
195
+ for (const proj of projs) {
196
+ newProjection.min = Math.min(proj.min, newProjection.min);
197
+ newProjection.max = Math.max(proj.max, newProjection.max);
198
+ }
199
+ return newProjection;
200
+ }
201
+ return null;
202
+ }
203
+ update(transform) {
204
+ if (transform) {
205
+ const colliders = this.getColliders();
206
+ for (const collider of colliders) {
207
+ collider.owner = this.owner;
208
+ collider.update(transform);
209
+ }
210
+ }
211
+ }
212
+ debug(ex, color) {
213
+ const colliders = this.getColliders();
214
+ for (const collider of colliders) {
215
+ collider.debug(ex, color);
216
+ }
217
+ }
218
+ clone() {
219
+ return new CompositeCollider(this._colliders.map((c) => c.clone()));
220
+ }
221
+ }
222
+ //# sourceMappingURL=CompositeCollider.js.map