@galacean/engine-physics-lite 1.6.8 → 1.6.9

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.
@@ -0,0 +1,1401 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.PhysicsLite = {}), global.Galacean));
5
+ })(this, (function (exports, engine) { 'use strict';
6
+
7
+ function _set_prototype_of(o, p) {
8
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
9
+ o.__proto__ = p;
10
+
11
+ return o;
12
+ };
13
+
14
+ return _set_prototype_of(o, p);
15
+ }
16
+
17
+ function _inherits(subClass, superClass) {
18
+ if (typeof superClass !== "function" && superClass !== null) {
19
+ throw new TypeError("Super expression must either be null or a function");
20
+ }
21
+
22
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
23
+
24
+ if (superClass) _set_prototype_of(subClass, superClass);
25
+ }
26
+
27
+ function _defineProperties(target, props) {
28
+ for (var i = 0; i < props.length; i++) {
29
+ var descriptor = props[i];
30
+ descriptor.enumerable = descriptor.enumerable || false;
31
+ descriptor.configurable = true;
32
+
33
+ if ("value" in descriptor) descriptor.writable = true;
34
+
35
+ Object.defineProperty(target, descriptor.key, descriptor);
36
+ }
37
+ }
38
+ function _create_class(Constructor, protoProps, staticProps) {
39
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
40
+ if (staticProps) _defineProperties(Constructor, staticProps);
41
+
42
+ return Constructor;
43
+ }
44
+
45
+ function _instanceof(left, right) {
46
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
47
+ return !!right[Symbol.hasInstance](left);
48
+ } else return left instanceof right;
49
+ }
50
+
51
+ /**
52
+ * Used to update tags.
53
+ */ var LiteUpdateFlag = /*#__PURE__*/ function() {
54
+ function LiteUpdateFlag(_flags) {
55
+ if (_flags === void 0) _flags = [];
56
+ this._flags = _flags;
57
+ this./** Flag. */ flag = true;
58
+ this._flags.push(this);
59
+ }
60
+ var _proto = LiteUpdateFlag.prototype;
61
+ /**
62
+ * Destroy.
63
+ */ _proto.destroy = function destroy() {
64
+ engine.Utils.removeFromArray(this._flags, this);
65
+ this._flags = null;
66
+ };
67
+ return LiteUpdateFlag;
68
+ }();
69
+
70
+ /**
71
+ * @internal
72
+ */ var LiteUpdateFlagManager = /*#__PURE__*/ function() {
73
+ function LiteUpdateFlagManager() {
74
+ this._updateFlags = [];
75
+ }
76
+ var _proto = LiteUpdateFlagManager.prototype;
77
+ _proto.register = function register() {
78
+ return new LiteUpdateFlag(this._updateFlags);
79
+ };
80
+ _proto.distribute = function distribute() {
81
+ var updateFlags = this._updateFlags;
82
+ for(var i = updateFlags.length - 1; i >= 0; i--){
83
+ updateFlags[i].flag = true;
84
+ }
85
+ };
86
+ return LiteUpdateFlagManager;
87
+ }();
88
+
89
+ /**
90
+ * Abstract class for collider shapes.
91
+ */ var LiteColliderShape = /*#__PURE__*/ function() {
92
+ function LiteColliderShape() {
93
+ /** @internal */ this._position = new engine.Vector3();
94
+ /** @internal */ this._worldScale = new engine.Vector3(1, 1, 1);
95
+ /** @internal */ this._transform = new LiteTransform();
96
+ /** @internal */ this._invModelMatrix = new engine.Matrix();
97
+ this._rotation = new engine.Vector3();
98
+ this._transform.owner = this;
99
+ this._inverseWorldMatFlag = this._transform.registerWorldChangeFlag();
100
+ }
101
+ var _proto = LiteColliderShape.prototype;
102
+ /**
103
+ * {@inheritDoc IColliderShape.setRotation }
104
+ */ _proto.setRotation = function setRotation(rotation) {
105
+ var rotationInRadians = this._rotation.set(engine.MathUtil.degreeToRadian(rotation.x), engine.MathUtil.degreeToRadian(rotation.y), engine.MathUtil.degreeToRadian(rotation.z));
106
+ engine.Quaternion.rotationEuler(rotationInRadians.x, rotationInRadians.y, rotationInRadians.z, this._transform.rotationQuaternion);
107
+ };
108
+ /**
109
+ * {@inheritDoc IColliderShape.setPosition }
110
+ */ _proto.setPosition = function setPosition(position) {
111
+ if (position !== this._position) {
112
+ this._position.copyFrom(position);
113
+ }
114
+ this._setLocalPose();
115
+ };
116
+ /**
117
+ * {@inheritDoc IColliderShape.setWorldScale }
118
+ */ _proto.setWorldScale = function setWorldScale(scale) {
119
+ this._worldScale.copyFrom(scale);
120
+ this._setLocalPose();
121
+ };
122
+ /**
123
+ * {@inheritDoc IColliderShape.setContactOffset }
124
+ */ _proto.setContactOffset = function setContactOffset(offset) {
125
+ console.log("Physics-lite don't support setContactOffset. Use Physics-PhysX instead!");
126
+ };
127
+ /**
128
+ * {@inheritDoc IColliderShape.setMaterial }
129
+ */ _proto.setMaterial = function setMaterial(material) {
130
+ console.log("Physics-lite don't support setMaterial. Use Physics-PhysX instead!");
131
+ };
132
+ /**
133
+ * {@inheritDoc IColliderShape.setUniqueID }
134
+ */ _proto.setUniqueID = function setUniqueID(id) {
135
+ this._id = id;
136
+ };
137
+ /**
138
+ * {@inheritDoc IColliderShape.setIsTrigger }
139
+ */ _proto.setIsTrigger = function setIsTrigger(value) {
140
+ console.log("Physics-lite don't support setIsTrigger. Use Physics-PhysX instead!");
141
+ };
142
+ /**
143
+ * {@inheritDoc IColliderShape.destroy }
144
+ */ _proto.destroy = function destroy() {};
145
+ _proto._updateHitResult = function _updateHitResult(ray, rayDistance, outHit, origin, isWorldRay) {
146
+ if (isWorldRay === void 0) isWorldRay = false;
147
+ var hitPoint = LiteColliderShape._tempPoint;
148
+ ray.getPoint(rayDistance, hitPoint);
149
+ if (!isWorldRay) {
150
+ engine.Vector3.transformCoordinate(hitPoint, this._transform.worldMatrix, hitPoint);
151
+ }
152
+ var distance = engine.Vector3.distance(origin, hitPoint);
153
+ if (distance < outHit.distance) {
154
+ outHit.point.copyFrom(hitPoint);
155
+ outHit.distance = distance;
156
+ outHit.shapeID = this._id;
157
+ }
158
+ };
159
+ _proto._getLocalRay = function _getLocalRay(ray) {
160
+ var worldToLocal = this._getInvModelMatrix();
161
+ var outRay = LiteColliderShape._ray;
162
+ engine.Vector3.transformCoordinate(ray.origin, worldToLocal, outRay.origin);
163
+ engine.Vector3.transformNormal(ray.direction, worldToLocal, outRay.direction);
164
+ outRay.direction.normalize();
165
+ return outRay;
166
+ };
167
+ _proto._getInvModelMatrix = function _getInvModelMatrix() {
168
+ if (this._inverseWorldMatFlag.flag) {
169
+ engine.Matrix.invert(this._transform.worldMatrix, this._invModelMatrix);
170
+ this._inverseWorldMatFlag.flag = false;
171
+ }
172
+ return this._invModelMatrix;
173
+ };
174
+ _proto._setLocalPose = function _setLocalPose() {
175
+ var shapePosition = LiteColliderShape._tempPoint;
176
+ engine.Vector3.multiply(this._position, this._worldScale, shapePosition);
177
+ this._transform.position = shapePosition;
178
+ };
179
+ return LiteColliderShape;
180
+ }();
181
+ LiteColliderShape._tempPos = new engine.Vector3();
182
+ LiteColliderShape._tempRot = new engine.Quaternion();
183
+ LiteColliderShape._tempScale = new engine.Vector3();
184
+ LiteColliderShape._tempPoint = new engine.Vector3();
185
+ LiteColliderShape._tempVector4 = new engine.Vector4();
186
+ LiteColliderShape._ray = new engine.Ray();
187
+
188
+ /**
189
+ * Used to implement transformation related functions.
190
+ */ var LiteTransform = /*#__PURE__*/ function() {
191
+ function LiteTransform() {
192
+ this._position = new engine.Vector3();
193
+ this._rotation = new engine.Vector3();
194
+ this._rotationQuaternion = new engine.Quaternion();
195
+ this._scale = new engine.Vector3(1, 1, 1);
196
+ this._worldRotationQuaternion = new engine.Quaternion();
197
+ this._localMatrix = new engine.Matrix();
198
+ this._worldMatrix = new engine.Matrix();
199
+ this._updateFlagManager = new LiteUpdateFlagManager();
200
+ this._isParentDirty = true;
201
+ this._parentTransformCache = null;
202
+ this._dirtyFlag = 188;
203
+ }
204
+ var _proto = LiteTransform.prototype;
205
+ /**
206
+ * Set local position by X, Y, Z value.
207
+ * @param x - X coordinate
208
+ * @param y - Y coordinate
209
+ * @param z - Z coordinate
210
+ */ _proto.setPosition = function setPosition(x, y, z) {
211
+ this._position.set(x, y, z);
212
+ this.position = this._position;
213
+ };
214
+ /**
215
+ * Set local rotation by the X, Y, Z, and W components of the quaternion.
216
+ * @param x - X component of quaternion
217
+ * @param y - Y component of quaternion
218
+ * @param z - Z component of quaternion
219
+ * @param w - W component of quaternion
220
+ */ _proto.setRotationQuaternion = function setRotationQuaternion(x, y, z, w) {
221
+ this._rotationQuaternion.set(x, y, z, w);
222
+ this.rotationQuaternion = this._rotationQuaternion;
223
+ };
224
+ /**
225
+ * Set local scaling by scaling values along X, Y, Z axis.
226
+ * @param x - Scaling along X axis
227
+ * @param y - Scaling along Y axis
228
+ * @param z - Scaling along Z axis
229
+ */ _proto.setScale = function setScale(x, y, z) {
230
+ this._scale.set(x, y, z);
231
+ this.scale = this._scale;
232
+ };
233
+ /**
234
+ * Register world transform change flag.
235
+ * @returns Change flag
236
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
237
+ return this._updateFlagManager.register();
238
+ };
239
+ /**
240
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
241
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
242
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
243
+ */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
244
+ if (!this._isContainDirtyFlags(132)) {
245
+ this._worldAssociatedChange(132);
246
+ if (_instanceof(this._owner, LiteCollider)) {
247
+ var shapes = this._owner._shapes;
248
+ for(var i = 0, n = shapes.length; i < n; i++){
249
+ shapes[i]._transform._updateWorldPositionFlag();
250
+ }
251
+ }
252
+ }
253
+ };
254
+ /**
255
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
256
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
257
+ * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
258
+ * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
259
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
260
+ */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
261
+ if (!this._isContainDirtyFlags(152)) {
262
+ this._worldAssociatedChange(152);
263
+ if (_instanceof(this._owner, LiteCollider)) {
264
+ var shapes = this._owner._shapes;
265
+ for(var i = 0, n = shapes.length; i < n; i++){
266
+ shapes[i]._transform._updateWorldRotationFlag();
267
+ }
268
+ }
269
+ }
270
+ };
271
+ /**
272
+ * Get worldMatrix: Will trigger the worldMatrix update of itself and all parent entities.
273
+ * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
274
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
275
+ * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
276
+ */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
277
+ if (!this._isContainDirtyFlags(160)) {
278
+ this._worldAssociatedChange(160);
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._updateWorldScaleFlag();
283
+ }
284
+ }
285
+ }
286
+ };
287
+ /**
288
+ * Update all world transform property dirty flag, the principle is the same as above.
289
+ */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
290
+ if (!this._isContainDirtyFlags(188)) {
291
+ this._worldAssociatedChange(188);
292
+ if (_instanceof(this._owner, LiteCollider)) {
293
+ var shapes = this._owner._shapes;
294
+ for(var i = 0, n = shapes.length; i < n; i++){
295
+ shapes[i]._transform._updateAllWorldFlag();
296
+ }
297
+ }
298
+ }
299
+ };
300
+ _proto._getParentTransform = function _getParentTransform() {
301
+ if (!this._isParentDirty) {
302
+ return this._parentTransformCache;
303
+ }
304
+ var parentCache = null;
305
+ if (_instanceof(this._owner, LiteColliderShape)) {
306
+ var parent = this._owner._collider;
307
+ parentCache = parent._transform;
308
+ }
309
+ this._parentTransformCache = parentCache;
310
+ this._isParentDirty = false;
311
+ return parentCache;
312
+ };
313
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
314
+ return (this._dirtyFlag & targetDirtyFlags) === targetDirtyFlags;
315
+ };
316
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
317
+ return (this._dirtyFlag & type) != 0;
318
+ };
319
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
320
+ this._dirtyFlag |= type;
321
+ };
322
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
323
+ this._dirtyFlag &= ~type;
324
+ };
325
+ _proto._worldAssociatedChange = function _worldAssociatedChange(type) {
326
+ this._dirtyFlag |= type;
327
+ this._updateFlagManager.distribute();
328
+ };
329
+ _create_class(LiteTransform, [
330
+ {
331
+ key: "owner",
332
+ set: function set(value) {
333
+ this._owner = value;
334
+ }
335
+ },
336
+ {
337
+ key: "position",
338
+ get: /**
339
+ * Local position.
340
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
341
+ */ function get() {
342
+ return this._position;
343
+ },
344
+ set: function set(value) {
345
+ if (this._position !== value) {
346
+ this._position.copyFrom(value);
347
+ }
348
+ this._setDirtyFlagTrue(64);
349
+ this._updateWorldPositionFlag();
350
+ }
351
+ },
352
+ {
353
+ key: "rotationQuaternion",
354
+ get: /**
355
+ * Local rotation, defining the rotation by using a unit quaternion.
356
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
357
+ */ function get() {
358
+ if (this._isContainDirtyFlag(2)) {
359
+ engine.Quaternion.rotationEuler(engine.MathUtil.degreeToRadian(this._rotation.x), engine.MathUtil.degreeToRadian(this._rotation.y), engine.MathUtil.degreeToRadian(this._rotation.z), this._rotationQuaternion);
360
+ this._setDirtyFlagFalse(2);
361
+ }
362
+ return this._rotationQuaternion;
363
+ },
364
+ set: function set(value) {
365
+ if (this._rotationQuaternion !== value) {
366
+ this._rotationQuaternion.copyFrom(value);
367
+ }
368
+ this._setDirtyFlagTrue(64 | 1);
369
+ this._setDirtyFlagFalse(2);
370
+ this._updateWorldRotationFlag();
371
+ }
372
+ },
373
+ {
374
+ key: "worldRotationQuaternion",
375
+ get: /**
376
+ * World rotation, defining the rotation by using a unit quaternion.
377
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
378
+ */ function get() {
379
+ if (this._isContainDirtyFlag(16)) {
380
+ var parent = this._getParentTransform();
381
+ if (parent != null) {
382
+ engine.Quaternion.multiply(parent.worldRotationQuaternion, this.rotationQuaternion, this._worldRotationQuaternion);
383
+ } else {
384
+ this._worldRotationQuaternion.copyFrom(this.rotationQuaternion);
385
+ }
386
+ this._setDirtyFlagFalse(16);
387
+ }
388
+ return this._worldRotationQuaternion;
389
+ },
390
+ set: function set(value) {
391
+ if (this._worldRotationQuaternion !== value) {
392
+ this._worldRotationQuaternion.copyFrom(value);
393
+ }
394
+ var parent = this._getParentTransform();
395
+ if (parent) {
396
+ engine.Quaternion.invert(parent.worldRotationQuaternion, LiteTransform._tempQuat0);
397
+ engine.Quaternion.multiply(value, LiteTransform._tempQuat0, this._rotationQuaternion);
398
+ } else {
399
+ this._rotationQuaternion.copyFrom(value);
400
+ }
401
+ this.rotationQuaternion = this._rotationQuaternion;
402
+ this._setDirtyFlagFalse(16);
403
+ }
404
+ },
405
+ {
406
+ key: "scale",
407
+ get: /**
408
+ * Local scaling.
409
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
410
+ */ function get() {
411
+ return this._scale;
412
+ },
413
+ set: function set(value) {
414
+ if (this._scale !== value) {
415
+ this._scale.copyFrom(value);
416
+ }
417
+ this._setDirtyFlagTrue(64);
418
+ this._updateWorldScaleFlag();
419
+ }
420
+ },
421
+ {
422
+ key: "localMatrix",
423
+ get: /**
424
+ * Local matrix.
425
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
426
+ */ function get() {
427
+ if (this._isContainDirtyFlag(64)) {
428
+ engine.Matrix.affineTransformation(this._scale, this.rotationQuaternion, this._position, this._localMatrix);
429
+ this._setDirtyFlagFalse(64);
430
+ }
431
+ return this._localMatrix;
432
+ },
433
+ set: function set(value) {
434
+ if (this._localMatrix !== value) {
435
+ this._localMatrix.copyFrom(value);
436
+ }
437
+ this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
438
+ this._setDirtyFlagTrue(1);
439
+ this._setDirtyFlagFalse(64);
440
+ this._updateAllWorldFlag();
441
+ }
442
+ },
443
+ {
444
+ key: "worldMatrix",
445
+ get: /**
446
+ * World matrix.
447
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
448
+ */ function get() {
449
+ if (this._isContainDirtyFlag(128)) {
450
+ var parent = this._getParentTransform();
451
+ if (parent) {
452
+ engine.Matrix.multiply(parent.worldMatrix, this.localMatrix, this._worldMatrix);
453
+ } else {
454
+ this._worldMatrix.copyFrom(this.localMatrix);
455
+ }
456
+ this._setDirtyFlagFalse(128);
457
+ }
458
+ return this._worldMatrix;
459
+ },
460
+ set: function set(value) {
461
+ if (this._worldMatrix !== value) {
462
+ this._worldMatrix.copyFrom(value);
463
+ }
464
+ var parent = this._getParentTransform();
465
+ if (parent) {
466
+ engine.Matrix.invert(parent.worldMatrix, LiteTransform._tempMat42);
467
+ engine.Matrix.multiply(LiteTransform._tempMat42, value, this._localMatrix);
468
+ } else {
469
+ this._localMatrix.copyFrom(value);
470
+ }
471
+ this.localMatrix = this._localMatrix;
472
+ this._setDirtyFlagFalse(128);
473
+ }
474
+ }
475
+ ]);
476
+ return LiteTransform;
477
+ }();
478
+ LiteTransform._tempQuat0 = new engine.Quaternion();
479
+ LiteTransform._tempMat42 = new engine.Matrix();
480
+
481
+ /**
482
+ * Abstract class of physical collider.
483
+ */ var LiteCollider = /*#__PURE__*/ function() {
484
+ function LiteCollider(litePhysics) {
485
+ /** @internal */ this._shapes = [];
486
+ /** @internal */ this._transform = new LiteTransform();
487
+ this._transform.owner = this;
488
+ this._litePhysics = litePhysics;
489
+ }
490
+ var _proto = LiteCollider.prototype;
491
+ /**
492
+ * {@inheritDoc ICollider.addShape }
493
+ */ _proto.addShape = function addShape(shape) {
494
+ var oldCollider = shape._collider;
495
+ if (oldCollider !== this) {
496
+ var _this__scene;
497
+ if (oldCollider) {
498
+ oldCollider.removeShape(shape);
499
+ }
500
+ this._shapes.push(shape);
501
+ shape._collider = this;
502
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape);
503
+ }
504
+ };
505
+ /**
506
+ * {@inheritDoc ICollider.removeShape }
507
+ */ _proto.removeShape = function removeShape(shape) {
508
+ var index = this._shapes.indexOf(shape);
509
+ if (index !== -1) {
510
+ var _this__scene;
511
+ this._shapes.splice(index, 1);
512
+ shape._collider = null;
513
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape);
514
+ }
515
+ };
516
+ /**
517
+ * {@inheritDoc ICollider.setWorldTransform }
518
+ */ _proto.setWorldTransform = function setWorldTransform(position, rotation) {
519
+ this._transform.setPosition(position.x, position.y, position.z);
520
+ this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
521
+ };
522
+ /**
523
+ * {@inheritDoc ICollider.getWorldTransform }
524
+ */ _proto.getWorldTransform = function getWorldTransform(outPosition, outRotation) {
525
+ var _this__transform = this._transform, position = _this__transform.position, rotationQuaternion = _this__transform.rotationQuaternion;
526
+ outPosition.set(position.x, position.y, position.z);
527
+ outRotation.set(rotationQuaternion.x, rotationQuaternion.y, rotationQuaternion.z, rotationQuaternion.w);
528
+ };
529
+ /**
530
+ * {@inheritDoc ICollider.setCollisionLayer }
531
+ */ _proto.setCollisionLayer = function setCollisionLayer(collisionLayer) {
532
+ this._litePhysics.setColliderLayer(this, collisionLayer);
533
+ };
534
+ /**
535
+ * {@inheritDoc ICollider.destroy }
536
+ */ _proto.destroy = function destroy() {};
537
+ /**
538
+ * @internal
539
+ */ _proto._raycast = function _raycast(ray, onRaycast, hit) {
540
+ hit.distance = Number.MAX_VALUE;
541
+ var shapes = this._shapes;
542
+ for(var i = 0, n = shapes.length; i < n; i++){
543
+ var shape = shapes[i];
544
+ onRaycast(shape._id) && shape._raycast(ray, hit);
545
+ }
546
+ return hit.distance != Number.MAX_VALUE;
547
+ };
548
+ return LiteCollider;
549
+ }();
550
+
551
+ /**
552
+ * A dynamic collider can act with self-defined movement or physical force
553
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
554
+ _inherits(LiteDynamicCollider, LiteCollider);
555
+ function LiteDynamicCollider(litePhysics, position, rotation) {
556
+ var _this;
557
+ _this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = false;
558
+ _this._transform.setPosition(position.x, position.y, position.z);
559
+ _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
560
+ return _this;
561
+ }
562
+ var _proto = LiteDynamicCollider.prototype;
563
+ /**
564
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
565
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
566
+ engine.Logger.error("Physics-lite don't support getInertiaTensor. Use Physics-PhysX instead!");
567
+ return out;
568
+ };
569
+ /**
570
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
571
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
572
+ engine.Logger.error("Physics-lite don't support getCenterOfMass. Use Physics-PhysX instead!");
573
+ return out;
574
+ };
575
+ /**
576
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
577
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
578
+ engine.Logger.error("Physics-lite don't support setMassAndUpdateInertia. Use Physics-PhysX instead!");
579
+ };
580
+ /**
581
+ * {@inheritDoc IDynamicCollider.addForce }
582
+ */ _proto.addForce = function addForce(force) {
583
+ throw "Physics-lite don't support addForce. Use Physics-PhysX instead!";
584
+ };
585
+ /**
586
+ * {@inheritDoc IDynamicCollider.addTorque }
587
+ */ _proto.addTorque = function addTorque(torque) {
588
+ throw "Physics-lite don't support addTorque. Use Physics-PhysX instead!";
589
+ };
590
+ /**
591
+ * {@inheritDoc IDynamicCollider.move }
592
+ */ _proto.move = function move(positionOrRotation, rotation) {
593
+ throw "Physics-lite don't support move. Use Physics-PhysX instead!";
594
+ };
595
+ /**
596
+ * {@inheritDoc IDynamicCollider.sleep }
597
+ */ _proto.sleep = function sleep() {
598
+ throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!";
599
+ };
600
+ /**
601
+ * {@inheritDoc IDynamicCollider.isSleeping }
602
+ */ _proto.isSleeping = function isSleeping() {
603
+ throw "Physics-lite don't support isSleeping. Use Physics-PhysX instead!";
604
+ };
605
+ /**
606
+ * {@inheritDoc IDynamicCollider.setAngularDamping }
607
+ */ _proto.setAngularDamping = function setAngularDamping(value) {
608
+ engine.Logger.error("Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!");
609
+ };
610
+ /**
611
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
612
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
613
+ engine.Logger.error("Physics-lite don't support getAngularVelocity. Use Physics-PhysX instead!");
614
+ return out;
615
+ };
616
+ /**
617
+ * {@inheritDoc IDynamicCollider.setAngularVelocity }
618
+ */ _proto.setAngularVelocity = function setAngularVelocity(value) {
619
+ engine.Logger.error("Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!");
620
+ };
621
+ /**
622
+ * {@inheritDoc IDynamicCollider.setCenterOfMass }
623
+ */ _proto.setCenterOfMass = function setCenterOfMass(value) {
624
+ engine.Logger.error("Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!");
625
+ };
626
+ /**
627
+ * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
628
+ */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
629
+ engine.Logger.error("Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!");
630
+ };
631
+ /**
632
+ * {@inheritDoc IDynamicCollider.setConstraints }
633
+ */ _proto.setConstraints = function setConstraints(flags) {
634
+ engine.Logger.error("Physics-lite don't support setConstraints. Use Physics-PhysX instead!");
635
+ };
636
+ /**
637
+ * {@inheritDoc IDynamicCollider.setInertiaTensor }
638
+ */ _proto.setInertiaTensor = function setInertiaTensor(value) {
639
+ engine.Logger.error("Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!");
640
+ };
641
+ /**
642
+ * {@inheritDoc IDynamicCollider.setUseGravity }
643
+ */ _proto.setUseGravity = function setUseGravity(value) {
644
+ engine.Logger.error("Physics-lite don't support setUseGravity. Use Physics-PhysX instead!");
645
+ };
646
+ /**
647
+ * {@inheritDoc IDynamicCollider.setIsKinematic }
648
+ */ _proto.setIsKinematic = function setIsKinematic(value) {
649
+ engine.Logger.error("Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!");
650
+ };
651
+ /**
652
+ * {@inheritDoc IDynamicCollider.setLinearDamping }
653
+ */ _proto.setLinearDamping = function setLinearDamping(value) {
654
+ engine.Logger.error("Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!");
655
+ };
656
+ /**
657
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
658
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
659
+ engine.Logger.error("Physics-lite don't support getLinearVelocity. Use Physics-PhysX instead!");
660
+ return out;
661
+ };
662
+ /**
663
+ * {@inheritDoc IDynamicCollider.setLinearVelocity }
664
+ */ _proto.setLinearVelocity = function setLinearVelocity(value) {
665
+ engine.Logger.error("Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!");
666
+ };
667
+ /**
668
+ * {@inheritDoc IDynamicCollider.setMass }
669
+ */ _proto.setMass = function setMass(value) {
670
+ engine.Logger.error("Physics-lite don't support setMass. Use Physics-PhysX instead!");
671
+ };
672
+ /**
673
+ * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
674
+ */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
675
+ engine.Logger.error("Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!");
676
+ };
677
+ /**
678
+ * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
679
+ */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
680
+ engine.Logger.error("Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!");
681
+ };
682
+ /**
683
+ * {@inheritDoc IDynamicCollider.setSleepThreshold }
684
+ */ _proto.setSleepThreshold = function setSleepThreshold(value) {
685
+ engine.Logger.error("Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!");
686
+ };
687
+ /**
688
+ * {@inheritDoc IDynamicCollider.setSolverIterations }
689
+ */ _proto.setSolverIterations = function setSolverIterations(value) {
690
+ engine.Logger.error("Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!");
691
+ };
692
+ /**
693
+ * {@inheritDoc IDynamicCollider.wakeUp }
694
+ */ _proto.wakeUp = function wakeUp() {
695
+ throw "Physics-lite don't support wakeUp. Use Physics-PhysX instead!";
696
+ };
697
+ return LiteDynamicCollider;
698
+ }(LiteCollider);
699
+
700
+ /**
701
+ * Physics material describes how to handle colliding objects (friction, bounciness).
702
+ */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
703
+ function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
704
+ var _proto = LitePhysicsMaterial.prototype;
705
+ /**
706
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
707
+ */ _proto.setBounciness = function setBounciness(value) {
708
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
709
+ };
710
+ /**
711
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
712
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
713
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
714
+ };
715
+ /**
716
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
717
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
718
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
719
+ };
720
+ /**
721
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
722
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
723
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
724
+ };
725
+ /**
726
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
727
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
728
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
729
+ };
730
+ /**
731
+ * {@inheritDoc IPhysicsMaterial.destroy }
732
+ */ _proto.destroy = function destroy() {};
733
+ return LitePhysicsMaterial;
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 engine.Vector3();
743
+ /** The hit normal of the collider that was hit in world space. */ this.normal = new engine.Vector3();
744
+ };
745
+
746
+ /**
747
+ * Box collider shape in Lite.
748
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
749
+ _inherits(LiteBoxColliderShape, LiteColliderShape1);
750
+ function LiteBoxColliderShape(uniqueID, size, material) {
751
+ var _this;
752
+ _this = LiteColliderShape1.call(this) || this, _this._halfSize = new engine.Vector3(), _this._sizeScale = new engine.Vector3(1, 1, 1), /** @internal */ _this._boxMin = new engine.Vector3(-0.5, -0.5, -0.5), /** @internal */ _this._boxMax = new engine.Vector3(0.5, 0.5, 0.5);
753
+ _this._id = uniqueID;
754
+ _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
755
+ _this._setBondingBox();
756
+ return _this;
757
+ }
758
+ var _proto = LiteBoxColliderShape.prototype;
759
+ /**
760
+ * {@inheritDoc IColliderShape.setPosition }
761
+ */ _proto.setPosition = function setPosition(position) {
762
+ LiteColliderShape1.prototype.setPosition.call(this, position);
763
+ this._setBondingBox();
764
+ };
765
+ /**
766
+ * {@inheritDoc IColliderShape.setWorldScale }
767
+ */ _proto.setWorldScale = function setWorldScale(scale) {
768
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
769
+ this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
770
+ this._setBondingBox();
771
+ };
772
+ /**
773
+ * {@inheritDoc IBoxColliderShape.setSize }
774
+ */ _proto.setSize = function setSize(value) {
775
+ this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
776
+ this._setBondingBox();
777
+ };
778
+ /**
779
+ * {@inheritDoc IColliderShape.pointDistance }
780
+ */ _proto.pointDistance = function pointDistance(point) {
781
+ var position = LiteColliderShape._tempPos;
782
+ var rotation = LiteColliderShape._tempRot;
783
+ this._transform.worldMatrix.decompose(position, rotation, LiteColliderShape._tempScale);
784
+ var _this__transform = this._transform, shapePosition = _this__transform.position;
785
+ var m = LiteBoxColliderShape._tempMatrix;
786
+ var invM = LiteBoxColliderShape._tempInvMatrix;
787
+ var p = LiteColliderShape._tempPoint;
788
+ var scale = this._sizeScale;
789
+ var boundingBox = LiteBoxColliderShape._tempBox;
790
+ var _this = this, _boxMin = _this._boxMin, _boxMax = _this._boxMax;
791
+ p.copyFrom(_boxMin);
792
+ p.subtract(shapePosition);
793
+ p.divide(scale);
794
+ boundingBox.min.copyFrom(p);
795
+ p.copyFrom(_boxMax);
796
+ p.subtract(shapePosition);
797
+ p.divide(scale);
798
+ boundingBox.max.copyFrom(p);
799
+ engine.Matrix.affineTransformation(scale, rotation, position, m);
800
+ engine.Matrix.invert(m, invM);
801
+ engine.Vector3.transformCoordinate(point, invM, p);
802
+ var min = boundingBox.min;
803
+ var max = boundingBox.max;
804
+ p.x = Math.max(min.x, Math.min(p.x, max.x));
805
+ p.y = Math.max(min.y, Math.min(p.y, max.y));
806
+ p.z = Math.max(min.z, Math.min(p.z, max.z));
807
+ engine.Vector3.transformCoordinate(p, m, p);
808
+ var res = LiteColliderShape._tempVector4;
809
+ if (engine.Vector3.equals(p, point)) {
810
+ res.set(point.x, point.y, point.z, 0);
811
+ } else {
812
+ res.set(p.x, p.y, p.z, engine.Vector3.distanceSquared(p, point));
813
+ }
814
+ return res;
815
+ };
816
+ /**
817
+ * @internal
818
+ */ _proto._raycast = function _raycast(ray, hit) {
819
+ var localRay = this._getLocalRay(ray);
820
+ var sizeScale = this._sizeScale;
821
+ var halfSize = this._halfSize;
822
+ var boundingBox = LiteBoxColliderShape._tempBox;
823
+ boundingBox.min.set(-halfSize.x * sizeScale.x, -halfSize.y * sizeScale.y, -halfSize.z * sizeScale.z);
824
+ boundingBox.max.set(halfSize.x * sizeScale.x, halfSize.y * sizeScale.y, halfSize.z * sizeScale.z);
825
+ var rayDistance = localRay.intersectBox(boundingBox);
826
+ if (rayDistance !== -1) {
827
+ this._updateHitResult(localRay, rayDistance, hit, ray.origin);
828
+ return true;
829
+ } else {
830
+ return false;
831
+ }
832
+ };
833
+ _proto._setBondingBox = function _setBondingBox() {
834
+ var position = this._transform.position;
835
+ var scale = this._sizeScale;
836
+ var halfSize = this._halfSize;
837
+ this._boxMin.set(-halfSize.x * scale.x + position.x, -halfSize.y * scale.y + position.y, -halfSize.z * scale.z + position.z);
838
+ this._boxMax.set(halfSize.x * scale.x + position.x, halfSize.y * scale.y + position.y, halfSize.z * scale.z + position.z);
839
+ };
840
+ return LiteBoxColliderShape;
841
+ }(LiteColliderShape);
842
+ LiteBoxColliderShape._tempBox = new engine.BoundingBox();
843
+ LiteBoxColliderShape._tempMatrix = new engine.Matrix();
844
+ LiteBoxColliderShape._tempInvMatrix = new engine.Matrix();
845
+
846
+ /**
847
+ * Sphere collider shape in Lite.
848
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
849
+ _inherits(LiteSphereColliderShape, LiteColliderShape1);
850
+ function LiteSphereColliderShape(uniqueID, radius, material) {
851
+ var _this;
852
+ _this = LiteColliderShape1.call(this) || this, _this._radius = 1, _this._maxScale = 1;
853
+ _this._radius = radius;
854
+ _this._id = uniqueID;
855
+ return _this;
856
+ }
857
+ var _proto = LiteSphereColliderShape.prototype;
858
+ /**
859
+ * {@inheritDoc ISphereColliderShape.setRadius }
860
+ */ _proto.setRadius = function setRadius(value) {
861
+ this._radius = value;
862
+ };
863
+ /**
864
+ * {@inheritDoc IColliderShape.setWorldScale }
865
+ */ _proto.setWorldScale = function setWorldScale(scale) {
866
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
867
+ this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
868
+ };
869
+ /**
870
+ * {@inheritDoc IColliderShape.pointDistance }
871
+ */ _proto.pointDistance = function pointDistance(point) {
872
+ var position = LiteColliderShape._tempPos;
873
+ var worldRadius = this.worldRadius;
874
+ this._transform.worldMatrix.decompose(position, LiteColliderShape._tempRot, LiteColliderShape._tempScale);
875
+ var p = LiteColliderShape._tempPoint;
876
+ engine.Vector3.subtract(point, position, p);
877
+ var distanceFromCenter = p.lengthSquared();
878
+ var direction = p.normalize();
879
+ engine.Vector3.scale(direction, worldRadius, p);
880
+ p.add(position);
881
+ var res = LiteColliderShape._tempVector4;
882
+ var distanceSquared = engine.Vector3.distanceSquared(p, point);
883
+ if (distanceFromCenter <= worldRadius * worldRadius) {
884
+ res.set(point.x, point.y, point.z, 0);
885
+ } else {
886
+ res.set(p.x, p.y, p.z, distanceSquared);
887
+ }
888
+ return res;
889
+ };
890
+ /**
891
+ * @internal
892
+ */ _proto._raycast = function _raycast(ray, hit) {
893
+ var boundingSphere = LiteSphereColliderShape._tempSphere;
894
+ engine.Vector3.transformCoordinate(this._transform.position, this._collider._transform.worldMatrix, boundingSphere.center);
895
+ boundingSphere.radius = this.worldRadius;
896
+ var rayDistance = ray.intersectSphere(boundingSphere);
897
+ if (rayDistance !== -1) {
898
+ this._updateHitResult(ray, rayDistance, hit, ray.origin, true);
899
+ return true;
900
+ } else {
901
+ return false;
902
+ }
903
+ };
904
+ _create_class(LiteSphereColliderShape, [
905
+ {
906
+ key: "worldRadius",
907
+ get: function get() {
908
+ return this._radius * this._maxScale;
909
+ }
910
+ }
911
+ ]);
912
+ return LiteSphereColliderShape;
913
+ }(LiteColliderShape);
914
+ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
915
+
916
+ /**
917
+ * A manager is a collection of colliders and constraints which can interact.
918
+ */ var LitePhysicsScene = /*#__PURE__*/ function() {
919
+ function LitePhysicsScene(physics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
920
+ this._staticColliders = [];
921
+ this._dynamicColliders = [];
922
+ this._sphere = new engine.BoundingSphere();
923
+ this._box = new engine.BoundingBox();
924
+ this._currentEvents = new engine.DisorderedArray();
925
+ this._eventMap = {};
926
+ this._eventPool = [];
927
+ this._physics = physics;
928
+ this._onContactEnter = onContactEnter;
929
+ this._onContactExit = onContactExit;
930
+ this._onContactStay = onContactStay;
931
+ this._onTriggerEnter = onTriggerEnter;
932
+ this._onTriggerExit = onTriggerExit;
933
+ this._onTriggerStay = onTriggerStay;
934
+ }
935
+ var _proto = LitePhysicsScene.prototype;
936
+ _proto.overlapBox = function overlapBox(center, orientation, halfExtents, onOverlap, outHitResult) {
937
+ throw new Error("Method not implemented.");
938
+ };
939
+ _proto.overlapSphere = function overlapSphere(center, radius, onOverlap, outHitResult) {
940
+ throw new Error("Method not implemented.");
941
+ };
942
+ _proto.overlapCapsule = function overlapCapsule(center, radius, height, orientation, onOverlap, outHitResult) {
943
+ throw new Error("Method not implemented.");
944
+ };
945
+ /**
946
+ * {@inheritDoc IPhysicsScene.setGravity }
947
+ */ _proto.setGravity = function setGravity(value) {
948
+ console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
949
+ };
950
+ /**
951
+ * {@inheritDoc IPhysicsScene.addCollider }
952
+ */ _proto.addCollider = function addCollider(actor) {
953
+ actor._scene = this;
954
+ var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
955
+ colliders.push(actor);
956
+ var shapes = actor._shapes;
957
+ for(var i = 0, n = shapes.length; i < n; i++){
958
+ this._addColliderShape(shapes[i]);
959
+ }
960
+ };
961
+ /**
962
+ * {@inheritDoc IPhysicsScene.removeCollider }
963
+ */ _proto.removeCollider = function removeCollider(collider) {
964
+ collider._scene = null;
965
+ var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
966
+ var index = colliders.indexOf(collider);
967
+ index > -1 && colliders.splice(index, 1);
968
+ var shapes = collider._shapes;
969
+ for(var i = 0, n = shapes.length; i < n; i++){
970
+ this._removeColliderShape(shapes[i]);
971
+ }
972
+ };
973
+ /**
974
+ * {@inheritDoc IPhysicsScene.update }
975
+ */ _proto.update = function update(deltaTime) {
976
+ var dynamicColliders = this._dynamicColliders;
977
+ for(var i = 0, len = dynamicColliders.length; i < len; i++){
978
+ var collider = dynamicColliders[i];
979
+ this._collisionDetection(collider, this._staticColliders);
980
+ this._collisionDetection(collider, dynamicColliders);
981
+ }
982
+ this._fireEvent();
983
+ };
984
+ /**
985
+ * {@inheritDoc IPhysicsScene.raycast }
986
+ */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
987
+ if (!hit) {
988
+ return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
989
+ } else {
990
+ var raycastStaticRes = this._raycast(ray, distance, onRaycast, this._staticColliders, hit);
991
+ if (raycastStaticRes) {
992
+ distance = LitePhysicsScene._currentHit.distance;
993
+ }
994
+ var raycastDynamicRes = this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
995
+ var isHit = raycastStaticRes || raycastDynamicRes;
996
+ var hitResult = LitePhysicsScene._hitResult;
997
+ if (!isHit) {
998
+ hitResult.shapeID = -1;
999
+ hitResult.distance = 0;
1000
+ hitResult.point.set(0, 0, 0);
1001
+ hitResult.normal.set(0, 0, 0);
1002
+ } else {
1003
+ hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
1004
+ }
1005
+ return isHit;
1006
+ }
1007
+ };
1008
+ /**
1009
+ * {@inheritDoc IPhysicsScene.addCharacterController }
1010
+ */ _proto.addCharacterController = function addCharacterController(characterController) {
1011
+ throw new Error("Physics-lite doesn't support addCharacterController. Use Physics-PhysX instead!");
1012
+ };
1013
+ /**
1014
+ * {@inheritDoc IPhysicsScene.removeCharacterController }
1015
+ */ _proto.removeCharacterController = function removeCharacterController(characterController) {
1016
+ throw new Error("Physics-lite doesn't support removeCharacterController. Use Physics-PhysX instead!");
1017
+ };
1018
+ /**
1019
+ * {@inheritDoc IPhysicsScene.boxCast }
1020
+ */ _proto.boxCast = function boxCast(center, orientation, halfExtents, direction, distance, onSweep, outHitResult) {
1021
+ throw new Error("Physics-lite doesn't support boxCast. Use Physics-PhysX instead!");
1022
+ };
1023
+ /**
1024
+ * {@inheritDoc IPhysicsScene.sphereCast }
1025
+ */ _proto.sphereCast = function sphereCast(center, radius, direction, distance, onSweep, outHitResult) {
1026
+ throw new Error("Physics-lite doesn't support sphereCast. Use Physics-PhysX instead!");
1027
+ };
1028
+ /**
1029
+ * {@inheritDoc IPhysicsScene.capsuleCast }
1030
+ */ _proto.capsuleCast = function capsuleCast(center, radius, height, orientation, direction, distance, onSweep, outHitResult) {
1031
+ throw new Error("Physics-lite doesn't support capsuleCast. Use Physics-PhysX instead!");
1032
+ };
1033
+ /**
1034
+ * {@inheritDoc IPhysicsScene.overlapBoxAll }
1035
+ */ _proto.overlapBoxAll = function overlapBoxAll(center, orientation, halfExtents, onOverlap) {
1036
+ throw new Error("Physics-lite doesn't support overlapBoxAll. Use Physics-PhysX instead!");
1037
+ };
1038
+ /**
1039
+ * {@inheritDoc IPhysicsScene.overlapSphereAll }
1040
+ */ _proto.overlapSphereAll = function overlapSphereAll(center, radius, onOverlap) {
1041
+ throw new Error("Physics-lite doesn't support overlapSphereAll. Use Physics-PhysX instead!");
1042
+ };
1043
+ /**
1044
+ * {@inheritDoc IPhysicsScene.overlapCapsuleAll }
1045
+ */ _proto.overlapCapsuleAll = function overlapCapsuleAll(center, radius, height, orientation, onOverlap) {
1046
+ throw new Error("Physics-lite doesn't support overlapCapsuleAll. Use Physics-PhysX instead!");
1047
+ };
1048
+ /**
1049
+ * {@inheritDoc IPhysicsScene.destroy }
1050
+ */ _proto.destroy = function destroy() {};
1051
+ /**
1052
+ * @internal
1053
+ */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
1054
+ this._eventMap[colliderShape._id] = {};
1055
+ };
1056
+ /**
1057
+ * @internal
1058
+ */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
1059
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
1060
+ var id = colliderShape._id;
1061
+ currentEvents.forEach(function(event, i) {
1062
+ if (event.index1 == id) {
1063
+ currentEvents.deleteByIndex(i);
1064
+ eventPool.push(event);
1065
+ } else if (event.index2 == id) {
1066
+ currentEvents.deleteByIndex(i);
1067
+ eventPool.push(event);
1068
+ // If the shape is big index, should clear from the small index shape subMap
1069
+ eventMap[event.index1][id] = undefined;
1070
+ }
1071
+ });
1072
+ delete eventMap[id];
1073
+ };
1074
+ _proto._getTrigger = function _getTrigger(index1, index2) {
1075
+ var event;
1076
+ if (this._eventPool.length) {
1077
+ event = this._eventPool.pop();
1078
+ event.index1 = index1;
1079
+ event.index2 = index2;
1080
+ } else {
1081
+ event = new TriggerEvent(index1, index2);
1082
+ }
1083
+ this._eventMap[index1][index2] = event;
1084
+ return event;
1085
+ };
1086
+ _proto._collisionDetection = function _collisionDetection(myCollider, colliders) {
1087
+ var myColliderShapes = myCollider._shapes;
1088
+ for(var i = 0, len = myColliderShapes.length; i < len; i++){
1089
+ var myShape = myColliderShapes[i];
1090
+ if (_instanceof(myShape, LiteBoxColliderShape)) {
1091
+ LitePhysicsScene._updateWorldBox(myShape, this._box);
1092
+ for(var j = 0, len1 = colliders.length; j < len1; j++){
1093
+ var collider = colliders[j];
1094
+ var colliderShape = collider._shapes;
1095
+ // Skip collision check if layers can't collide
1096
+ if (!this._checkColliderCollide(collider, myCollider)) {
1097
+ continue;
1098
+ }
1099
+ for(var k = 0, len2 = colliderShape.length; k < len2; k++){
1100
+ var shape = colliderShape[k];
1101
+ var index1 = shape._id;
1102
+ var index2 = myShape._id;
1103
+ var event = index1 < index2 ? this._eventMap[index1][index2] : this._eventMap[index2][index1];
1104
+ if (event !== undefined && !event.alreadyInvoked) {
1105
+ continue;
1106
+ }
1107
+ if (shape != myShape && this._boxCollision(shape)) {
1108
+ if (event === undefined) {
1109
+ var event1 = index1 < index2 ? this._getTrigger(index1, index2) : this._getTrigger(index2, index1);
1110
+ event1.state = 0;
1111
+ event1.alreadyInvoked = false;
1112
+ this._currentEvents.add(event1);
1113
+ } else if (event.state === 0) {
1114
+ event.state = 1;
1115
+ event.alreadyInvoked = false;
1116
+ } else if (event.state === 1) {
1117
+ event.alreadyInvoked = false;
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ } else if (_instanceof(myShape, LiteSphereColliderShape)) {
1123
+ LitePhysicsScene._upWorldSphere(myShape, this._sphere);
1124
+ for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
1125
+ var collider1 = colliders[j1];
1126
+ var colliderShape1 = collider1._shapes;
1127
+ // Skip collision check if layers can't collide
1128
+ if (!this._checkColliderCollide(collider1, myCollider)) {
1129
+ continue;
1130
+ }
1131
+ for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
1132
+ var shape1 = colliderShape1[k1];
1133
+ var index11 = shape1._id;
1134
+ var index21 = myShape._id;
1135
+ var event2 = index11 < index21 ? this._eventMap[index11][index21] : this._eventMap[index21][index11];
1136
+ if (event2 !== undefined && !event2.alreadyInvoked) {
1137
+ continue;
1138
+ }
1139
+ if (shape1 != myShape && this._sphereCollision(shape1)) {
1140
+ if (event2 === undefined) {
1141
+ var event3 = index11 < index21 ? this._getTrigger(index11, index21) : this._getTrigger(index21, index11);
1142
+ event3.state = 0;
1143
+ event3.alreadyInvoked = false;
1144
+ this._currentEvents.add(event3);
1145
+ } else if (event2.state === 0) {
1146
+ event2.state = 1;
1147
+ event2.alreadyInvoked = false;
1148
+ } else if (event2.state === 1) {
1149
+ event2.alreadyInvoked = false;
1150
+ }
1151
+ }
1152
+ }
1153
+ }
1154
+ }
1155
+ }
1156
+ };
1157
+ _proto._fireEvent = function _fireEvent() {
1158
+ var _this = this;
1159
+ var _this1 = this, eventPool = _this1._eventPool, currentEvents = _this1._currentEvents;
1160
+ currentEvents.forEach(function(event, i) {
1161
+ if (!event.alreadyInvoked) {
1162
+ if (event.state == 0) {
1163
+ _this._onTriggerEnter(event.index1, event.index2);
1164
+ event.alreadyInvoked = true;
1165
+ } else if (event.state == 1) {
1166
+ _this._onTriggerStay(event.index1, event.index2);
1167
+ event.alreadyInvoked = true;
1168
+ }
1169
+ } else {
1170
+ event.state = 2;
1171
+ _this._eventMap[event.index1][event.index2] = undefined;
1172
+ currentEvents.deleteByIndex(i);
1173
+ _this._onTriggerExit(event.index1, event.index2);
1174
+ eventPool.push(event);
1175
+ }
1176
+ });
1177
+ };
1178
+ _proto._boxCollision = function _boxCollision(other) {
1179
+ if (_instanceof(other, LiteBoxColliderShape)) {
1180
+ var box = LitePhysicsScene._tempBox;
1181
+ LitePhysicsScene._updateWorldBox(other, box);
1182
+ return engine.CollisionUtil.intersectsBoxAndBox(box, this._box);
1183
+ } else if (_instanceof(other, LiteSphereColliderShape)) {
1184
+ var sphere = LitePhysicsScene._tempSphere;
1185
+ LitePhysicsScene._upWorldSphere(other, sphere);
1186
+ return engine.CollisionUtil.intersectsSphereAndBox(sphere, this._box);
1187
+ }
1188
+ return false;
1189
+ };
1190
+ _proto._sphereCollision = function _sphereCollision(other) {
1191
+ if (_instanceof(other, LiteBoxColliderShape)) {
1192
+ var box = LitePhysicsScene._tempBox;
1193
+ LitePhysicsScene._updateWorldBox(other, box);
1194
+ return engine.CollisionUtil.intersectsSphereAndBox(this._sphere, box);
1195
+ } else if (_instanceof(other, LiteSphereColliderShape)) {
1196
+ var sphere = LitePhysicsScene._tempSphere;
1197
+ LitePhysicsScene._upWorldSphere(other, sphere);
1198
+ return engine.CollisionUtil.intersectsSphereAndSphere(sphere, this._sphere);
1199
+ }
1200
+ return false;
1201
+ };
1202
+ _proto._raycast = function _raycast(ray, distance, onRaycast, colliders, hit) {
1203
+ var isHit = false;
1204
+ var curHit = LitePhysicsScene._currentHit;
1205
+ for(var i = 0, len = colliders.length; i < len; i++){
1206
+ if (colliders[i]._raycast(ray, onRaycast, curHit) && curHit.distance < distance) {
1207
+ if (hit) {
1208
+ isHit = true;
1209
+ var hitResult = LitePhysicsScene._hitResult;
1210
+ hitResult.normal.copyFrom(curHit.normal);
1211
+ hitResult.point.copyFrom(curHit.point);
1212
+ hitResult.distance = distance = curHit.distance;
1213
+ hitResult.shapeID = curHit.shapeID;
1214
+ } else {
1215
+ return true;
1216
+ }
1217
+ }
1218
+ }
1219
+ return isHit;
1220
+ };
1221
+ _proto._checkColliderCollide = function _checkColliderCollide(collider1, collider2) {
1222
+ var group1 = collider1._collisionLayer;
1223
+ var group2 = collider2._collisionLayer;
1224
+ if (group1 === group2) {
1225
+ return true;
1226
+ }
1227
+ return this._physics.getColliderLayerCollision(group1, group2);
1228
+ };
1229
+ /**
1230
+ * Calculate the bounding box in world space from boxCollider.
1231
+ * @param boxCollider - The boxCollider to calculate
1232
+ * @param out - The calculated boundingBox
1233
+ */ LitePhysicsScene._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1234
+ var mat = boxCollider._transform.worldMatrix;
1235
+ out.min.copyFrom(boxCollider._boxMin);
1236
+ out.max.copyFrom(boxCollider._boxMax);
1237
+ engine.BoundingBox.transform(out, mat, out);
1238
+ };
1239
+ /**
1240
+ * Get the sphere info of the given sphere collider in world space.
1241
+ * @param sphereCollider - The given sphere collider
1242
+ * @param out - The calculated boundingSphere
1243
+ */ LitePhysicsScene._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1244
+ engine.Vector3.transformCoordinate(sphereCollider._transform.position, sphereCollider._transform.worldMatrix, out.center);
1245
+ out.radius = sphereCollider.worldRadius;
1246
+ };
1247
+ return LitePhysicsScene;
1248
+ }();
1249
+ LitePhysicsScene._tempSphere = new engine.BoundingSphere();
1250
+ LitePhysicsScene._tempBox = new engine.BoundingBox();
1251
+ LitePhysicsScene._currentHit = new LiteHitResult();
1252
+ LitePhysicsScene._hitResult = new LiteHitResult();
1253
+ /**
1254
+ * Trigger event to store interactive object ids and state.
1255
+ */ var TriggerEvent = function TriggerEvent(index1, index2) {
1256
+ this.alreadyInvoked = false;
1257
+ this.index1 = index1;
1258
+ this.index2 = index2;
1259
+ };
1260
+
1261
+ /**
1262
+ * A static collider component that will not move.
1263
+ * @remarks Mostly used for object which always stays at the same place and never moves around.
1264
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1265
+ _inherits(LiteStaticCollider, LiteCollider);
1266
+ function LiteStaticCollider(litePhysics, position, rotation) {
1267
+ var _this;
1268
+ _this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = true;
1269
+ _this._transform.setPosition(position.x, position.y, position.z);
1270
+ _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1271
+ return _this;
1272
+ }
1273
+ return LiteStaticCollider;
1274
+ }(LiteCollider);
1275
+
1276
+ var LitePhysics = /*#__PURE__*/ function() {
1277
+ function LitePhysics() {
1278
+ this._layerCollisionMatrix = [];
1279
+ }
1280
+ var _proto = LitePhysics.prototype;
1281
+ /**
1282
+ * {@inheritDoc IPhysics.initialize }
1283
+ */ _proto.initialize = function initialize() {
1284
+ return Promise.resolve();
1285
+ };
1286
+ /**
1287
+ * {@inheritDoc IPhysics.createPhysicsManager }
1288
+ */ _proto.createPhysicsManager = function createPhysicsManager() {
1289
+ return null;
1290
+ };
1291
+ /**
1292
+ * {@inheritDoc IPhysics.createPhysicsScene }
1293
+ */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1294
+ return new LitePhysicsScene(this, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1295
+ };
1296
+ /**
1297
+ * {@inheritDoc IPhysics.createStaticCollider }
1298
+ */ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
1299
+ return new LiteStaticCollider(this, position, rotation);
1300
+ };
1301
+ /**
1302
+ * {@inheritDoc IPhysics.createDynamicCollider }
1303
+ */ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
1304
+ return new LiteDynamicCollider(this, position, rotation);
1305
+ };
1306
+ /**
1307
+ * {@inheritDoc IPhysics.createCharacterController }
1308
+ */ _proto.createCharacterController = function createCharacterController() {
1309
+ throw "Physics-lite don't support createCharacterController. Use Physics-PhysX instead!";
1310
+ };
1311
+ /**
1312
+ * {@inheritDoc IPhysics.createPhysicsMaterial }
1313
+ */ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1314
+ return new LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1315
+ };
1316
+ /**
1317
+ * {@inheritDoc IPhysics.createBoxColliderShape }
1318
+ */ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1319
+ return new LiteBoxColliderShape(uniqueID, size, material);
1320
+ };
1321
+ /**
1322
+ * {@inheritDoc IPhysics.createSphereColliderShape }
1323
+ */ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1324
+ return new LiteSphereColliderShape(uniqueID, radius, material);
1325
+ };
1326
+ /**
1327
+ * {@inheritDoc IPhysics.createPlaneColliderShape }
1328
+ */ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1329
+ throw new Error("Physics-lite doesn't support PlaneColliderShape. Use Physics-PhysX instead!");
1330
+ };
1331
+ /**
1332
+ * {@inheritDoc IPhysics.createCapsuleColliderShape }
1333
+ */ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1334
+ throw new Error("Physics-lite doesn't support CapsuleColliderShape. Use Physics-PhysX instead!");
1335
+ };
1336
+ /**
1337
+ * {@inheritDoc IPhysics.createFixedJoint }
1338
+ */ _proto.createFixedJoint = function createFixedJoint(collider) {
1339
+ throw new Error("Physics-lite doesn't support FixedJoint. Use Physics-PhysX instead!");
1340
+ };
1341
+ /**
1342
+ * {@inheritDoc IPhysics.createHingeJoint }
1343
+ */ _proto.createHingeJoint = function createHingeJoint(collider) {
1344
+ throw new Error("Physics-lite doesn't support HingeJoint. Use Physics-PhysX instead!");
1345
+ };
1346
+ /**
1347
+ * {@inheritDoc IPhysics.createSpringJoint }
1348
+ */ _proto.createSpringJoint = function createSpringJoint(collider) {
1349
+ throw new Error("Physics-lite doesn't support SpringJoint. Use Physics-PhysX instead!");
1350
+ };
1351
+ /**
1352
+ * {@inheritDoc IPhysics.setColliderLayer }
1353
+ */ _proto.setColliderLayer = function setColliderLayer(collider, layer) {
1354
+ collider._collisionLayer = layer;
1355
+ };
1356
+ /**
1357
+ * {@inheritDoc IPhysics.getColliderLayerCollision }
1358
+ */ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
1359
+ var index = this._getColliderLayerIndex(layer1, layer2);
1360
+ if (index > -1) {
1361
+ var _this__layerCollisionMatrix_index;
1362
+ return (_this__layerCollisionMatrix_index = this._layerCollisionMatrix[index]) != null ? _this__layerCollisionMatrix_index : true;
1363
+ }
1364
+ // If either layer is Layer.Nothing, they cant collide
1365
+ return false;
1366
+ };
1367
+ /**
1368
+ * {@inheritDoc IPhysics.setColliderLayerCollision }
1369
+ */ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, collide) {
1370
+ var index = this._getColliderLayerIndex(layer1, layer2);
1371
+ if (index > -1) {
1372
+ this._layerCollisionMatrix[index] = collide;
1373
+ }
1374
+ };
1375
+ /**
1376
+ * {@inheritDoc IPhysics.destroy }
1377
+ */ _proto.destroy = function destroy() {};
1378
+ _proto._getColliderLayerIndex = function _getColliderLayerIndex(layer1, layer2) {
1379
+ if (layer1 === 32 || layer2 === 32) {
1380
+ return -1;
1381
+ }
1382
+ var min = Math.min(layer1, layer2);
1383
+ var max = Math.max(layer1, layer2);
1384
+ // Calculate a unique index for the layer pair using the triangular number formula
1385
+ // This ensures that each layer combination maps to a unique index in the collision matrix
1386
+ return max * (max + 1) / 2 + min;
1387
+ };
1388
+ return LitePhysics;
1389
+ }();
1390
+
1391
+ //@ts-ignore
1392
+ var version = "1.6.9";
1393
+ console.log("Galacean Engine Physics Lite Version: " + version);
1394
+
1395
+ exports.LitePhysics = LitePhysics;
1396
+ exports.version = version;
1397
+
1398
+ Object.defineProperty(exports, '__esModule', { value: true });
1399
+
1400
+ }));
1401
+ //# sourceMappingURL=browser.js.map