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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Utils, Ray, Vector3, Matrix, Quaternion, MathUtil, BoundingBox, BoundingSphere, DisorderedArray, CollisionUtil } from '@galacean/engine';
1
+ import { Utils, Vector3, Quaternion, Vector4, Ray, MathUtil, Matrix, Logger, BoundingBox, BoundingSphere, DisorderedArray, CollisionUtil } from '@galacean/engine';
2
2
 
3
3
  function _set_prototype_of(o, p) {
4
4
  _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
@@ -90,6 +90,7 @@ function _instanceof(left, right) {
90
90
  /** @internal */ this._worldScale = new Vector3(1, 1, 1);
91
91
  /** @internal */ this._transform = new LiteTransform();
92
92
  /** @internal */ this._invModelMatrix = new Matrix();
93
+ this._rotation = new Vector3();
93
94
  this._transform.owner = this;
94
95
  this._inverseWorldMatFlag = this._transform.registerWorldChangeFlag();
95
96
  }
@@ -97,7 +98,8 @@ function _instanceof(left, right) {
97
98
  /**
98
99
  * {@inheritDoc IColliderShape.setRotation }
99
100
  */ _proto.setRotation = function setRotation(rotation) {
100
- console.log("Physics-lite don't support setRotation. Use Physics-PhysX instead!");
101
+ var rotationInRadians = this._rotation.set(MathUtil.degreeToRadian(rotation.x), MathUtil.degreeToRadian(rotation.y), MathUtil.degreeToRadian(rotation.z));
102
+ Quaternion.rotationEuler(rotationInRadians.x, rotationInRadians.y, rotationInRadians.z, this._transform.rotationQuaternion);
101
103
  };
102
104
  /**
103
105
  * {@inheritDoc IColliderShape.setPosition }
@@ -172,12 +174,12 @@ function _instanceof(left, right) {
172
174
  };
173
175
  return LiteColliderShape;
174
176
  }();
175
- (function() {
176
- LiteColliderShape._ray = new Ray();
177
- })();
178
- (function() {
179
- LiteColliderShape._tempPoint = new Vector3();
180
- })();
177
+ LiteColliderShape._tempPos = new Vector3();
178
+ LiteColliderShape._tempRot = new Quaternion();
179
+ LiteColliderShape._tempScale = new Vector3();
180
+ LiteColliderShape._tempPoint = new Vector3();
181
+ LiteColliderShape._tempVector4 = new Vector4();
182
+ LiteColliderShape._ray = new Ray();
181
183
 
182
184
  /**
183
185
  * Used to implement transformation related functions.
@@ -193,7 +195,7 @@ function _instanceof(left, right) {
193
195
  this._updateFlagManager = new LiteUpdateFlagManager();
194
196
  this._isParentDirty = true;
195
197
  this._parentTransformCache = null;
196
- this._dirtyFlag = 0xbc;
198
+ this._dirtyFlag = 188;
197
199
  }
198
200
  var _proto = LiteTransform.prototype;
199
201
  /**
@@ -235,8 +237,8 @@ function _instanceof(left, right) {
235
237
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
236
238
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
237
239
  */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
238
- if (!this._isContainDirtyFlags(0x84)) {
239
- this._worldAssociatedChange(0x84);
240
+ if (!this._isContainDirtyFlags(132)) {
241
+ this._worldAssociatedChange(132);
240
242
  if (_instanceof(this._owner, LiteCollider)) {
241
243
  var shapes = this._owner._shapes;
242
244
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -252,8 +254,8 @@ function _instanceof(left, right) {
252
254
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
253
255
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
254
256
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
255
- if (!this._isContainDirtyFlags(0x98)) {
256
- this._worldAssociatedChange(0x98);
257
+ if (!this._isContainDirtyFlags(152)) {
258
+ this._worldAssociatedChange(152);
257
259
  if (_instanceof(this._owner, LiteCollider)) {
258
260
  var shapes = this._owner._shapes;
259
261
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -268,8 +270,8 @@ function _instanceof(left, right) {
268
270
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
269
271
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
270
272
  */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
271
- if (!this._isContainDirtyFlags(0xa0)) {
272
- this._worldAssociatedChange(0xa0);
273
+ if (!this._isContainDirtyFlags(160)) {
274
+ this._worldAssociatedChange(160);
273
275
  if (_instanceof(this._owner, LiteCollider)) {
274
276
  var shapes = this._owner._shapes;
275
277
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -281,8 +283,8 @@ function _instanceof(left, right) {
281
283
  /**
282
284
  * Update all world transform property dirty flag, the principle is the same as above.
283
285
  */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
284
- if (!this._isContainDirtyFlags(0xbc)) {
285
- this._worldAssociatedChange(0xbc);
286
+ if (!this._isContainDirtyFlags(188)) {
287
+ this._worldAssociatedChange(188);
286
288
  if (_instanceof(this._owner, LiteCollider)) {
287
289
  var shapes = this._owner._shapes;
288
290
  for(var i = 0, n = shapes.length; i < n; i++){
@@ -339,7 +341,7 @@ function _instanceof(left, right) {
339
341
  if (this._position !== value) {
340
342
  this._position.copyFrom(value);
341
343
  }
342
- this._setDirtyFlagTrue(0x40);
344
+ this._setDirtyFlagTrue(64);
343
345
  this._updateWorldPositionFlag();
344
346
  }
345
347
  },
@@ -349,9 +351,9 @@ function _instanceof(left, right) {
349
351
  * Local rotation, defining the rotation by using a unit quaternion.
350
352
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
351
353
  */ function get() {
352
- if (this._isContainDirtyFlag(0x2)) {
354
+ if (this._isContainDirtyFlag(2)) {
353
355
  Quaternion.rotationEuler(MathUtil.degreeToRadian(this._rotation.x), MathUtil.degreeToRadian(this._rotation.y), MathUtil.degreeToRadian(this._rotation.z), this._rotationQuaternion);
354
- this._setDirtyFlagFalse(0x2);
356
+ this._setDirtyFlagFalse(2);
355
357
  }
356
358
  return this._rotationQuaternion;
357
359
  },
@@ -359,8 +361,8 @@ function _instanceof(left, right) {
359
361
  if (this._rotationQuaternion !== value) {
360
362
  this._rotationQuaternion.copyFrom(value);
361
363
  }
362
- this._setDirtyFlagTrue(0x40 | 0x1);
363
- this._setDirtyFlagFalse(0x2);
364
+ this._setDirtyFlagTrue(64 | 1);
365
+ this._setDirtyFlagFalse(2);
364
366
  this._updateWorldRotationFlag();
365
367
  }
366
368
  },
@@ -370,14 +372,14 @@ function _instanceof(left, right) {
370
372
  * World rotation, defining the rotation by using a unit quaternion.
371
373
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
372
374
  */ function get() {
373
- if (this._isContainDirtyFlag(0x10)) {
375
+ if (this._isContainDirtyFlag(16)) {
374
376
  var parent = this._getParentTransform();
375
377
  if (parent != null) {
376
378
  Quaternion.multiply(parent.worldRotationQuaternion, this.rotationQuaternion, this._worldRotationQuaternion);
377
379
  } else {
378
380
  this._worldRotationQuaternion.copyFrom(this.rotationQuaternion);
379
381
  }
380
- this._setDirtyFlagFalse(0x10);
382
+ this._setDirtyFlagFalse(16);
381
383
  }
382
384
  return this._worldRotationQuaternion;
383
385
  },
@@ -393,7 +395,7 @@ function _instanceof(left, right) {
393
395
  this._rotationQuaternion.copyFrom(value);
394
396
  }
395
397
  this.rotationQuaternion = this._rotationQuaternion;
396
- this._setDirtyFlagFalse(0x10);
398
+ this._setDirtyFlagFalse(16);
397
399
  }
398
400
  },
399
401
  {
@@ -408,7 +410,7 @@ function _instanceof(left, right) {
408
410
  if (this._scale !== value) {
409
411
  this._scale.copyFrom(value);
410
412
  }
411
- this._setDirtyFlagTrue(0x40);
413
+ this._setDirtyFlagTrue(64);
412
414
  this._updateWorldScaleFlag();
413
415
  }
414
416
  },
@@ -418,9 +420,9 @@ function _instanceof(left, right) {
418
420
  * Local matrix.
419
421
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
420
422
  */ function get() {
421
- if (this._isContainDirtyFlag(0x40)) {
423
+ if (this._isContainDirtyFlag(64)) {
422
424
  Matrix.affineTransformation(this._scale, this.rotationQuaternion, this._position, this._localMatrix);
423
- this._setDirtyFlagFalse(0x40);
425
+ this._setDirtyFlagFalse(64);
424
426
  }
425
427
  return this._localMatrix;
426
428
  },
@@ -429,8 +431,8 @@ function _instanceof(left, right) {
429
431
  this._localMatrix.copyFrom(value);
430
432
  }
431
433
  this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
432
- this._setDirtyFlagTrue(0x1);
433
- this._setDirtyFlagFalse(0x40);
434
+ this._setDirtyFlagTrue(1);
435
+ this._setDirtyFlagFalse(64);
434
436
  this._updateAllWorldFlag();
435
437
  }
436
438
  },
@@ -440,14 +442,14 @@ function _instanceof(left, right) {
440
442
  * World matrix.
441
443
  * @remarks Need to re-assign after modification to ensure that the modification takes effect.
442
444
  */ function get() {
443
- if (this._isContainDirtyFlag(0x80)) {
445
+ if (this._isContainDirtyFlag(128)) {
444
446
  var parent = this._getParentTransform();
445
447
  if (parent) {
446
448
  Matrix.multiply(parent.worldMatrix, this.localMatrix, this._worldMatrix);
447
449
  } else {
448
450
  this._worldMatrix.copyFrom(this.localMatrix);
449
451
  }
450
- this._setDirtyFlagFalse(0x80);
452
+ this._setDirtyFlagFalse(128);
451
453
  }
452
454
  return this._worldMatrix;
453
455
  },
@@ -463,37 +465,14 @@ function _instanceof(left, right) {
463
465
  this._localMatrix.copyFrom(value);
464
466
  }
465
467
  this.localMatrix = this._localMatrix;
466
- this._setDirtyFlagFalse(0x80);
468
+ this._setDirtyFlagFalse(128);
467
469
  }
468
470
  }
469
471
  ]);
470
472
  return LiteTransform;
471
473
  }();
472
- (function() {
473
- LiteTransform._tempQuat0 = new Quaternion();
474
- })();
475
- (function() {
476
- LiteTransform._tempMat42 = new Matrix();
477
- })();
478
- var /**
479
- * Dirty flag of transform.
480
- */ TransformFlag;
481
- (function(TransformFlag) {
482
- TransformFlag[TransformFlag["LocalEuler"] = 0x1] = "LocalEuler";
483
- TransformFlag[TransformFlag["LocalQuat"] = 0x2] = "LocalQuat";
484
- TransformFlag[TransformFlag["WorldPosition"] = 0x4] = "WorldPosition";
485
- TransformFlag[TransformFlag["WorldEuler"] = 0x8] = "WorldEuler";
486
- TransformFlag[TransformFlag["WorldQuat"] = 0x10] = "WorldQuat";
487
- TransformFlag[TransformFlag["WorldScale"] = 0x20] = "WorldScale";
488
- TransformFlag[TransformFlag["LocalMatrix"] = 0x40] = "LocalMatrix";
489
- TransformFlag[TransformFlag["WorldMatrix"] = 0x80] = "WorldMatrix";
490
- TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition */ "WmWp"] = 0x84] = "WmWp";
491
- TransformFlag[TransformFlag[/** WorldMatrix | WorldEuler | WorldQuat */ "WmWeWq"] = 0x98] = "WmWeWq";
492
- TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ "WmWpWeWq"] = 0x9c] = "WmWpWeWq";
493
- TransformFlag[TransformFlag[/** WorldMatrix | WorldScale */ "WmWs"] = 0xa0] = "WmWs";
494
- TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldScale */ "WmWpWs"] = 0xa4] = "WmWpWs";
495
- TransformFlag[TransformFlag[/** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ "WmWpWeWqWs"] = 0xbc] = "WmWpWeWqWs";
496
- })(TransformFlag || (TransformFlag = {}));
474
+ LiteTransform._tempQuat0 = new Quaternion();
475
+ LiteTransform._tempMat42 = new Matrix();
497
476
 
498
477
  /**
499
478
  * Abstract class of physical collider.
@@ -509,11 +488,13 @@ var /**
509
488
  */ _proto.addShape = function addShape(shape) {
510
489
  var oldCollider = shape._collider;
511
490
  if (oldCollider !== this) {
491
+ var _this__scene;
512
492
  if (oldCollider) {
513
493
  oldCollider.removeShape(shape);
514
494
  }
515
495
  this._shapes.push(shape);
516
496
  shape._collider = this;
497
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape);
517
498
  }
518
499
  };
519
500
  /**
@@ -521,8 +502,10 @@ var /**
521
502
  */ _proto.removeShape = function removeShape(shape) {
522
503
  var index = this._shapes.indexOf(shape);
523
504
  if (index !== -1) {
505
+ var _this__scene;
524
506
  this._shapes.splice(index, 1);
525
507
  shape._collider = null;
508
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape);
526
509
  }
527
510
  };
528
511
  /**
@@ -557,18 +540,34 @@ var /**
557
540
 
558
541
  /**
559
542
  * A dynamic collider can act with self-defined movement or physical force
560
- */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider1) {
561
- _inherits(LiteDynamicCollider, LiteCollider1);
543
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
544
+ _inherits(LiteDynamicCollider, LiteCollider);
562
545
  function LiteDynamicCollider(position, rotation) {
563
546
  var _this;
564
- _this = LiteCollider1.call(this) || this;
565
- /** @internal */ _this._isStaticCollider = false;
547
+ _this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = false;
566
548
  _this._transform.setPosition(position.x, position.y, position.z);
567
549
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
568
550
  return _this;
569
551
  }
570
552
  var _proto = LiteDynamicCollider.prototype;
571
553
  /**
554
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
555
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
556
+ Logger.error("Physics-lite don't support getInertiaTensor. Use Physics-PhysX instead!");
557
+ return out;
558
+ };
559
+ /**
560
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
561
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
562
+ Logger.error("Physics-lite don't support getCenterOfMass. Use Physics-PhysX instead!");
563
+ return out;
564
+ };
565
+ /**
566
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
567
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
568
+ Logger.error("Physics-lite don't support setMassAndUpdateInertia. Use Physics-PhysX instead!");
569
+ };
570
+ /**
572
571
  * {@inheritDoc IDynamicCollider.addForce }
573
572
  */ _proto.addForce = function addForce(force) {
574
573
  throw "Physics-lite don't support addForce. Use Physics-PhysX instead!";
@@ -589,74 +588,96 @@ var /**
589
588
  throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!";
590
589
  };
591
590
  /**
591
+ * {@inheritDoc IDynamicCollider.isSleeping }
592
+ */ _proto.isSleeping = function isSleeping() {
593
+ throw "Physics-lite don't support isSleeping. Use Physics-PhysX instead!";
594
+ };
595
+ /**
592
596
  * {@inheritDoc IDynamicCollider.setAngularDamping }
593
597
  */ _proto.setAngularDamping = function setAngularDamping(value) {
594
- throw "Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!";
598
+ Logger.error("Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!");
599
+ };
600
+ /**
601
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
602
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
603
+ Logger.error("Physics-lite don't support getAngularVelocity. Use Physics-PhysX instead!");
604
+ return out;
595
605
  };
596
606
  /**
597
607
  * {@inheritDoc IDynamicCollider.setAngularVelocity }
598
608
  */ _proto.setAngularVelocity = function setAngularVelocity(value) {
599
- throw "Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!";
609
+ Logger.error("Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!");
600
610
  };
601
611
  /**
602
612
  * {@inheritDoc IDynamicCollider.setCenterOfMass }
603
613
  */ _proto.setCenterOfMass = function setCenterOfMass(value) {
604
- throw "Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!";
614
+ Logger.error("Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!");
605
615
  };
606
616
  /**
607
617
  * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
608
618
  */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
609
- throw "Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!";
619
+ Logger.error("Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!");
610
620
  };
611
621
  /**
612
622
  * {@inheritDoc IDynamicCollider.setConstraints }
613
623
  */ _proto.setConstraints = function setConstraints(flags) {
614
- throw "Physics-lite don't support setConstraints. Use Physics-PhysX instead!";
624
+ Logger.error("Physics-lite don't support setConstraints. Use Physics-PhysX instead!");
615
625
  };
616
626
  /**
617
627
  * {@inheritDoc IDynamicCollider.setInertiaTensor }
618
628
  */ _proto.setInertiaTensor = function setInertiaTensor(value) {
619
- throw "Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!";
629
+ Logger.error("Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!");
630
+ };
631
+ /**
632
+ * {@inheritDoc IDynamicCollider.setUseGravity }
633
+ */ _proto.setUseGravity = function setUseGravity(value) {
634
+ Logger.error("Physics-lite don't support setUseGravity. Use Physics-PhysX instead!");
620
635
  };
621
636
  /**
622
637
  * {@inheritDoc IDynamicCollider.setIsKinematic }
623
638
  */ _proto.setIsKinematic = function setIsKinematic(value) {
624
- throw "Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!";
639
+ Logger.error("Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!");
625
640
  };
626
641
  /**
627
642
  * {@inheritDoc IDynamicCollider.setLinearDamping }
628
643
  */ _proto.setLinearDamping = function setLinearDamping(value) {
629
- throw "Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!";
644
+ Logger.error("Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!");
645
+ };
646
+ /**
647
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
648
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
649
+ Logger.error("Physics-lite don't support getLinearVelocity. Use Physics-PhysX instead!");
650
+ return out;
630
651
  };
631
652
  /**
632
653
  * {@inheritDoc IDynamicCollider.setLinearVelocity }
633
654
  */ _proto.setLinearVelocity = function setLinearVelocity(value) {
634
- throw "Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!";
655
+ Logger.error("Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!");
635
656
  };
636
657
  /**
637
658
  * {@inheritDoc IDynamicCollider.setMass }
638
659
  */ _proto.setMass = function setMass(value) {
639
- throw "Physics-lite don't support setMass. Use Physics-PhysX instead!";
660
+ Logger.error("Physics-lite don't support setMass. Use Physics-PhysX instead!");
640
661
  };
641
662
  /**
642
663
  * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
643
664
  */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
644
- throw "Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!";
665
+ Logger.error("Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!");
645
666
  };
646
667
  /**
647
668
  * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
648
669
  */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
649
- throw "Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!";
670
+ Logger.error("Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!");
650
671
  };
651
672
  /**
652
673
  * {@inheritDoc IDynamicCollider.setSleepThreshold }
653
674
  */ _proto.setSleepThreshold = function setSleepThreshold(value) {
654
- throw "Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!";
675
+ Logger.error("Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!");
655
676
  };
656
677
  /**
657
678
  * {@inheritDoc IDynamicCollider.setSolverIterations }
658
679
  */ _proto.setSolverIterations = function setSolverIterations(value) {
659
- throw "Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!";
680
+ Logger.error("Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!");
660
681
  };
661
682
  /**
662
683
  * {@inheritDoc IDynamicCollider.wakeUp }
@@ -718,11 +739,7 @@ var /**
718
739
  _inherits(LiteBoxColliderShape, LiteColliderShape1);
719
740
  function LiteBoxColliderShape(uniqueID, size, material) {
720
741
  var _this;
721
- _this = LiteColliderShape1.call(this) || this;
722
- _this._halfSize = new Vector3();
723
- _this._sizeScale = new Vector3(1, 1, 1);
724
- /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5);
725
- /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
742
+ _this = LiteColliderShape1.call(this) || this, _this._halfSize = new Vector3(), _this._sizeScale = new Vector3(1, 1, 1), /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5), /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
726
743
  _this._id = uniqueID;
727
744
  _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
728
745
  _this._setBondingBox();
@@ -749,6 +766,44 @@ var /**
749
766
  this._setBondingBox();
750
767
  };
751
768
  /**
769
+ * {@inheritDoc IColliderShape.pointDistance }
770
+ */ _proto.pointDistance = function pointDistance(point) {
771
+ var position = LiteColliderShape._tempPos;
772
+ var rotation = LiteColliderShape._tempRot;
773
+ this._transform.worldMatrix.decompose(position, rotation, LiteColliderShape._tempScale);
774
+ var _this__transform = this._transform, shapePosition = _this__transform.position;
775
+ var m = LiteBoxColliderShape._tempMatrix;
776
+ var invM = LiteBoxColliderShape._tempInvMatrix;
777
+ var p = LiteColliderShape._tempPoint;
778
+ var scale = this._sizeScale;
779
+ var boundingBox = LiteBoxColliderShape._tempBox;
780
+ var _this = this, _boxMin = _this._boxMin, _boxMax = _this._boxMax;
781
+ p.copyFrom(_boxMin);
782
+ p.subtract(shapePosition);
783
+ p.divide(scale);
784
+ boundingBox.min.copyFrom(p);
785
+ p.copyFrom(_boxMax);
786
+ p.subtract(shapePosition);
787
+ p.divide(scale);
788
+ boundingBox.max.copyFrom(p);
789
+ Matrix.affineTransformation(scale, rotation, position, m);
790
+ Matrix.invert(m, invM);
791
+ Vector3.transformCoordinate(point, invM, p);
792
+ var min = boundingBox.min;
793
+ var max = boundingBox.max;
794
+ p.x = Math.max(min.x, Math.min(p.x, max.x));
795
+ p.y = Math.max(min.y, Math.min(p.y, max.y));
796
+ p.z = Math.max(min.z, Math.min(p.z, max.z));
797
+ Vector3.transformCoordinate(p, m, p);
798
+ var res = LiteColliderShape._tempVector4;
799
+ if (Vector3.equals(p, point)) {
800
+ res.set(point.x, point.y, point.z, 0);
801
+ } else {
802
+ res.set(p.x, p.y, p.z, Vector3.distanceSquared(p, point));
803
+ }
804
+ return res;
805
+ };
806
+ /**
752
807
  * @internal
753
808
  */ _proto._raycast = function _raycast(ray, hit) {
754
809
  var localRay = this._getLocalRay(ray);
@@ -774,9 +829,9 @@ var /**
774
829
  };
775
830
  return LiteBoxColliderShape;
776
831
  }(LiteColliderShape);
777
- (function() {
778
- LiteBoxColliderShape._tempBox = new BoundingBox();
779
- })();
832
+ LiteBoxColliderShape._tempBox = new BoundingBox();
833
+ LiteBoxColliderShape._tempMatrix = new Matrix();
834
+ LiteBoxColliderShape._tempInvMatrix = new Matrix();
780
835
 
781
836
  /**
782
837
  * Sphere collider shape in Lite.
@@ -784,9 +839,7 @@ var /**
784
839
  _inherits(LiteSphereColliderShape, LiteColliderShape1);
785
840
  function LiteSphereColliderShape(uniqueID, radius, material) {
786
841
  var _this;
787
- _this = LiteColliderShape1.call(this) || this;
788
- _this._radius = 1;
789
- _this._maxScale = 1;
842
+ _this = LiteColliderShape1.call(this) || this, _this._radius = 1, _this._maxScale = 1;
790
843
  _this._radius = radius;
791
844
  _this._id = uniqueID;
792
845
  return _this;
@@ -804,6 +857,27 @@ var /**
804
857
  this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
805
858
  };
806
859
  /**
860
+ * {@inheritDoc IColliderShape.pointDistance }
861
+ */ _proto.pointDistance = function pointDistance(point) {
862
+ var position = LiteColliderShape._tempPos;
863
+ var worldRadius = this.worldRadius;
864
+ this._transform.worldMatrix.decompose(position, LiteColliderShape._tempRot, LiteColliderShape._tempScale);
865
+ var p = LiteColliderShape._tempPoint;
866
+ Vector3.subtract(point, position, p);
867
+ var distanceFromCenter = p.lengthSquared();
868
+ var direction = p.normalize();
869
+ Vector3.scale(direction, worldRadius, p);
870
+ p.add(position);
871
+ var res = LiteColliderShape._tempVector4;
872
+ var distanceSquared = Vector3.distanceSquared(p, point);
873
+ if (distanceFromCenter <= worldRadius * worldRadius) {
874
+ res.set(point.x, point.y, point.z, 0);
875
+ } else {
876
+ res.set(p.x, p.y, p.z, distanceSquared);
877
+ }
878
+ return res;
879
+ };
880
+ /**
807
881
  * @internal
808
882
  */ _proto._raycast = function _raycast(ray, hit) {
809
883
  var boundingSphere = LiteSphereColliderShape._tempSphere;
@@ -827,9 +901,7 @@ var /**
827
901
  ]);
828
902
  return LiteSphereColliderShape;
829
903
  }(LiteColliderShape);
830
- (function() {
831
- LiteSphereColliderShape._tempSphere = new BoundingSphere();
832
- })();
904
+ LiteSphereColliderShape._tempSphere = new BoundingSphere();
833
905
 
834
906
  /**
835
907
  * A manager is a collection of colliders and constraints which can interact.
@@ -851,50 +923,35 @@ var /**
851
923
  }
852
924
  var _proto = LitePhysicsScene.prototype;
853
925
  /**
854
- * {@inheritDoc IPhysicsManager.setGravity }
926
+ * {@inheritDoc IPhysicsScene.setGravity }
855
927
  */ _proto.setGravity = function setGravity(value) {
856
928
  console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
857
929
  };
858
930
  /**
859
- * {@inheritDoc IPhysicsManager.addColliderShape }
860
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
861
- this._eventMap[colliderShape._id] = {};
862
- };
863
- /**
864
- * {@inheritDoc IPhysicsManager.removeColliderShape }
865
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
866
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
867
- var id = colliderShape._id;
868
- currentEvents.forEach(function(event, i) {
869
- if (event.index1 == id) {
870
- currentEvents.deleteByIndex(i);
871
- eventPool.push(event);
872
- } else if (event.index2 == id) {
873
- currentEvents.deleteByIndex(i);
874
- eventPool.push(event);
875
- // If the shape is big index, should clear from the small index shape subMap
876
- eventMap[event.index1][id] = undefined;
877
- }
878
- });
879
- delete eventMap[id];
880
- };
881
- /**
882
- * {@inheritDoc IPhysicsManager.addCollider }
931
+ * {@inheritDoc IPhysicsScene.addCollider }
883
932
  */ _proto.addCollider = function addCollider(actor) {
933
+ actor._scene = this;
884
934
  var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
885
935
  colliders.push(actor);
936
+ var shapes = actor._shapes;
937
+ for(var i = 0, n = shapes.length; i < n; i++){
938
+ this._addColliderShape(shapes[i]);
939
+ }
886
940
  };
887
941
  /**
888
- * {@inheritDoc IPhysicsManager.removeCollider }
942
+ * {@inheritDoc IPhysicsScene.removeCollider }
889
943
  */ _proto.removeCollider = function removeCollider(collider) {
944
+ collider._scene = null;
890
945
  var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
891
946
  var index = colliders.indexOf(collider);
892
- if (index !== -1) {
893
- colliders.splice(index, 1);
947
+ index > -1 && colliders.splice(index, 1);
948
+ var shapes = collider._shapes;
949
+ for(var i = 0, n = shapes.length; i < n; i++){
950
+ this._removeColliderShape(shapes[i]);
894
951
  }
895
952
  };
896
953
  /**
897
- * {@inheritDoc IPhysicsManager.update }
954
+ * {@inheritDoc IPhysicsScene.update }
898
955
  */ _proto.update = function update(deltaTime) {
899
956
  var dynamicColliders = this._dynamicColliders;
900
957
  for(var i = 0, len = dynamicColliders.length; i < len; i++){
@@ -905,7 +962,7 @@ var /**
905
962
  this._fireEvent();
906
963
  };
907
964
  /**
908
- * {@inheritDoc IPhysicsManager.raycast }
965
+ * {@inheritDoc IPhysicsScene.raycast }
909
966
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
910
967
  if (!hit) {
911
968
  return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
@@ -929,15 +986,41 @@ var /**
929
986
  }
930
987
  };
931
988
  /**
932
- * {@inheritDoc IPhysicsManager.addCharacterController }
989
+ * {@inheritDoc IPhysicsScene.addCharacterController }
933
990
  */ _proto.addCharacterController = function addCharacterController(characterController) {
934
991
  throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
935
992
  };
936
993
  /**
937
- * {@inheritDoc IPhysicsManager.removeCharacterController }
994
+ * {@inheritDoc IPhysicsScene.removeCharacterController }
938
995
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
939
996
  throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
940
997
  };
998
+ /**
999
+ * {@inheritDoc IPhysicsScene.destroy }
1000
+ */ _proto.destroy = function destroy() {};
1001
+ /**
1002
+ * @internal
1003
+ */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
1004
+ this._eventMap[colliderShape._id] = {};
1005
+ };
1006
+ /**
1007
+ * @internal
1008
+ */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
1009
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
1010
+ var id = colliderShape._id;
1011
+ currentEvents.forEach(function(event, i) {
1012
+ if (event.index1 == id) {
1013
+ currentEvents.deleteByIndex(i);
1014
+ eventPool.push(event);
1015
+ } else if (event.index2 == id) {
1016
+ currentEvents.deleteByIndex(i);
1017
+ eventPool.push(event);
1018
+ // If the shape is big index, should clear from the small index shape subMap
1019
+ eventMap[event.index1][id] = undefined;
1020
+ }
1021
+ });
1022
+ delete eventMap[id];
1023
+ };
941
1024
  _proto._getTrigger = function _getTrigger(index1, index2) {
942
1025
  var event;
943
1026
  if (this._eventPool.length) {
@@ -1095,26 +1178,10 @@ var /**
1095
1178
  };
1096
1179
  return LitePhysicsScene;
1097
1180
  }();
1098
- (function() {
1099
- LitePhysicsScene._tempSphere = new BoundingSphere();
1100
- })();
1101
- (function() {
1102
- LitePhysicsScene._tempBox = new BoundingBox();
1103
- })();
1104
- (function() {
1105
- LitePhysicsScene._currentHit = new LiteHitResult();
1106
- })();
1107
- (function() {
1108
- LitePhysicsScene._hitResult = new LiteHitResult();
1109
- })();
1110
- var /**
1111
- * Physics state
1112
- */ TriggerEventState;
1113
- (function(TriggerEventState) {
1114
- TriggerEventState[TriggerEventState["Enter"] = 0] = "Enter";
1115
- TriggerEventState[TriggerEventState["Stay"] = 1] = "Stay";
1116
- TriggerEventState[TriggerEventState["Exit"] = 2] = "Exit";
1117
- })(TriggerEventState || (TriggerEventState = {}));
1181
+ LitePhysicsScene._tempSphere = new BoundingSphere();
1182
+ LitePhysicsScene._tempBox = new BoundingBox();
1183
+ LitePhysicsScene._currentHit = new LiteHitResult();
1184
+ LitePhysicsScene._hitResult = new LiteHitResult();
1118
1185
  /**
1119
1186
  * Trigger event to store interactive object ids and state.
1120
1187
  */ var TriggerEvent = function TriggerEvent(index1, index2) {
@@ -1126,12 +1193,11 @@ var /**
1126
1193
  /**
1127
1194
  * A static collider component that will not move.
1128
1195
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1129
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1130
- _inherits(LiteStaticCollider, LiteCollider1);
1196
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1197
+ _inherits(LiteStaticCollider, LiteCollider);
1131
1198
  function LiteStaticCollider(position, rotation) {
1132
1199
  var _this;
1133
- _this = LiteCollider1.call(this) || this;
1134
- /** @internal */ _this._isStaticCollider = true;
1200
+ _this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = true;
1135
1201
  _this._transform.setPosition(position.x, position.y, position.z);
1136
1202
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1137
1203
  return _this;
@@ -1212,12 +1278,15 @@ var LitePhysics = /*#__PURE__*/ function() {
1212
1278
  */ _proto.createSpringJoint = function createSpringJoint(collider) {
1213
1279
  throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1214
1280
  };
1281
+ /**
1282
+ * {@inheritDoc IPhysics.destroy }
1283
+ */ _proto.destroy = function destroy() {};
1215
1284
  return LitePhysics;
1216
1285
  }();
1217
1286
 
1218
1287
  //@ts-ignore
1219
- var version = "0.0.0-experimental-1.3-xr.10";
1220
- console.log("Galacean PhysicsLite version: " + version);
1288
+ var version = "0.0.0-experimental-1.4-small-language.2";
1289
+ console.log("Galacean Engine Physics Lite Version: " + version);
1221
1290
 
1222
1291
  export { LitePhysics, version };
1223
1292
  //# sourceMappingURL=module.js.map