@galacean/engine-core 2.0.0-alpha.18 → 2.0.0-alpha.19

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
@@ -13057,118 +13057,13 @@ __decorate([
13057
13057
  this._fixedTimeStep = 1 / 60;
13058
13058
  this._colliders = new DisorderedArray();
13059
13059
  this._gravity = new Vector3(0, -9.81, 0);
13060
- this._onContactEnter = function(nativeCollision) {
13061
- var physicalObjectsMap = Engine._physicalObjectsMap;
13062
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
13063
- var shape1 = physicalObjectsMap[shape0Id];
13064
- var shape2 = physicalObjectsMap[shape1Id];
13065
- var collision = PhysicsScene._collision;
13066
- collision._nativeCollision = nativeCollision;
13067
- shape1.collider.entity._scripts.forEach(function(element) {
13068
- collision.shape = shape2;
13069
- element.onCollisionEnter(collision);
13070
- }, function(element, index) {
13071
- element._entityScriptsIndex = index;
13072
- });
13073
- shape2.collider.entity._scripts.forEach(function(element) {
13074
- collision.shape = shape1;
13075
- element.onCollisionEnter(collision);
13076
- }, function(element, index) {
13077
- element._entityScriptsIndex = index;
13078
- });
13079
- };
13080
- this._onContactExit = function(nativeCollision) {
13081
- var physicalObjectsMap = Engine._physicalObjectsMap;
13082
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
13083
- var shape1 = physicalObjectsMap[shape0Id];
13084
- var shape2 = physicalObjectsMap[shape1Id];
13085
- var collision = PhysicsScene._collision;
13086
- collision._nativeCollision = nativeCollision;
13087
- shape1.collider.entity._scripts.forEach(function(element) {
13088
- collision.shape = shape2;
13089
- element.onCollisionExit(collision);
13090
- }, function(element, index) {
13091
- element._entityScriptsIndex = index;
13092
- });
13093
- shape2.collider.entity._scripts.forEach(function(element) {
13094
- collision.shape = shape1;
13095
- element.onCollisionExit(collision);
13096
- }, function(element, index) {
13097
- element._entityScriptsIndex = index;
13098
- });
13099
- };
13100
- this._onContactStay = function(nativeCollision) {
13101
- var physicalObjectsMap = Engine._physicalObjectsMap;
13102
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
13103
- var shape1 = physicalObjectsMap[shape0Id];
13104
- var shape2 = physicalObjectsMap[shape1Id];
13105
- var collision = PhysicsScene._collision;
13106
- collision._nativeCollision = nativeCollision;
13107
- shape1.collider.entity._scripts.forEach(function(element) {
13108
- collision.shape = shape2;
13109
- element.onCollisionStay(collision);
13110
- }, function(element, index) {
13111
- element._entityScriptsIndex = index;
13112
- });
13113
- shape2.collider.entity._scripts.forEach(function(element) {
13114
- collision.shape = shape1;
13115
- element.onCollisionStay(collision);
13116
- }, function(element, index) {
13117
- element._entityScriptsIndex = index;
13118
- });
13119
- };
13120
- this._onTriggerEnter = function(obj1, obj2) {
13121
- var physicalObjectsMap = Engine._physicalObjectsMap;
13122
- var shape1 = physicalObjectsMap[obj1];
13123
- var shape2 = physicalObjectsMap[obj2];
13124
- shape1.collider.entity._scripts.forEach(function(element) {
13125
- element.onTriggerEnter(shape2);
13126
- }, function(element, index) {
13127
- element._entityScriptsIndex = index;
13128
- });
13129
- shape2.collider.entity._scripts.forEach(function(element) {
13130
- element.onTriggerEnter(shape1);
13131
- }, function(element, index) {
13132
- element._entityScriptsIndex = index;
13133
- });
13134
- };
13135
- this._onTriggerExit = function(obj1, obj2) {
13136
- var physicalObjectsMap = Engine._physicalObjectsMap;
13137
- var shape1 = physicalObjectsMap[obj1];
13138
- var shape2 = physicalObjectsMap[obj2];
13139
- shape1.collider.entity._scripts.forEach(function(element) {
13140
- element.onTriggerExit(shape2);
13141
- }, function(element, index) {
13142
- element._entityScriptsIndex = index;
13143
- });
13144
- shape2.collider.entity._scripts.forEach(function(element) {
13145
- element.onTriggerExit(shape1);
13146
- }, function(element, index) {
13147
- element._entityScriptsIndex = index;
13148
- });
13149
- };
13150
- this._onTriggerStay = function(obj1, obj2) {
13151
- var physicalObjectsMap = Engine._physicalObjectsMap;
13152
- var shape1 = physicalObjectsMap[obj1];
13153
- var shape2 = physicalObjectsMap[obj2];
13154
- shape1.collider.entity._scripts.forEach(function(element) {
13155
- element.onTriggerStay(shape2);
13156
- }, function(element, index) {
13157
- element._entityScriptsIndex = index;
13158
- });
13159
- shape2.collider.entity._scripts.forEach(function(element) {
13160
- element.onTriggerStay(shape1);
13161
- }, function(element, index) {
13162
- element._entityScriptsIndex = index;
13163
- });
13164
- };
13165
13060
  this._scene = scene;
13166
13061
  this._setGravity = this._setGravity.bind(this);
13167
13062
  //@ts-ignore
13168
13063
  this._gravity._onValueChanged = this._setGravity;
13169
13064
  var engine = scene.engine;
13170
13065
  if (engine._physicsInitialized) {
13171
- this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
13066
+ this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager);
13172
13067
  }
13173
13068
  }
13174
13069
  var _proto = PhysicsScene.prototype;
@@ -13380,6 +13275,7 @@ __decorate([
13380
13275
  this._callColliderOnUpdate();
13381
13276
  nativePhysicsManager.update(fixedTimeStep);
13382
13277
  this._callColliderOnLateUpdate();
13278
+ this._dispatchEvents(nativePhysicsManager.updateEvents());
13383
13279
  }
13384
13280
  };
13385
13281
  /**
@@ -13443,7 +13339,9 @@ __decorate([
13443
13339
  /**
13444
13340
  * @internal
13445
13341
  */ _proto._gc = function _gc() {
13342
+ var _this__nativePhysicsScene;
13446
13343
  this._colliders.garbageCollection();
13344
+ (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.gc();
13447
13345
  };
13448
13346
  /**
13449
13347
  * @internal
@@ -13451,6 +13349,92 @@ __decorate([
13451
13349
  var _this__nativePhysicsScene;
13452
13350
  (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.destroy();
13453
13351
  };
13352
+ _proto._dispatchEvents = function _dispatchEvents(events) {
13353
+ var _loop = function(i, n) {
13354
+ var _shape1_collider, _shape2_collider;
13355
+ var event = contactEvents[i];
13356
+ var shape1 = physicalObjectsMap[event.shape0Id];
13357
+ var shape2 = physicalObjectsMap[event.shape1Id];
13358
+ // entity.destroy() is deferred, so shapes/colliders stay valid through the dispatch loop
13359
+ // This guard covers synchronous removeShape()/clearShapes() which sets shape._collider = null
13360
+ if (!(shape1 == null ? void 0 : (_shape1_collider = shape1.collider) == null ? void 0 : _shape1_collider.entity) || !(shape2 == null ? void 0 : (_shape2_collider = shape2.collider) == null ? void 0 : _shape2_collider.entity)) return "continue";
13361
+ collision._nativeCollision = event;
13362
+ switch(event.state){
13363
+ case 0:
13364
+ shape1.collider.entity._scripts.forEach(function(element) {
13365
+ collision.shape = shape2;
13366
+ element.onCollisionEnter(collision);
13367
+ }, scriptIndexSetter);
13368
+ shape2.collider.entity._scripts.forEach(function(element) {
13369
+ collision.shape = shape1;
13370
+ element.onCollisionEnter(collision);
13371
+ }, scriptIndexSetter);
13372
+ break;
13373
+ case 1:
13374
+ shape1.collider.entity._scripts.forEach(function(element) {
13375
+ collision.shape = shape2;
13376
+ element.onCollisionStay(collision);
13377
+ }, scriptIndexSetter);
13378
+ shape2.collider.entity._scripts.forEach(function(element) {
13379
+ collision.shape = shape1;
13380
+ element.onCollisionStay(collision);
13381
+ }, scriptIndexSetter);
13382
+ break;
13383
+ case 2:
13384
+ shape1.collider.entity._scripts.forEach(function(element) {
13385
+ collision.shape = shape2;
13386
+ element.onCollisionExit(collision);
13387
+ }, scriptIndexSetter);
13388
+ shape2.collider.entity._scripts.forEach(function(element) {
13389
+ collision.shape = shape1;
13390
+ element.onCollisionExit(collision);
13391
+ }, scriptIndexSetter);
13392
+ break;
13393
+ }
13394
+ }, _loop1 = function(i1, n1) {
13395
+ var _shape1_collider, _shape2_collider;
13396
+ var event = triggerEvents[i1];
13397
+ var shape1 = physicalObjectsMap[event.index1];
13398
+ var shape2 = physicalObjectsMap[event.index2];
13399
+ // entity.destroy() is deferred, so shapes/colliders stay valid through the dispatch loop
13400
+ // This guard covers synchronous removeShape()/clearShapes() which sets shape._collider = null
13401
+ if (!(shape1 == null ? void 0 : (_shape1_collider = shape1.collider) == null ? void 0 : _shape1_collider.entity) || !(shape2 == null ? void 0 : (_shape2_collider = shape2.collider) == null ? void 0 : _shape2_collider.entity)) return "continue";
13402
+ switch(event.dispatchState){
13403
+ case 0:
13404
+ shape1.collider.entity._scripts.forEach(function(element) {
13405
+ element.onTriggerEnter(shape2);
13406
+ }, scriptIndexSetter);
13407
+ shape2.collider.entity._scripts.forEach(function(element) {
13408
+ element.onTriggerEnter(shape1);
13409
+ }, scriptIndexSetter);
13410
+ break;
13411
+ case 1:
13412
+ shape1.collider.entity._scripts.forEach(function(element) {
13413
+ element.onTriggerStay(shape2);
13414
+ }, scriptIndexSetter);
13415
+ shape2.collider.entity._scripts.forEach(function(element) {
13416
+ element.onTriggerStay(shape1);
13417
+ }, scriptIndexSetter);
13418
+ break;
13419
+ case 2:
13420
+ shape1.collider.entity._scripts.forEach(function(element) {
13421
+ element.onTriggerExit(shape2);
13422
+ }, scriptIndexSetter);
13423
+ shape2.collider.entity._scripts.forEach(function(element) {
13424
+ element.onTriggerExit(shape1);
13425
+ }, scriptIndexSetter);
13426
+ break;
13427
+ }
13428
+ };
13429
+ var physicalObjectsMap = Engine._physicalObjectsMap;
13430
+ var collision = PhysicsScene._collision;
13431
+ var scriptIndexSetter = PhysicsScene._scriptIndexSetter;
13432
+ var contactEvents = events.contactEvents, contactEventCount = events.contactEventCount, triggerEvents = events.triggerEvents;
13433
+ // Dispatch contact events
13434
+ for(var i = 0, n = contactEventCount; i < n; i++)_loop(i);
13435
+ // Dispatch trigger events
13436
+ for(var i1 = 0, n1 = triggerEvents.length; i1 < n1; i1++)_loop1(i1);
13437
+ };
13454
13438
  _proto._setGravity = function _setGravity() {
13455
13439
  this._nativePhysicsScene.setGravity(this._gravity);
13456
13440
  };
@@ -13510,6 +13494,9 @@ __decorate([
13510
13494
  }();
13511
13495
  PhysicsScene._collision = new Collision();
13512
13496
  PhysicsScene._identityQuaternion = new Quaternion(0, 0, 0, 1);
13497
+ PhysicsScene._scriptIndexSetter = function(element, index) {
13498
+ element._entityScriptsIndex = index;
13499
+ };
13513
13500
 
13514
13501
  /**
13515
13502
  * A static collider component that will not move.
@@ -27102,6 +27089,11 @@ ShaderPool.init();
27102
27089
  this._textSubRenderElementPool.garbageCollection();
27103
27090
  this._renderElementPool.garbageCollection();
27104
27091
  this._renderContext.garbageCollection();
27092
+ var scenes = this._sceneManager._scenes.getLoopArray();
27093
+ for(var i = 0, n = scenes.length; i < n; i++){
27094
+ var _scenes_i_physics, _scenes_i;
27095
+ (_scenes_i = scenes[i]) == null ? void 0 : (_scenes_i_physics = _scenes_i.physics) == null ? void 0 : _scenes_i_physics._gc();
27096
+ }
27105
27097
  };
27106
27098
  _create_class(Engine, [
27107
27099
  {