@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/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 }
@@ -722,11 +743,7 @@ var /**
722
743
  _inherits(LiteBoxColliderShape, LiteColliderShape1);
723
744
  function LiteBoxColliderShape(uniqueID, size, material) {
724
745
  var _this;
725
- _this = LiteColliderShape1.call(this) || this;
726
- _this._halfSize = new engine.Vector3();
727
- _this._sizeScale = new engine.Vector3(1, 1, 1);
728
- /** @internal */ _this._boxMin = new engine.Vector3(-0.5, -0.5, -0.5);
729
- /** @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);
730
747
  _this._id = uniqueID;
731
748
  _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
732
749
  _this._setBondingBox();
@@ -753,6 +770,44 @@ var /**
753
770
  this._setBondingBox();
754
771
  };
755
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
+ /**
756
811
  * @internal
757
812
  */ _proto._raycast = function _raycast(ray, hit) {
758
813
  var localRay = this._getLocalRay(ray);
@@ -778,9 +833,9 @@ var /**
778
833
  };
779
834
  return LiteBoxColliderShape;
780
835
  }(LiteColliderShape);
781
- (function() {
782
- LiteBoxColliderShape._tempBox = new engine.BoundingBox();
783
- })();
836
+ LiteBoxColliderShape._tempBox = new engine.BoundingBox();
837
+ LiteBoxColliderShape._tempMatrix = new engine.Matrix();
838
+ LiteBoxColliderShape._tempInvMatrix = new engine.Matrix();
784
839
 
785
840
  /**
786
841
  * Sphere collider shape in Lite.
@@ -788,9 +843,7 @@ var /**
788
843
  _inherits(LiteSphereColliderShape, LiteColliderShape1);
789
844
  function LiteSphereColliderShape(uniqueID, radius, material) {
790
845
  var _this;
791
- _this = LiteColliderShape1.call(this) || this;
792
- _this._radius = 1;
793
- _this._maxScale = 1;
846
+ _this = LiteColliderShape1.call(this) || this, _this._radius = 1, _this._maxScale = 1;
794
847
  _this._radius = radius;
795
848
  _this._id = uniqueID;
796
849
  return _this;
@@ -808,6 +861,27 @@ var /**
808
861
  this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
809
862
  };
810
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
+ /**
811
885
  * @internal
812
886
  */ _proto._raycast = function _raycast(ray, hit) {
813
887
  var boundingSphere = LiteSphereColliderShape._tempSphere;
@@ -831,9 +905,7 @@ var /**
831
905
  ]);
832
906
  return LiteSphereColliderShape;
833
907
  }(LiteColliderShape);
834
- (function() {
835
- LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
836
- })();
908
+ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
837
909
 
838
910
  /**
839
911
  * A manager is a collection of colliders and constraints which can interact.
@@ -855,50 +927,35 @@ var /**
855
927
  }
856
928
  var _proto = LitePhysicsScene.prototype;
857
929
  /**
858
- * {@inheritDoc IPhysicsManager.setGravity }
930
+ * {@inheritDoc IPhysicsScene.setGravity }
859
931
  */ _proto.setGravity = function setGravity(value) {
860
932
  console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
861
933
  };
862
934
  /**
863
- * {@inheritDoc IPhysicsManager.addColliderShape }
864
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
865
- this._eventMap[colliderShape._id] = {};
866
- };
867
- /**
868
- * {@inheritDoc IPhysicsManager.removeColliderShape }
869
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
870
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
871
- var id = colliderShape._id;
872
- currentEvents.forEach(function(event, i) {
873
- if (event.index1 == id) {
874
- currentEvents.deleteByIndex(i);
875
- eventPool.push(event);
876
- } else if (event.index2 == id) {
877
- currentEvents.deleteByIndex(i);
878
- eventPool.push(event);
879
- // If the shape is big index, should clear from the small index shape subMap
880
- eventMap[event.index1][id] = undefined;
881
- }
882
- });
883
- delete eventMap[id];
884
- };
885
- /**
886
- * {@inheritDoc IPhysicsManager.addCollider }
935
+ * {@inheritDoc IPhysicsScene.addCollider }
887
936
  */ _proto.addCollider = function addCollider(actor) {
937
+ actor._scene = this;
888
938
  var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
889
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
+ }
890
944
  };
891
945
  /**
892
- * {@inheritDoc IPhysicsManager.removeCollider }
946
+ * {@inheritDoc IPhysicsScene.removeCollider }
893
947
  */ _proto.removeCollider = function removeCollider(collider) {
948
+ collider._scene = null;
894
949
  var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
895
950
  var index = colliders.indexOf(collider);
896
- if (index !== -1) {
897
- 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]);
898
955
  }
899
956
  };
900
957
  /**
901
- * {@inheritDoc IPhysicsManager.update }
958
+ * {@inheritDoc IPhysicsScene.update }
902
959
  */ _proto.update = function update(deltaTime) {
903
960
  var dynamicColliders = this._dynamicColliders;
904
961
  for(var i = 0, len = dynamicColliders.length; i < len; i++){
@@ -909,7 +966,7 @@ var /**
909
966
  this._fireEvent();
910
967
  };
911
968
  /**
912
- * {@inheritDoc IPhysicsManager.raycast }
969
+ * {@inheritDoc IPhysicsScene.raycast }
913
970
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
914
971
  if (!hit) {
915
972
  return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
@@ -933,15 +990,41 @@ var /**
933
990
  }
934
991
  };
935
992
  /**
936
- * {@inheritDoc IPhysicsManager.addCharacterController }
993
+ * {@inheritDoc IPhysicsScene.addCharacterController }
937
994
  */ _proto.addCharacterController = function addCharacterController(characterController) {
938
995
  throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
939
996
  };
940
997
  /**
941
- * {@inheritDoc IPhysicsManager.removeCharacterController }
998
+ * {@inheritDoc IPhysicsScene.removeCharacterController }
942
999
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
943
1000
  throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
944
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
+ };
945
1028
  _proto._getTrigger = function _getTrigger(index1, index2) {
946
1029
  var event;
947
1030
  if (this._eventPool.length) {
@@ -1099,26 +1182,10 @@ var /**
1099
1182
  };
1100
1183
  return LitePhysicsScene;
1101
1184
  }();
1102
- (function() {
1103
- LitePhysicsScene._tempSphere = new engine.BoundingSphere();
1104
- })();
1105
- (function() {
1106
- LitePhysicsScene._tempBox = new engine.BoundingBox();
1107
- })();
1108
- (function() {
1109
- LitePhysicsScene._currentHit = new LiteHitResult();
1110
- })();
1111
- (function() {
1112
- LitePhysicsScene._hitResult = new LiteHitResult();
1113
- })();
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 = {}));
1185
+ LitePhysicsScene._tempSphere = new engine.BoundingSphere();
1186
+ LitePhysicsScene._tempBox = new engine.BoundingBox();
1187
+ LitePhysicsScene._currentHit = new LiteHitResult();
1188
+ LitePhysicsScene._hitResult = new LiteHitResult();
1122
1189
  /**
1123
1190
  * Trigger event to store interactive object ids and state.
1124
1191
  */ var TriggerEvent = function TriggerEvent(index1, index2) {
@@ -1130,12 +1197,11 @@ var /**
1130
1197
  /**
1131
1198
  * A static collider component that will not move.
1132
1199
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1133
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1134
- _inherits(LiteStaticCollider, LiteCollider1);
1200
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1201
+ _inherits(LiteStaticCollider, LiteCollider);
1135
1202
  function LiteStaticCollider(position, rotation) {
1136
1203
  var _this;
1137
- _this = LiteCollider1.call(this) || this;
1138
- /** @internal */ _this._isStaticCollider = true;
1204
+ _this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = true;
1139
1205
  _this._transform.setPosition(position.x, position.y, position.z);
1140
1206
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1141
1207
  return _this;
@@ -1216,12 +1282,15 @@ var LitePhysics = /*#__PURE__*/ function() {
1216
1282
  */ _proto.createSpringJoint = function createSpringJoint(collider) {
1217
1283
  throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
1218
1284
  };
1285
+ /**
1286
+ * {@inheritDoc IPhysics.destroy }
1287
+ */ _proto.destroy = function destroy() {};
1219
1288
  return LitePhysics;
1220
1289
  }();
1221
1290
 
1222
1291
  //@ts-ignore
1223
- var version = "0.0.0-experimental-1.3-xr.10";
1224
- console.log("Galacean PhysicsLite version: " + version);
1292
+ var version = "0.0.0-experimental-1.4-small-language.2";
1293
+ console.log("Galacean Engine Physics Lite Version: " + version);
1225
1294
 
1226
1295
  exports.LitePhysics = LitePhysics;
1227
1296
  exports.version = version;