@galacean/engine-physics-lite 1.2.0-beta.6 → 1.3.0-alpha.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.
@@ -566,6 +566,7 @@ var /**
566
566
  function LiteDynamicCollider(position, rotation) {
567
567
  var _this;
568
568
  _this = LiteCollider1.call(this) || this;
569
+ /** @internal */ _this._isStaticCollider = false;
569
570
  _this._transform.setPosition(position.x, position.y, position.z);
570
571
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
571
572
  return _this;
@@ -884,7 +885,8 @@ var /**
884
885
  * A manager is a collection of colliders and constraints which can interact.
885
886
  */ var LitePhysicsScene = /*#__PURE__*/ function() {
886
887
  function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
887
- this._colliders = [];
888
+ this._staticColliders = [];
889
+ this._dynamicColliders = [];
888
890
  this._sphere = new miniprogram.BoundingSphere();
889
891
  this._box = new miniprogram.BoundingBox();
890
892
  this._currentEvents = new DisorderedArray();
@@ -930,61 +932,49 @@ var /**
930
932
  /**
931
933
  * {@inheritDoc IPhysicsManager.addCollider }
932
934
  */ _proto.addCollider = function addCollider(actor) {
933
- this._colliders.push(actor);
935
+ var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
936
+ colliders.push(actor);
934
937
  };
935
938
  /**
936
939
  * {@inheritDoc IPhysicsManager.removeCollider }
937
940
  */ _proto.removeCollider = function removeCollider(collider) {
938
- var index = this._colliders.indexOf(collider);
941
+ var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
942
+ var index = colliders.indexOf(collider);
939
943
  if (index !== -1) {
940
- this._colliders.splice(index, 1);
944
+ colliders.splice(index, 1);
941
945
  }
942
946
  };
943
947
  /**
944
948
  * {@inheritDoc IPhysicsManager.update }
945
949
  */ _proto.update = function update(deltaTime) {
946
- var colliders = this._colliders;
947
- for(var i = 0, len = colliders.length; i < len; i++){
948
- this._collisionDetection(deltaTime, colliders[i]);
950
+ var dynamicColliders = this._dynamicColliders;
951
+ for(var i = 0, len = dynamicColliders.length; i < len; i++){
952
+ var collider = dynamicColliders[i];
953
+ this._collisionDetection(collider, this._staticColliders);
954
+ this._collisionDetection(collider, dynamicColliders);
949
955
  }
950
956
  this._fireEvent();
951
957
  };
952
958
  /**
953
959
  * {@inheritDoc IPhysicsManager.raycast }
954
960
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
955
- var colliders = this._colliders;
956
- var hitResult;
957
- if (hit) {
958
- hitResult = LitePhysicsScene._hitResult;
959
- }
960
- var isHit = false;
961
- var curHit = LitePhysicsScene._currentHit;
962
- for(var i = 0, len = colliders.length; i < len; i++){
963
- var collider = colliders[i];
964
- if (collider._raycast(ray, onRaycast, curHit)) {
965
- isHit = true;
966
- if (curHit.distance < distance) {
967
- if (hitResult) {
968
- hitResult.normal.copyFrom(curHit.normal);
969
- hitResult.point.copyFrom(curHit.point);
970
- hitResult.distance = curHit.distance;
971
- hitResult.shapeID = curHit.shapeID;
972
- } else {
973
- return true;
974
- }
975
- distance = curHit.distance;
976
- }
961
+ if (!hit) {
962
+ return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
963
+ } else {
964
+ var raycastStaticRes = this._raycast(ray, distance, onRaycast, this._staticColliders, hit);
965
+ var raycastDynamicRes = this._raycast(ray, LitePhysicsScene._currentHit.distance, onRaycast, this._dynamicColliders, hit);
966
+ var isHit = raycastStaticRes || raycastDynamicRes;
967
+ var hitResult = LitePhysicsScene._hitResult;
968
+ if (!isHit) {
969
+ hitResult.shapeID = -1;
970
+ hitResult.distance = 0;
971
+ hitResult.point.set(0, 0, 0);
972
+ hitResult.normal.set(0, 0, 0);
973
+ } else {
974
+ hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
977
975
  }
976
+ return isHit;
978
977
  }
979
- if (!isHit && hitResult) {
980
- hitResult.shapeID = -1;
981
- hitResult.distance = 0;
982
- hitResult.point.set(0, 0, 0);
983
- hitResult.normal.set(0, 0, 0);
984
- } else if (isHit && hitResult) {
985
- hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
986
- }
987
- return isHit;
988
978
  };
989
979
  /**
990
980
  * {@inheritDoc IPhysicsManager.addCharacterController }
@@ -1008,8 +998,7 @@ var /**
1008
998
  this._eventMap[index1][index2] = event;
1009
999
  return event;
1010
1000
  };
1011
- _proto._collisionDetection = function _collisionDetection(deltaTime, myCollider) {
1012
- var colliders = this._colliders;
1001
+ _proto._collisionDetection = function _collisionDetection(myCollider, colliders) {
1013
1002
  var myColliderShapes = myCollider._shapes;
1014
1003
  for(var i = 0, len = myColliderShapes.length; i < len; i++){
1015
1004
  var myShape = myColliderShapes[i];
@@ -1115,6 +1104,32 @@ var /**
1115
1104
  }
1116
1105
  return false;
1117
1106
  };
1107
+ _proto._raycast = function _raycast(ray, distance, onRaycast, colliders, hit) {
1108
+ var hitResult;
1109
+ if (hit) {
1110
+ hitResult = LitePhysicsScene._hitResult;
1111
+ }
1112
+ var isHit = false;
1113
+ var curHit = LitePhysicsScene._currentHit;
1114
+ for(var i = 0, len = colliders.length; i < len; i++){
1115
+ var collider = colliders[i];
1116
+ if (collider._raycast(ray, onRaycast, curHit)) {
1117
+ isHit = true;
1118
+ if (curHit.distance < distance) {
1119
+ if (hitResult) {
1120
+ hitResult.normal.copyFrom(curHit.normal);
1121
+ hitResult.point.copyFrom(curHit.point);
1122
+ hitResult.distance = curHit.distance;
1123
+ hitResult.shapeID = curHit.shapeID;
1124
+ } else {
1125
+ return true;
1126
+ }
1127
+ distance = curHit.distance;
1128
+ }
1129
+ }
1130
+ }
1131
+ return isHit;
1132
+ };
1118
1133
  /**
1119
1134
  * Calculate the bounding box in world space from boxCollider.
1120
1135
  * @param boxCollider - The boxCollider to calculate
@@ -1171,6 +1186,7 @@ var /**
1171
1186
  function LiteStaticCollider(position, rotation) {
1172
1187
  var _this;
1173
1188
  _this = LiteCollider1.call(this) || this;
1189
+ /** @internal */ _this._isStaticCollider = true;
1174
1190
  _this._transform.setPosition(position.x, position.y, position.z);
1175
1191
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1176
1192
  return _this;
@@ -1255,7 +1271,7 @@ var LitePhysics = /*#__PURE__*/ function() {
1255
1271
  }();
1256
1272
 
1257
1273
  //@ts-ignore
1258
- var version = "1.2.0-beta.6";
1274
+ var version = "1.3.0-alpha.0";
1259
1275
  console.log("Galacean PhysicsLite version: " + version);
1260
1276
 
1261
1277
  exports.LitePhysics = LitePhysics;
package/dist/module.js CHANGED
@@ -562,6 +562,7 @@ var /**
562
562
  function LiteDynamicCollider(position, rotation) {
563
563
  var _this;
564
564
  _this = LiteCollider1.call(this) || this;
565
+ /** @internal */ _this._isStaticCollider = false;
565
566
  _this._transform.setPosition(position.x, position.y, position.z);
566
567
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
567
568
  return _this;
@@ -880,7 +881,8 @@ var /**
880
881
  * A manager is a collection of colliders and constraints which can interact.
881
882
  */ var LitePhysicsScene = /*#__PURE__*/ function() {
882
883
  function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
883
- this._colliders = [];
884
+ this._staticColliders = [];
885
+ this._dynamicColliders = [];
884
886
  this._sphere = new BoundingSphere();
885
887
  this._box = new BoundingBox();
886
888
  this._currentEvents = new DisorderedArray();
@@ -926,61 +928,49 @@ var /**
926
928
  /**
927
929
  * {@inheritDoc IPhysicsManager.addCollider }
928
930
  */ _proto.addCollider = function addCollider(actor) {
929
- this._colliders.push(actor);
931
+ var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
932
+ colliders.push(actor);
930
933
  };
931
934
  /**
932
935
  * {@inheritDoc IPhysicsManager.removeCollider }
933
936
  */ _proto.removeCollider = function removeCollider(collider) {
934
- var index = this._colliders.indexOf(collider);
937
+ var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
938
+ var index = colliders.indexOf(collider);
935
939
  if (index !== -1) {
936
- this._colliders.splice(index, 1);
940
+ colliders.splice(index, 1);
937
941
  }
938
942
  };
939
943
  /**
940
944
  * {@inheritDoc IPhysicsManager.update }
941
945
  */ _proto.update = function update(deltaTime) {
942
- var colliders = this._colliders;
943
- for(var i = 0, len = colliders.length; i < len; i++){
944
- this._collisionDetection(deltaTime, colliders[i]);
946
+ var dynamicColliders = this._dynamicColliders;
947
+ for(var i = 0, len = dynamicColliders.length; i < len; i++){
948
+ var collider = dynamicColliders[i];
949
+ this._collisionDetection(collider, this._staticColliders);
950
+ this._collisionDetection(collider, dynamicColliders);
945
951
  }
946
952
  this._fireEvent();
947
953
  };
948
954
  /**
949
955
  * {@inheritDoc IPhysicsManager.raycast }
950
956
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
951
- var colliders = this._colliders;
952
- var hitResult;
953
- if (hit) {
954
- hitResult = LitePhysicsScene._hitResult;
955
- }
956
- var isHit = false;
957
- var curHit = LitePhysicsScene._currentHit;
958
- for(var i = 0, len = colliders.length; i < len; i++){
959
- var collider = colliders[i];
960
- if (collider._raycast(ray, onRaycast, curHit)) {
961
- isHit = true;
962
- if (curHit.distance < distance) {
963
- if (hitResult) {
964
- hitResult.normal.copyFrom(curHit.normal);
965
- hitResult.point.copyFrom(curHit.point);
966
- hitResult.distance = curHit.distance;
967
- hitResult.shapeID = curHit.shapeID;
968
- } else {
969
- return true;
970
- }
971
- distance = curHit.distance;
972
- }
957
+ if (!hit) {
958
+ return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
959
+ } else {
960
+ var raycastStaticRes = this._raycast(ray, distance, onRaycast, this._staticColliders, hit);
961
+ var raycastDynamicRes = this._raycast(ray, LitePhysicsScene._currentHit.distance, onRaycast, this._dynamicColliders, hit);
962
+ var isHit = raycastStaticRes || raycastDynamicRes;
963
+ var hitResult = LitePhysicsScene._hitResult;
964
+ if (!isHit) {
965
+ hitResult.shapeID = -1;
966
+ hitResult.distance = 0;
967
+ hitResult.point.set(0, 0, 0);
968
+ hitResult.normal.set(0, 0, 0);
969
+ } else {
970
+ hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
973
971
  }
972
+ return isHit;
974
973
  }
975
- if (!isHit && hitResult) {
976
- hitResult.shapeID = -1;
977
- hitResult.distance = 0;
978
- hitResult.point.set(0, 0, 0);
979
- hitResult.normal.set(0, 0, 0);
980
- } else if (isHit && hitResult) {
981
- hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
982
- }
983
- return isHit;
984
974
  };
985
975
  /**
986
976
  * {@inheritDoc IPhysicsManager.addCharacterController }
@@ -1004,8 +994,7 @@ var /**
1004
994
  this._eventMap[index1][index2] = event;
1005
995
  return event;
1006
996
  };
1007
- _proto._collisionDetection = function _collisionDetection(deltaTime, myCollider) {
1008
- var colliders = this._colliders;
997
+ _proto._collisionDetection = function _collisionDetection(myCollider, colliders) {
1009
998
  var myColliderShapes = myCollider._shapes;
1010
999
  for(var i = 0, len = myColliderShapes.length; i < len; i++){
1011
1000
  var myShape = myColliderShapes[i];
@@ -1111,6 +1100,32 @@ var /**
1111
1100
  }
1112
1101
  return false;
1113
1102
  };
1103
+ _proto._raycast = function _raycast(ray, distance, onRaycast, colliders, hit) {
1104
+ var hitResult;
1105
+ if (hit) {
1106
+ hitResult = LitePhysicsScene._hitResult;
1107
+ }
1108
+ var isHit = false;
1109
+ var curHit = LitePhysicsScene._currentHit;
1110
+ for(var i = 0, len = colliders.length; i < len; i++){
1111
+ var collider = colliders[i];
1112
+ if (collider._raycast(ray, onRaycast, curHit)) {
1113
+ isHit = true;
1114
+ if (curHit.distance < distance) {
1115
+ if (hitResult) {
1116
+ hitResult.normal.copyFrom(curHit.normal);
1117
+ hitResult.point.copyFrom(curHit.point);
1118
+ hitResult.distance = curHit.distance;
1119
+ hitResult.shapeID = curHit.shapeID;
1120
+ } else {
1121
+ return true;
1122
+ }
1123
+ distance = curHit.distance;
1124
+ }
1125
+ }
1126
+ }
1127
+ return isHit;
1128
+ };
1114
1129
  /**
1115
1130
  * Calculate the bounding box in world space from boxCollider.
1116
1131
  * @param boxCollider - The boxCollider to calculate
@@ -1167,6 +1182,7 @@ var /**
1167
1182
  function LiteStaticCollider(position, rotation) {
1168
1183
  var _this;
1169
1184
  _this = LiteCollider1.call(this) || this;
1185
+ /** @internal */ _this._isStaticCollider = true;
1170
1186
  _this._transform.setPosition(position.x, position.y, position.z);
1171
1187
  _this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
1172
1188
  return _this;
@@ -1251,7 +1267,7 @@ var LitePhysics = /*#__PURE__*/ function() {
1251
1267
  }();
1252
1268
 
1253
1269
  //@ts-ignore
1254
- var version = "1.2.0-beta.6";
1270
+ var version = "1.3.0-alpha.0";
1255
1271
  console.log("Galacean PhysicsLite version: " + version);
1256
1272
 
1257
1273
  export { LitePhysics, version };