@galacean/engine-physics-lite 0.0.0-experimental-double11.3 → 0.0.0-experimental-double11.5

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;
@@ -653,6 +671,42 @@ var /**
653
671
  return LiteDynamicCollider;
654
672
  }(LiteCollider);
655
673
 
674
+ /**
675
+ * Physics material describes how to handle colliding objects (friction, bounciness).
676
+ */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
677
+ function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
678
+ var _proto = LitePhysicsMaterial.prototype;
679
+ /**
680
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
681
+ */ _proto.setBounciness = function setBounciness(value) {
682
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
683
+ };
684
+ /**
685
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
686
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
687
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
688
+ };
689
+ /**
690
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
691
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
692
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
693
+ };
694
+ /**
695
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
696
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
697
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
698
+ };
699
+ /**
700
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
701
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
702
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
703
+ };
704
+ /**
705
+ * {@inheritDoc IPhysicsMaterial.destroy }
706
+ */ _proto.destroy = function destroy() {};
707
+ return LitePhysicsMaterial;
708
+ }();
709
+
656
710
  /**
657
711
  * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
658
712
  */ var DisorderedArray = /*#__PURE__*/ function() {
@@ -711,13 +765,12 @@ var /**
711
765
 
712
766
  /**
713
767
  * Box collider shape in Lite.
714
- */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
715
- _inherits(LiteBoxColliderShape, LiteColliderShape);
768
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
769
+ _inherits(LiteBoxColliderShape, LiteColliderShape1);
716
770
  function LiteBoxColliderShape(uniqueID, size, material) {
717
771
  var _this;
718
- _this = LiteColliderShape.call(this) || this;
772
+ _this = LiteColliderShape1.call(this) || this;
719
773
  _this._halfSize = new miniprogram.Vector3();
720
- _this._scale = new miniprogram.Vector3(1, 1, 1);
721
774
  /** @internal */ _this._boxMin = new miniprogram.Vector3(-0.5, -0.5, -0.5);
722
775
  /** @internal */ _this._boxMax = new miniprogram.Vector3(0.5, 0.5, 0.5);
723
776
  _this._id = uniqueID;
@@ -729,14 +782,14 @@ var /**
729
782
  /**
730
783
  * {@inheritDoc IColliderShape.setPosition }
731
784
  */ _proto.setPosition = function setPosition(position) {
732
- LiteColliderShape.prototype.setPosition.call(this, position);
785
+ LiteColliderShape1.prototype.setPosition.call(this, position);
733
786
  this._setBondingBox();
734
787
  };
735
788
  /**
736
789
  * {@inheritDoc IColliderShape.setWorldScale }
737
790
  */ _proto.setWorldScale = function setWorldScale(scale) {
738
- this._transform.position = this._transform.position.multiply(scale);
739
- this._scale.copyFrom(scale);
791
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
792
+ this._setBondingBox();
740
793
  };
741
794
  /**
742
795
  * {@inheritDoc IBoxColliderShape.setSize }
@@ -749,8 +802,8 @@ var /**
749
802
  */ _proto._raycast = function _raycast(ray, hit) {
750
803
  var localRay = this._getLocalRay(ray);
751
804
  var boundingBox = LiteBoxColliderShape._tempBox;
752
- boundingBox.min.set(-this._halfSize.x * this._scale.x, -this._halfSize.y * this._scale.y, -this._halfSize.z * this._scale.z);
753
- 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);
754
807
  var rayDistance = localRay.intersectBox(boundingBox);
755
808
  if (rayDistance !== -1) {
756
809
  this._updateHitResult(localRay, rayDistance, hit, ray.origin);
@@ -760,10 +813,11 @@ var /**
760
813
  }
761
814
  };
762
815
  _proto._setBondingBox = function _setBondingBox() {
763
- var _this__transform = this._transform, center = _this__transform.position;
816
+ var position = this._transform.position;
817
+ var scale = this._worldScale;
764
818
  var halfSize = this._halfSize;
765
- miniprogram.Vector3.add(center, halfSize, this._boxMax);
766
- 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);
767
821
  };
768
822
  return LiteBoxColliderShape;
769
823
  }(LiteColliderShape);
@@ -773,11 +827,11 @@ var /**
773
827
 
774
828
  /**
775
829
  * Sphere collider shape in Lite.
776
- */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
777
- _inherits(LiteSphereColliderShape, LiteColliderShape);
830
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
831
+ _inherits(LiteSphereColliderShape, LiteColliderShape1);
778
832
  function LiteSphereColliderShape(uniqueID, radius, material) {
779
833
  var _this;
780
- _this = LiteColliderShape.call(this) || this;
834
+ _this = LiteColliderShape1.call(this) || this;
781
835
  _this._radius = 1;
782
836
  _this._maxScale = 1;
783
837
  _this._radius = radius;
@@ -793,6 +847,7 @@ var /**
793
847
  /**
794
848
  * {@inheritDoc IColliderShape.setWorldScale }
795
849
  */ _proto.setWorldScale = function setWorldScale(scale) {
850
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
796
851
  this._maxScale = Math.max(scale.x, scale.y, scale.z);
797
852
  };
798
853
  /**
@@ -825,8 +880,8 @@ var /**
825
880
 
826
881
  /**
827
882
  * A manager is a collection of colliders and constraints which can interact.
828
- */ var LitePhysicsManager = /*#__PURE__*/ function() {
829
- function LitePhysicsManager(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
883
+ */ var LitePhysicsScene = /*#__PURE__*/ function() {
884
+ function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
830
885
  this._colliders = [];
831
886
  this._sphere = new miniprogram.BoundingSphere();
832
887
  this._box = new miniprogram.BoundingBox();
@@ -840,7 +895,7 @@ var /**
840
895
  this._onTriggerExit = onTriggerExit;
841
896
  this._onTriggerStay = onTriggerStay;
842
897
  }
843
- var _proto = LitePhysicsManager.prototype;
898
+ var _proto = LitePhysicsScene.prototype;
844
899
  /**
845
900
  * {@inheritDoc IPhysicsManager.setGravity }
846
901
  */ _proto.setGravity = function setGravity(value) {
@@ -893,23 +948,25 @@ var /**
893
948
  var colliders = this._colliders;
894
949
  var hitResult;
895
950
  if (hit) {
896
- hitResult = LitePhysicsManager._hitResult;
951
+ hitResult = LitePhysicsScene._hitResult;
897
952
  }
898
953
  var isHit = false;
899
- var curHit = LitePhysicsManager._currentHit;
954
+ var curHit = LitePhysicsScene._currentHit;
900
955
  for(var i = 0, len = colliders.length; i < len; i++){
901
956
  var collider = colliders[i];
902
- if (collider._raycast(ray, onRaycast, curHit) && curHit.distance < distance) {
957
+ if (collider._raycast(ray, onRaycast, curHit)) {
903
958
  isHit = true;
904
- if (hitResult) {
905
- hitResult.normal.copyFrom(curHit.normal);
906
- hitResult.point.copyFrom(curHit.point);
907
- hitResult.distance = curHit.distance;
908
- hitResult.shapeID = curHit.shapeID;
909
- } else {
910
- return true;
959
+ if (curHit.distance < distance) {
960
+ if (hitResult) {
961
+ hitResult.normal.copyFrom(curHit.normal);
962
+ hitResult.point.copyFrom(curHit.point);
963
+ hitResult.distance = curHit.distance;
964
+ hitResult.shapeID = curHit.shapeID;
965
+ } else {
966
+ return true;
967
+ }
968
+ distance = curHit.distance;
911
969
  }
912
- distance = curHit.distance;
913
970
  }
914
971
  }
915
972
  if (!isHit && hitResult) {
@@ -950,7 +1007,7 @@ var /**
950
1007
  for(var i = 0, len = myColliderShapes.length; i < len; i++){
951
1008
  var myShape = myColliderShapes[i];
952
1009
  if (_instanceof(myShape, LiteBoxColliderShape)) {
953
- LitePhysicsManager._updateWorldBox(myShape, this._box);
1010
+ LitePhysicsScene._updateWorldBox(myShape, this._box);
954
1011
  for(var j = 0, len1 = colliders.length; j < len1; j++){
955
1012
  var colliderShape = colliders[j]._shapes;
956
1013
  for(var k = 0, len2 = colliderShape.length; k < len2; k++){
@@ -977,7 +1034,7 @@ var /**
977
1034
  }
978
1035
  }
979
1036
  } else if (_instanceof(myShape, LiteSphereColliderShape)) {
980
- LitePhysicsManager._upWorldSphere(myShape, this._sphere);
1037
+ LitePhysicsScene._upWorldSphere(myShape, this._sphere);
981
1038
  for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
982
1039
  var colliderShape1 = colliders[j1]._shapes;
983
1040
  for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
@@ -1029,24 +1086,24 @@ var /**
1029
1086
  };
1030
1087
  _proto._boxCollision = function _boxCollision(other) {
1031
1088
  if (_instanceof(other, LiteBoxColliderShape)) {
1032
- var box = LitePhysicsManager._tempBox;
1033
- LitePhysicsManager._updateWorldBox(other, box);
1089
+ var box = LitePhysicsScene._tempBox;
1090
+ LitePhysicsScene._updateWorldBox(other, box);
1034
1091
  return miniprogram.CollisionUtil.intersectsBoxAndBox(box, this._box);
1035
1092
  } else if (_instanceof(other, LiteSphereColliderShape)) {
1036
- var sphere = LitePhysicsManager._tempSphere;
1037
- LitePhysicsManager._upWorldSphere(other, sphere);
1093
+ var sphere = LitePhysicsScene._tempSphere;
1094
+ LitePhysicsScene._upWorldSphere(other, sphere);
1038
1095
  return miniprogram.CollisionUtil.intersectsSphereAndBox(sphere, this._box);
1039
1096
  }
1040
1097
  return false;
1041
1098
  };
1042
1099
  _proto._sphereCollision = function _sphereCollision(other) {
1043
1100
  if (_instanceof(other, LiteBoxColliderShape)) {
1044
- var box = LitePhysicsManager._tempBox;
1045
- LitePhysicsManager._updateWorldBox(other, box);
1101
+ var box = LitePhysicsScene._tempBox;
1102
+ LitePhysicsScene._updateWorldBox(other, box);
1046
1103
  return miniprogram.CollisionUtil.intersectsSphereAndBox(this._sphere, box);
1047
1104
  } else if (_instanceof(other, LiteSphereColliderShape)) {
1048
- var sphere = LitePhysicsManager._tempSphere;
1049
- LitePhysicsManager._upWorldSphere(other, sphere);
1105
+ var sphere = LitePhysicsScene._tempSphere;
1106
+ LitePhysicsScene._upWorldSphere(other, sphere);
1050
1107
  return miniprogram.CollisionUtil.intersectsSphereAndSphere(sphere, this._sphere);
1051
1108
  }
1052
1109
  return false;
@@ -1055,7 +1112,7 @@ var /**
1055
1112
  * Calculate the bounding box in world space from boxCollider.
1056
1113
  * @param boxCollider - The boxCollider to calculate
1057
1114
  * @param out - The calculated boundingBox
1058
- */ LitePhysicsManager._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1115
+ */ LitePhysicsScene._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1059
1116
  var mat = boxCollider._transform.worldMatrix;
1060
1117
  out.min.copyFrom(boxCollider._boxMin);
1061
1118
  out.max.copyFrom(boxCollider._boxMax);
@@ -1065,23 +1122,23 @@ var /**
1065
1122
  * Get the sphere info of the given sphere collider in world space.
1066
1123
  * @param sphereCollider - The given sphere collider
1067
1124
  * @param out - The calculated boundingSphere
1068
- */ LitePhysicsManager._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1125
+ */ LitePhysicsScene._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1069
1126
  miniprogram.Vector3.transformCoordinate(sphereCollider._transform.position, sphereCollider._transform.worldMatrix, out.center);
1070
1127
  out.radius = sphereCollider.worldRadius;
1071
1128
  };
1072
- return LitePhysicsManager;
1129
+ return LitePhysicsScene;
1073
1130
  }();
1074
1131
  (function() {
1075
- LitePhysicsManager._tempSphere = new miniprogram.BoundingSphere();
1132
+ LitePhysicsScene._tempSphere = new miniprogram.BoundingSphere();
1076
1133
  })();
1077
1134
  (function() {
1078
- LitePhysicsManager._tempBox = new miniprogram.BoundingBox();
1135
+ LitePhysicsScene._tempBox = new miniprogram.BoundingBox();
1079
1136
  })();
1080
1137
  (function() {
1081
- LitePhysicsManager._currentHit = new LiteHitResult();
1138
+ LitePhysicsScene._currentHit = new LiteHitResult();
1082
1139
  })();
1083
1140
  (function() {
1084
- LitePhysicsManager._hitResult = new LiteHitResult();
1141
+ LitePhysicsScene._hitResult = new LiteHitResult();
1085
1142
  })();
1086
1143
  var /**
1087
1144
  * Physics state
@@ -1099,50 +1156,14 @@ var /**
1099
1156
  this.index2 = index2;
1100
1157
  };
1101
1158
 
1102
- /**
1103
- * Physics material describes how to handle colliding objects (friction, bounciness).
1104
- */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
1105
- function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
1106
- var _proto = LitePhysicsMaterial.prototype;
1107
- /**
1108
- * {@inheritDoc IPhysicsMaterial.setBounciness }
1109
- */ _proto.setBounciness = function setBounciness(value) {
1110
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1111
- };
1112
- /**
1113
- * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
1114
- */ _proto.setDynamicFriction = function setDynamicFriction(value) {
1115
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1116
- };
1117
- /**
1118
- * {@inheritDoc IPhysicsMaterial.setStaticFriction }
1119
- */ _proto.setStaticFriction = function setStaticFriction(value) {
1120
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1121
- };
1122
- /**
1123
- * {@inheritDoc IPhysicsMaterial.setBounceCombine }
1124
- */ _proto.setBounceCombine = function setBounceCombine(value) {
1125
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1126
- };
1127
- /**
1128
- * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
1129
- */ _proto.setFrictionCombine = function setFrictionCombine(value) {
1130
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1131
- };
1132
- /**
1133
- * {@inheritDoc IPhysicsMaterial.destroy }
1134
- */ _proto.destroy = function destroy() {};
1135
- return LitePhysicsMaterial;
1136
- }();
1137
-
1138
1159
  /**
1139
1160
  * A static collider component that will not move.
1140
1161
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1141
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1142
- _inherits(LiteStaticCollider, LiteCollider);
1162
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1163
+ _inherits(LiteStaticCollider, LiteCollider1);
1143
1164
  function LiteStaticCollider(position, rotation) {
1144
1165
  var _this;
1145
- _this = LiteCollider.call(this) || this;
1166
+ _this = LiteCollider1.call(this) || this;
1146
1167
  _this._transform.setPosition(position.x, position.y, position.z);
1147
1168
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1148
1169
  return _this;
@@ -1160,8 +1181,13 @@ var LitePhysics = /*#__PURE__*/ function() {
1160
1181
  };
1161
1182
  /**
1162
1183
  * {@inheritDoc IPhysics.createPhysicsManager }
1163
- */ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1164
- return new LitePhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1184
+ */ _proto.createPhysicsManager = function createPhysicsManager() {
1185
+ return null;
1186
+ };
1187
+ /**
1188
+ * {@inheritDoc IPhysics.createPhysicsScene }
1189
+ */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1190
+ return new LitePhysicsScene(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1165
1191
  };
1166
1192
  /**
1167
1193
  * {@inheritDoc IPhysics.createStaticCollider }
@@ -1221,4 +1247,9 @@ var LitePhysics = /*#__PURE__*/ function() {
1221
1247
  return LitePhysics;
1222
1248
  }();
1223
1249
 
1250
+ //@ts-ignore
1251
+ var version = "0.0.0-experimental-double11.5";
1252
+ console.log("Galacean PhysicsLite version: " + version);
1253
+
1224
1254
  exports.LitePhysics = LitePhysics;
1255
+ exports.version = version;