@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.
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;
@@ -649,6 +667,42 @@ var /**
649
667
  return LiteDynamicCollider;
650
668
  }(LiteCollider);
651
669
 
670
+ /**
671
+ * Physics material describes how to handle colliding objects (friction, bounciness).
672
+ */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
673
+ function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
674
+ var _proto = LitePhysicsMaterial.prototype;
675
+ /**
676
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
677
+ */ _proto.setBounciness = function setBounciness(value) {
678
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
679
+ };
680
+ /**
681
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
682
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
683
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
684
+ };
685
+ /**
686
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
687
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
688
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
689
+ };
690
+ /**
691
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
692
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
693
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
694
+ };
695
+ /**
696
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
697
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
698
+ throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
699
+ };
700
+ /**
701
+ * {@inheritDoc IPhysicsMaterial.destroy }
702
+ */ _proto.destroy = function destroy() {};
703
+ return LitePhysicsMaterial;
704
+ }();
705
+
652
706
  /**
653
707
  * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
654
708
  */ var DisorderedArray = /*#__PURE__*/ function() {
@@ -707,13 +761,12 @@ var /**
707
761
 
708
762
  /**
709
763
  * Box collider shape in Lite.
710
- */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
711
- _inherits(LiteBoxColliderShape, LiteColliderShape);
764
+ */ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
765
+ _inherits(LiteBoxColliderShape, LiteColliderShape1);
712
766
  function LiteBoxColliderShape(uniqueID, size, material) {
713
767
  var _this;
714
- _this = LiteColliderShape.call(this) || this;
768
+ _this = LiteColliderShape1.call(this) || this;
715
769
  _this._halfSize = new Vector3();
716
- _this._scale = new Vector3(1, 1, 1);
717
770
  /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5);
718
771
  /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
719
772
  _this._id = uniqueID;
@@ -725,14 +778,14 @@ var /**
725
778
  /**
726
779
  * {@inheritDoc IColliderShape.setPosition }
727
780
  */ _proto.setPosition = function setPosition(position) {
728
- LiteColliderShape.prototype.setPosition.call(this, position);
781
+ LiteColliderShape1.prototype.setPosition.call(this, position);
729
782
  this._setBondingBox();
730
783
  };
731
784
  /**
732
785
  * {@inheritDoc IColliderShape.setWorldScale }
733
786
  */ _proto.setWorldScale = function setWorldScale(scale) {
734
- this._transform.position = this._transform.position.multiply(scale);
735
- this._scale.copyFrom(scale);
787
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
788
+ this._setBondingBox();
736
789
  };
737
790
  /**
738
791
  * {@inheritDoc IBoxColliderShape.setSize }
@@ -745,8 +798,8 @@ var /**
745
798
  */ _proto._raycast = function _raycast(ray, hit) {
746
799
  var localRay = this._getLocalRay(ray);
747
800
  var boundingBox = LiteBoxColliderShape._tempBox;
748
- boundingBox.min.set(-this._halfSize.x * this._scale.x, -this._halfSize.y * this._scale.y, -this._halfSize.z * this._scale.z);
749
- 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);
750
803
  var rayDistance = localRay.intersectBox(boundingBox);
751
804
  if (rayDistance !== -1) {
752
805
  this._updateHitResult(localRay, rayDistance, hit, ray.origin);
@@ -756,10 +809,11 @@ var /**
756
809
  }
757
810
  };
758
811
  _proto._setBondingBox = function _setBondingBox() {
759
- var _this__transform = this._transform, center = _this__transform.position;
812
+ var position = this._transform.position;
813
+ var scale = this._worldScale;
760
814
  var halfSize = this._halfSize;
761
- Vector3.add(center, halfSize, this._boxMax);
762
- 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);
763
817
  };
764
818
  return LiteBoxColliderShape;
765
819
  }(LiteColliderShape);
@@ -769,11 +823,11 @@ var /**
769
823
 
770
824
  /**
771
825
  * Sphere collider shape in Lite.
772
- */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
773
- _inherits(LiteSphereColliderShape, LiteColliderShape);
826
+ */ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
827
+ _inherits(LiteSphereColliderShape, LiteColliderShape1);
774
828
  function LiteSphereColliderShape(uniqueID, radius, material) {
775
829
  var _this;
776
- _this = LiteColliderShape.call(this) || this;
830
+ _this = LiteColliderShape1.call(this) || this;
777
831
  _this._radius = 1;
778
832
  _this._maxScale = 1;
779
833
  _this._radius = radius;
@@ -789,6 +843,7 @@ var /**
789
843
  /**
790
844
  * {@inheritDoc IColliderShape.setWorldScale }
791
845
  */ _proto.setWorldScale = function setWorldScale(scale) {
846
+ LiteColliderShape1.prototype.setWorldScale.call(this, scale);
792
847
  this._maxScale = Math.max(scale.x, scale.y, scale.z);
793
848
  };
794
849
  /**
@@ -821,8 +876,8 @@ var /**
821
876
 
822
877
  /**
823
878
  * A manager is a collection of colliders and constraints which can interact.
824
- */ var LitePhysicsManager = /*#__PURE__*/ function() {
825
- function LitePhysicsManager(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
879
+ */ var LitePhysicsScene = /*#__PURE__*/ function() {
880
+ function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
826
881
  this._colliders = [];
827
882
  this._sphere = new BoundingSphere();
828
883
  this._box = new BoundingBox();
@@ -836,7 +891,7 @@ var /**
836
891
  this._onTriggerExit = onTriggerExit;
837
892
  this._onTriggerStay = onTriggerStay;
838
893
  }
839
- var _proto = LitePhysicsManager.prototype;
894
+ var _proto = LitePhysicsScene.prototype;
840
895
  /**
841
896
  * {@inheritDoc IPhysicsManager.setGravity }
842
897
  */ _proto.setGravity = function setGravity(value) {
@@ -889,23 +944,25 @@ var /**
889
944
  var colliders = this._colliders;
890
945
  var hitResult;
891
946
  if (hit) {
892
- hitResult = LitePhysicsManager._hitResult;
947
+ hitResult = LitePhysicsScene._hitResult;
893
948
  }
894
949
  var isHit = false;
895
- var curHit = LitePhysicsManager._currentHit;
950
+ var curHit = LitePhysicsScene._currentHit;
896
951
  for(var i = 0, len = colliders.length; i < len; i++){
897
952
  var collider = colliders[i];
898
- if (collider._raycast(ray, onRaycast, curHit) && curHit.distance < distance) {
953
+ if (collider._raycast(ray, onRaycast, curHit)) {
899
954
  isHit = true;
900
- if (hitResult) {
901
- hitResult.normal.copyFrom(curHit.normal);
902
- hitResult.point.copyFrom(curHit.point);
903
- hitResult.distance = curHit.distance;
904
- hitResult.shapeID = curHit.shapeID;
905
- } else {
906
- return true;
955
+ if (curHit.distance < distance) {
956
+ if (hitResult) {
957
+ hitResult.normal.copyFrom(curHit.normal);
958
+ hitResult.point.copyFrom(curHit.point);
959
+ hitResult.distance = curHit.distance;
960
+ hitResult.shapeID = curHit.shapeID;
961
+ } else {
962
+ return true;
963
+ }
964
+ distance = curHit.distance;
907
965
  }
908
- distance = curHit.distance;
909
966
  }
910
967
  }
911
968
  if (!isHit && hitResult) {
@@ -946,7 +1003,7 @@ var /**
946
1003
  for(var i = 0, len = myColliderShapes.length; i < len; i++){
947
1004
  var myShape = myColliderShapes[i];
948
1005
  if (_instanceof(myShape, LiteBoxColliderShape)) {
949
- LitePhysicsManager._updateWorldBox(myShape, this._box);
1006
+ LitePhysicsScene._updateWorldBox(myShape, this._box);
950
1007
  for(var j = 0, len1 = colliders.length; j < len1; j++){
951
1008
  var colliderShape = colliders[j]._shapes;
952
1009
  for(var k = 0, len2 = colliderShape.length; k < len2; k++){
@@ -973,7 +1030,7 @@ var /**
973
1030
  }
974
1031
  }
975
1032
  } else if (_instanceof(myShape, LiteSphereColliderShape)) {
976
- LitePhysicsManager._upWorldSphere(myShape, this._sphere);
1033
+ LitePhysicsScene._upWorldSphere(myShape, this._sphere);
977
1034
  for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
978
1035
  var colliderShape1 = colliders[j1]._shapes;
979
1036
  for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
@@ -1025,24 +1082,24 @@ var /**
1025
1082
  };
1026
1083
  _proto._boxCollision = function _boxCollision(other) {
1027
1084
  if (_instanceof(other, LiteBoxColliderShape)) {
1028
- var box = LitePhysicsManager._tempBox;
1029
- LitePhysicsManager._updateWorldBox(other, box);
1085
+ var box = LitePhysicsScene._tempBox;
1086
+ LitePhysicsScene._updateWorldBox(other, box);
1030
1087
  return CollisionUtil.intersectsBoxAndBox(box, this._box);
1031
1088
  } else if (_instanceof(other, LiteSphereColliderShape)) {
1032
- var sphere = LitePhysicsManager._tempSphere;
1033
- LitePhysicsManager._upWorldSphere(other, sphere);
1089
+ var sphere = LitePhysicsScene._tempSphere;
1090
+ LitePhysicsScene._upWorldSphere(other, sphere);
1034
1091
  return CollisionUtil.intersectsSphereAndBox(sphere, this._box);
1035
1092
  }
1036
1093
  return false;
1037
1094
  };
1038
1095
  _proto._sphereCollision = function _sphereCollision(other) {
1039
1096
  if (_instanceof(other, LiteBoxColliderShape)) {
1040
- var box = LitePhysicsManager._tempBox;
1041
- LitePhysicsManager._updateWorldBox(other, box);
1097
+ var box = LitePhysicsScene._tempBox;
1098
+ LitePhysicsScene._updateWorldBox(other, box);
1042
1099
  return CollisionUtil.intersectsSphereAndBox(this._sphere, box);
1043
1100
  } else if (_instanceof(other, LiteSphereColliderShape)) {
1044
- var sphere = LitePhysicsManager._tempSphere;
1045
- LitePhysicsManager._upWorldSphere(other, sphere);
1101
+ var sphere = LitePhysicsScene._tempSphere;
1102
+ LitePhysicsScene._upWorldSphere(other, sphere);
1046
1103
  return CollisionUtil.intersectsSphereAndSphere(sphere, this._sphere);
1047
1104
  }
1048
1105
  return false;
@@ -1051,7 +1108,7 @@ var /**
1051
1108
  * Calculate the bounding box in world space from boxCollider.
1052
1109
  * @param boxCollider - The boxCollider to calculate
1053
1110
  * @param out - The calculated boundingBox
1054
- */ LitePhysicsManager._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1111
+ */ LitePhysicsScene._updateWorldBox = function _updateWorldBox(boxCollider, out) {
1055
1112
  var mat = boxCollider._transform.worldMatrix;
1056
1113
  out.min.copyFrom(boxCollider._boxMin);
1057
1114
  out.max.copyFrom(boxCollider._boxMax);
@@ -1061,23 +1118,23 @@ var /**
1061
1118
  * Get the sphere info of the given sphere collider in world space.
1062
1119
  * @param sphereCollider - The given sphere collider
1063
1120
  * @param out - The calculated boundingSphere
1064
- */ LitePhysicsManager._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1121
+ */ LitePhysicsScene._upWorldSphere = function _upWorldSphere(sphereCollider, out) {
1065
1122
  Vector3.transformCoordinate(sphereCollider._transform.position, sphereCollider._transform.worldMatrix, out.center);
1066
1123
  out.radius = sphereCollider.worldRadius;
1067
1124
  };
1068
- return LitePhysicsManager;
1125
+ return LitePhysicsScene;
1069
1126
  }();
1070
1127
  (function() {
1071
- LitePhysicsManager._tempSphere = new BoundingSphere();
1128
+ LitePhysicsScene._tempSphere = new BoundingSphere();
1072
1129
  })();
1073
1130
  (function() {
1074
- LitePhysicsManager._tempBox = new BoundingBox();
1131
+ LitePhysicsScene._tempBox = new BoundingBox();
1075
1132
  })();
1076
1133
  (function() {
1077
- LitePhysicsManager._currentHit = new LiteHitResult();
1134
+ LitePhysicsScene._currentHit = new LiteHitResult();
1078
1135
  })();
1079
1136
  (function() {
1080
- LitePhysicsManager._hitResult = new LiteHitResult();
1137
+ LitePhysicsScene._hitResult = new LiteHitResult();
1081
1138
  })();
1082
1139
  var /**
1083
1140
  * Physics state
@@ -1095,50 +1152,14 @@ var /**
1095
1152
  this.index2 = index2;
1096
1153
  };
1097
1154
 
1098
- /**
1099
- * Physics material describes how to handle colliding objects (friction, bounciness).
1100
- */ var LitePhysicsMaterial = /*#__PURE__*/ function() {
1101
- function LitePhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {}
1102
- var _proto = LitePhysicsMaterial.prototype;
1103
- /**
1104
- * {@inheritDoc IPhysicsMaterial.setBounciness }
1105
- */ _proto.setBounciness = function setBounciness(value) {
1106
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1107
- };
1108
- /**
1109
- * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
1110
- */ _proto.setDynamicFriction = function setDynamicFriction(value) {
1111
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1112
- };
1113
- /**
1114
- * {@inheritDoc IPhysicsMaterial.setStaticFriction }
1115
- */ _proto.setStaticFriction = function setStaticFriction(value) {
1116
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1117
- };
1118
- /**
1119
- * {@inheritDoc IPhysicsMaterial.setBounceCombine }
1120
- */ _proto.setBounceCombine = function setBounceCombine(value) {
1121
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1122
- };
1123
- /**
1124
- * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
1125
- */ _proto.setFrictionCombine = function setFrictionCombine(value) {
1126
- throw "Physics-lite don't support physics material. Use Physics-PhysX instead!";
1127
- };
1128
- /**
1129
- * {@inheritDoc IPhysicsMaterial.destroy }
1130
- */ _proto.destroy = function destroy() {};
1131
- return LitePhysicsMaterial;
1132
- }();
1133
-
1134
1155
  /**
1135
1156
  * A static collider component that will not move.
1136
1157
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1137
- */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
1138
- _inherits(LiteStaticCollider, LiteCollider);
1158
+ */ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider1) {
1159
+ _inherits(LiteStaticCollider, LiteCollider1);
1139
1160
  function LiteStaticCollider(position, rotation) {
1140
1161
  var _this;
1141
- _this = LiteCollider.call(this) || this;
1162
+ _this = LiteCollider1.call(this) || this;
1142
1163
  _this._transform.setPosition(position.x, position.y, position.z);
1143
1164
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1144
1165
  return _this;
@@ -1156,8 +1177,13 @@ var LitePhysics = /*#__PURE__*/ function() {
1156
1177
  };
1157
1178
  /**
1158
1179
  * {@inheritDoc IPhysics.createPhysicsManager }
1159
- */ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1160
- return new LitePhysicsManager(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1180
+ */ _proto.createPhysicsManager = function createPhysicsManager() {
1181
+ return null;
1182
+ };
1183
+ /**
1184
+ * {@inheritDoc IPhysics.createPhysicsScene }
1185
+ */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1186
+ return new LitePhysicsScene(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1161
1187
  };
1162
1188
  /**
1163
1189
  * {@inheritDoc IPhysics.createStaticCollider }
@@ -1217,5 +1243,9 @@ var LitePhysics = /*#__PURE__*/ function() {
1217
1243
  return LitePhysics;
1218
1244
  }();
1219
1245
 
1220
- export { LitePhysics };
1246
+ //@ts-ignore
1247
+ var version = "0.0.0-experimental-double11.5";
1248
+ console.log("Galacean PhysicsLite version: " + version);
1249
+
1250
+ export { LitePhysics, version };
1221
1251
  //# sourceMappingURL=module.js.map