@galacean/engine-physics-lite 0.0.0-experimental-1.3-xr.9 → 0.0.0-experimental-1.4-small-language.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -94,6 +94,7 @@ function _instanceof(left, right) {
94
94
  /** @internal */ this._worldScale = new engine.Vector3(1, 1, 1);
95
95
  /** @internal */ this._transform = new LiteTransform();
96
96
  /** @internal */ this._invModelMatrix = new engine.Matrix();
97
+ this._rotation = new engine.Vector3();
97
98
  this._transform.owner = this;
98
99
  this._inverseWorldMatFlag = this._transform.registerWorldChangeFlag();
99
100
  }
@@ -101,7 +102,8 @@ function _instanceof(left, right) {
101
102
  /**
102
103
  * {@inheritDoc IColliderShape.setRotation }
103
104
  */ _proto.setRotation = function setRotation(rotation) {
104
- console.log("Physics-lite don't support setRotation. Use Physics-PhysX instead!");
105
+ var rotationInRadians = this._rotation.set(engine.MathUtil.degreeToRadian(rotation.x), engine.MathUtil.degreeToRadian(rotation.y), engine.MathUtil.degreeToRadian(rotation.z));
106
+ engine.Quaternion.rotationEuler(rotationInRadians.x, rotationInRadians.y, rotationInRadians.z, this._transform.rotationQuaternion);
105
107
  };
106
108
  /**
107
109
  * {@inheritDoc IColliderShape.setPosition }
@@ -176,12 +178,12 @@ function _instanceof(left, right) {
176
178
  };
177
179
  return LiteColliderShape;
178
180
  }();
179
- (function() {
180
- LiteColliderShape._ray = new engine.Ray();
181
- })();
182
- (function() {
183
- LiteColliderShape._tempPoint = new engine.Vector3();
184
- })();
181
+ LiteColliderShape._tempPos = new engine.Vector3();
182
+ LiteColliderShape._tempRot = new engine.Quaternion();
183
+ LiteColliderShape._tempScale = new engine.Vector3();
184
+ LiteColliderShape._tempPoint = new engine.Vector3();
185
+ LiteColliderShape._tempVector4 = new engine.Vector4();
186
+ LiteColliderShape._ray = new engine.Ray();
185
187
 
186
188
  /**
187
189
  * Used to implement transformation related functions.
@@ -197,7 +199,7 @@ function _instanceof(left, right) {
197
199
  this._updateFlagManager = new LiteUpdateFlagManager();
198
200
  this._isParentDirty = true;
199
201
  this._parentTransformCache = null;
200
- this._dirtyFlag = 0xbc;
202
+ this._dirtyFlag = 188;
201
203
  }
202
204
  var _proto = LiteTransform.prototype;
203
205
  /**
@@ -239,8 +241,8 @@ function _instanceof(left, right) {
239
241
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
240
242
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
241
243
  */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
242
- if (!this._isContainDirtyFlags(0x84)) {
243
- this._worldAssociatedChange(0x84);
244
+ if (!this._isContainDirtyFlags(132)) {
245
+ this._worldAssociatedChange(132);
244
246
  if (_instanceof(this._owner, LiteCollider)) {
245
247
  var shapes = this._owner._shapes;
246
248
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -256,8 +258,8 @@ function _instanceof(left, right) {
256
258
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
257
259
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
258
260
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
259
- if (!this._isContainDirtyFlags(0x98)) {
260
- this._worldAssociatedChange(0x98);
261
+ if (!this._isContainDirtyFlags(152)) {
262
+ this._worldAssociatedChange(152);
261
263
  if (_instanceof(this._owner, LiteCollider)) {
262
264
  var shapes = this._owner._shapes;
263
265
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -272,8 +274,8 @@ function _instanceof(left, right) {
272
274
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
273
275
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
274
276
  */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
275
- if (!this._isContainDirtyFlags(0xa0)) {
276
- this._worldAssociatedChange(0xa0);
277
+ if (!this._isContainDirtyFlags(160)) {
278
+ this._worldAssociatedChange(160);
277
279
  if (_instanceof(this._owner, LiteCollider)) {
278
280
  var shapes = this._owner._shapes;
279
281
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -285,8 +287,8 @@ function _instanceof(left, right) {
285
287
  /**
286
288
  * Update all world transform property dirty flag, the principle is the same as above.
287
289
  */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
288
- if (!this._isContainDirtyFlags(0xbc)) {
289
- this._worldAssociatedChange(0xbc);
290
+ if (!this._isContainDirtyFlags(188)) {
291
+ this._worldAssociatedChange(188);
290
292
  if (_instanceof(this._owner, LiteCollider)) {
291
293
  var shapes = this._owner._shapes;
292
294
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -343,7 +345,7 @@ function _instanceof(left, right) {
343
345
  if (this._position !== value) {
344
346
  this._position.copyFrom(value);
345
347
  }
346
- this._setDirtyFlagTrue(0x40);
348
+ this._setDirtyFlagTrue(64);
347
349
  this._updateWorldPositionFlag();
348
350
  }
349
351
  },
@@ -353,9 +355,9 @@ function _instanceof(left, right) {
353
355
  * Local rotation, defining the rotation by using a unit quaternion.
354
356
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
355
357
  */ function get() {
356
- if (this._isContainDirtyFlag(0x2)) {
358
+ if (this._isContainDirtyFlag(2)) {
357
359
  engine.Quaternion.rotationEuler(engine.MathUtil.degreeToRadian(this._rotation.x), engine.MathUtil.degreeToRadian(this._rotation.y), engine.MathUtil.degreeToRadian(this._rotation.z), this._rotationQuaternion);
358
- this._setDirtyFlagFalse(0x2);
360
+ this._setDirtyFlagFalse(2);
359
361
  }
360
362
  return this._rotationQuaternion;
361
363
  },
@@ -363,8 +365,8 @@ function _instanceof(left, right) {
363
365
  if (this._rotationQuaternion !== value) {
364
366
  this._rotationQuaternion.copyFrom(value);
365
367
  }
366
- this._setDirtyFlagTrue(0x40 | 0x1);
367
- this._setDirtyFlagFalse(0x2);
368
+ this._setDirtyFlagTrue(64 | 1);
369
+ this._setDirtyFlagFalse(2);
368
370
  this._updateWorldRotationFlag();
369
371
  }
370
372
  },
@@ -374,14 +376,14 @@ function _instanceof(left, right) {
374
376
  * World rotation, defining the rotation by using a unit quaternion.
375
377
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
376
378
  */ function get() {
377
- if (this._isContainDirtyFlag(0x10)) {
379
+ if (this._isContainDirtyFlag(16)) {
378
380
  var parent = this._getParentTransform();
379
381
  if (parent != null) {
380
382
  engine.Quaternion.multiply(parent.worldRotationQuaternion, this.rotationQuaternion, this._worldRotationQuaternion);
381
383
  } else {
382
384
  this._worldRotationQuaternion.copyFrom(this.rotationQuaternion);
383
385
  }
384
- this._setDirtyFlagFalse(0x10);
386
+ this._setDirtyFlagFalse(16);
385
387
  }
386
388
  return this._worldRotationQuaternion;
387
389
  },
@@ -397,7 +399,7 @@ function _instanceof(left, right) {
397
399
  this._rotationQuaternion.copyFrom(value);
398
400
  }
399
401
  this.rotationQuaternion = this._rotationQuaternion;
400
- this._setDirtyFlagFalse(0x10);
402
+ this._setDirtyFlagFalse(16);
401
403
  }
402
404
  },
403
405
  {
@@ -412,7 +414,7 @@ function _instanceof(left, right) {
412
414
  if (this._scale !== value) {
413
415
  this._scale.copyFrom(value);
414
416
  }
415
- this._setDirtyFlagTrue(0x40);
417
+ this._setDirtyFlagTrue(64);
416
418
  this._updateWorldScaleFlag();
417
419
  }
418
420
  },
@@ -422,9 +424,9 @@ function _instanceof(left, right) {
422
424
  * Local matrix.
423
425
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
424
426
  */ function get() {
425
- if (this._isContainDirtyFlag(0x40)) {
427
+ if (this._isContainDirtyFlag(64)) {
426
428
  engine.Matrix.affineTransformation(this._scale, this.rotationQuaternion, this._position, this._localMatrix);
427
- this._setDirtyFlagFalse(0x40);
429
+ this._setDirtyFlagFalse(64);
428
430
  }
429
431
  return this._localMatrix;
430
432
  },
@@ -433,8 +435,8 @@ function _instanceof(left, right) {
433
435
  this._localMatrix.copyFrom(value);
434
436
  }
435
437
  this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
436
- this._setDirtyFlagTrue(0x1);
437
- this._setDirtyFlagFalse(0x40);
438
+ this._setDirtyFlagTrue(1);
439
+ this._setDirtyFlagFalse(64);
438
440
  this._updateAllWorldFlag();
439
441
  }
440
442
  },
@@ -444,14 +446,14 @@ function _instanceof(left, right) {
444
446
  * World matrix.
445
447
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
446
448
  */ function get() {
447
- if (this._isContainDirtyFlag(0x80)) {
449
+ if (this._isContainDirtyFlag(128)) {
448
450
  var parent = this._getParentTransform();
449
451
  if (parent) {
450
452
  engine.Matrix.multiply(parent.worldMatrix, this.localMatrix, this._worldMatrix);
451
453
  } else {
452
454
  this._worldMatrix.copyFrom(this.localMatrix);
453
455
  }
454
- this._setDirtyFlagFalse(0x80);
456
+ this._setDirtyFlagFalse(128);
455
457
  }
456
458
  return this._worldMatrix;
457
459
  },
@@ -467,37 +469,14 @@ function _instanceof(left, right) {
467
469
  this._localMatrix.copyFrom(value);
468
470
  }
469
471
  this.localMatrix = this._localMatrix;
470
- this._setDirtyFlagFalse(0x80);
472
+ this._setDirtyFlagFalse(128);
471
473
  }
472
474
  }
473
475
  ]);
474
476
  return LiteTransform;
475
477
  }();
476
- (function() {
477
- LiteTransform._tempQuat0 = new engine.Quaternion();
478
- })();
479
- (function() {
480
- LiteTransform._tempMat42 = new engine.Matrix();
481
- })();
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 = {}));
478
+ LiteTransform._tempQuat0 = new engine.Quaternion();
479
+ LiteTransform._tempMat42 = new engine.Matrix();
501
480
 
502
481
  /**
503
482
  * Abstract class of physical collider.
@@ -513,11 +492,13 @@ var /**
513
492
  */ _proto.addShape = function addShape(shape) {
514
493
  var oldCollider = shape._collider;
515
494
  if (oldCollider !== this) {
495
+ var _this__scene;
516
496
  if (oldCollider) {
517
497
  oldCollider.removeShape(shape);
518
498
  }
519
499
  this._shapes.push(shape);
520
500
  shape._collider = this;
501
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape);
521
502
  }
522
503
  };
523
504
  /**
@@ -525,8 +506,10 @@ var /**
525
506
  */ _proto.removeShape = function removeShape(shape) {
526
507
  var index = this._shapes.indexOf(shape);
527
508
  if (index !== -1) {
509
+ var _this__scene;
528
510
  this._shapes.splice(index, 1);
529
511
  shape._collider = null;
512
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape);
530
513
  }
531
514
  };
532
515
  /**
@@ -561,18 +544,34 @@ var /**
561
544
 
562
545
  /**
563
546
  * A dynamic collider can act with self-defined movement or physical force
564
- */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider1) {
565
- _inherits(LiteDynamicCollider, LiteCollider1);
547
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
548
+ _inherits(LiteDynamicCollider, LiteCollider);
566
549
  function LiteDynamicCollider(position, rotation) {
567
550
  var _this;
568
- _this = LiteCollider1.call(this) || this;
569
- /** @internal */ _this._isStaticCollider = false;
551
+ _this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = false;
570
552
  _this._transform.setPosition(position.x, position.y, position.z);
571
553
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
572
554
  return _this;
573
555
  }
574
556
  var _proto = LiteDynamicCollider.prototype;
575
557
  /**
558
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
559
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
560
+ engine.Logger.error("Physics-lite don't support getInertiaTensor. Use Physics-PhysX instead!");
561
+ return out;
562
+ };
563
+ /**
564
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
565
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
566
+ engine.Logger.error("Physics-lite don't support getCenterOfMass. Use Physics-PhysX instead!");
567
+ return out;
568
+ };
569
+ /**
570
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
571
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
572
+ engine.Logger.error("Physics-lite don't support setMassAndUpdateInertia. Use Physics-PhysX instead!");
573
+ };
574
+ /**
576
575
  * {@inheritDoc IDynamicCollider.addForce }
577
576
  */ _proto.addForce = function addForce(force) {
578
577
  throw "Physics-lite don't support addForce. Use Physics-PhysX instead!";
@@ -593,74 +592,96 @@ var /**
593
592
  throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!";
594
593
  };
595
594
  /**
595
+ * {@inheritDoc IDynamicCollider.isSleeping }
596
+ */ _proto.isSleeping = function isSleeping() {
597
+ throw "Physics-lite don't support isSleeping. Use Physics-PhysX instead!";
598
+ };
599
+ /**
596
600
  * {@inheritDoc IDynamicCollider.setAngularDamping }
597
601
  */ _proto.setAngularDamping = function setAngularDamping(value) {
598
- throw "Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!";
602
+ engine.Logger.error("Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!");
603
+ };
604
+ /**
605
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
606
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
607
+ engine.Logger.error("Physics-lite don't support getAngularVelocity. Use Physics-PhysX instead!");
608
+ return out;
599
609
  };
600
610
  /**
601
611
  * {@inheritDoc IDynamicCollider.setAngularVelocity }
602
612
  */ _proto.setAngularVelocity = function setAngularVelocity(value) {
603
- throw "Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!";
613
+ engine.Logger.error("Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!");
604
614
  };
605
615
  /**
606
616
  * {@inheritDoc IDynamicCollider.setCenterOfMass }
607
617
  */ _proto.setCenterOfMass = function setCenterOfMass(value) {
608
- throw "Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!";
618
+ engine.Logger.error("Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!");
609
619
  };
610
620
  /**
611
621
  * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
612
622
  */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
613
- throw "Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!";
623
+ engine.Logger.error("Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!");
614
624
  };
615
625
  /**
616
626
  * {@inheritDoc IDynamicCollider.setConstraints }
617
627
  */ _proto.setConstraints = function setConstraints(flags) {
618
- throw "Physics-lite don't support setConstraints. Use Physics-PhysX instead!";
628
+ engine.Logger.error("Physics-lite don't support setConstraints. Use Physics-PhysX instead!");
619
629
  };
620
630
  /**
621
631
  * {@inheritDoc IDynamicCollider.setInertiaTensor }
622
632
  */ _proto.setInertiaTensor = function setInertiaTensor(value) {
623
- throw "Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!";
633
+ engine.Logger.error("Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!");
634
+ };
635
+ /**
636
+ * {@inheritDoc IDynamicCollider.setUseGravity }
637
+ */ _proto.setUseGravity = function setUseGravity(value) {
638
+ engine.Logger.error("Physics-lite don't support setUseGravity. Use Physics-PhysX instead!");
624
639
  };
625
640
  /**
626
641
  * {@inheritDoc IDynamicCollider.setIsKinematic }
627
642
  */ _proto.setIsKinematic = function setIsKinematic(value) {
628
- throw "Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!";
643
+ engine.Logger.error("Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!");
629
644
  };
630
645
  /**
631
646
  * {@inheritDoc IDynamicCollider.setLinearDamping }
632
647
  */ _proto.setLinearDamping = function setLinearDamping(value) {
633
- throw "Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!";
648
+ engine.Logger.error("Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!");
649
+ };
650
+ /**
651
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
652
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
653
+ engine.Logger.error("Physics-lite don't support getLinearVelocity. Use Physics-PhysX instead!");
654
+ return out;
634
655
  };
635
656
  /**
636
657
  * {@inheritDoc IDynamicCollider.setLinearVelocity }
637
658
  */ _proto.setLinearVelocity = function setLinearVelocity(value) {
638
- throw "Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!";
659
+ engine.Logger.error("Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!");
639
660
  };
640
661
  /**
641
662
  * {@inheritDoc IDynamicCollider.setMass }
642
663
  */ _proto.setMass = function setMass(value) {
643
- throw "Physics-lite don't support setMass. Use Physics-PhysX instead!";
664
+ engine.Logger.error("Physics-lite don't support setMass. Use Physics-PhysX instead!");
644
665
  };
645
666
  /**
646
667
  * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
647
668
  */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
648
- throw "Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!";
669
+ engine.Logger.error("Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!");
649
670
  };
650
671
  /**
651
672
  * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
652
673
  */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
653
- throw "Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!";
674
+ engine.Logger.error("Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!");
654
675
  };
655
676
  /**
656
677
  * {@inheritDoc IDynamicCollider.setSleepThreshold }
657
678
  */ _proto.setSleepThreshold = function setSleepThreshold(value) {
658
- throw "Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!";
679
+ engine.Logger.error("Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!");
659
680
  };
660
681
  /**
661
682
  * {@inheritDoc IDynamicCollider.setSolverIterations }
662
683
  */ _proto.setSolverIterations = function setSolverIterations(value) {
663
- throw "Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!";
684
+ engine.Logger.error("Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!");
664
685
  };
665
686
  /**
666
687
  * {@inheritDoc IDynamicCollider.wakeUp }
@@ -706,52 +727,6 @@ var /**
706
727
  return LitePhysicsMaterial;
707
728
  }();
708
729
 
709
- /**
710
- * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
711
- */ var DisorderedArray = /*#__PURE__*/ function() {
712
- function DisorderedArray(count) {
713
- if (count === void 0) count = 0;
714
- this.length = 0;
715
- this._elements = new Array(count);
716
- }
717
- var _proto = DisorderedArray.prototype;
718
- _proto.add = function add(element) {
719
- if (this.length === this._elements.length) this._elements.push(element);
720
- else this._elements[this.length] = element;
721
- this.length++;
722
- };
723
- _proto.delete = function _delete(element) {
724
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
725
- var index = this._elements.indexOf(element);
726
- this.deleteByIndex(index);
727
- };
728
- _proto.get = function get(index) {
729
- if (index >= this.length) {
730
- throw "Index is out of range.";
731
- }
732
- return this._elements[index];
733
- };
734
- /**
735
- *
736
- * @param index
737
- * @returns The replaced item is used to reset its index.
738
- */ _proto.deleteByIndex = function deleteByIndex(index) {
739
- var elements = this._elements;
740
- var end = null;
741
- var lastIndex = this.length - 1;
742
- if (index !== lastIndex) {
743
- end = elements[lastIndex];
744
- elements[index] = end;
745
- }
746
- this.length--;
747
- return end;
748
- };
749
- _proto.garbageCollection = function garbageCollection() {
750
- this._elements.length = this.length;
751
- };
752
- return DisorderedArray;
753
- }();
754
-
755
730
  /**
756
731
  * Structure used to get information back from a raycast or a sweep.
757
732
  * @internal
@@ -768,11 +743,7 @@ var /**
768
743
  _inherits(LiteBoxColliderShape, LiteColliderShape1);
769
744
  function LiteBoxColliderShape(uniqueID, size, material) {
770
745
  var _this;
771
- _this = LiteColliderShape1.call(this) || this;
772
- _this._halfSize = new engine.Vector3();
773
- _this._sizeScale = new engine.Vector3(1, 1, 1);
774
- /** @internal */ _this._boxMin = new engine.Vector3(-0.5, -0.5, -0.5);
775
- /** @internal */ _this._boxMax = new engine.Vector3(0.5, 0.5, 0.5);
746
+ _this = LiteColliderShape1.call(this) || this, _this._halfSize = new engine.Vector3(), _this._sizeScale = new engine.Vector3(1, 1, 1), /** @internal */ _this._boxMin = new engine.Vector3(-0.5, -0.5, -0.5), /** @internal */ _this._boxMax = new engine.Vector3(0.5, 0.5, 0.5);
776
747
  _this._id = uniqueID;
777
748
  _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
778
749
  _this._setBondingBox();
@@ -799,6 +770,44 @@ var /**
799
770
  this._setBondingBox();
800
771
  };
801
772
  /**
773
+ * {@inheritDoc IColliderShape.pointDistance }
774
+ */ _proto.pointDistance = function pointDistance(point) {
775
+ var position = LiteColliderShape._tempPos;
776
+ var rotation = LiteColliderShape._tempRot;
777
+ this._transform.worldMatrix.decompose(position, rotation, LiteColliderShape._tempScale);
778
+ var _this__transform = this._transform, shapePosition = _this__transform.position;
779
+ var m = LiteBoxColliderShape._tempMatrix;
780
+ var invM = LiteBoxColliderShape._tempInvMatrix;
781
+ var p = LiteColliderShape._tempPoint;
782
+ var scale = this._sizeScale;
783
+ var boundingBox = LiteBoxColliderShape._tempBox;
784
+ var _this = this, _boxMin = _this._boxMin, _boxMax = _this._boxMax;
785
+ p.copyFrom(_boxMin);
786
+ p.subtract(shapePosition);
787
+ p.divide(scale);
788
+ boundingBox.min.copyFrom(p);
789
+ p.copyFrom(_boxMax);
790
+ p.subtract(shapePosition);
791
+ p.divide(scale);
792
+ boundingBox.max.copyFrom(p);
793
+ engine.Matrix.affineTransformation(scale, rotation, position, m);
794
+ engine.Matrix.invert(m, invM);
795
+ engine.Vector3.transformCoordinate(point, invM, p);
796
+ var min = boundingBox.min;
797
+ var max = boundingBox.max;
798
+ p.x = Math.max(min.x, Math.min(p.x, max.x));
799
+ p.y = Math.max(min.y, Math.min(p.y, max.y));
800
+ p.z = Math.max(min.z, Math.min(p.z, max.z));
801
+ engine.Vector3.transformCoordinate(p, m, p);
802
+ var res = LiteColliderShape._tempVector4;
803
+ if (engine.Vector3.equals(p, point)) {
804
+ res.set(point.x, point.y, point.z, 0);
805
+ } else {
806
+ res.set(p.x, p.y, p.z, engine.Vector3.distanceSquared(p, point));
807
+ }
808
+ return res;
809
+ };
810
+ /**
802
811
  * @internal
803
812
  */ _proto._raycast = function _raycast(ray, hit) {
804
813
  var localRay = this._getLocalRay(ray);
@@ -824,9 +833,9 @@ var /**
824
833
  };
825
834
  return LiteBoxColliderShape;
826
835
  }(LiteColliderShape);
827
- (function() {
828
- LiteBoxColliderShape._tempBox = new engine.BoundingBox();
829
- })();
836
+ LiteBoxColliderShape._tempBox = new engine.BoundingBox();
837
+ LiteBoxColliderShape._tempMatrix = new engine.Matrix();
838
+ LiteBoxColliderShape._tempInvMatrix = new engine.Matrix();
830
839
 
831
840
  /**
832
841
  * Sphere collider shape in Lite.
@@ -834,9 +843,7 @@ var /**
834
843
  _inherits(LiteSphereColliderShape, LiteColliderShape1);
835
844
  function LiteSphereColliderShape(uniqueID, radius, material) {
836
845
  var _this;
837
- _this = LiteColliderShape1.call(this) || this;
838
- _this._radius = 1;
839
- _this._maxScale = 1;
846
+ _this = LiteColliderShape1.call(this) || this, _this._radius = 1, _this._maxScale = 1;
840
847
  _this._radius = radius;
841
848
  _this._id = uniqueID;
842
849
  return _this;
@@ -854,6 +861,27 @@ var /**
854
861
  this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
855
862
  };
856
863
  /**
864
+ * {@inheritDoc IColliderShape.pointDistance }
865
+ */ _proto.pointDistance = function pointDistance(point) {
866
+ var position = LiteColliderShape._tempPos;
867
+ var worldRadius = this.worldRadius;
868
+ this._transform.worldMatrix.decompose(position, LiteColliderShape._tempRot, LiteColliderShape._tempScale);
869
+ var p = LiteColliderShape._tempPoint;
870
+ engine.Vector3.subtract(point, position, p);
871
+ var distanceFromCenter = p.lengthSquared();
872
+ var direction = p.normalize();
873
+ engine.Vector3.scale(direction, worldRadius, p);
874
+ p.add(position);
875
+ var res = LiteColliderShape._tempVector4;
876
+ var distanceSquared = engine.Vector3.distanceSquared(p, point);
877
+ if (distanceFromCenter <= worldRadius * worldRadius) {
878
+ res.set(point.x, point.y, point.z, 0);
879
+ } else {
880
+ res.set(p.x, p.y, p.z, distanceSquared);
881
+ }
882
+ return res;
883
+ };
884
+ /**
857
885
  * @internal
858
886
  */ _proto._raycast = function _raycast(ray, hit) {
859
887
  var boundingSphere = LiteSphereColliderShape._tempSphere;
@@ -877,9 +905,7 @@ var /**
877
905
  ]);
878
906
  return LiteSphereColliderShape;
879
907
  }(LiteColliderShape);
880
- (function() {
881
- LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
882
- })();
908
+ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
883
909
 
884
910
  /**
885
911
  * A manager is a collection of colliders and constraints which can interact.
@@ -889,7 +915,7 @@ var /**
889
915
  this._dynamicColliders = [];
890
916
  this._sphere = new engine.BoundingSphere();
891
917
  this._box = new engine.BoundingBox();
892
- this._currentEvents = new DisorderedArray();
918
+ this._currentEvents = new engine.DisorderedArray();
893
919
  this._eventMap = {};
894
920
  this._eventPool = [];
895
921
  this._onContactEnter = onContactEnter;
@@ -901,51 +927,35 @@ var /**
901
927
  }
902
928
  var _proto = LitePhysicsScene.prototype;
903
929
  /**
904
- * {@inheritDoc IPhysicsManager.setGravity }
930
+ * {@inheritDoc IPhysicsScene.setGravity }
905
931
  */ _proto.setGravity = function setGravity(value) {
906
932
  console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
907
933
  };
908
934
  /**
909
- * {@inheritDoc IPhysicsManager.addColliderShape }
910
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
911
- this._eventMap[colliderShape._id] = {};
912
- };
913
- /**
914
- * {@inheritDoc IPhysicsManager.removeColliderShape }
915
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
916
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
917
- var id = colliderShape._id;
918
- for(var i = currentEvents.length - 1; i >= 0; i--){
919
- var event = currentEvents.get(i);
920
- if (event.index1 == id) {
921
- currentEvents.deleteByIndex(i);
922
- eventPool.push(event);
923
- } else if (event.index2 == id) {
924
- currentEvents.deleteByIndex(i);
925
- eventPool.push(event);
926
- // If the shape is big index, should clear from the small index shape subMap
927
- eventMap[event.index1][id] = undefined;
928
- }
929
- }
930
- delete eventMap[id];
931
- };
932
- /**
933
- * {@inheritDoc IPhysicsManager.addCollider }
935
+ * {@inheritDoc IPhysicsScene.addCollider }
934
936
  */ _proto.addCollider = function addCollider(actor) {
937
+ actor._scene = this;
935
938
  var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
936
939
  colliders.push(actor);
940
+ var shapes = actor._shapes;
941
+ for(var i = 0, n = shapes.length; i < n; i++){
942
+ this._addColliderShape(shapes[i]);
943
+ }
937
944
  };
938
945
  /**
939
- * {@inheritDoc IPhysicsManager.removeCollider }
946
+ * {@inheritDoc IPhysicsScene.removeCollider }
940
947
  */ _proto.removeCollider = function removeCollider(collider) {
948
+ collider._scene = null;
941
949
  var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
942
950
  var index = colliders.indexOf(collider);
943
- if (index !== -1) {
944
- colliders.splice(index, 1);
951
+ index > -1 && colliders.splice(index, 1);
952
+ var shapes = collider._shapes;
953
+ for(var i = 0, n = shapes.length; i < n; i++){
954
+ this._removeColliderShape(shapes[i]);
945
955
  }
946
956
  };
947
957
  /**
948
- * {@inheritDoc IPhysicsManager.update }
958
+ * {@inheritDoc IPhysicsScene.update }
949
959
  */ _proto.update = function update(deltaTime) {
950
960
  var dynamicColliders = this._dynamicColliders;
951
961
  for(var i = 0, len = dynamicColliders.length; i < len; i++){
@@ -956,13 +966,16 @@ var /**
956
966
  this._fireEvent();
957
967
  };
958
968
  /**
959
- * {@inheritDoc IPhysicsManager.raycast }
969
+ * {@inheritDoc IPhysicsScene.raycast }
960
970
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
961
971
  if (!hit) {
962
972
  return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
963
973
  } else {
964
974
  var raycastStaticRes = this._raycast(ray, distance, onRaycast, this._staticColliders, hit);
965
- var raycastDynamicRes = this._raycast(ray, LitePhysicsScene._currentHit.distance, onRaycast, this._dynamicColliders, hit);
975
+ if (raycastStaticRes) {
976
+ distance = LitePhysicsScene._currentHit.distance;
977
+ }
978
+ var raycastDynamicRes = this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
966
979
  var isHit = raycastStaticRes || raycastDynamicRes;
967
980
  var hitResult = LitePhysicsScene._hitResult;
968
981
  if (!isHit) {
@@ -977,15 +990,41 @@ var /**
977
990
  }
978
991
  };
979
992
  /**
980
- * {@inheritDoc IPhysicsManager.addCharacterController }
993
+ * {@inheritDoc IPhysicsScene.addCharacterController }
981
994
  */ _proto.addCharacterController = function addCharacterController(characterController) {
982
995
  throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
983
996
  };
984
997
  /**
985
- * {@inheritDoc IPhysicsManager.removeCharacterController }
998
+ * {@inheritDoc IPhysicsScene.removeCharacterController }
986
999
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
987
1000
  throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
988
1001
  };
1002
+ /**
1003
+ * {@inheritDoc IPhysicsScene.destroy }
1004
+ */ _proto.destroy = function destroy() {};
1005
+ /**
1006
+ * @internal
1007
+ */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
1008
+ this._eventMap[colliderShape._id] = {};
1009
+ };
1010
+ /**
1011
+ * @internal
1012
+ */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
1013
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
1014
+ var id = colliderShape._id;
1015
+ currentEvents.forEach(function(event, i) {
1016
+ if (event.index1 == id) {
1017
+ currentEvents.deleteByIndex(i);
1018
+ eventPool.push(event);
1019
+ } else if (event.index2 == id) {
1020
+ currentEvents.deleteByIndex(i);
1021
+ eventPool.push(event);
1022
+ // If the shape is big index, should clear from the small index shape subMap
1023
+ eventMap[event.index1][id] = undefined;
1024
+ }
1025
+ });
1026
+ delete eventMap[id];
1027
+ };
989
1028
  _proto._getTrigger = function _getTrigger(index1, index2) {
990
1029
  var event;
991
1030
  if (this._eventPool.length) {
@@ -1060,25 +1099,25 @@ var /**
1060
1099
  }
1061
1100
  };
1062
1101
  _proto._fireEvent = function _fireEvent() {
1063
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
1064
- for(var i = currentEvents.length - 1; i >= 0; i--){
1065
- var event = currentEvents.get(i);
1102
+ var _this = this;
1103
+ var _this1 = this, eventPool = _this1._eventPool, currentEvents = _this1._currentEvents;
1104
+ currentEvents.forEach(function(event, i) {
1066
1105
  if (!event.alreadyInvoked) {
1067
1106
  if (event.state == 0) {
1068
- this._onTriggerEnter(event.index1, event.index2);
1107
+ _this._onTriggerEnter(event.index1, event.index2);
1069
1108
  event.alreadyInvoked = true;
1070
1109
  } else if (event.state == 1) {
1071
- this._onTriggerStay(event.index1, event.index2);
1110
+ _this._onTriggerStay(event.index1, event.index2);
1072
1111
  event.alreadyInvoked = true;
1073
1112
  }
1074
1113
  } else {
1075
1114
  event.state = 2;
1076
- this._eventMap[event.index1][event.index2] = undefined;
1077
- this._onTriggerExit(event.index1, event.index2);
1115
+ _this._eventMap[event.index1][event.index2] = undefined;
1078
1116
  currentEvents.deleteByIndex(i);
1117
+ _this._onTriggerExit(event.index1, event.index2);
1079
1118
  eventPool.push(event);
1080
1119
  }
1081
- }
1120
+ });
1082
1121
  };
1083
1122
  _proto._boxCollision = function _boxCollision(other) {
1084
1123
  if (_instanceof(other, LiteBoxColliderShape)) {
@@ -1105,26 +1144,19 @@ var /**
1105
1144
  return false;
1106
1145
  };
1107
1146
  _proto._raycast = function _raycast(ray, distance, onRaycast, colliders, hit) {
1108
- var hitResult;
1109
- if (hit) {
1110
- hitResult = LitePhysicsScene._hitResult;
1111
- }
1112
1147
  var isHit = false;
1113
1148
  var curHit = LitePhysicsScene._currentHit;
1114
1149
  for(var i = 0, len = colliders.length; i < len; i++){
1115
- var collider = colliders[i];
1116
- if (collider._raycast(ray, onRaycast, curHit)) {
1117
- isHit = true;
1118
- if (curHit.distance < distance) {
1119
- if (hitResult) {
1120
- hitResult.normal.copyFrom(curHit.normal);
1121
- hitResult.point.copyFrom(curHit.point);
1122
- hitResult.distance = curHit.distance;
1123
- hitResult.shapeID = curHit.shapeID;
1124
- } else {
1125
- return true;
1126
- }
1127
- distance = curHit.distance;
1150
+ if (colliders[i]._raycast(ray, onRaycast, curHit) && curHit.distance < distance) {
1151
+ if (hit) {
1152
+ isHit = true;
1153
+ var hitResult = LitePhysicsScene._hitResult;
1154
+ hitResult.normal.copyFrom(curHit.normal);
1155
+ hitResult.point.copyFrom(curHit.point);
1156
+ hitResult.distance = distance = curHit.distance;
1157
+ hitResult.shapeID = curHit.shapeID;
1158
+ } else {
1159
+ return true;
1128
1160
  }
1129
1161
  }
1130
1162
  }
@@ -1150,26 +1182,10 @@ var /**
1150
1182
  };
1151
1183
  return LitePhysicsScene;
1152
1184
  }();
1153
- (function() {
1154
- LitePhysicsScene._tempSphere = new engine.BoundingSphere();
1155
- })();
1156
- (function() {
1157
- LitePhysicsScene._tempBox = new engine.BoundingBox();
1158
- })();
1159
- (function() {
1160
- LitePhysicsScene._currentHit = new LiteHitResult();
1161
- })();
1162
- (function() {
1163
- LitePhysicsScene._hitResult = new LiteHitResult();
1164
- })();
1165
- var /**
1166
- * Physics state
1167
- */ TriggerEventState;
1168
- (function(TriggerEventState) {
1169
- TriggerEventState[TriggerEventState["Enter"] = 0] = "Enter";
1170
- TriggerEventState[TriggerEventState["Stay"] = 1] = "Stay";
1171
- TriggerEventState[TriggerEventState["Exit"] = 2] = "Exit";
1172
- })(TriggerEventState || (TriggerEventState = {}));
1185
+ LitePhysicsScene._tempSphere = new engine.BoundingSphere();
1186
+ LitePhysicsScene._tempBox = new engine.BoundingBox();
1187
+ LitePhysicsScene._currentHit = new LiteHitResult();
1188
+ LitePhysicsScene._hitResult = new LiteHitResult();
1173
1189
  /**
1174
1190
  * Trigger event to store interactive object ids and state.
1175
1191
  */ var TriggerEvent = function TriggerEvent(index1, index2) {
@@ -1181,12 +1197,11 @@ var /**
1181
1197
  /**
1182
1198
  * A static collider component that will not move.
1183
1199
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1184
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1185
- _inherits(LiteStaticCollider, LiteCollider1);
1200
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1201
+ _inherits(LiteStaticCollider, LiteCollider);
1186
1202
  function LiteStaticCollider(position, rotation) {
1187
1203
  var _this;
1188
- _this = LiteCollider1.call(this) || this;
1189
- /** @internal */ _this._isStaticCollider = true;
1204
+ _this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = true;
1190
1205
  _this._transform.setPosition(position.x, position.y, position.z);
1191
1206
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1192
1207
  return _this;
@@ -1267,12 +1282,15 @@ var LitePhysics = /*#__PURE__*/ function() {
1267
1282
  */ _proto.createSpringJoint = function createSpringJoint(collider) {
1268
1283
  throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1269
1284
  };
1285
+ /**
1286
+ * {@inheritDoc IPhysics.destroy }
1287
+ */ _proto.destroy = function destroy() {};
1270
1288
  return LitePhysics;
1271
1289
  }();
1272
1290
 
1273
1291
  //@ts-ignore
1274
- var version = "0.0.0-experimental-1.3-xr.9";
1275
- console.log("Galacean PhysicsLite version: " + version);
1292
+ var version = "0.0.0-experimental-1.4-small-language.0";
1293
+ console.log("Galacean Engine Physics Lite Version: " + version);
1276
1294
 
1277
1295
  exports.LitePhysics = LitePhysics;
1278
1296
  exports.version = version;