@galacean/engine-core 1.4.15 → 1.4.16

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/main.js CHANGED
@@ -2587,7 +2587,7 @@ var Utils = /*#__PURE__*/ function() {
2587
2587
  return relativeUrl;
2588
2588
  }
2589
2589
  if (!/^https?:/.test(baseUrl)) {
2590
- var fileSchema = "files://";
2590
+ var fileSchema = "file://";
2591
2591
  baseUrl = fileSchema + baseUrl;
2592
2592
  return new URL(relativeUrl, baseUrl).href.substring(fileSchema.length);
2593
2593
  }
@@ -20835,347 +20835,6 @@ exports.Collider = __decorate([
20835
20835
  dependentComponents(Transform, DependentMode.CheckOnly)
20836
20836
  ], exports.Collider);
20837
20837
 
20838
- /**
20839
- * Describes a contact point where the collision occurs.
20840
- */ var ContactPoint = function ContactPoint() {
20841
- /** The position of the contact point between the shapes, in world space. */ this.position = new engineMath.Vector3();
20842
- /** The normal of the contacting surfaces at the contact point. The normal direction points from the other shape to the self shape. */ this.normal = new engineMath.Vector3();
20843
- /** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */ this.impulse = new engineMath.Vector3();
20844
- };
20845
-
20846
- /**
20847
- * Collision information between two shapes when they collide.
20848
- */ var Collision = /*#__PURE__*/ function() {
20849
- function Collision() {}
20850
- var _proto = Collision.prototype;
20851
- /**
20852
- * Get contact points.
20853
- * @param outContacts - The result of contact points
20854
- * @returns The actual count of contact points
20855
- *
20856
- * @remarks To optimize performance, the engine does not modify the length of the array you pass.
20857
- * You need to obtain the actual number of contact points from the function's return value.
20858
- */ _proto.getContacts = function getContacts(outContacts) {
20859
- var nativeCollision = this._nativeCollision;
20860
- var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
20861
- var factor = this.shape.id === smallerShapeId ? 1 : -1;
20862
- var nativeContactPoints = nativeCollision.getContacts();
20863
- var length = nativeContactPoints.size();
20864
- for(var i = 0; i < length; i++){
20865
- var _outContacts, _i;
20866
- var nativeContractPoint = nativeContactPoints.get(i);
20867
- var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
20868
- contact.position.copyFrom(nativeContractPoint.position);
20869
- contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
20870
- contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
20871
- contact.separation = nativeContractPoint.separation;
20872
- }
20873
- return length;
20874
- };
20875
- _create_class(Collision, [
20876
- {
20877
- key: "contactCount",
20878
- get: /**
20879
- * Count of contact points.
20880
- */ function get() {
20881
- return this._nativeCollision.contactCount;
20882
- }
20883
- }
20884
- ]);
20885
- return Collision;
20886
- }();
20887
-
20888
- /**
20889
- * A physics scene is a collection of colliders and constraints which can interact.
20890
- */ var PhysicsScene = /*#__PURE__*/ function() {
20891
- function PhysicsScene(scene) {
20892
- this._restTime = 0;
20893
- this._fixedTimeStep = 1 / 60;
20894
- this._colliders = new DisorderedArray();
20895
- this._gravity = new engineMath.Vector3(0, -9.81, 0);
20896
- this._onContactEnter = function(nativeCollision) {
20897
- var physicalObjectsMap = Engine._physicalObjectsMap;
20898
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20899
- var shape1 = physicalObjectsMap[shape0Id];
20900
- var shape2 = physicalObjectsMap[shape1Id];
20901
- var collision = PhysicsScene._collision;
20902
- collision._nativeCollision = nativeCollision;
20903
- shape1.collider.entity._scripts.forEach(function(element) {
20904
- collision.shape = shape2;
20905
- element.onCollisionEnter(collision);
20906
- }, function(element, index) {
20907
- element._entityScriptsIndex = index;
20908
- });
20909
- shape2.collider.entity._scripts.forEach(function(element) {
20910
- collision.shape = shape1;
20911
- element.onCollisionEnter(collision);
20912
- }, function(element, index) {
20913
- element._entityScriptsIndex = index;
20914
- });
20915
- };
20916
- this._onContactExit = function(nativeCollision) {
20917
- var physicalObjectsMap = Engine._physicalObjectsMap;
20918
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20919
- var shape1 = physicalObjectsMap[shape0Id];
20920
- var shape2 = physicalObjectsMap[shape1Id];
20921
- var collision = PhysicsScene._collision;
20922
- collision._nativeCollision = nativeCollision;
20923
- shape1.collider.entity._scripts.forEach(function(element) {
20924
- collision.shape = shape2;
20925
- element.onCollisionExit(collision);
20926
- }, function(element, index) {
20927
- element._entityScriptsIndex = index;
20928
- });
20929
- shape2.collider.entity._scripts.forEach(function(element) {
20930
- collision.shape = shape1;
20931
- element.onCollisionExit(collision);
20932
- }, function(element, index) {
20933
- element._entityScriptsIndex = index;
20934
- });
20935
- };
20936
- this._onContactStay = function(nativeCollision) {
20937
- var physicalObjectsMap = Engine._physicalObjectsMap;
20938
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20939
- var shape1 = physicalObjectsMap[shape0Id];
20940
- var shape2 = physicalObjectsMap[shape1Id];
20941
- var collision = PhysicsScene._collision;
20942
- collision._nativeCollision = nativeCollision;
20943
- shape1.collider.entity._scripts.forEach(function(element) {
20944
- collision.shape = shape2;
20945
- element.onCollisionStay(collision);
20946
- }, function(element, index) {
20947
- element._entityScriptsIndex = index;
20948
- });
20949
- shape2.collider.entity._scripts.forEach(function(element) {
20950
- collision.shape = shape1;
20951
- element.onCollisionStay(collision);
20952
- }, function(element, index) {
20953
- element._entityScriptsIndex = index;
20954
- });
20955
- };
20956
- this._onTriggerEnter = function(obj1, obj2) {
20957
- var physicalObjectsMap = Engine._physicalObjectsMap;
20958
- var shape1 = physicalObjectsMap[obj1];
20959
- var shape2 = physicalObjectsMap[obj2];
20960
- shape1.collider.entity._scripts.forEach(function(element) {
20961
- element.onTriggerEnter(shape2);
20962
- }, function(element, index) {
20963
- element._entityScriptsIndex = index;
20964
- });
20965
- shape2.collider.entity._scripts.forEach(function(element) {
20966
- element.onTriggerEnter(shape1);
20967
- }, function(element, index) {
20968
- element._entityScriptsIndex = index;
20969
- });
20970
- };
20971
- this._onTriggerExit = function(obj1, obj2) {
20972
- var physicalObjectsMap = Engine._physicalObjectsMap;
20973
- var shape1 = physicalObjectsMap[obj1];
20974
- var shape2 = physicalObjectsMap[obj2];
20975
- shape1.collider.entity._scripts.forEach(function(element) {
20976
- element.onTriggerExit(shape2);
20977
- }, function(element, index) {
20978
- element._entityScriptsIndex = index;
20979
- });
20980
- shape2.collider.entity._scripts.forEach(function(element) {
20981
- element.onTriggerExit(shape1);
20982
- }, function(element, index) {
20983
- element._entityScriptsIndex = index;
20984
- });
20985
- };
20986
- this._onTriggerStay = function(obj1, obj2) {
20987
- var physicalObjectsMap = Engine._physicalObjectsMap;
20988
- var shape1 = physicalObjectsMap[obj1];
20989
- var shape2 = physicalObjectsMap[obj2];
20990
- shape1.collider.entity._scripts.forEach(function(element) {
20991
- element.onTriggerStay(shape2);
20992
- }, function(element, index) {
20993
- element._entityScriptsIndex = index;
20994
- });
20995
- shape2.collider.entity._scripts.forEach(function(element) {
20996
- element.onTriggerStay(shape1);
20997
- }, function(element, index) {
20998
- element._entityScriptsIndex = index;
20999
- });
21000
- };
21001
- this._scene = scene;
21002
- this._setGravity = this._setGravity.bind(this);
21003
- //@ts-ignore
21004
- this._gravity._onValueChanged = this._setGravity;
21005
- var engine = scene.engine;
21006
- if (engine._physicsInitialized) {
21007
- this._nativePhysicsScene = PhysicsScene._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
21008
- }
21009
- }
21010
- var _proto = PhysicsScene.prototype;
21011
- _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
21012
- var hitResult;
21013
- var distance = Number.MAX_VALUE;
21014
- if (typeof distanceOrResult === "number") {
21015
- distance = distanceOrResult;
21016
- } else if (distanceOrResult != undefined) {
21017
- hitResult = distanceOrResult;
21018
- }
21019
- var layerMask = Layer.Everything;
21020
- if (typeof layerMaskOrResult === "number") {
21021
- layerMask = layerMaskOrResult;
21022
- } else if (layerMaskOrResult != undefined) {
21023
- hitResult = layerMaskOrResult;
21024
- }
21025
- if (outHitResult) {
21026
- hitResult = outHitResult;
21027
- }
21028
- var onRaycast = function(obj) {
21029
- var shape = Engine._physicalObjectsMap[obj];
21030
- if (!shape) {
21031
- return false;
21032
- }
21033
- return shape.collider.entity.layer & layerMask && shape.isSceneQuery;
21034
- };
21035
- var outIDX;
21036
- var outDistance;
21037
- var outPosition;
21038
- var outNormal;
21039
- if (hitResult != undefined) {
21040
- var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
21041
- outIDX = idx;
21042
- outDistance = distance;
21043
- outPosition = position;
21044
- outNormal = normal;
21045
- });
21046
- if (result) {
21047
- var hitShape = Engine._physicalObjectsMap[outIDX];
21048
- hitResult.entity = hitShape._collider.entity;
21049
- hitResult.shape = hitShape;
21050
- hitResult.distance = outDistance;
21051
- hitResult.point.copyFrom(outPosition);
21052
- hitResult.normal.copyFrom(outNormal);
21053
- return true;
21054
- } else {
21055
- hitResult.entity = null;
21056
- hitResult.shape = null;
21057
- hitResult.distance = 0;
21058
- hitResult.point.set(0, 0, 0);
21059
- hitResult.normal.set(0, 0, 0);
21060
- return false;
21061
- }
21062
- } else {
21063
- return this._nativePhysicsScene.raycast(ray, distance, onRaycast);
21064
- }
21065
- };
21066
- /**
21067
- * Call on every frame to update pose of objects.
21068
- * @internal
21069
- */ _proto._update = function _update(deltaTime) {
21070
- var _this = this, fixedTimeStep = _this._fixedTimeStep, nativePhysicsManager = _this._nativePhysicsScene;
21071
- var componentsManager = this._scene._componentsManager;
21072
- var simulateTime = this._restTime + deltaTime;
21073
- var step = Math.floor(simulateTime / fixedTimeStep);
21074
- this._restTime = simulateTime - step * fixedTimeStep;
21075
- for(var i = 0; i < step; i++){
21076
- componentsManager.callScriptOnPhysicsUpdate();
21077
- this._callColliderOnUpdate();
21078
- nativePhysicsManager.update(fixedTimeStep);
21079
- this._callColliderOnLateUpdate();
21080
- }
21081
- };
21082
- /**
21083
- * Add collider into the manager.
21084
- * @param collider - StaticCollider or DynamicCollider.
21085
- * @internal
21086
- */ _proto._addCollider = function _addCollider(collider) {
21087
- if (collider._index === -1) {
21088
- collider._index = this._colliders.length;
21089
- this._colliders.add(collider);
21090
- }
21091
- this._nativePhysicsScene.addCollider(collider._nativeCollider);
21092
- };
21093
- /**
21094
- * Add character controller into the manager.
21095
- * @param controller - Character Controller.
21096
- * @internal
21097
- */ _proto._addCharacterController = function _addCharacterController(controller) {
21098
- if (controller._index === -1) {
21099
- controller._index = this._colliders.length;
21100
- this._colliders.add(controller);
21101
- }
21102
- this._nativePhysicsScene.addCharacterController(controller._nativeCollider);
21103
- };
21104
- /**
21105
- * Remove collider.
21106
- * @param collider - StaticCollider or DynamicCollider.
21107
- * @internal
21108
- */ _proto._removeCollider = function _removeCollider(collider) {
21109
- var replaced = this._colliders.deleteByIndex(collider._index);
21110
- replaced && (replaced._index = collider._index);
21111
- collider._index = -1;
21112
- this._nativePhysicsScene.removeCollider(collider._nativeCollider);
21113
- };
21114
- /**
21115
- * Remove collider.
21116
- * @param controller - Character Controller.
21117
- * @internal
21118
- */ _proto._removeCharacterController = function _removeCharacterController(controller) {
21119
- var replaced = this._colliders.deleteByIndex(controller._index);
21120
- replaced && (replaced._index = controller._index);
21121
- controller._index = -1;
21122
- this._nativePhysicsScene.removeCharacterController(controller._nativeCollider);
21123
- };
21124
- /**
21125
- * @internal
21126
- */ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
21127
- var elements = this._colliders._elements;
21128
- for(var i = this._colliders.length - 1; i >= 0; --i){
21129
- elements[i]._onUpdate();
21130
- }
21131
- };
21132
- /**
21133
- * @internal
21134
- */ _proto._callColliderOnLateUpdate = function _callColliderOnLateUpdate() {
21135
- var elements = this._colliders._elements;
21136
- for(var i = this._colliders.length - 1; i >= 0; --i){
21137
- elements[i]._onLateUpdate();
21138
- }
21139
- };
21140
- /**
21141
- * @internal
21142
- */ _proto._gc = function _gc() {
21143
- this._colliders.garbageCollection();
21144
- };
21145
- _proto._setGravity = function _setGravity() {
21146
- this._nativePhysicsScene.setGravity(this._gravity);
21147
- };
21148
- _create_class(PhysicsScene, [
21149
- {
21150
- key: "gravity",
21151
- get: /**
21152
- * The gravity of physics scene.
21153
- */ function get() {
21154
- return this._gravity;
21155
- },
21156
- set: function set(value) {
21157
- var gravity = this._gravity;
21158
- if (gravity !== value) {
21159
- gravity.copyFrom(value);
21160
- }
21161
- }
21162
- },
21163
- {
21164
- key: "fixedTimeStep",
21165
- get: /**
21166
- * The fixed time step in seconds at which physics are performed.
21167
- */ function get() {
21168
- return this._fixedTimeStep;
21169
- },
21170
- set: function set(value) {
21171
- this._fixedTimeStep = Math.max(value, engineMath.MathUtil.zeroTolerance);
21172
- }
21173
- }
21174
- ]);
21175
- return PhysicsScene;
21176
- }();
21177
- PhysicsScene._collision = new Collision();
21178
-
21179
20838
  /**
21180
20839
  * The up axis of the collider shape.
21181
20840
  */ var ControllerNonWalkableMode = /*#__PURE__*/ function(ControllerNonWalkableMode) {
@@ -21191,7 +20850,7 @@ PhysicsScene._collision = new Collision();
21191
20850
  function CharacterController(entity) {
21192
20851
  var _this;
21193
20852
  _this = Collider.call(this, entity) || this, _this._stepOffset = 0.5, _this._nonWalkableMode = ControllerNonWalkableMode.PreventClimbing, _this._upDirection = new engineMath.Vector3(0, 1, 0), _this._slopeLimit = 45;
21194
- _this._nativeCollider = PhysicsScene._nativePhysics.createCharacterController();
20853
+ _this._nativeCollider = Engine._nativePhysics.createCharacterController();
21195
20854
  _this._setUpDirection = _this._setUpDirection.bind(_this);
21196
20855
  //@ts-ignore
21197
20856
  _this._upDirection._onValueChanged = _this._setUpDirection;
@@ -21341,7 +21000,7 @@ __decorate([
21341
21000
  var _this;
21342
21001
  _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new engineMath.Vector3(), _this._angularVelocity = new engineMath.Vector3(), _this._mass = 1.0, _this._centerOfMass = new engineMath.Vector3(), _this._inertiaTensor = new engineMath.Vector3(1, 1, 1), _this._maxAngularVelocity = 18000 / Math.PI, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._useGravity = true, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
21343
21002
  var transform = _this.entity.transform;
21344
- _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
21003
+ _this._nativeCollider = Engine._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
21345
21004
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
21346
21005
  _this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
21347
21006
  _this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
@@ -21815,7 +21474,7 @@ __decorate([
21815
21474
  this._staticFriction = 0.6;
21816
21475
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
21817
21476
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
21818
- this._nativeMaterial = PhysicsScene._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
21477
+ this._nativeMaterial = Engine._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
21819
21478
  }
21820
21479
  var _proto = PhysicsMaterial.prototype;
21821
21480
  /**
@@ -21899,6 +21558,353 @@ __decorate([
21899
21558
  return PhysicsMaterial;
21900
21559
  }();
21901
21560
 
21561
+ /**
21562
+ * Describes a contact point where the collision occurs.
21563
+ */ var ContactPoint = function ContactPoint() {
21564
+ /** The position of the contact point between the shapes, in world space. */ this.position = new engineMath.Vector3();
21565
+ /** The normal of the contacting surfaces at the contact point. The normal direction points from the other shape to the self shape. */ this.normal = new engineMath.Vector3();
21566
+ /** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */ this.impulse = new engineMath.Vector3();
21567
+ };
21568
+
21569
+ /**
21570
+ * Collision information between two shapes when they collide.
21571
+ */ var Collision = /*#__PURE__*/ function() {
21572
+ function Collision() {}
21573
+ var _proto = Collision.prototype;
21574
+ /**
21575
+ * Get contact points.
21576
+ * @param outContacts - The result of contact points
21577
+ * @returns The actual count of contact points
21578
+ *
21579
+ * @remarks To optimize performance, the engine does not modify the length of the array you pass.
21580
+ * You need to obtain the actual number of contact points from the function's return value.
21581
+ */ _proto.getContacts = function getContacts(outContacts) {
21582
+ var nativeCollision = this._nativeCollision;
21583
+ var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
21584
+ var factor = this.shape.id === smallerShapeId ? 1 : -1;
21585
+ var nativeContactPoints = nativeCollision.getContacts();
21586
+ var length = nativeContactPoints.size();
21587
+ for(var i = 0; i < length; i++){
21588
+ var _outContacts, _i;
21589
+ var nativeContractPoint = nativeContactPoints.get(i);
21590
+ var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
21591
+ contact.position.copyFrom(nativeContractPoint.position);
21592
+ contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
21593
+ contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
21594
+ contact.separation = nativeContractPoint.separation;
21595
+ }
21596
+ return length;
21597
+ };
21598
+ _create_class(Collision, [
21599
+ {
21600
+ key: "contactCount",
21601
+ get: /**
21602
+ * Count of contact points.
21603
+ */ function get() {
21604
+ return this._nativeCollision.contactCount;
21605
+ }
21606
+ }
21607
+ ]);
21608
+ return Collision;
21609
+ }();
21610
+
21611
+ /**
21612
+ * A physics scene is a collection of colliders and constraints which can interact.
21613
+ */ var PhysicsScene = /*#__PURE__*/ function() {
21614
+ function PhysicsScene(scene) {
21615
+ this._restTime = 0;
21616
+ this._fixedTimeStep = 1 / 60;
21617
+ this._colliders = new DisorderedArray();
21618
+ this._gravity = new engineMath.Vector3(0, -9.81, 0);
21619
+ this._onContactEnter = function(nativeCollision) {
21620
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21621
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
21622
+ var shape1 = physicalObjectsMap[shape0Id];
21623
+ var shape2 = physicalObjectsMap[shape1Id];
21624
+ var collision = PhysicsScene._collision;
21625
+ collision._nativeCollision = nativeCollision;
21626
+ shape1.collider.entity._scripts.forEach(function(element) {
21627
+ collision.shape = shape2;
21628
+ element.onCollisionEnter(collision);
21629
+ }, function(element, index) {
21630
+ element._entityScriptsIndex = index;
21631
+ });
21632
+ shape2.collider.entity._scripts.forEach(function(element) {
21633
+ collision.shape = shape1;
21634
+ element.onCollisionEnter(collision);
21635
+ }, function(element, index) {
21636
+ element._entityScriptsIndex = index;
21637
+ });
21638
+ };
21639
+ this._onContactExit = function(nativeCollision) {
21640
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21641
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
21642
+ var shape1 = physicalObjectsMap[shape0Id];
21643
+ var shape2 = physicalObjectsMap[shape1Id];
21644
+ var collision = PhysicsScene._collision;
21645
+ collision._nativeCollision = nativeCollision;
21646
+ shape1.collider.entity._scripts.forEach(function(element) {
21647
+ collision.shape = shape2;
21648
+ element.onCollisionExit(collision);
21649
+ }, function(element, index) {
21650
+ element._entityScriptsIndex = index;
21651
+ });
21652
+ shape2.collider.entity._scripts.forEach(function(element) {
21653
+ collision.shape = shape1;
21654
+ element.onCollisionExit(collision);
21655
+ }, function(element, index) {
21656
+ element._entityScriptsIndex = index;
21657
+ });
21658
+ };
21659
+ this._onContactStay = function(nativeCollision) {
21660
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21661
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
21662
+ var shape1 = physicalObjectsMap[shape0Id];
21663
+ var shape2 = physicalObjectsMap[shape1Id];
21664
+ var collision = PhysicsScene._collision;
21665
+ collision._nativeCollision = nativeCollision;
21666
+ shape1.collider.entity._scripts.forEach(function(element) {
21667
+ collision.shape = shape2;
21668
+ element.onCollisionStay(collision);
21669
+ }, function(element, index) {
21670
+ element._entityScriptsIndex = index;
21671
+ });
21672
+ shape2.collider.entity._scripts.forEach(function(element) {
21673
+ collision.shape = shape1;
21674
+ element.onCollisionStay(collision);
21675
+ }, function(element, index) {
21676
+ element._entityScriptsIndex = index;
21677
+ });
21678
+ };
21679
+ this._onTriggerEnter = function(obj1, obj2) {
21680
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21681
+ var shape1 = physicalObjectsMap[obj1];
21682
+ var shape2 = physicalObjectsMap[obj2];
21683
+ shape1.collider.entity._scripts.forEach(function(element) {
21684
+ element.onTriggerEnter(shape2);
21685
+ }, function(element, index) {
21686
+ element._entityScriptsIndex = index;
21687
+ });
21688
+ shape2.collider.entity._scripts.forEach(function(element) {
21689
+ element.onTriggerEnter(shape1);
21690
+ }, function(element, index) {
21691
+ element._entityScriptsIndex = index;
21692
+ });
21693
+ };
21694
+ this._onTriggerExit = function(obj1, obj2) {
21695
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21696
+ var shape1 = physicalObjectsMap[obj1];
21697
+ var shape2 = physicalObjectsMap[obj2];
21698
+ shape1.collider.entity._scripts.forEach(function(element) {
21699
+ element.onTriggerExit(shape2);
21700
+ }, function(element, index) {
21701
+ element._entityScriptsIndex = index;
21702
+ });
21703
+ shape2.collider.entity._scripts.forEach(function(element) {
21704
+ element.onTriggerExit(shape1);
21705
+ }, function(element, index) {
21706
+ element._entityScriptsIndex = index;
21707
+ });
21708
+ };
21709
+ this._onTriggerStay = function(obj1, obj2) {
21710
+ var physicalObjectsMap = Engine._physicalObjectsMap;
21711
+ var shape1 = physicalObjectsMap[obj1];
21712
+ var shape2 = physicalObjectsMap[obj2];
21713
+ shape1.collider.entity._scripts.forEach(function(element) {
21714
+ element.onTriggerStay(shape2);
21715
+ }, function(element, index) {
21716
+ element._entityScriptsIndex = index;
21717
+ });
21718
+ shape2.collider.entity._scripts.forEach(function(element) {
21719
+ element.onTriggerStay(shape1);
21720
+ }, function(element, index) {
21721
+ element._entityScriptsIndex = index;
21722
+ });
21723
+ };
21724
+ this._scene = scene;
21725
+ this._setGravity = this._setGravity.bind(this);
21726
+ //@ts-ignore
21727
+ this._gravity._onValueChanged = this._setGravity;
21728
+ var engine = scene.engine;
21729
+ if (engine._physicsInitialized) {
21730
+ this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
21731
+ }
21732
+ }
21733
+ var _proto = PhysicsScene.prototype;
21734
+ _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
21735
+ var hitResult;
21736
+ var distance = Number.MAX_VALUE;
21737
+ if (typeof distanceOrResult === "number") {
21738
+ distance = distanceOrResult;
21739
+ } else if (distanceOrResult != undefined) {
21740
+ hitResult = distanceOrResult;
21741
+ }
21742
+ var layerMask = Layer.Everything;
21743
+ if (typeof layerMaskOrResult === "number") {
21744
+ layerMask = layerMaskOrResult;
21745
+ } else if (layerMaskOrResult != undefined) {
21746
+ hitResult = layerMaskOrResult;
21747
+ }
21748
+ if (outHitResult) {
21749
+ hitResult = outHitResult;
21750
+ }
21751
+ var onRaycast = function(obj) {
21752
+ var shape = Engine._physicalObjectsMap[obj];
21753
+ if (!shape) {
21754
+ return false;
21755
+ }
21756
+ return shape.collider.entity.layer & layerMask && shape.isSceneQuery;
21757
+ };
21758
+ var outIDX;
21759
+ var outDistance;
21760
+ var outPosition;
21761
+ var outNormal;
21762
+ if (hitResult != undefined) {
21763
+ var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
21764
+ outIDX = idx;
21765
+ outDistance = distance;
21766
+ outPosition = position;
21767
+ outNormal = normal;
21768
+ });
21769
+ if (result) {
21770
+ var hitShape = Engine._physicalObjectsMap[outIDX];
21771
+ hitResult.entity = hitShape._collider.entity;
21772
+ hitResult.shape = hitShape;
21773
+ hitResult.distance = outDistance;
21774
+ hitResult.point.copyFrom(outPosition);
21775
+ hitResult.normal.copyFrom(outNormal);
21776
+ return true;
21777
+ } else {
21778
+ hitResult.entity = null;
21779
+ hitResult.shape = null;
21780
+ hitResult.distance = 0;
21781
+ hitResult.point.set(0, 0, 0);
21782
+ hitResult.normal.set(0, 0, 0);
21783
+ return false;
21784
+ }
21785
+ } else {
21786
+ return this._nativePhysicsScene.raycast(ray, distance, onRaycast);
21787
+ }
21788
+ };
21789
+ /**
21790
+ * Call on every frame to update pose of objects.
21791
+ * @internal
21792
+ */ _proto._update = function _update(deltaTime) {
21793
+ var _this = this, fixedTimeStep = _this._fixedTimeStep, nativePhysicsManager = _this._nativePhysicsScene;
21794
+ var componentsManager = this._scene._componentsManager;
21795
+ var simulateTime = this._restTime + deltaTime;
21796
+ var step = Math.floor(simulateTime / fixedTimeStep);
21797
+ this._restTime = simulateTime - step * fixedTimeStep;
21798
+ for(var i = 0; i < step; i++){
21799
+ componentsManager.callScriptOnPhysicsUpdate();
21800
+ this._callColliderOnUpdate();
21801
+ nativePhysicsManager.update(fixedTimeStep);
21802
+ this._callColliderOnLateUpdate();
21803
+ }
21804
+ };
21805
+ /**
21806
+ * Add collider into the manager.
21807
+ * @param collider - StaticCollider or DynamicCollider.
21808
+ * @internal
21809
+ */ _proto._addCollider = function _addCollider(collider) {
21810
+ if (collider._index === -1) {
21811
+ collider._index = this._colliders.length;
21812
+ this._colliders.add(collider);
21813
+ }
21814
+ this._nativePhysicsScene.addCollider(collider._nativeCollider);
21815
+ };
21816
+ /**
21817
+ * Add character controller into the manager.
21818
+ * @param controller - Character Controller.
21819
+ * @internal
21820
+ */ _proto._addCharacterController = function _addCharacterController(controller) {
21821
+ if (controller._index === -1) {
21822
+ controller._index = this._colliders.length;
21823
+ this._colliders.add(controller);
21824
+ }
21825
+ this._nativePhysicsScene.addCharacterController(controller._nativeCollider);
21826
+ };
21827
+ /**
21828
+ * Remove collider.
21829
+ * @param collider - StaticCollider or DynamicCollider.
21830
+ * @internal
21831
+ */ _proto._removeCollider = function _removeCollider(collider) {
21832
+ var replaced = this._colliders.deleteByIndex(collider._index);
21833
+ replaced && (replaced._index = collider._index);
21834
+ collider._index = -1;
21835
+ this._nativePhysicsScene.removeCollider(collider._nativeCollider);
21836
+ };
21837
+ /**
21838
+ * Remove collider.
21839
+ * @param controller - Character Controller.
21840
+ * @internal
21841
+ */ _proto._removeCharacterController = function _removeCharacterController(controller) {
21842
+ var replaced = this._colliders.deleteByIndex(controller._index);
21843
+ replaced && (replaced._index = controller._index);
21844
+ controller._index = -1;
21845
+ this._nativePhysicsScene.removeCharacterController(controller._nativeCollider);
21846
+ };
21847
+ /**
21848
+ * @internal
21849
+ */ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
21850
+ var elements = this._colliders._elements;
21851
+ for(var i = this._colliders.length - 1; i >= 0; --i){
21852
+ elements[i]._onUpdate();
21853
+ }
21854
+ };
21855
+ /**
21856
+ * @internal
21857
+ */ _proto._callColliderOnLateUpdate = function _callColliderOnLateUpdate() {
21858
+ var elements = this._colliders._elements;
21859
+ for(var i = this._colliders.length - 1; i >= 0; --i){
21860
+ elements[i]._onLateUpdate();
21861
+ }
21862
+ };
21863
+ /**
21864
+ * @internal
21865
+ */ _proto._gc = function _gc() {
21866
+ this._colliders.garbageCollection();
21867
+ };
21868
+ /**
21869
+ * @internal
21870
+ */ _proto._destroy = function _destroy() {
21871
+ var _this__nativePhysicsScene;
21872
+ (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.destroy();
21873
+ };
21874
+ _proto._setGravity = function _setGravity() {
21875
+ this._nativePhysicsScene.setGravity(this._gravity);
21876
+ };
21877
+ _create_class(PhysicsScene, [
21878
+ {
21879
+ key: "gravity",
21880
+ get: /**
21881
+ * The gravity of physics scene.
21882
+ */ function get() {
21883
+ return this._gravity;
21884
+ },
21885
+ set: function set(value) {
21886
+ var gravity = this._gravity;
21887
+ if (gravity !== value) {
21888
+ gravity.copyFrom(value);
21889
+ }
21890
+ }
21891
+ },
21892
+ {
21893
+ key: "fixedTimeStep",
21894
+ get: /**
21895
+ * The fixed time step in seconds at which physics are performed.
21896
+ */ function get() {
21897
+ return this._fixedTimeStep;
21898
+ },
21899
+ set: function set(value) {
21900
+ this._fixedTimeStep = Math.max(value, engineMath.MathUtil.zeroTolerance);
21901
+ }
21902
+ }
21903
+ ]);
21904
+ return PhysicsScene;
21905
+ }();
21906
+ PhysicsScene._collision = new Collision();
21907
+
21902
21908
  /**
21903
21909
  * A static collider component that will not move.
21904
21910
  * @remarks Mostly used for object which always stays at the same place and never moves around.
@@ -21908,7 +21914,7 @@ __decorate([
21908
21914
  var _this;
21909
21915
  _this = Collider.call(this, entity) || this;
21910
21916
  var transform = _this.entity.transform;
21911
- _this._nativeCollider = PhysicsScene._nativePhysics.createStaticCollider(transform.worldPosition, transform.worldRotationQuaternion);
21917
+ _this._nativeCollider = Engine._nativePhysics.createStaticCollider(transform.worldPosition, transform.worldRotationQuaternion);
21912
21918
  return _this;
21913
21919
  }
21914
21920
  return StaticCollider;
@@ -22264,7 +22270,7 @@ __decorate([
22264
22270
  _proto._createJoint = function _createJoint() {
22265
22271
  var colliderInfo = this._colliderInfo;
22266
22272
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22267
- this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
22273
+ this._nativeJoint = Engine._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
22268
22274
  };
22269
22275
  return FixedJoint;
22270
22276
  }(exports.Joint);
@@ -22306,7 +22312,7 @@ __decorate([
22306
22312
  _proto._createJoint = function _createJoint() {
22307
22313
  var colliderInfo = this._colliderInfo;
22308
22314
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22309
- this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
22315
+ this._nativeJoint = Engine._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
22310
22316
  };
22311
22317
  _proto._syncNative = function _syncNative() {
22312
22318
  Joint.prototype._syncNative.call(this);
@@ -22501,7 +22507,7 @@ __decorate([
22501
22507
  _proto._createJoint = function _createJoint() {
22502
22508
  var colliderInfo = this._colliderInfo;
22503
22509
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22504
- this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22510
+ this._nativeJoint = Engine._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22505
22511
  };
22506
22512
  _proto._syncNative = function _syncNative() {
22507
22513
  Joint.prototype._syncNative.call(this);
@@ -22961,7 +22967,7 @@ __decorate([
22961
22967
  function BoxColliderShape() {
22962
22968
  var _this;
22963
22969
  _this = ColliderShape.call(this) || this, _this._size = new engineMath.Vector3(1, 1, 1);
22964
- _this._nativeShape = PhysicsScene._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
22970
+ _this._nativeShape = Engine._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
22965
22971
  //@ts-ignore
22966
22972
  _this._size._onValueChanged = _this._setSize.bind(_this);
22967
22973
  return _this;
@@ -23005,7 +23011,7 @@ __decorate([
23005
23011
  function SphereColliderShape() {
23006
23012
  var _this;
23007
23013
  _this = ColliderShape.call(this) || this, _this._radius = 1;
23008
- _this._nativeShape = PhysicsScene._nativePhysics.createSphereColliderShape(_this._id, _this._radius, _this._material._nativeMaterial);
23014
+ _this._nativeShape = Engine._nativePhysics.createSphereColliderShape(_this._id, _this._radius, _this._material._nativeMaterial);
23009
23015
  return _this;
23010
23016
  }
23011
23017
  var _proto = SphereColliderShape.prototype;
@@ -23039,7 +23045,7 @@ __decorate([
23039
23045
  function PlaneColliderShape() {
23040
23046
  var _this;
23041
23047
  _this = ColliderShape.call(this) || this;
23042
- _this._nativeShape = PhysicsScene._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
23048
+ _this._nativeShape = Engine._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
23043
23049
  return _this;
23044
23050
  }
23045
23051
  var _proto = PlaneColliderShape.prototype;
@@ -23057,7 +23063,7 @@ __decorate([
23057
23063
  function CapsuleColliderShape() {
23058
23064
  var _this;
23059
23065
  _this = ColliderShape.call(this) || this, _this._radius = 1, _this._height = 2, _this._upAxis = ColliderShapeUpAxis.Y;
23060
- _this._nativeShape = PhysicsScene._nativePhysics.createCapsuleColliderShape(_this._id, _this._radius, _this._height, _this._material._nativeMaterial);
23066
+ _this._nativeShape = Engine._nativePhysics.createCapsuleColliderShape(_this._id, _this._radius, _this._height, _this._material._nativeMaterial);
23061
23067
  return _this;
23062
23068
  }
23063
23069
  var _proto = CapsuleColliderShape.prototype;
@@ -25125,7 +25131,10 @@ ShaderPool.init();
25125
25131
  var initializePromises = new Array();
25126
25132
  if (physics) {
25127
25133
  initializePromises.push(physics.initialize().then(function() {
25128
- PhysicsScene._nativePhysics = physics;
25134
+ if (Engine._nativePhysics) {
25135
+ console.warn("A physics engine has already been configured. All physics operations will now be handled by the newly specified physics engine.");
25136
+ }
25137
+ Engine._nativePhysics = physics;
25129
25138
  _this._nativePhysicsManager = physics.createPhysicsManager();
25130
25139
  _this._physicsInitialized = true;
25131
25140
  return _this;
@@ -27197,6 +27206,7 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
27197
27206
  this._maskManager.destroy();
27198
27207
  var allCreatedScenes = sceneManager._allCreatedScenes;
27199
27208
  allCreatedScenes.splice(allCreatedScenes.indexOf(this), 1);
27209
+ this.physics._destroy();
27200
27210
  };
27201
27211
  _proto._computeLinearFogParams = function _computeLinearFogParams(fogStart, fogEnd) {
27202
27212
  var fogRange = fogEnd - fogStart;
@@ -35873,10 +35883,11 @@ __decorate([
35873
35883
  function Polyfill() {}
35874
35884
  Polyfill.registerPolyfill = function registerPolyfill() {
35875
35885
  Polyfill._registerMatchAll();
35886
+ Polyfill._registerAudioContext();
35876
35887
  };
35877
35888
  Polyfill._registerMatchAll = function _registerMatchAll() {
35878
35889
  if (!String.prototype.matchAll) {
35879
- Logger.info("polyfill String.prototype.matchAll");
35890
+ Logger.info("Polyfill String.prototype.matchAll");
35880
35891
  String.prototype.matchAll = function(pattern) {
35881
35892
  var flags = pattern.flags;
35882
35893
  var globalFlagIdx = flags.indexOf("g");
@@ -35930,6 +35941,26 @@ __decorate([
35930
35941
  };
35931
35942
  }
35932
35943
  };
35944
+ Polyfill._registerAudioContext = function _registerAudioContext() {
35945
+ // IOS 12 and the following system do not support AudioContext, need to switch to webkitAudioContext
35946
+ if (!window.AudioContext && window.webkitAudioContext) {
35947
+ Logger.info("Polyfill window.AudioContext");
35948
+ window.AudioContext = window.webkitAudioContext;
35949
+ var originalDecodeAudioData = AudioContext.prototype.decodeAudioData;
35950
+ AudioContext.prototype.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
35951
+ var _this = this;
35952
+ return new Promise(function(resolve, reject) {
35953
+ originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
35954
+ successCallback == null ? void 0 : successCallback(buffer);
35955
+ resolve(buffer);
35956
+ }, function(error) {
35957
+ errorCallback == null ? void 0 : errorCallback(error);
35958
+ reject(error);
35959
+ });
35960
+ });
35961
+ };
35962
+ }
35963
+ };
35933
35964
  return Polyfill;
35934
35965
  }();
35935
35966