@galacean/engine-physics-lite 1.0.0-alpha.6 → 1.0.0-beta.0

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