@galacean/engine-core 1.4.14 → 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
  }
@@ -19391,12 +19391,24 @@ var AssetPromise = /*#__PURE__*/ function() {
19391
19391
  this._onCancelHandler && this._onCancelHandler();
19392
19392
  return this;
19393
19393
  };
19394
- /**
19395
- * Return a new resource Promise through the provided asset promise collection.
19396
- * The resolved of the new AssetPromise will be triggered when all the Promises in the provided set are completed.
19397
- * @param - Promise Collection
19398
- * @returns AssetPromise
19399
- */ AssetPromise.all = function all(promises) {
19394
+ AssetPromise.resolve = function resolve(value) {
19395
+ if (value === undefined) {
19396
+ return new AssetPromise(function(resolve) {
19397
+ return resolve();
19398
+ });
19399
+ } else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
19400
+ return new AssetPromise(function(resolve, reject) {
19401
+ value.then(function(resolved) {
19402
+ return resolve(resolved);
19403
+ }, reject);
19404
+ });
19405
+ } else {
19406
+ return new AssetPromise(function(resolve) {
19407
+ return resolve(value);
19408
+ });
19409
+ }
19410
+ };
19411
+ AssetPromise.all = function all(values) {
19400
19412
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
19401
19413
  var onComplete = function onComplete(index, resultValue) {
19402
19414
  completed++;
@@ -19407,7 +19419,7 @@ var AssetPromise = /*#__PURE__*/ function() {
19407
19419
  }
19408
19420
  };
19409
19421
  var onProgress = function onProgress(promise, index) {
19410
- if (_instanceof(promise, Promise) || _instanceof(promise, AssetPromise)) {
19422
+ if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
19411
19423
  promise.then(function(value) {
19412
19424
  onComplete(index, value);
19413
19425
  }, reject);
@@ -19417,14 +19429,14 @@ var AssetPromise = /*#__PURE__*/ function() {
19417
19429
  });
19418
19430
  }
19419
19431
  };
19420
- var count = promises.length;
19432
+ var count = Array.from(values).length;
19421
19433
  var results = new Array(count);
19422
19434
  var completed = 0;
19423
19435
  if (count === 0) {
19424
19436
  return resolve(results);
19425
19437
  }
19426
19438
  for(var i = 0; i < count; i++){
19427
- onProgress(promises[i], i);
19439
+ onProgress(values[i], i);
19428
19440
  }
19429
19441
  });
19430
19442
  };
@@ -20007,12 +20019,12 @@ var MultiExecutor = /*#__PURE__*/ function() {
20007
20019
  var obj = this._objectPool[refId];
20008
20020
  var promise;
20009
20021
  if (obj) {
20010
- promise = Promise.resolve(obj);
20022
+ promise = AssetPromise.resolve(obj);
20011
20023
  } else {
20012
20024
  var resourceConfig = this._idResourceMap[refId];
20013
20025
  if (!resourceConfig) {
20014
20026
  Logger.warn("refId:" + refId + " is not find in this._idResourceMap.");
20015
- return Promise.resolve(null);
20027
+ return AssetPromise.resolve(null);
20016
20028
  }
20017
20029
  var url = resourceConfig.virtualPath;
20018
20030
  if (key) {
@@ -20823,347 +20835,6 @@ exports.Collider = __decorate([
20823
20835
  dependentComponents(Transform, DependentMode.CheckOnly)
20824
20836
  ], exports.Collider);
20825
20837
 
20826
- /**
20827
- * Describes a contact point where the collision occurs.
20828
- */ var ContactPoint = function ContactPoint() {
20829
- /** The position of the contact point between the shapes, in world space. */ this.position = new engineMath.Vector3();
20830
- /** 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();
20831
- /** 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();
20832
- };
20833
-
20834
- /**
20835
- * Collision information between two shapes when they collide.
20836
- */ var Collision = /*#__PURE__*/ function() {
20837
- function Collision() {}
20838
- var _proto = Collision.prototype;
20839
- /**
20840
- * Get contact points.
20841
- * @param outContacts - The result of contact points
20842
- * @returns The actual count of contact points
20843
- *
20844
- * @remarks To optimize performance, the engine does not modify the length of the array you pass.
20845
- * You need to obtain the actual number of contact points from the function's return value.
20846
- */ _proto.getContacts = function getContacts(outContacts) {
20847
- var nativeCollision = this._nativeCollision;
20848
- var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
20849
- var factor = this.shape.id === smallerShapeId ? 1 : -1;
20850
- var nativeContactPoints = nativeCollision.getContacts();
20851
- var length = nativeContactPoints.size();
20852
- for(var i = 0; i < length; i++){
20853
- var _outContacts, _i;
20854
- var nativeContractPoint = nativeContactPoints.get(i);
20855
- var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
20856
- contact.position.copyFrom(nativeContractPoint.position);
20857
- contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
20858
- contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
20859
- contact.separation = nativeContractPoint.separation;
20860
- }
20861
- return length;
20862
- };
20863
- _create_class(Collision, [
20864
- {
20865
- key: "contactCount",
20866
- get: /**
20867
- * Count of contact points.
20868
- */ function get() {
20869
- return this._nativeCollision.contactCount;
20870
- }
20871
- }
20872
- ]);
20873
- return Collision;
20874
- }();
20875
-
20876
- /**
20877
- * A physics scene is a collection of colliders and constraints which can interact.
20878
- */ var PhysicsScene = /*#__PURE__*/ function() {
20879
- function PhysicsScene(scene) {
20880
- this._restTime = 0;
20881
- this._fixedTimeStep = 1 / 60;
20882
- this._colliders = new DisorderedArray();
20883
- this._gravity = new engineMath.Vector3(0, -9.81, 0);
20884
- this._onContactEnter = function(nativeCollision) {
20885
- var physicalObjectsMap = Engine._physicalObjectsMap;
20886
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20887
- var shape1 = physicalObjectsMap[shape0Id];
20888
- var shape2 = physicalObjectsMap[shape1Id];
20889
- var collision = PhysicsScene._collision;
20890
- collision._nativeCollision = nativeCollision;
20891
- shape1.collider.entity._scripts.forEach(function(element) {
20892
- collision.shape = shape2;
20893
- element.onCollisionEnter(collision);
20894
- }, function(element, index) {
20895
- element._entityScriptsIndex = index;
20896
- });
20897
- shape2.collider.entity._scripts.forEach(function(element) {
20898
- collision.shape = shape1;
20899
- element.onCollisionEnter(collision);
20900
- }, function(element, index) {
20901
- element._entityScriptsIndex = index;
20902
- });
20903
- };
20904
- this._onContactExit = function(nativeCollision) {
20905
- var physicalObjectsMap = Engine._physicalObjectsMap;
20906
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20907
- var shape1 = physicalObjectsMap[shape0Id];
20908
- var shape2 = physicalObjectsMap[shape1Id];
20909
- var collision = PhysicsScene._collision;
20910
- collision._nativeCollision = nativeCollision;
20911
- shape1.collider.entity._scripts.forEach(function(element) {
20912
- collision.shape = shape2;
20913
- element.onCollisionExit(collision);
20914
- }, function(element, index) {
20915
- element._entityScriptsIndex = index;
20916
- });
20917
- shape2.collider.entity._scripts.forEach(function(element) {
20918
- collision.shape = shape1;
20919
- element.onCollisionExit(collision);
20920
- }, function(element, index) {
20921
- element._entityScriptsIndex = index;
20922
- });
20923
- };
20924
- this._onContactStay = function(nativeCollision) {
20925
- var physicalObjectsMap = Engine._physicalObjectsMap;
20926
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20927
- var shape1 = physicalObjectsMap[shape0Id];
20928
- var shape2 = physicalObjectsMap[shape1Id];
20929
- var collision = PhysicsScene._collision;
20930
- collision._nativeCollision = nativeCollision;
20931
- shape1.collider.entity._scripts.forEach(function(element) {
20932
- collision.shape = shape2;
20933
- element.onCollisionStay(collision);
20934
- }, function(element, index) {
20935
- element._entityScriptsIndex = index;
20936
- });
20937
- shape2.collider.entity._scripts.forEach(function(element) {
20938
- collision.shape = shape1;
20939
- element.onCollisionStay(collision);
20940
- }, function(element, index) {
20941
- element._entityScriptsIndex = index;
20942
- });
20943
- };
20944
- this._onTriggerEnter = function(obj1, obj2) {
20945
- var physicalObjectsMap = Engine._physicalObjectsMap;
20946
- var shape1 = physicalObjectsMap[obj1];
20947
- var shape2 = physicalObjectsMap[obj2];
20948
- shape1.collider.entity._scripts.forEach(function(element) {
20949
- element.onTriggerEnter(shape2);
20950
- }, function(element, index) {
20951
- element._entityScriptsIndex = index;
20952
- });
20953
- shape2.collider.entity._scripts.forEach(function(element) {
20954
- element.onTriggerEnter(shape1);
20955
- }, function(element, index) {
20956
- element._entityScriptsIndex = index;
20957
- });
20958
- };
20959
- this._onTriggerExit = function(obj1, obj2) {
20960
- var physicalObjectsMap = Engine._physicalObjectsMap;
20961
- var shape1 = physicalObjectsMap[obj1];
20962
- var shape2 = physicalObjectsMap[obj2];
20963
- shape1.collider.entity._scripts.forEach(function(element) {
20964
- element.onTriggerExit(shape2);
20965
- }, function(element, index) {
20966
- element._entityScriptsIndex = index;
20967
- });
20968
- shape2.collider.entity._scripts.forEach(function(element) {
20969
- element.onTriggerExit(shape1);
20970
- }, function(element, index) {
20971
- element._entityScriptsIndex = index;
20972
- });
20973
- };
20974
- this._onTriggerStay = function(obj1, obj2) {
20975
- var physicalObjectsMap = Engine._physicalObjectsMap;
20976
- var shape1 = physicalObjectsMap[obj1];
20977
- var shape2 = physicalObjectsMap[obj2];
20978
- shape1.collider.entity._scripts.forEach(function(element) {
20979
- element.onTriggerStay(shape2);
20980
- }, function(element, index) {
20981
- element._entityScriptsIndex = index;
20982
- });
20983
- shape2.collider.entity._scripts.forEach(function(element) {
20984
- element.onTriggerStay(shape1);
20985
- }, function(element, index) {
20986
- element._entityScriptsIndex = index;
20987
- });
20988
- };
20989
- this._scene = scene;
20990
- this._setGravity = this._setGravity.bind(this);
20991
- //@ts-ignore
20992
- this._gravity._onValueChanged = this._setGravity;
20993
- var engine = scene.engine;
20994
- if (engine._physicsInitialized) {
20995
- this._nativePhysicsScene = PhysicsScene._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
20996
- }
20997
- }
20998
- var _proto = PhysicsScene.prototype;
20999
- _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
21000
- var hitResult;
21001
- var distance = Number.MAX_VALUE;
21002
- if (typeof distanceOrResult === "number") {
21003
- distance = distanceOrResult;
21004
- } else if (distanceOrResult != undefined) {
21005
- hitResult = distanceOrResult;
21006
- }
21007
- var layerMask = Layer.Everything;
21008
- if (typeof layerMaskOrResult === "number") {
21009
- layerMask = layerMaskOrResult;
21010
- } else if (layerMaskOrResult != undefined) {
21011
- hitResult = layerMaskOrResult;
21012
- }
21013
- if (outHitResult) {
21014
- hitResult = outHitResult;
21015
- }
21016
- var onRaycast = function(obj) {
21017
- var shape = Engine._physicalObjectsMap[obj];
21018
- if (!shape) {
21019
- return false;
21020
- }
21021
- return shape.collider.entity.layer & layerMask && shape.isSceneQuery;
21022
- };
21023
- var outIDX;
21024
- var outDistance;
21025
- var outPosition;
21026
- var outNormal;
21027
- if (hitResult != undefined) {
21028
- var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
21029
- outIDX = idx;
21030
- outDistance = distance;
21031
- outPosition = position;
21032
- outNormal = normal;
21033
- });
21034
- if (result) {
21035
- var hitShape = Engine._physicalObjectsMap[outIDX];
21036
- hitResult.entity = hitShape._collider.entity;
21037
- hitResult.shape = hitShape;
21038
- hitResult.distance = outDistance;
21039
- hitResult.point.copyFrom(outPosition);
21040
- hitResult.normal.copyFrom(outNormal);
21041
- return true;
21042
- } else {
21043
- hitResult.entity = null;
21044
- hitResult.shape = null;
21045
- hitResult.distance = 0;
21046
- hitResult.point.set(0, 0, 0);
21047
- hitResult.normal.set(0, 0, 0);
21048
- return false;
21049
- }
21050
- } else {
21051
- return this._nativePhysicsScene.raycast(ray, distance, onRaycast);
21052
- }
21053
- };
21054
- /**
21055
- * Call on every frame to update pose of objects.
21056
- * @internal
21057
- */ _proto._update = function _update(deltaTime) {
21058
- var _this = this, fixedTimeStep = _this._fixedTimeStep, nativePhysicsManager = _this._nativePhysicsScene;
21059
- var componentsManager = this._scene._componentsManager;
21060
- var simulateTime = this._restTime + deltaTime;
21061
- var step = Math.floor(simulateTime / fixedTimeStep);
21062
- this._restTime = simulateTime - step * fixedTimeStep;
21063
- for(var i = 0; i < step; i++){
21064
- componentsManager.callScriptOnPhysicsUpdate();
21065
- this._callColliderOnUpdate();
21066
- nativePhysicsManager.update(fixedTimeStep);
21067
- this._callColliderOnLateUpdate();
21068
- }
21069
- };
21070
- /**
21071
- * Add collider into the manager.
21072
- * @param collider - StaticCollider or DynamicCollider.
21073
- * @internal
21074
- */ _proto._addCollider = function _addCollider(collider) {
21075
- if (collider._index === -1) {
21076
- collider._index = this._colliders.length;
21077
- this._colliders.add(collider);
21078
- }
21079
- this._nativePhysicsScene.addCollider(collider._nativeCollider);
21080
- };
21081
- /**
21082
- * Add character controller into the manager.
21083
- * @param controller - Character Controller.
21084
- * @internal
21085
- */ _proto._addCharacterController = function _addCharacterController(controller) {
21086
- if (controller._index === -1) {
21087
- controller._index = this._colliders.length;
21088
- this._colliders.add(controller);
21089
- }
21090
- this._nativePhysicsScene.addCharacterController(controller._nativeCollider);
21091
- };
21092
- /**
21093
- * Remove collider.
21094
- * @param collider - StaticCollider or DynamicCollider.
21095
- * @internal
21096
- */ _proto._removeCollider = function _removeCollider(collider) {
21097
- var replaced = this._colliders.deleteByIndex(collider._index);
21098
- replaced && (replaced._index = collider._index);
21099
- collider._index = -1;
21100
- this._nativePhysicsScene.removeCollider(collider._nativeCollider);
21101
- };
21102
- /**
21103
- * Remove collider.
21104
- * @param controller - Character Controller.
21105
- * @internal
21106
- */ _proto._removeCharacterController = function _removeCharacterController(controller) {
21107
- var replaced = this._colliders.deleteByIndex(controller._index);
21108
- replaced && (replaced._index = controller._index);
21109
- controller._index = -1;
21110
- this._nativePhysicsScene.removeCharacterController(controller._nativeCollider);
21111
- };
21112
- /**
21113
- * @internal
21114
- */ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
21115
- var elements = this._colliders._elements;
21116
- for(var i = this._colliders.length - 1; i >= 0; --i){
21117
- elements[i]._onUpdate();
21118
- }
21119
- };
21120
- /**
21121
- * @internal
21122
- */ _proto._callColliderOnLateUpdate = function _callColliderOnLateUpdate() {
21123
- var elements = this._colliders._elements;
21124
- for(var i = this._colliders.length - 1; i >= 0; --i){
21125
- elements[i]._onLateUpdate();
21126
- }
21127
- };
21128
- /**
21129
- * @internal
21130
- */ _proto._gc = function _gc() {
21131
- this._colliders.garbageCollection();
21132
- };
21133
- _proto._setGravity = function _setGravity() {
21134
- this._nativePhysicsScene.setGravity(this._gravity);
21135
- };
21136
- _create_class(PhysicsScene, [
21137
- {
21138
- key: "gravity",
21139
- get: /**
21140
- * The gravity of physics scene.
21141
- */ function get() {
21142
- return this._gravity;
21143
- },
21144
- set: function set(value) {
21145
- var gravity = this._gravity;
21146
- if (gravity !== value) {
21147
- gravity.copyFrom(value);
21148
- }
21149
- }
21150
- },
21151
- {
21152
- key: "fixedTimeStep",
21153
- get: /**
21154
- * The fixed time step in seconds at which physics are performed.
21155
- */ function get() {
21156
- return this._fixedTimeStep;
21157
- },
21158
- set: function set(value) {
21159
- this._fixedTimeStep = Math.max(value, engineMath.MathUtil.zeroTolerance);
21160
- }
21161
- }
21162
- ]);
21163
- return PhysicsScene;
21164
- }();
21165
- PhysicsScene._collision = new Collision();
21166
-
21167
20838
  /**
21168
20839
  * The up axis of the collider shape.
21169
20840
  */ var ControllerNonWalkableMode = /*#__PURE__*/ function(ControllerNonWalkableMode) {
@@ -21179,7 +20850,7 @@ PhysicsScene._collision = new Collision();
21179
20850
  function CharacterController(entity) {
21180
20851
  var _this;
21181
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;
21182
- _this._nativeCollider = PhysicsScene._nativePhysics.createCharacterController();
20853
+ _this._nativeCollider = Engine._nativePhysics.createCharacterController();
21183
20854
  _this._setUpDirection = _this._setUpDirection.bind(_this);
21184
20855
  //@ts-ignore
21185
20856
  _this._upDirection._onValueChanged = _this._setUpDirection;
@@ -21329,7 +21000,7 @@ __decorate([
21329
21000
  var _this;
21330
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;
21331
21002
  var transform = _this.entity.transform;
21332
- _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
21003
+ _this._nativeCollider = Engine._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
21333
21004
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
21334
21005
  _this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
21335
21006
  _this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
@@ -21803,7 +21474,7 @@ __decorate([
21803
21474
  this._staticFriction = 0.6;
21804
21475
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
21805
21476
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
21806
- 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);
21807
21478
  }
21808
21479
  var _proto = PhysicsMaterial.prototype;
21809
21480
  /**
@@ -21887,6 +21558,353 @@ __decorate([
21887
21558
  return PhysicsMaterial;
21888
21559
  }();
21889
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
+
21890
21908
  /**
21891
21909
  * A static collider component that will not move.
21892
21910
  * @remarks Mostly used for object which always stays at the same place and never moves around.
@@ -21896,7 +21914,7 @@ __decorate([
21896
21914
  var _this;
21897
21915
  _this = Collider.call(this, entity) || this;
21898
21916
  var transform = _this.entity.transform;
21899
- _this._nativeCollider = PhysicsScene._nativePhysics.createStaticCollider(transform.worldPosition, transform.worldRotationQuaternion);
21917
+ _this._nativeCollider = Engine._nativePhysics.createStaticCollider(transform.worldPosition, transform.worldRotationQuaternion);
21900
21918
  return _this;
21901
21919
  }
21902
21920
  return StaticCollider;
@@ -22252,7 +22270,7 @@ __decorate([
22252
22270
  _proto._createJoint = function _createJoint() {
22253
22271
  var colliderInfo = this._colliderInfo;
22254
22272
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22255
- this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
22273
+ this._nativeJoint = Engine._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
22256
22274
  };
22257
22275
  return FixedJoint;
22258
22276
  }(exports.Joint);
@@ -22294,7 +22312,7 @@ __decorate([
22294
22312
  _proto._createJoint = function _createJoint() {
22295
22313
  var colliderInfo = this._colliderInfo;
22296
22314
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22297
- this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
22315
+ this._nativeJoint = Engine._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
22298
22316
  };
22299
22317
  _proto._syncNative = function _syncNative() {
22300
22318
  Joint.prototype._syncNative.call(this);
@@ -22489,7 +22507,7 @@ __decorate([
22489
22507
  _proto._createJoint = function _createJoint() {
22490
22508
  var colliderInfo = this._colliderInfo;
22491
22509
  colliderInfo.collider = this.entity.getComponent(exports.Collider);
22492
- this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22510
+ this._nativeJoint = Engine._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22493
22511
  };
22494
22512
  _proto._syncNative = function _syncNative() {
22495
22513
  Joint.prototype._syncNative.call(this);
@@ -22949,7 +22967,7 @@ __decorate([
22949
22967
  function BoxColliderShape() {
22950
22968
  var _this;
22951
22969
  _this = ColliderShape.call(this) || this, _this._size = new engineMath.Vector3(1, 1, 1);
22952
- _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);
22953
22971
  //@ts-ignore
22954
22972
  _this._size._onValueChanged = _this._setSize.bind(_this);
22955
22973
  return _this;
@@ -22993,7 +23011,7 @@ __decorate([
22993
23011
  function SphereColliderShape() {
22994
23012
  var _this;
22995
23013
  _this = ColliderShape.call(this) || this, _this._radius = 1;
22996
- _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);
22997
23015
  return _this;
22998
23016
  }
22999
23017
  var _proto = SphereColliderShape.prototype;
@@ -23027,7 +23045,7 @@ __decorate([
23027
23045
  function PlaneColliderShape() {
23028
23046
  var _this;
23029
23047
  _this = ColliderShape.call(this) || this;
23030
- _this._nativeShape = PhysicsScene._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
23048
+ _this._nativeShape = Engine._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
23031
23049
  return _this;
23032
23050
  }
23033
23051
  var _proto = PlaneColliderShape.prototype;
@@ -23045,7 +23063,7 @@ __decorate([
23045
23063
  function CapsuleColliderShape() {
23046
23064
  var _this;
23047
23065
  _this = ColliderShape.call(this) || this, _this._radius = 1, _this._height = 2, _this._upAxis = ColliderShapeUpAxis.Y;
23048
- _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);
23049
23067
  return _this;
23050
23068
  }
23051
23069
  var _proto = CapsuleColliderShape.prototype;
@@ -24126,7 +24144,7 @@ var fragBlurH = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\
24126
24144
 
24127
24145
  var fragBlurV = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n vec2 texelSize = renderer_texelSize.xy;\n\n // Optimized bilinear 5-tap gaussian on the same-sized source (9-tap equivalent)\n mediump vec4 c0 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 3.23076923));\n mediump vec4 c1 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c2 = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 c3 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c4 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 3.23076923));\n\n gl_FragColor = c0 * 0.07027027 + c1 * 0.31621622\n + c2 * 0.22702703\n + c3 * 0.31621622 + c4 * 0.07027027;\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
24128
24146
 
24129
- var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\t#ifdef BLOOM_HQ\n vec2 texelSize = renderer_texelSize.xy;\n mediump vec4 A = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, -1.0));\n mediump vec4 C = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, -1.0));\n mediump vec4 D = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, -0.5));\n mediump vec4 F = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 H = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 0.0));\n mediump vec4 I = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, 0.5));\n mediump vec4 K = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, 1.0));\n mediump vec4 M = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 1.0));\n\n mediump vec2 scale = vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 samplerColor = (D + E + I + J) * div.x;\n samplerColor += (A + B + G + F) * div.y;\n samplerColor += (B + C + H + G) * div.y;\n samplerColor += (F + G + L + K) * div.y;\n samplerColor += (G + H + M + L) * div.y;\n #else\n mediump vec4 samplerColor = sampleTexture(renderer_BlitTexture, v_uv);\n #endif\n\n mediump vec3 color = samplerColor.rgb;\n\n // User controlled clamp to limit crazy high broken spec\n color = min(color, HALF_MAX);\n\n // Thresholding\n mediump float brightness = max3(color);\n float threshold = material_BloomParams.x;\n float thresholdKnee = material_BloomParams.y;\n mediump float softness = clamp(brightness - threshold + thresholdKnee, 0.0, 2.0 * thresholdKnee);\n softness = (softness * softness) / (4.0 * thresholdKnee + 1e-4);\n mediump float multiplier = max(brightness - threshold, softness) / max(brightness, 1e-4);\n color *= multiplier;\n\n // Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.\n color = max(color, 0.0);\n\n gl_FragColor = vec4(color, samplerColor.a);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
24147
+ var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\t#ifdef BLOOM_HQ\n vec2 texelSize = renderer_texelSize.xy;\n mediump vec4 A = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, -1.0));\n mediump vec4 C = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, -1.0));\n mediump vec4 D = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, -0.5));\n mediump vec4 F = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 H = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 0.0));\n mediump vec4 I = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, 0.5));\n mediump vec4 K = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, 1.0));\n mediump vec4 M = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 1.0));\n\n mediump vec2 scale = vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 samplerColor = (D + E + I + J) * div.x;\n samplerColor += (A + B + G + F) * div.y;\n samplerColor += (B + C + H + G) * div.y;\n samplerColor += (F + G + L + K) * div.y;\n samplerColor += (G + H + M + L) * div.y;\n #else\n mediump vec4 samplerColor = sampleTexture(renderer_BlitTexture, v_uv);\n #endif\n\n mediump vec3 color = samplerColor.rgb;\n\n // User controlled clamp to limit crazy high broken spec\n color = min(color, HALF_MAX);\n\n // Thresholding\n mediump float brightness = max3(color);\n float threshold = material_BloomParams.x;\n float thresholdKnee = material_BloomParams.y;\n mediump float softness = clamp(brightness - threshold + thresholdKnee, 0.0, 2.0 * thresholdKnee);\n softness = (softness * softness) / (4.0 * thresholdKnee + 1e-4);\n mediump float multiplier = max(brightness - threshold, softness) / max(brightness, 1e-4);\n color *= multiplier;\n\n // Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.\n color = max(color, 0.0);\n\n // Bloom is addtive blend mode, we should set alpha 0 to avoid browser background color dark when canvas alpha and premultiplyAlpha is true\n gl_FragColor = vec4(color, 0.0);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24130
24148
 
24131
24149
  var fragUpsample = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform sampler2D material_lowMipTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 material_lowMipTexelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n mediump vec4 highMip = sampleTexture(renderer_BlitTexture, v_uv);\n\n #ifdef BLOOM_HQ\n mediump vec4 lowMip = sampleTexture2DBicubic(material_lowMipTexture, v_uv, material_lowMipTexelSize);\n #else\n mediump vec4 lowMip = sampleTexture(material_lowMipTexture, v_uv);\n #endif\n \n gl_FragColor = mix(highMip, lowMip, material_BloomParams.z);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
24132
24150
 
@@ -25113,7 +25131,10 @@ ShaderPool.init();
25113
25131
  var initializePromises = new Array();
25114
25132
  if (physics) {
25115
25133
  initializePromises.push(physics.initialize().then(function() {
25116
- 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;
25117
25138
  _this._nativePhysicsManager = physics.createPhysicsManager();
25118
25139
  _this._physicsInitialized = true;
25119
25140
  return _this;
@@ -27185,6 +27206,7 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
27185
27206
  this._maskManager.destroy();
27186
27207
  var allCreatedScenes = sceneManager._allCreatedScenes;
27187
27208
  allCreatedScenes.splice(allCreatedScenes.indexOf(this), 1);
27209
+ this.physics._destroy();
27188
27210
  };
27189
27211
  _proto._computeLinearFogParams = function _computeLinearFogParams(fogStart, fogEnd) {
27190
27212
  var fogRange = fogEnd - fogStart;
@@ -35861,10 +35883,11 @@ __decorate([
35861
35883
  function Polyfill() {}
35862
35884
  Polyfill.registerPolyfill = function registerPolyfill() {
35863
35885
  Polyfill._registerMatchAll();
35886
+ Polyfill._registerAudioContext();
35864
35887
  };
35865
35888
  Polyfill._registerMatchAll = function _registerMatchAll() {
35866
35889
  if (!String.prototype.matchAll) {
35867
- Logger.info("polyfill String.prototype.matchAll");
35890
+ Logger.info("Polyfill String.prototype.matchAll");
35868
35891
  String.prototype.matchAll = function(pattern) {
35869
35892
  var flags = pattern.flags;
35870
35893
  var globalFlagIdx = flags.indexOf("g");
@@ -35918,6 +35941,26 @@ __decorate([
35918
35941
  };
35919
35942
  }
35920
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
+ };
35921
35964
  return Polyfill;
35922
35965
  }();
35923
35966