@galacean/engine-physics-lite 1.1.0-alpha.4 → 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,6 +90,8 @@ function _instanceof(left, right) {
90
90
  * Abstract class for collider shapes.
91
91
  */ var LiteColliderShape = /*#__PURE__*/ function() {
92
92
  function LiteColliderShape() {
93
+ /** @internal */ this._position = new miniprogram.Vector3();
94
+ /** @internal */ this._worldScale = new miniprogram.Vector3(1, 1, 1);
93
95
  /** @internal */ this._transform = new LiteTransform();
94
96
  /** @internal */ this._invModelMatrix = new miniprogram.Matrix();
95
97
  this._transform.owner = this;
@@ -104,7 +106,18 @@ function _instanceof(left, right) {
104
106
  /**
105
107
  * {@inheritDoc IColliderShape.setPosition }
106
108
  */ _proto.setPosition = function setPosition(position) {
107
- this._transform.setPosition(position.x, position.y, position.z);
109
+ if (position !== this._position) {
110
+ this._position.copyFrom(position);
111
+ }
112
+ this._setLocalPose();
113
+ };
114
+ /**
115
+ * {@inheritDoc IColliderShape.setWorldScale }
116
+ */ _proto.setWorldScale = function setWorldScale(scale) {
117
+ if (scale !== this._worldScale) {
118
+ this._worldScale.copyFrom(scale);
119
+ }
120
+ this._setLocalPose();
108
121
  };
109
122
  /**
110
123
  * {@inheritDoc IColliderShape.setContactOffset }
@@ -158,6 +171,11 @@ function _instanceof(left, right) {
158
171
  }
159
172
  return this._invModelMatrix;
160
173
  };
174
+ _proto._setLocalPose = function _setLocalPose() {
175
+ var shapePosition = LiteColliderShape._tempPoint;
176
+ miniprogram.Vector3.multiply(this._position, this._worldScale, shapePosition);
177
+ this._transform.position = shapePosition;
178
+ };
161
179
  return LiteColliderShape;
162
180
  }();
163
181
  (function() {
@@ -545,11 +563,11 @@ var /**
545
563
 
546
564
  /**
547
565
  * A dynamic collider can act with self-defined movement or physical force
548
- */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
549
- _inherits(LiteDynamicCollider, LiteCollider);
566
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider1) {
567
+ _inherits(LiteDynamicCollider, LiteCollider1);
550
568
  function LiteDynamicCollider(position, rotation) {
551
569
  var _this;
552
- _this = LiteCollider.call(this) || this;
570
+ _this = LiteCollider1.call(this) || this;
553
571
  _this._transform.setPosition(position.x, position.y, position.z);
554
572
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
555
573
  return _this;
@@ -747,13 +765,12 @@ var /**
747
765
 
748
766
  /**
749
767
  * Box collider shape in Lite.
750
- */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
751
- _inherits(LiteBoxColliderShape, LiteColliderShape);
768
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
769
+ _inherits(LiteBoxColliderShape, LiteColliderShape1);
752
770
  function LiteBoxColliderShape(uniqueID, size, material) {
753
771
  var _this;
754
- _this = LiteColliderShape.call(this) || this;
772
+ _this = LiteColliderShape1.call(this) || this;
755
773
  _this._halfSize = new miniprogram.Vector3();
756
- _this._scale = new miniprogram.Vector3(1, 1, 1);
757
774
  /** @internal */ _this._boxMin = new miniprogram.Vector3(-0.5, -0.5, -0.5);
758
775
  /** @internal */ _this._boxMax = new miniprogram.Vector3(0.5, 0.5, 0.5);
759
776
  _this._id = uniqueID;
@@ -765,14 +782,14 @@ var /**
765
782
  /**
766
783
  * {@inheritDoc IColliderShape.setPosition }
767
784
  */ _proto.setPosition = function setPosition(position) {
768
- LiteColliderShape.prototype.setPosition.call(this, position);
785
+ LiteColliderShape1.prototype.setPosition.call(this, position);
769
786
  this._setBondingBox();
770
787
  };
771
788
  /**
772
789
  * {@inheritDoc IColliderShape.setWorldScale }
773
790
  */ _proto.setWorldScale = function setWorldScale(scale) {
774
- this._transform.position = this._transform.position.multiply(scale);
775
- this._scale.copyFrom(scale);
791
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
792
+ this._setBondingBox();
776
793
  };
777
794
  /**
778
795
  * {@inheritDoc IBoxColliderShape.setSize }
@@ -785,8 +802,8 @@ var /**
785
802
  */ _proto._raycast = function _raycast(ray, hit) {
786
803
  var localRay = this._getLocalRay(ray);
787
804
  var boundingBox = LiteBoxColliderShape._tempBox;
788
- boundingBox.min.set(-this._halfSize.x * this._scale.x, -this._halfSize.y * this._scale.y, -this._halfSize.z * this._scale.z);
789
- boundingBox.max.set(this._halfSize.x * this._scale.x, this._halfSize.y * this._scale.y, this._halfSize.z * this._scale.z);
805
+ boundingBox.min.set(-this._halfSize.x * this._worldScale.x, -this._halfSize.y * this._worldScale.y, -this._halfSize.z * this._worldScale.z);
806
+ boundingBox.max.set(this._halfSize.x * this._worldScale.x, this._halfSize.y * this._worldScale.y, this._halfSize.z * this._worldScale.z);
790
807
  var rayDistance = localRay.intersectBox(boundingBox);
791
808
  if (rayDistance !== -1) {
792
809
  this._updateHitResult(localRay, rayDistance, hit, ray.origin);
@@ -796,10 +813,11 @@ var /**
796
813
  }
797
814
  };
798
815
  _proto._setBondingBox = function _setBondingBox() {
799
- var _this__transform = this._transform, center = _this__transform.position;
816
+ var position = this._transform.position;
817
+ var scale = this._worldScale;
800
818
  var halfSize = this._halfSize;
801
- miniprogram.Vector3.add(center, halfSize, this._boxMax);
802
- miniprogram.Vector3.subtract(center, halfSize, this._boxMin);
819
+ this._boxMin.set(-halfSize.x * scale.x + position.x, -halfSize.y * scale.y + position.y, -halfSize.z * scale.z + position.z);
820
+ this._boxMax.set(halfSize.x * scale.x + position.x, halfSize.y * scale.y + position.y, halfSize.z * scale.z + position.z);
803
821
  };
804
822
  return LiteBoxColliderShape;
805
823
  }(LiteColliderShape);
@@ -809,11 +827,11 @@ var /**
809
827
 
810
828
  /**
811
829
  * Sphere collider shape in Lite.
812
- */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
813
- _inherits(LiteSphereColliderShape, LiteColliderShape);
830
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
831
+ _inherits(LiteSphereColliderShape, LiteColliderShape1);
814
832
  function LiteSphereColliderShape(uniqueID, radius, material) {
815
833
  var _this;
816
- _this = LiteColliderShape.call(this) || this;
834
+ _this = LiteColliderShape1.call(this) || this;
817
835
  _this._radius = 1;
818
836
  _this._maxScale = 1;
819
837
  _this._radius = radius;
@@ -829,6 +847,7 @@ var /**
829
847
  /**
830
848
  * {@inheritDoc IColliderShape.setWorldScale }
831
849
  */ _proto.setWorldScale = function setWorldScale(scale) {
850
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
832
851
  this._maxScale = Math.max(scale.x, scale.y, scale.z);
833
852
  };
834
853
  /**
@@ -1140,11 +1159,11 @@ var /**
1140
1159
  /**
1141
1160
  * A static collider component that will not move.
1142
1161
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1143
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1144
- _inherits(LiteStaticCollider, LiteCollider);
1162
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1163
+ _inherits(LiteStaticCollider, LiteCollider1);
1145
1164
  function LiteStaticCollider(position, rotation) {
1146
1165
  var _this;
1147
- _this = LiteCollider.call(this) || this;
1166
+ _this = LiteCollider1.call(this) || this;
1148
1167
  _this._transform.setPosition(position.x, position.y, position.z);
1149
1168
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1150
1169
  return _this;
package/dist/module.js CHANGED
@@ -86,6 +86,8 @@ function _instanceof(left, right) {
86
86
  * Abstract class for collider shapes.
87
87
  */ var LiteColliderShape = /*#__PURE__*/ function() {
88
88
  function LiteColliderShape() {
89
+ /** @internal */ this._position = new Vector3();
90
+ /** @internal */ this._worldScale = new Vector3(1, 1, 1);
89
91
  /** @internal */ this._transform = new LiteTransform();
90
92
  /** @internal */ this._invModelMatrix = new Matrix();
91
93
  this._transform.owner = this;
@@ -100,7 +102,18 @@ function _instanceof(left, right) {
100
102
  /**
101
103
  * {@inheritDoc IColliderShape.setPosition }
102
104
  */ _proto.setPosition = function setPosition(position) {
103
- this._transform.setPosition(position.x, position.y, position.z);
105
+ if (position !== this._position) {
106
+ this._position.copyFrom(position);
107
+ }
108
+ this._setLocalPose();
109
+ };
110
+ /**
111
+ * {@inheritDoc IColliderShape.setWorldScale }
112
+ */ _proto.setWorldScale = function setWorldScale(scale) {
113
+ if (scale !== this._worldScale) {
114
+ this._worldScale.copyFrom(scale);
115
+ }
116
+ this._setLocalPose();
104
117
  };
105
118
  /**
106
119
  * {@inheritDoc IColliderShape.setContactOffset }
@@ -154,6 +167,11 @@ function _instanceof(left, right) {
154
167
  }
155
168
  return this._invModelMatrix;
156
169
  };
170
+ _proto._setLocalPose = function _setLocalPose() {
171
+ var shapePosition = LiteColliderShape._tempPoint;
172
+ Vector3.multiply(this._position, this._worldScale, shapePosition);
173
+ this._transform.position = shapePosition;
174
+ };
157
175
  return LiteColliderShape;
158
176
  }();
159
177
  (function() {
@@ -541,11 +559,11 @@ var /**
541
559
 
542
560
  /**
543
561
  * A dynamic collider can act with self-defined movement or physical force
544
- */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
545
- _inherits(LiteDynamicCollider, LiteCollider);
562
+ */ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider1) {
563
+ _inherits(LiteDynamicCollider, LiteCollider1);
546
564
  function LiteDynamicCollider(position, rotation) {
547
565
  var _this;
548
- _this = LiteCollider.call(this) || this;
566
+ _this = LiteCollider1.call(this) || this;
549
567
  _this._transform.setPosition(position.x, position.y, position.z);
550
568
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
551
569
  return _this;
@@ -743,13 +761,12 @@ var /**
743
761
 
744
762
  /**
745
763
  * Box collider shape in Lite.
746
- */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
747
- _inherits(LiteBoxColliderShape, LiteColliderShape);
764
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
765
+ _inherits(LiteBoxColliderShape, LiteColliderShape1);
748
766
  function LiteBoxColliderShape(uniqueID, size, material) {
749
767
  var _this;
750
- _this = LiteColliderShape.call(this) || this;
768
+ _this = LiteColliderShape1.call(this) || this;
751
769
  _this._halfSize = new Vector3();
752
- _this._scale = new Vector3(1, 1, 1);
753
770
  /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5);
754
771
  /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
755
772
  _this._id = uniqueID;
@@ -761,14 +778,14 @@ var /**
761
778
  /**
762
779
  * {@inheritDoc IColliderShape.setPosition }
763
780
  */ _proto.setPosition = function setPosition(position) {
764
- LiteColliderShape.prototype.setPosition.call(this, position);
781
+ LiteColliderShape1.prototype.setPosition.call(this, position);
765
782
  this._setBondingBox();
766
783
  };
767
784
  /**
768
785
  * {@inheritDoc IColliderShape.setWorldScale }
769
786
  */ _proto.setWorldScale = function setWorldScale(scale) {
770
- this._transform.position = this._transform.position.multiply(scale);
771
- this._scale.copyFrom(scale);
787
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
788
+ this._setBondingBox();
772
789
  };
773
790
  /**
774
791
  * {@inheritDoc IBoxColliderShape.setSize }
@@ -781,8 +798,8 @@ var /**
781
798
  */ _proto._raycast = function _raycast(ray, hit) {
782
799
  var localRay = this._getLocalRay(ray);
783
800
  var boundingBox = LiteBoxColliderShape._tempBox;
784
- boundingBox.min.set(-this._halfSize.x * this._scale.x, -this._halfSize.y * this._scale.y, -this._halfSize.z * this._scale.z);
785
- boundingBox.max.set(this._halfSize.x * this._scale.x, this._halfSize.y * this._scale.y, this._halfSize.z * this._scale.z);
801
+ boundingBox.min.set(-this._halfSize.x * this._worldScale.x, -this._halfSize.y * this._worldScale.y, -this._halfSize.z * this._worldScale.z);
802
+ boundingBox.max.set(this._halfSize.x * this._worldScale.x, this._halfSize.y * this._worldScale.y, this._halfSize.z * this._worldScale.z);
786
803
  var rayDistance = localRay.intersectBox(boundingBox);
787
804
  if (rayDistance !== -1) {
788
805
  this._updateHitResult(localRay, rayDistance, hit, ray.origin);
@@ -792,10 +809,11 @@ var /**
792
809
  }
793
810
  };
794
811
  _proto._setBondingBox = function _setBondingBox() {
795
- var _this__transform = this._transform, center = _this__transform.position;
812
+ var position = this._transform.position;
813
+ var scale = this._worldScale;
796
814
  var halfSize = this._halfSize;
797
- Vector3.add(center, halfSize, this._boxMax);
798
- Vector3.subtract(center, halfSize, this._boxMin);
815
+ this._boxMin.set(-halfSize.x * scale.x + position.x, -halfSize.y * scale.y + position.y, -halfSize.z * scale.z + position.z);
816
+ this._boxMax.set(halfSize.x * scale.x + position.x, halfSize.y * scale.y + position.y, halfSize.z * scale.z + position.z);
799
817
  };
800
818
  return LiteBoxColliderShape;
801
819
  }(LiteColliderShape);
@@ -805,11 +823,11 @@ var /**
805
823
 
806
824
  /**
807
825
  * Sphere collider shape in Lite.
808
- */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
809
- _inherits(LiteSphereColliderShape, LiteColliderShape);
826
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
827
+ _inherits(LiteSphereColliderShape, LiteColliderShape1);
810
828
  function LiteSphereColliderShape(uniqueID, radius, material) {
811
829
  var _this;
812
- _this = LiteColliderShape.call(this) || this;
830
+ _this = LiteColliderShape1.call(this) || this;
813
831
  _this._radius = 1;
814
832
  _this._maxScale = 1;
815
833
  _this._radius = radius;
@@ -825,6 +843,7 @@ var /**
825
843
  /**
826
844
  * {@inheritDoc IColliderShape.setWorldScale }
827
845
  */ _proto.setWorldScale = function setWorldScale(scale) {
846
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
828
847
  this._maxScale = Math.max(scale.x, scale.y, scale.z);
829
848
  };
830
849
  /**
@@ -1136,11 +1155,11 @@ var /**
1136
1155
  /**
1137
1156
  * A static collider component that will not move.
1138
1157
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1139
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1140
- _inherits(LiteStaticCollider, LiteCollider);
1158
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1159
+ _inherits(LiteStaticCollider, LiteCollider1);
1141
1160
  function LiteStaticCollider(position, rotation) {
1142
1161
  var _this;
1143
- _this = LiteCollider.call(this) || this;
1162
+ _this = LiteCollider1.call(this) || this;
1144
1163
  _this._transform.setPosition(position.x, position.y, position.z);
1145
1164
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1146
1165
  return _this;