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

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