@galacean/engine-physics-lite 0.0.0-experimental-animator-additive.1

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/dist/module.js ADDED
@@ -0,0 +1,1266 @@
1
+ import { Ray, Vector3, Matrix, Quaternion, MathUtil, BoundingBox, BoundingSphere, CollisionUtil } from '@galacean/engine';
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+
18
+ function __decorate(decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ }
24
+
25
+ function _set_prototype_of(o, p) {
26
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
27
+ o.__proto__ = p;
28
+
29
+ return o;
30
+ };
31
+
32
+ return _set_prototype_of(o, p);
33
+ }
34
+
35
+ function _inherits(subClass, superClass) {
36
+ if (typeof superClass !== "function" && superClass !== null) {
37
+ throw new TypeError("Super expression must either be null or a function");
38
+ }
39
+
40
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
41
+
42
+ if (superClass) _set_prototype_of(subClass, superClass);
43
+ }
44
+
45
+ function _defineProperties(target, props) {
46
+ for (var i = 0; i < props.length; i++) {
47
+ var descriptor = props[i];
48
+ descriptor.enumerable = descriptor.enumerable || false;
49
+ descriptor.configurable = true;
50
+
51
+ if ("value" in descriptor) descriptor.writable = true;
52
+
53
+ Object.defineProperty(target, descriptor.key, descriptor);
54
+ }
55
+ }
56
+ function _create_class(Constructor, protoProps, staticProps) {
57
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58
+ if (staticProps) _defineProperties(Constructor, staticProps);
59
+
60
+ return Constructor;
61
+ }
62
+
63
+ function _instanceof(left, right) {
64
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
65
+ return !!right[Symbol.hasInstance](left);
66
+ } else return left instanceof right;
67
+ }
68
+
69
+ /**
70
+ * Fastly remove an element from array.
71
+ * @param array - Array
72
+ * @param item - Element
73
+ */ function removeFromArray(array, item) {
74
+ var index = array.indexOf(item);
75
+ if (index < 0) {
76
+ return false;
77
+ }
78
+ var last = array.length - 1;
79
+ if (index !== last) {
80
+ array[index] = array[last];
81
+ }
82
+ array.length--;
83
+ return true;
84
+ }
85
+ /**
86
+ * Used to update tags.
87
+ */ var LiteUpdateFlag = /*#__PURE__*/ function() {
88
+ function LiteUpdateFlag(_flags) {
89
+ if (_flags === void 0) _flags = [];
90
+ this._flags = _flags;
91
+ this./** Flag. */ flag = true;
92
+ this._flags.push(this);
93
+ }
94
+ var _proto = LiteUpdateFlag.prototype;
95
+ /**
96
+ * Destroy.
97
+ */ _proto.destroy = function destroy() {
98
+ removeFromArray(this._flags, this);
99
+ this._flags = null;
100
+ };
101
+ return LiteUpdateFlag;
102
+ }();
103
+
104
+ /**
105
+ * @internal
106
+ */ var LiteUpdateFlagManager = /*#__PURE__*/ function() {
107
+ function LiteUpdateFlagManager() {
108
+ this._updateFlags = [];
109
+ }
110
+ var _proto = LiteUpdateFlagManager.prototype;
111
+ _proto.register = function register() {
112
+ return new LiteUpdateFlag(this._updateFlags);
113
+ };
114
+ _proto.distribute = function distribute() {
115
+ var updateFlags = this._updateFlags;
116
+ for(var i = updateFlags.length - 1; i >= 0; i--){
117
+ updateFlags[i].flag = true;
118
+ }
119
+ };
120
+ return LiteUpdateFlagManager;
121
+ }();
122
+
123
+ /**
124
+ * Abstract class for collider shapes.
125
+ */ var LiteColliderShape = /*#__PURE__*/ function() {
126
+ function LiteColliderShape() {
127
+ /** @internal */ this._transform = new LiteTransform();
128
+ /** @internal */ this._invModelMatrix = new Matrix();
129
+ this._transform.owner = this;
130
+ this._inverseWorldMatFlag = this._transform.registerWorldChangeFlag();
131
+ }
132
+ var _proto = LiteColliderShape.prototype;
133
+ /**
134
+ * {@inheritDoc IColliderShape.setRotation }
135
+ */ _proto.setRotation = function setRotation(rotation) {
136
+ console.log("Physics-lite don't support setRotation. Use Physics-PhysX instead!");
137
+ };
138
+ /**
139
+ * {@inheritDoc IColliderShape.setPosition }
140
+ */ _proto.setPosition = function setPosition(position) {
141
+ this._transform.setPosition(position.x, position.y, position.z);
142
+ };
143
+ /**
144
+ * {@inheritDoc IColliderShape.setContactOffset }
145
+ */ _proto.setContactOffset = function setContactOffset(offset) {
146
+ console.log("Physics-lite don't support setContactOffset. Use Physics-PhysX instead!");
147
+ };
148
+ /**
149
+ * {@inheritDoc IColliderShape.setMaterial }
150
+ */ _proto.setMaterial = function setMaterial(material) {
151
+ console.log("Physics-lite don't support setMaterial. Use Physics-PhysX instead!");
152
+ };
153
+ /**
154
+ * {@inheritDoc IColliderShape.setUniqueID }
155
+ */ _proto.setUniqueID = function setUniqueID(id) {
156
+ this._id = id;
157
+ };
158
+ /**
159
+ * {@inheritDoc IColliderShape.setIsTrigger }
160
+ */ _proto.setIsTrigger = function setIsTrigger(value) {
161
+ console.log("Physics-lite don't support setIsTrigger. Use Physics-PhysX instead!");
162
+ };
163
+ /**
164
+ * {@inheritDoc IColliderShape.destroy }
165
+ */ _proto.destroy = function destroy() {};
166
+ _proto._updateHitResult = function _updateHitResult(ray, rayDistance, outHit, origin, isWorldRay) {
167
+ if (isWorldRay === void 0) isWorldRay = false;
168
+ var hitPoint = LiteColliderShape._tempPoint;
169
+ ray.getPoint(rayDistance, hitPoint);
170
+ if (!isWorldRay) {
171
+ Vector3.transformCoordinate(hitPoint, this._transform.worldMatrix, hitPoint);
172
+ }
173
+ var distance = Vector3.distance(origin, hitPoint);
174
+ if (distance < outHit.distance) {
175
+ outHit.point.copyFrom(hitPoint);
176
+ outHit.distance = distance;
177
+ outHit.shapeID = this._id;
178
+ }
179
+ };
180
+ _proto._getLocalRay = function _getLocalRay(ray) {
181
+ var worldToLocal = this._getInvModelMatrix();
182
+ var outRay = LiteColliderShape._ray;
183
+ Vector3.transformCoordinate(ray.origin, worldToLocal, outRay.origin);
184
+ Vector3.transformNormal(ray.direction, worldToLocal, outRay.direction);
185
+ outRay.direction.normalize();
186
+ return outRay;
187
+ };
188
+ _proto._getInvModelMatrix = function _getInvModelMatrix() {
189
+ if (this._inverseWorldMatFlag.flag) {
190
+ Matrix.invert(this._transform.worldMatrix, this._invModelMatrix);
191
+ this._inverseWorldMatFlag.flag = false;
192
+ }
193
+ return this._invModelMatrix;
194
+ };
195
+ return LiteColliderShape;
196
+ }();
197
+ (function() {
198
+ LiteColliderShape._ray = new Ray();
199
+ })();
200
+ (function() {
201
+ LiteColliderShape._tempPoint = new Vector3();
202
+ })();
203
+
204
+ /**
205
+ * Used to implement transformation related functions.
206
+ */ var LiteTransform = /*#__PURE__*/ function() {
207
+ function LiteTransform() {
208
+ this._position = new Vector3();
209
+ this._rotation = new Vector3();
210
+ this._rotationQuaternion = new Quaternion();
211
+ this._scale = new Vector3(1, 1, 1);
212
+ this._worldRotationQuaternion = new Quaternion();
213
+ this._localMatrix = new Matrix();
214
+ this._worldMatrix = new Matrix();
215
+ this._updateFlagManager = new LiteUpdateFlagManager();
216
+ this._isParentDirty = true;
217
+ this._parentTransformCache = null;
218
+ this._dirtyFlag = 0xbc;
219
+ }
220
+ var _proto = LiteTransform.prototype;
221
+ /**
222
+ * Set local position by X, Y, Z value.
223
+ * @param x - X coordinate
224
+ * @param y - Y coordinate
225
+ * @param z - Z coordinate
226
+ */ _proto.setPosition = function setPosition(x, y, z) {
227
+ this._position.set(x, y, z);
228
+ this.position = this._position;
229
+ };
230
+ /**
231
+ * Set local rotation by the X, Y, Z, and W components of the quaternion.
232
+ * @param x - X component of quaternion
233
+ * @param y - Y component of quaternion
234
+ * @param z - Z component of quaternion
235
+ * @param w - W component of quaternion
236
+ */ _proto.setRotationQuaternion = function setRotationQuaternion(x, y, z, w) {
237
+ this._rotationQuaternion.set(x, y, z, w);
238
+ this.rotationQuaternion = this._rotationQuaternion;
239
+ };
240
+ /**
241
+ * Set local scaling by scaling values along X, Y, Z axis.
242
+ * @param x - Scaling along X axis
243
+ * @param y - Scaling along Y axis
244
+ * @param z - Scaling along Z axis
245
+ */ _proto.setScale = function setScale(x, y, z) {
246
+ this._scale.set(x, y, z);
247
+ this.scale = this._scale;
248
+ };
249
+ /**
250
+ * Register world transform change flag.
251
+ * @returns Change flag
252
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
253
+ return this._updateFlagManager.register();
254
+ };
255
+ /**
256
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
257
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
258
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
259
+ */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
260
+ if (!this._isContainDirtyFlags(0x84)) {
261
+ this._worldAssociatedChange(0x84);
262
+ if (_instanceof(this._owner, LiteCollider)) {
263
+ var shapes = this._owner._shapes;
264
+ for(var i = 0, n = shapes.length; i < n; i++){
265
+ shapes[i]._transform._updateWorldPositionFlag();
266
+ }
267
+ }
268
+ }
269
+ };
270
+ /**
271
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
272
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
273
+ * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
274
+ * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
275
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
276
+ */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
277
+ if (!this._isContainDirtyFlags(0x98)) {
278
+ this._worldAssociatedChange(0x98);
279
+ if (_instanceof(this._owner, LiteCollider)) {
280
+ var shapes = this._owner._shapes;
281
+ for(var i = 0, n = shapes.length; i < n; i++){
282
+ shapes[i]._transform._updateWorldRotationFlag();
283
+ }
284
+ }
285
+ }
286
+ };
287
+ /**
288
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
289
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
290
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
291
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
292
+ */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
293
+ if (!this._isContainDirtyFlags(0xa0)) {
294
+ this._worldAssociatedChange(0xa0);
295
+ if (_instanceof(this._owner, LiteCollider)) {
296
+ var shapes = this._owner._shapes;
297
+ for(var i = 0, n = shapes.length; i < n; i++){
298
+ shapes[i]._transform._updateWorldScaleFlag();
299
+ }
300
+ }
301
+ }
302
+ };
303
+ /**
304
+ * Update all world transform property dirty flag, the principle is the same as above.
305
+ */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
306
+ if (!this._isContainDirtyFlags(0xbc)) {
307
+ this._worldAssociatedChange(0xbc);
308
+ if (_instanceof(this._owner, LiteCollider)) {
309
+ var shapes = this._owner._shapes;
310
+ for(var i = 0, n = shapes.length; i < n; i++){
311
+ shapes[i]._transform._updateAllWorldFlag();
312
+ }
313
+ }
314
+ }
315
+ };
316
+ _proto._getParentTransform = function _getParentTransform() {
317
+ if (!this._isParentDirty) {
318
+ return this._parentTransformCache;
319
+ }
320
+ var parentCache = null;
321
+ if (_instanceof(this._owner, LiteColliderShape)) {
322
+ var parent = this._owner._collider;
323
+ parentCache = parent._transform;
324
+ }
325
+ this._parentTransformCache = parentCache;
326
+ this._isParentDirty = false;
327
+ return parentCache;
328
+ };
329
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
330
+ return (this._dirtyFlag & targetDirtyFlags) === targetDirtyFlags;
331
+ };
332
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
333
+ return (this._dirtyFlag & type) != 0;
334
+ };
335
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
336
+ this._dirtyFlag |= type;
337
+ };
338
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
339
+ this._dirtyFlag &= ~type;
340
+ };
341
+ _proto._worldAssociatedChange = function _worldAssociatedChange(type) {
342
+ this._dirtyFlag |= type;
343
+ this._updateFlagManager.distribute();
344
+ };
345
+ _create_class(LiteTransform, [
346
+ {
347
+ key: "owner",
348
+ set: function set(value) {
349
+ this._owner = value;
350
+ }
351
+ },
352
+ {
353
+ key: "position",
354
+ get: /**
355
+ * Local position.
356
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
357
+ */ function get() {
358
+ return this._position;
359
+ },
360
+ set: function set(value) {
361
+ if (this._position !== value) {
362
+ this._position.copyFrom(value);
363
+ }
364
+ this._setDirtyFlagTrue(0x40);
365
+ this._updateWorldPositionFlag();
366
+ }
367
+ },
368
+ {
369
+ key: "rotationQuaternion",
370
+ get: /**
371
+ * Local rotation, defining the rotation by using a unit quaternion.
372
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
373
+ */ function get() {
374
+ if (this._isContainDirtyFlag(0x2)) {
375
+ Quaternion.rotationEuler(MathUtil.degreeToRadian(this._rotation.x), MathUtil.degreeToRadian(this._rotation.y), MathUtil.degreeToRadian(this._rotation.z), this._rotationQuaternion);
376
+ this._setDirtyFlagFalse(0x2);
377
+ }
378
+ return this._rotationQuaternion;
379
+ },
380
+ set: function set(value) {
381
+ if (this._rotationQuaternion !== value) {
382
+ this._rotationQuaternion.copyFrom(value);
383
+ }
384
+ this._setDirtyFlagTrue(0x40 | 0x1);
385
+ this._setDirtyFlagFalse(0x2);
386
+ this._updateWorldRotationFlag();
387
+ }
388
+ },
389
+ {
390
+ key: "worldRotationQuaternion",
391
+ get: /**
392
+ * World rotation, defining the rotation by using a unit quaternion.
393
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
394
+ */ function get() {
395
+ if (this._isContainDirtyFlag(0x10)) {
396
+ var parent = this._getParentTransform();
397
+ if (parent != null) {
398
+ Quaternion.multiply(parent.worldRotationQuaternion, this.rotationQuaternion, this._worldRotationQuaternion);
399
+ } else {
400
+ this._worldRotationQuaternion.copyFrom(this.rotationQuaternion);
401
+ }
402
+ this._setDirtyFlagFalse(0x10);
403
+ }
404
+ return this._worldRotationQuaternion;
405
+ },
406
+ set: function set(value) {
407
+ if (this._worldRotationQuaternion !== value) {
408
+ this._worldRotationQuaternion.copyFrom(value);
409
+ }
410
+ var parent = this._getParentTransform();
411
+ if (parent) {
412
+ Quaternion.invert(parent.worldRotationQuaternion, LiteTransform._tempQuat0);
413
+ Quaternion.multiply(value, LiteTransform._tempQuat0, this._rotationQuaternion);
414
+ } else {
415
+ this._rotationQuaternion.copyFrom(value);
416
+ }
417
+ this.rotationQuaternion = this._rotationQuaternion;
418
+ this._setDirtyFlagFalse(0x10);
419
+ }
420
+ },
421
+ {
422
+ key: "scale",
423
+ get: /**
424
+ * Local scaling.
425
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
426
+ */ function get() {
427
+ return this._scale;
428
+ },
429
+ set: function set(value) {
430
+ if (this._scale !== value) {
431
+ this._scale.copyFrom(value);
432
+ }
433
+ this._setDirtyFlagTrue(0x40);
434
+ this._updateWorldScaleFlag();
435
+ }
436
+ },
437
+ {
438
+ key: "localMatrix",
439
+ get: /**
440
+ * Local matrix.
441
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
442
+ */ function get() {
443
+ if (this._isContainDirtyFlag(0x40)) {
444
+ Matrix.affineTransformation(this._scale, this.rotationQuaternion, this._position, this._localMatrix);
445
+ this._setDirtyFlagFalse(0x40);
446
+ }
447
+ return this._localMatrix;
448
+ },
449
+ set: function set(value) {
450
+ if (this._localMatrix !== value) {
451
+ this._localMatrix.copyFrom(value);
452
+ }
453
+ this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
454
+ this._setDirtyFlagTrue(0x1);
455
+ this._setDirtyFlagFalse(0x40);
456
+ this._updateAllWorldFlag();
457
+ }
458
+ },
459
+ {
460
+ key: "worldMatrix",
461
+ get: /**
462
+ * World matrix.
463
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
464
+ */ function get() {
465
+ if (this._isContainDirtyFlag(0x80)) {
466
+ var parent = this._getParentTransform();
467
+ if (parent) {
468
+ Matrix.multiply(parent.worldMatrix, this.localMatrix, this._worldMatrix);
469
+ } else {
470
+ this._worldMatrix.copyFrom(this.localMatrix);
471
+ }
472
+ this._setDirtyFlagFalse(0x80);
473
+ }
474
+ return this._worldMatrix;
475
+ },
476
+ set: function set(value) {
477
+ if (this._worldMatrix !== value) {
478
+ this._worldMatrix.copyFrom(value);
479
+ }
480
+ var parent = this._getParentTransform();
481
+ if (parent) {
482
+ Matrix.invert(parent.worldMatrix, LiteTransform._tempMat42);
483
+ Matrix.multiply(LiteTransform._tempMat42, value, this._localMatrix);
484
+ } else {
485
+ this._localMatrix.copyFrom(value);
486
+ }
487
+ this.localMatrix = this._localMatrix;
488
+ this._setDirtyFlagFalse(0x80);
489
+ }
490
+ }
491
+ ]);
492
+ return LiteTransform;
493
+ }();
494
+ (function() {
495
+ LiteTransform._tempQuat0 = new Quaternion();
496
+ })();
497
+ (function() {
498
+ LiteTransform._tempMat42 = new Matrix();
499
+ })();
500
+ var /**
501
+ * Dirty flag of transform.
502
+ */ TransformFlag;
503
+ (function(TransformFlag) {
504
+ TransformFlag[TransformFlag["LocalEuler"] = 0x1] = "LocalEuler";
505
+ TransformFlag[TransformFlag["LocalQuat"] = 0x2] = "LocalQuat";
506
+ TransformFlag[TransformFlag["WorldPosition"] = 0x4] = "WorldPosition";
507
+ TransformFlag[TransformFlag["WorldEuler"] = 0x8] = "WorldEuler";
508
+ TransformFlag[TransformFlag["WorldQuat"] = 0x10] = "WorldQuat";
509
+ TransformFlag[TransformFlag["WorldScale"] = 0x20] = "WorldScale";
510
+ TransformFlag[TransformFlag["LocalMatrix"] = 0x40] = "LocalMatrix";
511
+ TransformFlag[TransformFlag["WorldMatrix"] = 0x80] = "WorldMatrix";
512
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition */ "WmWp"] = 0x84] = "WmWp";
513
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldEuler | WorldQuat */ "WmWeWq"] = 0x98] = "WmWeWq";
514
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ "WmWpWeWq"] = 0x9c] = "WmWpWeWq";
515
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldScale */ "WmWs"] = 0xa0] = "WmWs";
516
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldScale */ "WmWpWs"] = 0xa4] = "WmWpWs";
517
+ TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ "WmWpWeWqWs"] = 0xbc] = "WmWpWeWqWs";
518
+ })(TransformFlag || (TransformFlag = {}));
519
+
520
+ /**
521
+ * Abstract class of physical collider.
522
+ */ var LiteCollider = /*#__PURE__*/ function() {
523
+ function LiteCollider() {
524
+ /** @internal */ this._shapes = [];
525
+ /** @internal */ this._transform = new LiteTransform();
526
+ this._transform.owner = this;
527
+ }
528
+ var _proto = LiteCollider.prototype;
529
+ /**
530
+ * {@inheritDoc ICollider.addShape }
531
+ */ _proto.addShape = function addShape(shape) {
532
+ var oldCollider = shape._collider;
533
+ if (oldCollider !== this) {
534
+ if (oldCollider) {
535
+ oldCollider.removeShape(shape);
536
+ }
537
+ this._shapes.push(shape);
538
+ shape._collider = this;
539
+ }
540
+ };
541
+ /**
542
+ * {@inheritDoc ICollider.removeShape }
543
+ */ _proto.removeShape = function removeShape(shape) {
544
+ var index = this._shapes.indexOf(shape);
545
+ if (index !== -1) {
546
+ this._shapes.splice(index, 1);
547
+ shape._collider = null;
548
+ }
549
+ };
550
+ /**
551
+ * {@inheritDoc ICollider.setWorldTransform }
552
+ */ _proto.setWorldTransform = function setWorldTransform(position, rotation) {
553
+ this._transform.setPosition(position.x, position.y, position.z);
554
+ this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
555
+ };
556
+ /**
557
+ * {@inheritDoc ICollider.getWorldTransform }
558
+ */ _proto.getWorldTransform = function getWorldTransform(outPosition, outRotation) {
559
+ var _this__transform = this._transform, position = _this__transform.position, rotationQuaternion = _this__transform.rotationQuaternion;
560
+ outPosition.set(position.x, position.y, position.z);
561
+ outRotation.set(rotationQuaternion.x, rotationQuaternion.y, rotationQuaternion.z, rotationQuaternion.w);
562
+ };
563
+ /**
564
+ * {@inheritDoc ICollider.destroy }
565
+ */ _proto.destroy = function destroy() {};
566
+ /**
567
+ * @internal
568
+ */ _proto._raycast = function _raycast(ray, onRaycast, hit) {
569
+ hit.distance = Number.MAX_VALUE;
570
+ var shapes = this._shapes;
571
+ for(var i = 0, n = shapes.length; i < n; i++){
572
+ var shape = shapes[i];
573
+ onRaycast(shape._id) && shape._raycast(ray, hit);
574
+ }
575
+ return hit.distance != Number.MAX_VALUE;
576
+ };
577
+ return LiteCollider;
578
+ }();
579
+
580
+ /**
581
+ * A dynamic collider can act with self-defined movement or physical force
582
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
583
+ _inherits(LiteDynamicCollider, LiteCollider);
584
+ function LiteDynamicCollider(position, rotation) {
585
+ var _this;
586
+ _this = LiteCollider.call(this) || this;
587
+ _this._transform.setPosition(position.x, position.y, position.z);
588
+ _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
589
+ return _this;
590
+ }
591
+ var _proto = LiteDynamicCollider.prototype;
592
+ /**
593
+ * {@inheritDoc IDynamicCollider.addForce }
594
+ */ _proto.addForce = function addForce(force) {
595
+ throw "Physics-lite don't support addForce. Use Physics-PhysX instead!";
596
+ };
597
+ /**
598
+ * {@inheritDoc IDynamicCollider.addTorque }
599
+ */ _proto.addTorque = function addTorque(torque) {
600
+ throw "Physics-lite don't support addTorque. Use Physics-PhysX instead!";
601
+ };
602
+ /**
603
+ * {@inheritDoc IDynamicCollider.move }
604
+ */ _proto.move = function move(positionOrRotation, rotation) {
605
+ throw "Physics-lite don't support move. Use Physics-PhysX instead!";
606
+ };
607
+ /**
608
+ * {@inheritDoc IDynamicCollider.sleep }
609
+ */ _proto.sleep = function sleep() {
610
+ throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!";
611
+ };
612
+ /**
613
+ * {@inheritDoc IDynamicCollider.setAngularDamping }
614
+ */ _proto.setAngularDamping = function setAngularDamping(value) {
615
+ throw "Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!";
616
+ };
617
+ /**
618
+ * {@inheritDoc IDynamicCollider.setAngularVelocity }
619
+ */ _proto.setAngularVelocity = function setAngularVelocity(value) {
620
+ throw "Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!";
621
+ };
622
+ /**
623
+ * {@inheritDoc IDynamicCollider.setCenterOfMass }
624
+ */ _proto.setCenterOfMass = function setCenterOfMass(value) {
625
+ throw "Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!";
626
+ };
627
+ /**
628
+ * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
629
+ */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
630
+ throw "Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!";
631
+ };
632
+ /**
633
+ * {@inheritDoc IDynamicCollider.setConstraints }
634
+ */ _proto.setConstraints = function setConstraints(flags) {
635
+ throw "Physics-lite don't support setConstraints. Use Physics-PhysX instead!";
636
+ };
637
+ /**
638
+ * {@inheritDoc IDynamicCollider.setInertiaTensor }
639
+ */ _proto.setInertiaTensor = function setInertiaTensor(value) {
640
+ throw "Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!";
641
+ };
642
+ /**
643
+ * {@inheritDoc IDynamicCollider.setIsKinematic }
644
+ */ _proto.setIsKinematic = function setIsKinematic(value) {
645
+ throw "Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!";
646
+ };
647
+ /**
648
+ * {@inheritDoc IDynamicCollider.setLinearDamping }
649
+ */ _proto.setLinearDamping = function setLinearDamping(value) {
650
+ throw "Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!";
651
+ };
652
+ /**
653
+ * {@inheritDoc IDynamicCollider.setLinearVelocity }
654
+ */ _proto.setLinearVelocity = function setLinearVelocity(value) {
655
+ throw "Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!";
656
+ };
657
+ /**
658
+ * {@inheritDoc IDynamicCollider.setMass }
659
+ */ _proto.setMass = function setMass(value) {
660
+ throw "Physics-lite don't support setMass. Use Physics-PhysX instead!";
661
+ };
662
+ /**
663
+ * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
664
+ */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
665
+ throw "Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!";
666
+ };
667
+ /**
668
+ * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
669
+ */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
670
+ throw "Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!";
671
+ };
672
+ /**
673
+ * {@inheritDoc IDynamicCollider.setSleepThreshold }
674
+ */ _proto.setSleepThreshold = function setSleepThreshold(value) {
675
+ throw "Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!";
676
+ };
677
+ /**
678
+ * {@inheritDoc IDynamicCollider.setSolverIterations }
679
+ */ _proto.setSolverIterations = function setSolverIterations(value) {
680
+ throw "Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!";
681
+ };
682
+ /**
683
+ * {@inheritDoc IDynamicCollider.wakeUp }
684
+ */ _proto.wakeUp = function wakeUp() {
685
+ throw "Physics-lite don't support wakeUp. Use Physics-PhysX instead!";
686
+ };
687
+ return LiteDynamicCollider;
688
+ }(LiteCollider);
689
+
690
+ /**
691
+ * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
692
+ */ var DisorderedArray = /*#__PURE__*/ function() {
693
+ function DisorderedArray(count) {
694
+ if (count === void 0) count = 0;
695
+ this.length = 0;
696
+ this._elements = new Array(count);
697
+ }
698
+ var _proto = DisorderedArray.prototype;
699
+ _proto.add = function add(element) {
700
+ if (this.length === this._elements.length) this._elements.push(element);
701
+ else this._elements[this.length] = element;
702
+ this.length++;
703
+ };
704
+ _proto.delete = function _delete(element) {
705
+ //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
706
+ var index = this._elements.indexOf(element);
707
+ this.deleteByIndex(index);
708
+ };
709
+ _proto.get = function get(index) {
710
+ if (index >= this.length) {
711
+ throw "Index is out of range.";
712
+ }
713
+ return this._elements[index];
714
+ };
715
+ /**
716
+ *
717
+ * @param index
718
+ * @returns The replaced item is used to reset its index.
719
+ */ _proto.deleteByIndex = function deleteByIndex(index) {
720
+ var elements = this._elements;
721
+ var end = null;
722
+ var lastIndex = this.length - 1;
723
+ if (index !== lastIndex) {
724
+ end = elements[lastIndex];
725
+ elements[index] = end;
726
+ }
727
+ this.length--;
728
+ return end;
729
+ };
730
+ _proto.garbageCollection = function garbageCollection() {
731
+ this._elements.length = this.length;
732
+ };
733
+ return DisorderedArray;
734
+ }();
735
+
736
+ /**
737
+ * Structure used to get information back from a raycast or a sweep.
738
+ * @internal
739
+ */ var LiteHitResult = function LiteHitResult() {
740
+ /** The collider that was hit. */ this.shapeID = -1;
741
+ /** The distance from the origin to the hit point. */ this.distance = 0;
742
+ /** The hit point of the collider that was hit in world space. */ this.point = new Vector3();
743
+ /** The hit normal of the collider that was hit in world space. */ this.normal = new Vector3();
744
+ };
745
+
746
+ /**
747
+ * Box collider shape in Lite.
748
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
749
+ _inherits(LiteBoxColliderShape, LiteColliderShape);
750
+ function LiteBoxColliderShape(uniqueID, size, material) {
751
+ var _this;
752
+ _this = LiteColliderShape.call(this) || this;
753
+ _this._halfSize = new Vector3();
754
+ _this._scale = new Vector3(1, 1, 1);
755
+ /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5);
756
+ /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
757
+ _this._id = uniqueID;
758
+ _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
759
+ _this._setBondingBox();
760
+ return _this;
761
+ }
762
+ var _proto = LiteBoxColliderShape.prototype;
763
+ /**
764
+ * {@inheritDoc IColliderShape.setPosition }
765
+ */ _proto.setPosition = function setPosition(position) {
766
+ LiteColliderShape.prototype.setPosition.call(this, position);
767
+ this._setBondingBox();
768
+ };
769
+ /**
770
+ * {@inheritDoc IColliderShape.setWorldScale }
771
+ */ _proto.setWorldScale = function setWorldScale(scale) {
772
+ this._transform.position = this._transform.position.multiply(scale);
773
+ this._scale.copyFrom(scale);
774
+ };
775
+ /**
776
+ * {@inheritDoc IBoxColliderShape.setSize }
777
+ */ _proto.setSize = function setSize(value) {
778
+ this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
779
+ this._setBondingBox();
780
+ };
781
+ /**
782
+ * @internal
783
+ */ _proto._raycast = function _raycast(ray, hit) {
784
+ var localRay = this._getLocalRay(ray);
785
+ var boundingBox = LiteBoxColliderShape._tempBox;
786
+ boundingBox.min.set(-this._halfSize.x * this._scale.x, -this._halfSize.y * this._scale.y, -this._halfSize.z * this._scale.z);
787
+ boundingBox.max.set(this._halfSize.x * this._scale.x, this._halfSize.y * this._scale.y, this._halfSize.z * this._scale.z);
788
+ var rayDistance = localRay.intersectBox(boundingBox);
789
+ if (rayDistance !== -1) {
790
+ this._updateHitResult(localRay, rayDistance, hit, ray.origin);
791
+ return true;
792
+ } else {
793
+ return false;
794
+ }
795
+ };
796
+ _proto._setBondingBox = function _setBondingBox() {
797
+ var _this__transform = this._transform, center = _this__transform.position;
798
+ var halfSize = this._halfSize;
799
+ Vector3.add(center, halfSize, this._boxMax);
800
+ Vector3.subtract(center, halfSize, this._boxMin);
801
+ };
802
+ return LiteBoxColliderShape;
803
+ }(LiteColliderShape);
804
+ (function() {
805
+ LiteBoxColliderShape._tempBox = new BoundingBox();
806
+ })();
807
+
808
+ /**
809
+ * Sphere collider shape in Lite.
810
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
811
+ _inherits(LiteSphereColliderShape, LiteColliderShape);
812
+ function LiteSphereColliderShape(uniqueID, radius, material) {
813
+ var _this;
814
+ _this = LiteColliderShape.call(this) || this;
815
+ _this._radius = 1;
816
+ _this._maxScale = 1;
817
+ _this._radius = radius;
818
+ _this._id = uniqueID;
819
+ return _this;
820
+ }
821
+ var _proto = LiteSphereColliderShape.prototype;
822
+ /**
823
+ * {@inheritDoc ISphereColliderShape.setRadius }
824
+ */ _proto.setRadius = function setRadius(value) {
825
+ this._radius = value;
826
+ };
827
+ /**
828
+ * {@inheritDoc IColliderShape.setWorldScale }
829
+ */ _proto.setWorldScale = function setWorldScale(scale) {
830
+ this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
831
+ };
832
+ /**
833
+ * @internal
834
+ */ _proto._raycast = function _raycast(ray, hit) {
835
+ var boundingSphere = LiteSphereColliderShape._tempSphere;
836
+ Vector3.transformCoordinate(this._transform.position, this._collider._transform.worldMatrix, boundingSphere.center);
837
+ boundingSphere.radius = this.worldRadius;
838
+ var rayDistance = ray.intersectSphere(boundingSphere);
839
+ if (rayDistance !== -1) {
840
+ this._updateHitResult(ray, rayDistance, hit, ray.origin, true);
841
+ return true;
842
+ } else {
843
+ return false;
844
+ }
845
+ };
846
+ _create_class(LiteSphereColliderShape, [
847
+ {
848
+ key: "worldRadius",
849
+ get: function get() {
850
+ return this._radius * this._maxScale;
851
+ }
852
+ }
853
+ ]);
854
+ return LiteSphereColliderShape;
855
+ }(LiteColliderShape);
856
+ (function() {
857
+ LiteSphereColliderShape._tempSphere = new BoundingSphere();
858
+ })();
859
+
860
+ /**
861
+ * A manager is a collection of colliders and constraints which can interact.
862
+ */ var LitePhysicsManager = /*#__PURE__*/ function() {
863
+ function LitePhysicsManager(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
864
+ this._colliders = [];
865
+ this._sphere = new BoundingSphere();
866
+ this._box = new BoundingBox();
867
+ this._currentEvents = new DisorderedArray();
868
+ this._eventMap = {};
869
+ this._eventPool = [];
870
+ this._onContactEnter = onContactEnter;
871
+ this._onContactExit = onContactExit;
872
+ this._onContactStay = onContactStay;
873
+ this._onTriggerEnter = onTriggerEnter;
874
+ this._onTriggerExit = onTriggerExit;
875
+ this._onTriggerStay = onTriggerStay;
876
+ }
877
+ var _proto = LitePhysicsManager.prototype;
878
+ /**
879
+ * {@inheritDoc IPhysicsManager.setGravity }
880
+ */ _proto.setGravity = function setGravity(value) {
881
+ console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
882
+ };
883
+ /**
884
+ * {@inheritDoc IPhysicsManager.addColliderShape }
885
+ */ _proto.addColliderShape = function addColliderShape(colliderShape) {
886
+ this._eventMap[colliderShape._id] = {};
887
+ };
888
+ /**
889
+ * {@inheritDoc IPhysicsManager.removeColliderShape }
890
+ */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
891
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
892
+ var shapeID = colliderShape._id;
893
+ for(var i = currentEvents.length - 1; i >= 0; i--){
894
+ var event = currentEvents.get(i);
895
+ if (event.index1 == shapeID || event.index2 == shapeID) {
896
+ currentEvents.deleteByIndex(i);
897
+ eventPool.push(event);
898
+ }
899
+ }
900
+ delete this._eventMap[shapeID];
901
+ };
902
+ /**
903
+ * {@inheritDoc IPhysicsManager.addCollider }
904
+ */ _proto.addCollider = function addCollider(actor) {
905
+ this._colliders.push(actor);
906
+ };
907
+ /**
908
+ * {@inheritDoc IPhysicsManager.removeCollider }
909
+ */ _proto.removeCollider = function removeCollider(collider) {
910
+ var index = this._colliders.indexOf(collider);
911
+ if (index !== -1) {
912
+ this._colliders.splice(index, 1);
913
+ }
914
+ };
915
+ /**
916
+ * {@inheritDoc IPhysicsManager.update }
917
+ */ _proto.update = function update(deltaTime) {
918
+ var colliders = this._colliders;
919
+ for(var i = 0, len = colliders.length; i < len; i++){
920
+ this._collisionDetection(deltaTime, colliders[i]);
921
+ }
922
+ this._fireEvent();
923
+ };
924
+ /**
925
+ * {@inheritDoc IPhysicsManager.raycast }
926
+ */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
927
+ var colliders = this._colliders;
928
+ var hitResult;
929
+ if (hit) {
930
+ hitResult = LitePhysicsManager._hitResult;
931
+ }
932
+ var isHit = false;
933
+ var curHit = LitePhysicsManager._currentHit;
934
+ for(var i = 0, len = colliders.length; i < len; i++){
935
+ var collider = colliders[i];
936
+ if (collider._raycast(ray, onRaycast, curHit)) {
937
+ isHit = true;
938
+ if (curHit.distance < distance) {
939
+ if (hitResult) {
940
+ hitResult.normal.copyFrom(curHit.normal);
941
+ hitResult.point.copyFrom(curHit.point);
942
+ hitResult.distance = curHit.distance;
943
+ hitResult.shapeID = curHit.shapeID;
944
+ } else {
945
+ return true;
946
+ }
947
+ distance = curHit.distance;
948
+ }
949
+ }
950
+ }
951
+ if (!isHit && hitResult) {
952
+ hitResult.shapeID = -1;
953
+ hitResult.distance = 0;
954
+ hitResult.point.set(0, 0, 0);
955
+ hitResult.normal.set(0, 0, 0);
956
+ } else if (isHit && hitResult) {
957
+ hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
958
+ }
959
+ return isHit;
960
+ };
961
+ /**
962
+ * {@inheritDoc IPhysicsManager.addCharacterController }
963
+ */ _proto.addCharacterController = function addCharacterController(characterController) {
964
+ throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
965
+ };
966
+ /**
967
+ * {@inheritDoc IPhysicsManager.removeCharacterController }
968
+ */ _proto.removeCharacterController = function removeCharacterController(characterController) {
969
+ throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
970
+ };
971
+ _proto._getTrigger = function _getTrigger(index1, index2) {
972
+ var event;
973
+ if (this._eventPool.length) {
974
+ event = this._eventPool.pop();
975
+ event.index1 = index1;
976
+ event.index2 = index2;
977
+ } else {
978
+ event = new TriggerEvent(index1, index2);
979
+ }
980
+ this._eventMap[index1][index2] = event;
981
+ return event;
982
+ };
983
+ _proto._collisionDetection = function _collisionDetection(deltaTime, myCollider) {
984
+ var colliders = this._colliders;
985
+ var myColliderShapes = myCollider._shapes;
986
+ for(var i = 0, len = myColliderShapes.length; i < len; i++){
987
+ var myShape = myColliderShapes[i];
988
+ if (_instanceof(myShape, LiteBoxColliderShape)) {
989
+ LitePhysicsManager._updateWorldBox(myShape, this._box);
990
+ for(var j = 0, len1 = colliders.length; j < len1; j++){
991
+ var colliderShape = colliders[j]._shapes;
992
+ for(var k = 0, len2 = colliderShape.length; k < len2; k++){
993
+ var shape = colliderShape[k];
994
+ var index1 = shape._id;
995
+ var index2 = myShape._id;
996
+ var event = index1 < index2 ? this._eventMap[index1][index2] : this._eventMap[index2][index1];
997
+ if (event !== undefined && !event.alreadyInvoked) {
998
+ continue;
999
+ }
1000
+ if (shape != myShape && this._boxCollision(shape)) {
1001
+ if (event === undefined) {
1002
+ var event1 = index1 < index2 ? this._getTrigger(index1, index2) : this._getTrigger(index2, index1);
1003
+ event1.state = 0;
1004
+ event1.alreadyInvoked = false;
1005
+ this._currentEvents.add(event1);
1006
+ } else if (event.state === 0) {
1007
+ event.state = 1;
1008
+ event.alreadyInvoked = false;
1009
+ } else if (event.state === 1) {
1010
+ event.alreadyInvoked = false;
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ } else if (_instanceof(myShape, LiteSphereColliderShape)) {
1016
+ LitePhysicsManager._upWorldSphere(myShape, this._sphere);
1017
+ for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
1018
+ var colliderShape1 = colliders[j1]._shapes;
1019
+ for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
1020
+ var shape1 = colliderShape1[k1];
1021
+ var index11 = shape1._id;
1022
+ var index21 = myShape._id;
1023
+ var event2 = index11 < index21 ? this._eventMap[index11][index21] : this._eventMap[index21][index11];
1024
+ if (event2 !== undefined && !event2.alreadyInvoked) {
1025
+ continue;
1026
+ }
1027
+ if (shape1 != myShape && this._sphereCollision(shape1)) {
1028
+ if (event2 === undefined) {
1029
+ var event3 = index11 < index21 ? this._getTrigger(index11, index21) : this._getTrigger(index21, index11);
1030
+ event3.state = 0;
1031
+ event3.alreadyInvoked = false;
1032
+ this._currentEvents.add(event3);
1033
+ } else if (event2.state === 0) {
1034
+ event2.state = 1;
1035
+ event2.alreadyInvoked = false;
1036
+ } else if (event2.state === 1) {
1037
+ event2.alreadyInvoked = false;
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ }
1044
+ };
1045
+ _proto._fireEvent = function _fireEvent() {
1046
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
1047
+ for(var i = currentEvents.length - 1; i >= 0; i--){
1048
+ var event = currentEvents.get(i);
1049
+ if (!event.alreadyInvoked) {
1050
+ if (event.state == 0) {
1051
+ this._onTriggerEnter(event.index1, event.index2);
1052
+ event.alreadyInvoked = true;
1053
+ } else if (event.state == 1) {
1054
+ this._onTriggerStay(event.index1, event.index2);
1055
+ event.alreadyInvoked = true;
1056
+ }
1057
+ } else {
1058
+ event.state = 2;
1059
+ this._eventMap[event.index1][event.index2] = undefined;
1060
+ this._onTriggerExit(event.index1, event.index2);
1061
+ currentEvents.deleteByIndex(i);
1062
+ eventPool.push(event);
1063
+ }
1064
+ }
1065
+ };
1066
+ _proto._boxCollision = function _boxCollision(other) {
1067
+ if (_instanceof(other, LiteBoxColliderShape)) {
1068
+ var box = LitePhysicsManager._tempBox;
1069
+ LitePhysicsManager._updateWorldBox(other, box);
1070
+ return CollisionUtil.intersectsBoxAndBox(box, this._box);
1071
+ } else if (_instanceof(other, LiteSphereColliderShape)) {
1072
+ var sphere = LitePhysicsManager._tempSphere;
1073
+ LitePhysicsManager._upWorldSphere(other, sphere);
1074
+ return CollisionUtil.intersectsSphereAndBox(sphere, this._box);
1075
+ }
1076
+ return false;
1077
+ };
1078
+ _proto._sphereCollision = function _sphereCollision(other) {
1079
+ if (_instanceof(other, LiteBoxColliderShape)) {
1080
+ var box = LitePhysicsManager._tempBox;
1081
+ LitePhysicsManager._updateWorldBox(other, box);
1082
+ return CollisionUtil.intersectsSphereAndBox(this._sphere, box);
1083
+ } else if (_instanceof(other, LiteSphereColliderShape)) {
1084
+ var sphere = LitePhysicsManager._tempSphere;
1085
+ LitePhysicsManager._upWorldSphere(other, sphere);
1086
+ return CollisionUtil.intersectsSphereAndSphere(sphere, this._sphere);
1087
+ }
1088
+ return false;
1089
+ };
1090
+ /**
1091
+ * Calculate the bounding box in world space from boxCollider.
1092
+ * @param boxCollider - The boxCollider to calculate
1093
+ * @param out - The calculated boundingBox
1094
+ */ LitePhysicsManager._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1095
+ var mat = boxCollider._transform.worldMatrix;
1096
+ out.min.copyFrom(boxCollider._boxMin);
1097
+ out.max.copyFrom(boxCollider._boxMax);
1098
+ BoundingBox.transform(out, mat, out);
1099
+ };
1100
+ /**
1101
+ * Get the sphere info of the given sphere collider in world space.
1102
+ * @param sphereCollider - The given sphere collider
1103
+ * @param out - The calculated boundingSphere
1104
+ */ LitePhysicsManager._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1105
+ Vector3.transformCoordinate(sphereCollider._transform.position, sphereCollider._transform.worldMatrix, out.center);
1106
+ out.radius = sphereCollider.worldRadius;
1107
+ };
1108
+ return LitePhysicsManager;
1109
+ }();
1110
+ (function() {
1111
+ LitePhysicsManager._tempSphere = new BoundingSphere();
1112
+ })();
1113
+ (function() {
1114
+ LitePhysicsManager._tempBox = new BoundingBox();
1115
+ })();
1116
+ (function() {
1117
+ LitePhysicsManager._currentHit = new LiteHitResult();
1118
+ })();
1119
+ (function() {
1120
+ LitePhysicsManager._hitResult = new LiteHitResult();
1121
+ })();
1122
+ var /**
1123
+ * Physics state
1124
+ */ TriggerEventState;
1125
+ (function(TriggerEventState) {
1126
+ TriggerEventState[TriggerEventState["Enter"] = 0] = "Enter";
1127
+ TriggerEventState[TriggerEventState["Stay"] = 1] = "Stay";
1128
+ TriggerEventState[TriggerEventState["Exit"] = 2] = "Exit";
1129
+ })(TriggerEventState || (TriggerEventState = {}));
1130
+ /**
1131
+ * Trigger event to store interactive object ids and state.
1132
+ */ var TriggerEvent = function TriggerEvent(index1, index2) {
1133
+ this.alreadyInvoked = false;
1134
+ this.index1 = index1;
1135
+ this.index2 = index2;
1136
+ };
1137
+
1138
+ /**
1139
+ * Physics material describes how to handle colliding objects (friction, bounciness).
1140
+ */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
1141
+ function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
1142
+ var _proto = LitePhysicsMaterial.prototype;
1143
+ /**
1144
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
1145
+ */ _proto.setBounciness = function setBounciness(value) {
1146
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1147
+ };
1148
+ /**
1149
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
1150
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
1151
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1152
+ };
1153
+ /**
1154
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
1155
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
1156
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1157
+ };
1158
+ /**
1159
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
1160
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
1161
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1162
+ };
1163
+ /**
1164
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
1165
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
1166
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1167
+ };
1168
+ /**
1169
+ * {@inheritDoc IPhysicsMaterial.destroy }
1170
+ */ _proto.destroy = function destroy() {};
1171
+ return LitePhysicsMaterial;
1172
+ }();
1173
+
1174
+ /**
1175
+ * A static collider component that will not move.
1176
+ * @remarks Mostly used for object which always stays at the same place and never moves around.
1177
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1178
+ _inherits(LiteStaticCollider, LiteCollider);
1179
+ function LiteStaticCollider(position, rotation) {
1180
+ var _this;
1181
+ _this = LiteCollider.call(this) || this;
1182
+ _this._transform.setPosition(position.x, position.y, position.z);
1183
+ _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1184
+ return _this;
1185
+ }
1186
+ return LiteStaticCollider;
1187
+ }(LiteCollider);
1188
+
1189
+ /**
1190
+ * Static interface implement decorator.
1191
+ * https://stackoverflow.com/questions/13955157/how-to-define-static-property-in-typescript-interface
1192
+ */ function StaticInterfaceImplement() {
1193
+ return function(constructor) {
1194
+ };
1195
+ }
1196
+
1197
+ var LitePhysics = /*#__PURE__*/ function() {
1198
+ function LitePhysics() {}
1199
+ /**
1200
+ * {@inheritDoc IPhysics.createPhysicsManager }
1201
+ */ LitePhysics.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1202
+ return new LitePhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1203
+ };
1204
+ /**
1205
+ * {@inheritDoc IPhysics.createStaticCollider }
1206
+ */ LitePhysics.createStaticCollider = function createStaticCollider(position, rotation) {
1207
+ return new LiteStaticCollider(position, rotation);
1208
+ };
1209
+ /**
1210
+ * {@inheritDoc IPhysics.createDynamicCollider }
1211
+ */ LitePhysics.createDynamicCollider = function createDynamicCollider(position, rotation) {
1212
+ return new LiteDynamicCollider(position, rotation);
1213
+ };
1214
+ /**
1215
+ * {@inheritDoc IPhysics.createCharacterController }
1216
+ */ LitePhysics.createCharacterController = function createCharacterController() {
1217
+ throw "Physics-lite don't support createCharacterController. Use Physics-PhysX instead!";
1218
+ };
1219
+ /**
1220
+ * {@inheritDoc IPhysics.createPhysicsMaterial }
1221
+ */ LitePhysics.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1222
+ return new LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1223
+ };
1224
+ /**
1225
+ * {@inheritDoc IPhysics.createBoxColliderShape }
1226
+ */ LitePhysics.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1227
+ return new LiteBoxColliderShape(uniqueID, size, material);
1228
+ };
1229
+ /**
1230
+ * {@inheritDoc IPhysics.createSphereColliderShape }
1231
+ */ LitePhysics.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1232
+ return new LiteSphereColliderShape(uniqueID, radius, material);
1233
+ };
1234
+ /**
1235
+ * {@inheritDoc IPhysics.createPlaneColliderShape }
1236
+ */ LitePhysics.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1237
+ throw "Physics-lite don't support PlaneColliderShape. Use Physics-PhysX instead!";
1238
+ };
1239
+ /**
1240
+ * {@inheritDoc IPhysics.createCapsuleColliderShape }
1241
+ */ LitePhysics.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1242
+ throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1243
+ };
1244
+ /**
1245
+ * {@inheritDoc IPhysics.createFixedJoint }
1246
+ */ LitePhysics.createFixedJoint = function createFixedJoint(collider) {
1247
+ throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1248
+ };
1249
+ /**
1250
+ * {@inheritDoc IPhysics.createHingeJoint }
1251
+ */ LitePhysics.createHingeJoint = function createHingeJoint(collider) {
1252
+ throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1253
+ };
1254
+ /**
1255
+ * {@inheritDoc IPhysics.createSpringJoint }
1256
+ */ LitePhysics.createSpringJoint = function createSpringJoint(collider) {
1257
+ throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1258
+ };
1259
+ return LitePhysics;
1260
+ }();
1261
+ LitePhysics = __decorate([
1262
+ StaticInterfaceImplement()
1263
+ ], LitePhysics);
1264
+
1265
+ export { LitePhysics };
1266
+ //# sourceMappingURL=module.js.map