@galacean/engine-physics-lite 2.0.0-alpha.2 → 2.0.0-alpha.21

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
@@ -912,21 +912,21 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
912
912
  /**
913
913
  * A manager is a collection of colliders and constraints which can interact.
914
914
  */ var LitePhysicsScene = /*#__PURE__*/ function() {
915
- function LitePhysicsScene(physics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
915
+ function LitePhysicsScene(physics) {
916
916
  this._staticColliders = [];
917
917
  this._dynamicColliders = [];
918
918
  this._sphere = new BoundingSphere();
919
919
  this._box = new BoundingBox();
920
- this._currentEvents = new DisorderedArray();
920
+ this._activeTriggers = new DisorderedArray();
921
921
  this._eventMap = {};
922
- this._eventPool = [];
922
+ this._triggerEventPool = [];
923
+ this._triggerEvents = [];
924
+ this._physicsEvents = {
925
+ contactEvents: [],
926
+ contactEventCount: 0,
927
+ triggerEvents: []
928
+ };
923
929
  this._physics = physics;
924
- this._onContactEnter = onContactEnter;
925
- this._onContactExit = onContactExit;
926
- this._onContactStay = onContactStay;
927
- this._onTriggerEnter = onTriggerEnter;
928
- this._onTriggerExit = onTriggerExit;
929
- this._onTriggerStay = onTriggerStay;
930
930
  }
931
931
  var _proto = LitePhysicsScene.prototype;
932
932
  _proto.overlapBox = function overlapBox(center, orientation, halfExtents, onOverlap, outHitResult) {
@@ -975,7 +975,29 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
975
975
  this._collisionDetection(collider, this._staticColliders);
976
976
  this._collisionDetection(collider, dynamicColliders);
977
977
  }
978
- this._fireEvent();
978
+ };
979
+ /**
980
+ * {@inheritDoc IPhysicsScene.updateEvents }
981
+ */ _proto.updateEvents = function updateEvents() {
982
+ var _this = this;
983
+ var _this1 = this, triggerEventPool = _this1._triggerEventPool, activeTriggers = _this1._activeTriggers, triggerEvents = _this1._triggerEvents, physicsEvents = _this1._physicsEvents;
984
+ triggerEvents.length = 0;
985
+ activeTriggers.forEach(function(event, i) {
986
+ if (!event.alreadyInvoked) {
987
+ event.dispatchState = event.state;
988
+ triggerEvents.push(event);
989
+ event.alreadyInvoked = true;
990
+ } else {
991
+ event.state = 2;
992
+ event.dispatchState = 2;
993
+ _this._eventMap[event.index1][event.index2] = undefined;
994
+ activeTriggers.deleteByIndex(i);
995
+ triggerEvents.push(event);
996
+ triggerEventPool.push(event);
997
+ }
998
+ });
999
+ physicsEvents.triggerEvents = triggerEvents;
1000
+ return physicsEvents;
979
1001
  };
980
1002
  /**
981
1003
  * {@inheritDoc IPhysicsScene.raycast }
@@ -1042,6 +1064,9 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1042
1064
  throw new Error("Physics-lite doesn't support overlapCapsuleAll. Use Physics-PhysX instead!");
1043
1065
  };
1044
1066
  /**
1067
+ * {@inheritDoc IPhysicsScene.gc }
1068
+ */ _proto.gc = function gc() {};
1069
+ /**
1045
1070
  * {@inheritDoc IPhysicsScene.destroy }
1046
1071
  */ _proto.destroy = function destroy() {};
1047
1072
  /**
@@ -1052,15 +1077,15 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1052
1077
  /**
1053
1078
  * @internal
1054
1079
  */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
1055
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents, eventMap = _this._eventMap;
1080
+ var _this = this, triggerEventPool = _this._triggerEventPool, activeTriggers = _this._activeTriggers, eventMap = _this._eventMap;
1056
1081
  var id = colliderShape._id;
1057
- currentEvents.forEach(function(event, i) {
1082
+ activeTriggers.forEach(function(event, i) {
1058
1083
  if (event.index1 == id) {
1059
- currentEvents.deleteByIndex(i);
1060
- eventPool.push(event);
1084
+ activeTriggers.deleteByIndex(i);
1085
+ triggerEventPool.push(event);
1061
1086
  } else if (event.index2 == id) {
1062
- currentEvents.deleteByIndex(i);
1063
- eventPool.push(event);
1087
+ activeTriggers.deleteByIndex(i);
1088
+ triggerEventPool.push(event);
1064
1089
  // If the shape is big index, should clear from the small index shape subMap
1065
1090
  eventMap[event.index1][id] = undefined;
1066
1091
  }
@@ -1069,8 +1094,8 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1069
1094
  };
1070
1095
  _proto._getTrigger = function _getTrigger(index1, index2) {
1071
1096
  var event;
1072
- if (this._eventPool.length) {
1073
- event = this._eventPool.pop();
1097
+ if (this._triggerEventPool.length) {
1098
+ event = this._triggerEventPool.pop();
1074
1099
  event.index1 = index1;
1075
1100
  event.index2 = index2;
1076
1101
  } else {
@@ -1105,7 +1130,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1105
1130
  var event1 = index1 < index2 ? this._getTrigger(index1, index2) : this._getTrigger(index2, index1);
1106
1131
  event1.state = 0;
1107
1132
  event1.alreadyInvoked = false;
1108
- this._currentEvents.add(event1);
1133
+ this._activeTriggers.add(event1);
1109
1134
  } else if (event.state === 0) {
1110
1135
  event.state = 1;
1111
1136
  event.alreadyInvoked = false;
@@ -1137,7 +1162,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1137
1162
  var event3 = index11 < index21 ? this._getTrigger(index11, index21) : this._getTrigger(index21, index11);
1138
1163
  event3.state = 0;
1139
1164
  event3.alreadyInvoked = false;
1140
- this._currentEvents.add(event3);
1165
+ this._activeTriggers.add(event3);
1141
1166
  } else if (event2.state === 0) {
1142
1167
  event2.state = 1;
1143
1168
  event2.alreadyInvoked = false;
@@ -1150,27 +1175,6 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
1150
1175
  }
1151
1176
  }
1152
1177
  };
1153
- _proto._fireEvent = function _fireEvent() {
1154
- var _this = this;
1155
- var _this1 = this, eventPool = _this1._eventPool, currentEvents = _this1._currentEvents;
1156
- currentEvents.forEach(function(event, i) {
1157
- if (!event.alreadyInvoked) {
1158
- if (event.state == 0) {
1159
- _this._onTriggerEnter(event.index1, event.index2);
1160
- event.alreadyInvoked = true;
1161
- } else if (event.state == 1) {
1162
- _this._onTriggerStay(event.index1, event.index2);
1163
- event.alreadyInvoked = true;
1164
- }
1165
- } else {
1166
- event.state = 2;
1167
- _this._eventMap[event.index1][event.index2] = undefined;
1168
- currentEvents.deleteByIndex(i);
1169
- _this._onTriggerExit(event.index1, event.index2);
1170
- eventPool.push(event);
1171
- }
1172
- });
1173
- };
1174
1178
  _proto._boxCollision = function _boxCollision(other) {
1175
1179
  if (_instanceof(other, LiteBoxColliderShape)) {
1176
1180
  var box = LitePhysicsScene._tempBox;
@@ -1286,8 +1290,8 @@ var LitePhysics = /*#__PURE__*/ function() {
1286
1290
  };
1287
1291
  /**
1288
1292
  * {@inheritDoc IPhysics.createPhysicsScene }
1289
- */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
1290
- return new LitePhysicsScene(this, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
1293
+ */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager) {
1294
+ return new LitePhysicsScene(this);
1291
1295
  };
1292
1296
  /**
1293
1297
  * {@inheritDoc IPhysics.createStaticCollider }
@@ -1331,7 +1335,7 @@ var LitePhysics = /*#__PURE__*/ function() {
1331
1335
  };
1332
1336
  /**
1333
1337
  * {@inheritDoc IPhysics.createMeshColliderShape }
1334
- */ _proto.createMeshColliderShape = function createMeshColliderShape(uniqueID, vertices, vertexCount, indices, isConvex, material) {
1338
+ */ _proto.createMeshColliderShape = function createMeshColliderShape(uniqueID, positions, indices, isConvex, material, cookingFlags) {
1335
1339
  throw new Error("Physics-lite doesn't support MeshColliderShape. Use Physics-PhysX instead!");
1336
1340
  };
1337
1341
  /**
@@ -1390,7 +1394,7 @@ var LitePhysics = /*#__PURE__*/ function() {
1390
1394
  }();
1391
1395
 
1392
1396
  //@ts-ignore
1393
- var version = "2.0.0-alpha.2";
1397
+ var version = "2.0.0-alpha.21";
1394
1398
  console.log("Galacean Engine Physics Lite Version: " + version);
1395
1399
 
1396
1400
  export { LitePhysics, version };