@galacean/engine-core 1.4.0-alpha.0 → 1.4.0-alpha.1

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
@@ -94,6 +94,34 @@ function __decorate(decorators, target, key, desc) {
94
94
  return c > 3 && r && Object.defineProperty(target, key, r), r;
95
95
  }
96
96
 
97
+ function __generator(thisArg, body) {
98
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
99
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
100
+ function verb(n) { return function (v) { return step([n, v]); }; }
101
+ function step(op) {
102
+ if (f) throw new TypeError("Generator is already executing.");
103
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
104
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
105
+ if (y = 0, t) op = [op[0] & 2, t.value];
106
+ switch (op[0]) {
107
+ case 0: case 1: t = op; break;
108
+ case 4: _.label++; return { value: op[1], done: false };
109
+ case 5: _.label++; y = op[1]; op = [0]; continue;
110
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
111
+ default:
112
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
113
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
114
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
115
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
116
+ if (t[2]) _.ops.pop();
117
+ _.trys.pop(); continue;
118
+ }
119
+ op = body.call(thisArg, _);
120
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
121
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
122
+ }
123
+ }
124
+
97
125
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
98
126
  var e = new Error(message);
99
127
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -5172,11 +5200,13 @@ __decorate([
5172
5200
  /**
5173
5201
  * @internal
5174
5202
  * @todo Should merge when we can delete material render state
5175
- */ _proto._applyRenderQueueByShaderData = function _applyRenderQueueByShaderData(renderStateDataMap, shaderData) {
5203
+ */ _proto._getRenderQueueByShaderData = function _getRenderQueueByShaderData(renderStateDataMap, shaderData) {
5176
5204
  var renderQueueType = renderStateDataMap[RenderStateElementKey.RenderQueueType];
5177
- if (renderQueueType !== undefined) {
5205
+ if (renderQueueType === undefined) {
5206
+ return this.renderQueueType;
5207
+ } else {
5178
5208
  var _shaderData_getFloat;
5179
- this.renderQueueType = (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
5209
+ return (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
5180
5210
  }
5181
5211
  };
5182
5212
  _proto._applyStatesByShaderData = function _applyStatesByShaderData(renderStateDataMap, shaderData) {
@@ -5985,12 +6015,18 @@ __decorate([
5985
6015
  /**
5986
6016
  * @internal
5987
6017
  */ ComponentsDependencies._removeCheck = function _removeCheck(entity, type) {
6018
+ var components = entity._components;
6019
+ var n = components.length;
5988
6020
  while(type !== Component){
6021
+ var count = 0;
6022
+ for(var i = 0; i < n; i++){
6023
+ if (_instanceof(components[i], type) && ++count > 1) return;
6024
+ }
5989
6025
  var invDependencies = ComponentsDependencies._invDependenciesMap.get(type);
5990
6026
  if (invDependencies) {
5991
- for(var i = 0, len = invDependencies.length; i < len; i++){
5992
- if (entity.getComponent(invDependencies[i])) {
5993
- throw "Should remove " + invDependencies[i].name + " before adding " + type.name;
6027
+ for(var i1 = 0, len = invDependencies.length; i1 < len; i1++){
6028
+ if (entity.getComponent(invDependencies[i1])) {
6029
+ throw "Should remove " + invDependencies[i1].name + " before remove " + type.name;
5994
6030
  }
5995
6031
  }
5996
6032
  }
@@ -6101,7 +6137,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
6101
6137
  _inherits(Transform, Component);
6102
6138
  function Transform(entity) {
6103
6139
  var _this;
6104
- _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188, /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
6140
+ _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._localUniformScaling = true, _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._worldUniformScaling = true, _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188;
6105
6141
  _this._onPositionChanged = _this._onPositionChanged.bind(_this);
6106
6142
  _this._onWorldPositionChanged = _this._onWorldPositionChanged.bind(_this);
6107
6143
  _this._onRotationChanged = _this._onRotationChanged.bind(_this);
@@ -6249,16 +6285,10 @@ function dependentComponents(componentOrComponents, dependentMode) {
6249
6285
  rotMat.getRotation(this._worldRotationQuaternion);
6250
6286
  };
6251
6287
  /**
6252
- * Register world transform change flag.
6253
- * @returns Change flag
6254
- */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
6255
- return this._updateFlagManager.createFlag(BoolUpdateFlag);
6256
- };
6257
- /**
6258
6288
  * @internal
6259
6289
  */ _proto._parentChange = function _parentChange() {
6260
6290
  this._isParentDirty = true;
6261
- this._updateAllWorldFlag();
6291
+ this._updateAllWorldFlag(444);
6262
6292
  };
6263
6293
  /**
6264
6294
  * @internal
@@ -6269,6 +6299,13 @@ function dependentComponents(componentOrComponents, dependentMode) {
6269
6299
  scale.z < 0 && (isInvert = !isInvert);
6270
6300
  return isInvert;
6271
6301
  };
6302
+ /**
6303
+ * @internal
6304
+ */ _proto._copyFrom = function _copyFrom(transform) {
6305
+ this._position.copyFrom(transform.position);
6306
+ this._rotation.copyFrom(transform.rotation);
6307
+ this._scale.copyFrom(transform.scale);
6308
+ };
6272
6309
  _proto._onDestroy = function _onDestroy() {
6273
6310
  Component.prototype._onDestroy.call(this);
6274
6311
  //@ts-ignore
@@ -6293,10 +6330,10 @@ function dependentComponents(componentOrComponents, dependentMode) {
6293
6330
  */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
6294
6331
  if (!this._isContainDirtyFlags(132)) {
6295
6332
  this._worldAssociatedChange(132);
6296
- var nodeChildren = this._entity._children;
6297
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6298
- var _nodeChildren_i_transform;
6299
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionFlag();
6333
+ var children = this._entity._children;
6334
+ for(var i = 0, n = children.length; i < n; i++){
6335
+ var _children_i_transform;
6336
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionFlag();
6300
6337
  }
6301
6338
  }
6302
6339
  };
@@ -6305,14 +6342,19 @@ function dependentComponents(componentOrComponents, dependentMode) {
6305
6342
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6306
6343
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
6307
6344
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
6345
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6308
6346
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
6309
6347
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
6310
- if (!this._isContainDirtyFlags(152)) {
6311
- this._worldAssociatedChange(152);
6312
- var nodeChildren = this._entity._children;
6313
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6314
- var _nodeChildren_i_transform;
6315
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndRotationFlag(); // Rotation update of parent entity will trigger world position and rotation update of all child entity.
6348
+ var parent = this._getParentTransform();
6349
+ var parentWorldUniformScaling = parent ? parent._getWorldUniformScaling() : true;
6350
+ var flags = parentWorldUniformScaling ? 152 : 184;
6351
+ if (!this._isContainDirtyFlags(flags)) {
6352
+ this._worldAssociatedChange(flags);
6353
+ flags = this._getWorldUniformScaling() ? 156 : 188;
6354
+ var children = this._entity._children;
6355
+ for(var i = 0, n = children.length; i < n; i++){
6356
+ var _children_i_transform;
6357
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndRotationFlag(flags); // Rotation update of parent entity will trigger world position, rotation and scale update of all child entity.
6316
6358
  }
6317
6359
  }
6318
6360
  };
@@ -6321,14 +6363,17 @@ function dependentComponents(componentOrComponents, dependentMode) {
6321
6363
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6322
6364
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
6323
6365
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
6366
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6324
6367
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
6325
- */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag() {
6326
- if (!this._isContainDirtyFlags(156)) {
6327
- this._worldAssociatedChange(156);
6328
- var nodeChildren = this._entity._children;
6329
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6330
- var _nodeChildren_i_transform;
6331
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndRotationFlag();
6368
+ * @param flags - Dirty flag
6369
+ */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag(flags) {
6370
+ if (!this._isContainDirtyFlags(flags)) {
6371
+ this._worldAssociatedChange(flags);
6372
+ flags = this._getWorldUniformScaling() ? 156 : 188;
6373
+ var children = this._entity._children;
6374
+ for(var i = 0, n = children.length; i < n; i++){
6375
+ var _children_i_transform;
6376
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndRotationFlag(flags);
6332
6377
  }
6333
6378
  }
6334
6379
  };
@@ -6337,13 +6382,15 @@ function dependentComponents(componentOrComponents, dependentMode) {
6337
6382
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6338
6383
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6339
6384
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
6340
- */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
6341
- if (!this._isContainDirtyFlags(160)) {
6342
- this._worldAssociatedChange(160);
6343
- var nodeChildren = this._entity._children;
6344
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6345
- var _nodeChildren_i_transform;
6346
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
6385
+ * @param flags - Dirty flag
6386
+ */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag(flags) {
6387
+ if (!this._isContainDirtyFlags(flags)) {
6388
+ this._worldAssociatedChange(flags);
6389
+ flags |= 4;
6390
+ var children = this._entity._children;
6391
+ for(var i = 0, n = children.length; i < n; i++){
6392
+ var _children_i_transform;
6393
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
6347
6394
  }
6348
6395
  }
6349
6396
  };
@@ -6352,25 +6399,27 @@ function dependentComponents(componentOrComponents, dependentMode) {
6352
6399
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6353
6400
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6354
6401
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
6355
- */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag() {
6356
- if (!this._isContainDirtyFlags(164)) {
6357
- this._worldAssociatedChange(164);
6358
- var nodeChildren = this._entity._children;
6359
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6360
- var _nodeChildren_i_transform;
6361
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
6402
+ * @param flags - Dirty flag
6403
+ */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag(flags) {
6404
+ if (!this._isContainDirtyFlags(flags)) {
6405
+ this._worldAssociatedChange(flags);
6406
+ var children = this._entity._children;
6407
+ for(var i = 0, n = children.length; i < n; i++){
6408
+ var _children_i_transform;
6409
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
6362
6410
  }
6363
6411
  }
6364
6412
  };
6365
6413
  /**
6366
6414
  * Update all world transform property dirty flag, the principle is the same as above.
6367
- */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
6368
- if (!this._isContainDirtyFlags(188)) {
6369
- this._worldAssociatedChange(188);
6370
- var nodeChildren = this._entity._children;
6371
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6372
- var _nodeChildren_i_transform;
6373
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateAllWorldFlag();
6415
+ * @param flags - Dirty flag
6416
+ */ _proto._updateAllWorldFlag = function _updateAllWorldFlag(flags) {
6417
+ if (!this._isContainDirtyFlags(flags)) {
6418
+ this._worldAssociatedChange(flags);
6419
+ var children = this._entity._children;
6420
+ for(var i = 0, n = children.length; i < n; i++){
6421
+ var _children_i_transform;
6422
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateAllWorldFlag(flags);
6374
6423
  }
6375
6424
  }
6376
6425
  };
@@ -6418,7 +6467,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
6418
6467
  };
6419
6468
  _proto._worldAssociatedChange = function _worldAssociatedChange(type) {
6420
6469
  this._dirtyFlag |= type;
6421
- this._updateFlagManager.dispatch(128);
6470
+ this._entity._updateFlagManager.dispatch(type);
6422
6471
  };
6423
6472
  _proto._rotateByQuat = function _rotateByQuat(rotateQuat, relativeToLocal) {
6424
6473
  if (relativeToLocal) {
@@ -6487,8 +6536,36 @@ function dependentComponents(componentOrComponents, dependentMode) {
6487
6536
  this._setDirtyFlagFalse(16);
6488
6537
  };
6489
6538
  _proto._onScaleChanged = function _onScaleChanged() {
6539
+ var _this__scale = this._scale, x = _this__scale.x, y = _this__scale.y, z = _this__scale.z;
6490
6540
  this._setDirtyFlagTrue(64);
6491
- this._updateWorldScaleFlag();
6541
+ var localUniformScaling = x == y && y == z;
6542
+ if (this._localUniformScaling !== localUniformScaling) {
6543
+ this._localUniformScaling = localUniformScaling;
6544
+ this._updateWorldScaleFlag(416);
6545
+ } else {
6546
+ this._updateWorldScaleFlag(160);
6547
+ }
6548
+ };
6549
+ _proto._getWorldUniformScaling = function _getWorldUniformScaling() {
6550
+ if (this._isContainDirtyFlag(256)) {
6551
+ var localUniformScaling = this._localUniformScaling;
6552
+ if (localUniformScaling) {
6553
+ var parent = this._getParentTransform();
6554
+ this._worldUniformScaling = localUniformScaling && (parent ? parent._getWorldUniformScaling() : true);
6555
+ } else {
6556
+ this._worldUniformScaling = false;
6557
+ }
6558
+ this._setDirtyFlagFalse(256);
6559
+ }
6560
+ return this._worldUniformScaling;
6561
+ };
6562
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
6563
+ /**
6564
+ * @deprecated
6565
+ * Listen for changes in the world pose of this `Entity`.
6566
+ * @returns Change flag
6567
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
6568
+ return this.entity._updateFlagManager.createFlag(BoolUpdateFlag);
6492
6569
  };
6493
6570
  _create_class(Transform, [
6494
6571
  {
@@ -6655,11 +6732,12 @@ function dependentComponents(componentOrComponents, dependentMode) {
6655
6732
  key: "lossyWorldScale",
6656
6733
  get: /**
6657
6734
  * Local lossy scaling.
6658
- * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has scaling,
6659
- * and the child node has a rotation), the scaling will be tilted. Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3.
6735
+ * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has non-uniform world scaling,
6736
+ * and the child node has a rotation), the scaling will be tilted.
6660
6737
  */ function get() {
6661
6738
  if (this._isContainDirtyFlag(32)) {
6662
6739
  if (this._getParentTransform()) {
6740
+ // Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3
6663
6741
  var scaleMat = this._getScaleMatrix();
6664
6742
  var e = scaleMat.elements;
6665
6743
  this._lossyWorldScale.set(e[0], e[4], e[8]);
@@ -6687,18 +6765,25 @@ function dependentComponents(componentOrComponents, dependentMode) {
6687
6765
  if (this._localMatrix !== value) {
6688
6766
  this._localMatrix.copyFrom(value);
6689
6767
  }
6768
+ var _this = this, position = _this._position, rotationQuaternion = _this._rotationQuaternion, scale = _this._scale;
6690
6769
  // @ts-ignore
6691
- this._position._onValueChanged = this._rotationQuaternion._onValueChanged = this._scale._onValueChanged = null;
6692
- this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
6770
+ position._onValueChanged = rotationQuaternion._onValueChanged = scale._onValueChanged = null;
6771
+ this._localMatrix.decompose(position, rotationQuaternion, scale);
6693
6772
  // @ts-ignore
6694
- this._position._onValueChanged = this._onPositionChanged;
6773
+ position._onValueChanged = this._onPositionChanged;
6695
6774
  // @ts-ignore
6696
- this._rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
6775
+ rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
6697
6776
  // @ts-ignore
6698
- this._scale._onValueChanged = this._onScaleChanged;
6777
+ scale._onValueChanged = this._onScaleChanged;
6699
6778
  this._setDirtyFlagTrue(1);
6700
6779
  this._setDirtyFlagFalse(64 | 2);
6701
- this._updateAllWorldFlag();
6780
+ var localUniformScaling = scale.x === scale.y && scale.y === scale.z;
6781
+ if (this._localUniformScaling !== localUniformScaling) {
6782
+ this._localUniformScaling = localUniformScaling;
6783
+ this._updateAllWorldFlag(444);
6784
+ } else {
6785
+ this._updateAllWorldFlag(188);
6786
+ }
6702
6787
  }
6703
6788
  },
6704
6789
  {
@@ -6790,6 +6875,9 @@ __decorate([
6790
6875
  __decorate([
6791
6876
  deepClone
6792
6877
  ], Transform.prototype, "_scale", void 0);
6878
+ __decorate([
6879
+ assignmentClone
6880
+ ], Transform.prototype, "_localUniformScaling", void 0);
6793
6881
  __decorate([
6794
6882
  deepClone
6795
6883
  ], Transform.prototype, "_worldPosition", void 0);
@@ -6799,6 +6887,9 @@ __decorate([
6799
6887
  __decorate([
6800
6888
  deepClone
6801
6889
  ], Transform.prototype, "_worldRotationQuaternion", void 0);
6890
+ __decorate([
6891
+ assignmentClone
6892
+ ], Transform.prototype, "_worldUniformScaling", void 0);
6802
6893
  __decorate([
6803
6894
  deepClone
6804
6895
  ], Transform.prototype, "_lossyWorldScale", void 0);
@@ -6823,9 +6914,6 @@ __decorate([
6823
6914
  __decorate([
6824
6915
  ignoreClone
6825
6916
  ], Transform.prototype, "_parentTransformCache", void 0);
6826
- __decorate([
6827
- ignoreClone
6828
- ], Transform.prototype, "_updateFlagManager", void 0);
6829
6917
  __decorate([
6830
6918
  ignoreClone
6831
6919
  ], Transform.prototype, "_onPositionChanged", null);
@@ -6858,12 +6946,18 @@ __decorate([
6858
6946
  TransformModifyFlags[TransformModifyFlags["WorldScale"] = 32] = "WorldScale";
6859
6947
  TransformModifyFlags[TransformModifyFlags["LocalMatrix"] = 64] = "LocalMatrix";
6860
6948
  TransformModifyFlags[TransformModifyFlags["WorldMatrix"] = 128] = "WorldMatrix";
6949
+ /** This is an internal flag used to assist in determining the dispatch
6950
+ * of world scaling dirty flags in the case of non-uniform scaling.
6951
+ */ TransformModifyFlags[TransformModifyFlags["IsWorldUniformScaling"] = 256] = "IsWorldUniformScaling";
6861
6952
  /** WorldMatrix | WorldPosition */ TransformModifyFlags[TransformModifyFlags["WmWp"] = 132] = "WmWp";
6862
6953
  /** WorldMatrix | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWeWq"] = 152] = "WmWeWq";
6954
+ /** WorldMatrix | WorldEuler | WorldQuat | WorldScale*/ TransformModifyFlags[TransformModifyFlags["WmWeWqWs"] = 184] = "WmWeWqWs";
6863
6955
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWpWeWq"] = 156] = "WmWpWeWq";
6864
6956
  /** WorldMatrix | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWs"] = 160] = "WmWs";
6957
+ /** WorldMatrix | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWsWus"] = 416] = "WmWsWus";
6865
6958
  /** WorldMatrix | WorldPosition | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWs"] = 164] = "WmWpWs";
6866
6959
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWs"] = 188] = "WmWpWeWqWs";
6960
+ /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWsWus"] = 444] = "WmWpWeWqWsWus";
6867
6961
  return TransformModifyFlags;
6868
6962
  }({});
6869
6963
 
@@ -6918,7 +7012,7 @@ var Renderer = /*#__PURE__*/ function(Component) {
6918
7012
  _this._overrideUpdate = _this.update !== prototype.update;
6919
7013
  _this._addResourceReferCount(_this.shaderData, 1);
6920
7014
  _this._onTransformChanged = _this._onTransformChanged.bind(_this);
6921
- _this._setTransform(entity.transform);
7015
+ _this._setTransformEntity(entity);
6922
7016
  shaderData.enableMacro(Renderer._receiveShadowMacro);
6923
7017
  shaderData.setVector4(Renderer._rendererLayerProperty, _this._rendererLayer);
6924
7018
  return _this;
@@ -7044,7 +7138,7 @@ var Renderer = /*#__PURE__*/ function(Component) {
7044
7138
  * @internal
7045
7139
  */ _proto._onDestroy = function _onDestroy() {
7046
7140
  Component.prototype._onDestroy.call(this);
7047
- this._setTransform(null);
7141
+ this._setTransformEntity(null);
7048
7142
  this._addResourceReferCount(this.shaderData, -1);
7049
7143
  var materials = this._materials;
7050
7144
  for(var i = 0, n = materials.length; i < n; i++){
@@ -7066,7 +7160,7 @@ var Renderer = /*#__PURE__*/ function(Component) {
7066
7160
  /**
7067
7161
  * @internal
7068
7162
  */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
7069
- var worldMatrix = this._transform.worldMatrix;
7163
+ var worldMatrix = this._transformEntity.transform.worldMatrix;
7070
7164
  if (onlyMVP) {
7071
7165
  this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
7072
7166
  } else {
@@ -7105,7 +7199,7 @@ var Renderer = /*#__PURE__*/ function(Component) {
7105
7199
  Matrix.invert(mvMatrix, mvInvMatrix);
7106
7200
  Matrix.invert(worldMatrix, normalMatrix);
7107
7201
  normalMatrix.transpose();
7108
- shaderData.setMatrix(Renderer._localMatrixProperty, this._transform.localMatrix);
7202
+ shaderData.setMatrix(Renderer._localMatrixProperty, this._transformEntity.transform.localMatrix);
7109
7203
  shaderData.setMatrix(Renderer._worldMatrixProperty, worldMatrix);
7110
7204
  shaderData.setMatrix(Renderer._mvMatrixProperty, mvMatrix);
7111
7205
  shaderData.setMatrix(Renderer._mvInvMatrixProperty, mvInvMatrix);
@@ -7124,11 +7218,13 @@ var Renderer = /*#__PURE__*/ function(Component) {
7124
7218
  };
7125
7219
  /**
7126
7220
  * @internal
7127
- */ _proto._setTransform = function _setTransform(transform) {
7128
- var _this__transform;
7129
- (_this__transform = this._transform) == null ? void 0 : _this__transform._updateFlagManager.removeListener(this._onTransformChanged);
7130
- transform == null ? void 0 : transform._updateFlagManager.addListener(this._onTransformChanged);
7131
- this._transform = transform;
7221
+ */ _proto._setTransformEntity = function _setTransformEntity(entity) {
7222
+ var preEntity = this._transformEntity;
7223
+ if (entity !== preEntity) {
7224
+ preEntity == null ? void 0 : preEntity._updateFlagManager.removeListener(this._onTransformChanged);
7225
+ entity == null ? void 0 : entity._updateFlagManager.addListener(this._onTransformChanged);
7226
+ this._transformEntity = entity;
7227
+ }
7132
7228
  };
7133
7229
  /**
7134
7230
  * @internal
@@ -7279,6 +7375,9 @@ __decorate([
7279
7375
  __decorate([
7280
7376
  ignoreClone
7281
7377
  ], Renderer.prototype, "_batchedTransformShaderData", void 0);
7378
+ __decorate([
7379
+ ignoreClone
7380
+ ], Renderer.prototype, "_transformEntity", void 0);
7282
7381
  __decorate([
7283
7382
  ignoreClone
7284
7383
  ], Renderer.prototype, "_overrideUpdate", void 0);
@@ -7291,9 +7390,6 @@ __decorate([
7291
7390
  __decorate([
7292
7391
  ignoreClone
7293
7392
  ], Renderer.prototype, "_rendererLayer", void 0);
7294
- __decorate([
7295
- ignoreClone
7296
- ], Renderer.prototype, "_transform", void 0);
7297
7393
  __decorate([
7298
7394
  deepClone
7299
7395
  ], Renderer.prototype, "_shaderData", void 0);
@@ -8701,11 +8797,13 @@ __decorate([
8701
8797
  * @param viewport - Viewport
8702
8798
  * @param material - The material to use when blitting
8703
8799
  * @param passIndex - Pass index to use of the provided material
8704
- */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex) {
8800
+ * @param flipYOfSource - Whether flip Y axis of source texture
8801
+ */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex, flipYOfSource) {
8705
8802
  if (mipLevel === void 0) mipLevel = 0;
8706
8803
  if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
8707
8804
  if (material === void 0) material = null;
8708
8805
  if (passIndex === void 0) passIndex = 0;
8806
+ if (flipYOfSource === void 0) flipYOfSource = false;
8709
8807
  var basicResources = engine._basicResources;
8710
8808
  var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
8711
8809
  var blitMaterial = material || basicResources.blitMaterial;
@@ -8719,9 +8817,15 @@ __decorate([
8719
8817
  rendererShaderData.setFloat(PipelineUtils._blitMipLevelProperty, mipLevel);
8720
8818
  PipelineUtils._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
8721
8819
  rendererShaderData.setVector4(PipelineUtils._blitTexelSizeProperty, PipelineUtils._texelSize);
8820
+ if (flipYOfSource) {
8821
+ rendererShaderData.enableMacro(PipelineUtils._flipYTextureMacro);
8822
+ } else {
8823
+ rendererShaderData.disableMacro(PipelineUtils._flipYTextureMacro);
8824
+ }
8722
8825
  var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
8723
8826
  var compileMacros = Shader._compileMacros;
8724
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, blitMaterial.shaderData._macroCollection, compileMacros);
8827
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, rendererShaderData._macroCollection, compileMacros);
8828
+ ShaderMacroCollection.unionCollection(compileMacros, blitMaterial.shaderData._macroCollection, compileMacros);
8725
8829
  var program = pass._getShaderProgram(engine, compileMacros);
8726
8830
  program.bind();
8727
8831
  program.groupingOtherUniformBlock();
@@ -8737,6 +8841,7 @@ PipelineUtils._blitTextureProperty = ShaderProperty.getByName("renderer_BlitText
8737
8841
  PipelineUtils._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
8738
8842
  PipelineUtils._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
8739
8843
  ;
8844
+ PipelineUtils._flipYTextureMacro = ShaderMacro.getByName("renderer_FlipYBlitTexture");
8740
8845
  PipelineUtils._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
8741
8846
  PipelineUtils._texelSize = new Vector4();
8742
8847
  PipelineUtils.defaultViewport = new Vector4(0, 0, 1, 1);
@@ -8841,13 +8946,11 @@ var Camera = /*#__PURE__*/ function(Component) {
8841
8946
  */ _this.opaqueTextureDownsampling = Downsampling.TwoX, /**
8842
8947
  * Multi-sample anti-aliasing samples when use independent canvas mode.
8843
8948
  *
8844
- * @remarks The `independentCanvasEnabled` property should be `true` to take effect, otherwise it will be invalid.
8949
+ * @remarks It will take effect when `independentCanvasEnabled` property is `true`, otherwise it will be invalid.
8845
8950
  */ _this.msaaSamples = MSAASamples.None, /** @internal */ _this._cameraType = CameraType.Normal, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._frustum = new BoundingFrustum(), /** @internal */ _this._virtualCamera = new VirtualCamera(), /** @internal */ _this._replacementShader = null, /** @internal */ _this._replacementSubShaderTag = null, /** @internal */ _this._replacementFailureStrategy = null, /** @internal */ _this._cameraIndex = -1, _this._priority = 0, _this._shaderData = new ShaderData(ShaderDataGroup.Camera), _this._isCustomViewMatrix = false, _this._isCustomProjectionMatrix = false, _this._fieldOfView = 45, _this._orthographicSize = 10, _this._isProjectionDirty = true, _this._isInvProjMatDirty = true, _this._customAspectRatio = undefined, _this._renderTarget = null, _this._depthBufferParams = new Vector4(), _this._opaqueTextureEnabled = false, _this._enableHDR = false, _this._enablePostProcess = false, _this._viewport = new Vector4(0, 0, 1, 1), _this._pixelViewport = new Rect(0, 0, 0, 0), _this._inverseProjectionMatrix = new Matrix(), _this._invViewProjMat = new Matrix();
8846
- var transform = _this.entity.transform;
8847
- _this._transform = transform;
8848
- _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
8849
- _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
8850
- _this._frustumChangeFlag = transform.registerWorldChangeFlag();
8951
+ _this._isViewMatrixDirty = entity.registerWorldChangeFlag();
8952
+ _this._isInvViewProjDirty = entity.registerWorldChangeFlag();
8953
+ _this._frustumChangeFlag = entity.registerWorldChangeFlag();
8851
8954
  _this._renderPipeline = new BasicRenderPipeline(_this);
8852
8955
  _this._addResourceReferCount(_this.shaderData, 1);
8853
8956
  _this._updatePixelViewport();
@@ -8994,7 +9097,7 @@ var Camera = /*#__PURE__*/ function(Component) {
8994
9097
  var engine = this._engine;
8995
9098
  var context = engine._renderContext;
8996
9099
  var virtualCamera = this._virtualCamera;
8997
- var transform = this.entity.transform;
9100
+ var transform = this._entity.transform;
8998
9101
  Matrix.multiply(this.projectionMatrix, this.viewMatrix, virtualCamera.viewProjectionMatrix);
8999
9102
  virtualCamera.position.copyFrom(transform.worldPosition);
9000
9103
  if (virtualCamera.isOrthographic) {
@@ -9072,7 +9175,6 @@ var Camera = /*#__PURE__*/ function(Component) {
9072
9175
  this._virtualCamera = null;
9073
9176
  this._shaderData = null;
9074
9177
  this._frustumChangeFlag = null;
9075
- this._transform = null;
9076
9178
  this._isViewMatrixDirty = null;
9077
9179
  this._isInvViewProjDirty = null;
9078
9180
  this._viewport = null;
@@ -9114,7 +9216,7 @@ var Camera = /*#__PURE__*/ function(Component) {
9114
9216
  };
9115
9217
  _proto._updateShaderData = function _updateShaderData() {
9116
9218
  var shaderData = this.shaderData;
9117
- var transform = this._transform;
9219
+ var transform = this._entity.transform;
9118
9220
  shaderData.setMatrix(Camera._inverseViewMatrixProperty, transform.worldMatrix);
9119
9221
  shaderData.setVector3(Camera._cameraPositionProperty, transform.worldPosition);
9120
9222
  shaderData.setVector3(Camera._cameraForwardProperty, transform.worldForward);
@@ -9129,7 +9231,7 @@ var Camera = /*#__PURE__*/ function(Component) {
9129
9231
  */ _proto._getInvViewProjMat = function _getInvViewProjMat() {
9130
9232
  if (this._isInvViewProjDirty.flag) {
9131
9233
  this._isInvViewProjDirty.flag = false;
9132
- Matrix.multiply(this._transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
9234
+ Matrix.multiply(this._entity.transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
9133
9235
  }
9134
9236
  return this._invViewProjMat;
9135
9237
  };
@@ -9176,13 +9278,17 @@ var Camera = /*#__PURE__*/ function(Component) {
9176
9278
  key: "independentCanvasEnabled",
9177
9279
  get: /**
9178
9280
  * Whether independent canvas is enabled.
9179
- *
9180
9281
  * @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
9181
9282
  */ function get() {
9182
- if (this.enableHDR || this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
9283
+ // Uber pass need internal RT
9284
+ if (this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
9183
9285
  return true;
9184
9286
  }
9185
- return this.opaqueTextureEnabled && !this._renderTarget;
9287
+ if (this.enableHDR || this.opaqueTextureEnabled) {
9288
+ var _this_renderTarget;
9289
+ return this._getInternalColorTextureFormat() !== ((_this_renderTarget = this.renderTarget) == null ? void 0 : _this_renderTarget.getColorTexture(0).format);
9290
+ }
9291
+ return false;
9186
9292
  }
9187
9293
  },
9188
9294
  {
@@ -9324,7 +9430,7 @@ var Camera = /*#__PURE__*/ function(Component) {
9324
9430
  }
9325
9431
  this._isViewMatrixDirty.flag = false;
9326
9432
  // Ignore scale
9327
- var transform = this._transform;
9433
+ var transform = this._entity.transform;
9328
9434
  Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
9329
9435
  viewMatrix.invert();
9330
9436
  return viewMatrix;
@@ -9442,9 +9548,6 @@ __decorate([
9442
9548
  __decorate([
9443
9549
  ignoreClone
9444
9550
  ], Camera.prototype, "_frustumChangeFlag", void 0);
9445
- __decorate([
9446
- ignoreClone
9447
- ], Camera.prototype, "_transform", void 0);
9448
9551
  __decorate([
9449
9552
  ignoreClone
9450
9553
  ], Camera.prototype, "_isViewMatrixDirty", void 0);
@@ -9631,9 +9734,21 @@ RenderContext._flipYViewProjectionMatrix = new Matrix();
9631
9734
  if (shaderPass.getTagValue(pipelineStageKey) !== pipelineStageTagValue) {
9632
9735
  continue;
9633
9736
  }
9634
- if (!needMaskType) {
9635
- var _shaderPass__renderState;
9636
- if (((_shaderPass__renderState = shaderPass._renderState) != null ? _shaderPass__renderState : renderStates[j]).renderQueueType !== renderQueueType) {
9737
+ var renderState = shaderPass._renderState;
9738
+ if (needMaskType) {
9739
+ // Mask don't care render queue type
9740
+ if (!renderState) {
9741
+ renderState = renderStates[j];
9742
+ }
9743
+ } else {
9744
+ var passQueueType = void 0;
9745
+ if (renderState) {
9746
+ passQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, materialData);
9747
+ } else {
9748
+ renderState = renderStates[j];
9749
+ passQueueType = renderState.renderQueueType;
9750
+ }
9751
+ if (passQueueType !== renderQueueType) {
9637
9752
  continue;
9638
9753
  }
9639
9754
  }
@@ -9688,9 +9803,7 @@ RenderContext._flipYViewProjectionMatrix = new Matrix();
9688
9803
  program.uploadUnGroupTextures();
9689
9804
  }
9690
9805
  }
9691
- var _shaderPass__renderState1;
9692
- var renderState = (_shaderPass__renderState1 = shaderPass._renderState) != null ? _shaderPass__renderState1 : renderStates[j];
9693
- renderState._applyStates(engine, renderer.entity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
9806
+ renderState._applyStates(engine, renderer._transformEntity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
9694
9807
  rhi.drawPrimitive(primitive, subElement.subPrimitive, program);
9695
9808
  }
9696
9809
  }
@@ -10550,6 +10663,8 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
10550
10663
  function BasicRenderPipeline(camera) {
10551
10664
  this._lastCanvasSize = new Vector2();
10552
10665
  this._internalColorTarget = null;
10666
+ this._canUseBlitFrameBuffer = false;
10667
+ this._shouldGrabColor = false;
10553
10668
  this._camera = camera;
10554
10669
  var engine = camera.engine;
10555
10670
  this._cullingResults = new CullingResults();
@@ -10574,10 +10689,19 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
10574
10689
  context.rendererUpdateFlag = ContextRendererUpdateFlag.All;
10575
10690
  var camera = this._camera;
10576
10691
  var scene = camera.scene, engine = camera.engine;
10692
+ var rhi = engine._hardwareRenderer;
10577
10693
  var cullingResults = this._cullingResults;
10578
10694
  var sunlight = scene._lightManager._sunlight;
10579
10695
  var depthOnlyPass = this._depthOnlyPass;
10580
10696
  var depthPassEnabled = camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
10697
+ var finalClearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
10698
+ var independentCanvasEnabled = camera.independentCanvasEnabled;
10699
+ var msaaSamples = camera.renderTarget ? camera.renderTarget.antiAliasing : camera.msaaSamples;
10700
+ this._shouldGrabColor = independentCanvasEnabled && !(finalClearFlags & CameraClearFlags.Color);
10701
+ // 1. Only support blitFramebuffer in webgl2 context
10702
+ // 2. Can't blit normal FBO to MSAA FBO
10703
+ // 3. Can't blit screen MSAA FBO to normal FBO in mac safari platform and mobile, but mac chrome and firfox is OK
10704
+ this._canUseBlitFrameBuffer = rhi.isWebGL2 && msaaSamples === 1 && (!!camera.renderTarget || !rhi.context.antialias);
10581
10705
  if (scene.castShadows && sunlight && sunlight.shadowType !== ShadowType.None) {
10582
10706
  this._cascadedShadowCasterPass.onRender(context);
10583
10707
  context.rendererUpdateFlag = ContextRendererUpdateFlag.None;
@@ -10597,24 +10721,46 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
10597
10721
  } else {
10598
10722
  camera.shaderData.setTexture(Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
10599
10723
  }
10600
- // Check if need to create internal color texture
10601
- var independentCanvasEnabled = camera.independentCanvasEnabled;
10724
+ // Check if need to create internal color texture or grab texture
10602
10725
  if (independentCanvasEnabled) {
10726
+ var depthFormat;
10727
+ if (camera.renderTarget) {
10728
+ depthFormat = camera.renderTarget._depthFormat;
10729
+ } else if (rhi.context.depth && rhi.context.stencil) {
10730
+ depthFormat = TextureFormat.Depth24Stencil8;
10731
+ } else if (rhi.context.depth) {
10732
+ depthFormat = TextureFormat.Depth24;
10733
+ } else if (rhi.context.stencil) {
10734
+ depthFormat = TextureFormat.Stencil;
10735
+ } else {
10736
+ depthFormat = null;
10737
+ }
10603
10738
  var viewport = camera.pixelViewport;
10604
- var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), TextureFormat.Depth24Stencil8, false, false, camera.msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
10739
+ var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
10740
+ if (!this._canUseBlitFrameBuffer && this._shouldGrabColor) {
10741
+ var _camera_renderTarget;
10742
+ var _camera_renderTarget_getColorTexture_format;
10743
+ var grabTexture = PipelineUtils.recreateTextureIfNeeded(engine, this._grabTexture, viewport.width, viewport.height, (_camera_renderTarget_getColorTexture_format = (_camera_renderTarget = camera.renderTarget) == null ? void 0 : _camera_renderTarget.getColorTexture(0).format) != null ? _camera_renderTarget_getColorTexture_format : TextureFormat.R8G8B8A8, false, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
10744
+ this._grabTexture = grabTexture;
10745
+ }
10605
10746
  this._internalColorTarget = internalColorTarget;
10606
10747
  } else {
10607
10748
  var internalColorTarget1 = this._internalColorTarget;
10749
+ var grabTexture1 = this._grabTexture;
10608
10750
  if (internalColorTarget1) {
10609
10751
  var _internalColorTarget_getColorTexture;
10610
10752
  (_internalColorTarget_getColorTexture = internalColorTarget1.getColorTexture(0)) == null ? void 0 : _internalColorTarget_getColorTexture.destroy(true);
10611
10753
  internalColorTarget1.destroy(true);
10612
10754
  this._internalColorTarget = null;
10613
10755
  }
10756
+ if (grabTexture1) {
10757
+ grabTexture1.destroy(true);
10758
+ this._grabTexture = null;
10759
+ }
10614
10760
  }
10615
- this._drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear);
10761
+ this._drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel);
10616
10762
  };
10617
- _proto._drawRenderPass = function _drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear) {
10763
+ _proto._drawRenderPass = function _drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel) {
10618
10764
  var cullingResults = this._cullingResults;
10619
10765
  var opaqueQueue = cullingResults.opaqueQueue, alphaTestQueue = cullingResults.alphaTestQueue, transparentQueue = cullingResults.transparentQueue;
10620
10766
  var engine = camera.engine, scene = camera.scene;
@@ -10630,18 +10776,38 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
10630
10776
  context.applyVirtualCamera(camera._virtualCamera, needFlipProjection);
10631
10777
  }
10632
10778
  rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
10633
- var clearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
10634
10779
  var color = background.solidColor;
10635
- if (clearFlags !== CameraClearFlags.None) {
10636
- rhi.clearRenderTarget(engine, clearFlags, color);
10780
+ if (internalColorTarget && finalClearFlags !== CameraClearFlags.All) {
10781
+ // Can use `blitFramebuffer` API to copy color/depth/stencil buffer from back buffer to internal RT
10782
+ if (this._canUseBlitFrameBuffer) {
10783
+ finalClearFlags !== CameraClearFlags.None && rhi.clearRenderTarget(engine, finalClearFlags, color);
10784
+ rhi.blitInternalRTByBlitFrameBuffer(camera.renderTarget, internalColorTarget, finalClearFlags, camera.viewport);
10785
+ } else {
10786
+ if (!(finalClearFlags & CameraClearFlags.Depth) || !(finalClearFlags & CameraClearFlags.Stencil)) {
10787
+ Logger.warn("We clear all depth/stencil state cause of the internalRT can't copy depth/stencil buffer from back buffer when use copy plan");
10788
+ }
10789
+ if (this._shouldGrabColor) {
10790
+ rhi.clearRenderTarget(engine, CameraClearFlags.DepthStencil);
10791
+ // Copy RT's color buffer to grab texture
10792
+ rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._grabTexture, camera.viewport);
10793
+ // Then blit grab texture to internal RT's color buffer
10794
+ PipelineUtils.blitTexture(engine, this._grabTexture, internalColorTarget, 0, undefined, undefined, undefined, // Only flip Y axis in webgl context
10795
+ !camera.renderTarget);
10796
+ } else {
10797
+ rhi.clearRenderTarget(engine, CameraClearFlags.All, color);
10798
+ }
10799
+ }
10800
+ rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
10801
+ } else if (finalClearFlags !== CameraClearFlags.None) {
10802
+ rhi.clearRenderTarget(engine, finalClearFlags, color);
10637
10803
  }
10638
10804
  var maskManager = scene._maskManager;
10639
- if (clearFlags & CameraClearFlags.Stencil) {
10805
+ if (finalClearFlags & CameraClearFlags.Stencil) {
10640
10806
  maskManager.hasStencilWritten = false;
10641
10807
  }
10642
10808
  opaqueQueue.render(context, PipelineStage.Forward);
10643
10809
  alphaTestQueue.render(context, PipelineStage.Forward);
10644
- if (clearFlags & CameraClearFlags.Color) {
10810
+ if (finalClearFlags & CameraClearFlags.Color) {
10645
10811
  if (background.mode === BackgroundMode.Sky) {
10646
10812
  background.sky._render(context);
10647
10813
  } else if (background.mode === BackgroundMode.Texture && background.texture) {
@@ -10718,8 +10884,7 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
10718
10884
  var shaderPass = shaderPasses[i];
10719
10885
  var renderState = shaderPass._renderState;
10720
10886
  if (renderState) {
10721
- renderState._applyRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
10722
- renderQueueType = renderState.renderQueueType;
10887
+ renderQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
10723
10888
  } else {
10724
10889
  renderQueueType = renderStates[i].renderQueueType;
10725
10890
  }
@@ -12989,15 +13154,29 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
12989
13154
  _inherits(PBRMaterial, PBRBaseMaterial);
12990
13155
  function PBRMaterial(engine) {
12991
13156
  var _this;
12992
- _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new Vector2(100, 400);
13157
+ _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new Vector2(100, 400), _this._sheenEnabled = false;
12993
13158
  var shaderData = _this.shaderData;
12994
13159
  shaderData.setFloat(PBRMaterial._metallicProp, 1);
12995
13160
  shaderData.setFloat(PBRMaterial._roughnessProp, 1);
12996
13161
  shaderData.setFloat(PBRMaterial._iorProp, 1.5);
12997
13162
  shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
12998
13163
  shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new Vector4(0, 1.3, 100, 400));
13164
+ var sheenColor = new Color(0, 0, 0);
13165
+ shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor);
12999
13166
  // @ts-ignore
13000
13167
  _this._iridescenceRange._onValueChanged = _this._onIridescenceRangeChanged.bind(_this);
13168
+ // @ts-ignore
13169
+ sheenColor._onValueChanged = function() {
13170
+ var enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0;
13171
+ if (enableSheen !== _this._sheenEnabled) {
13172
+ _this._sheenEnabled = enableSheen;
13173
+ if (enableSheen) {
13174
+ _this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
13175
+ } else {
13176
+ _this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
13177
+ }
13178
+ }
13179
+ };
13001
13180
  return _this;
13002
13181
  }
13003
13182
  var _proto = PBRMaterial.prototype;
@@ -13178,7 +13357,7 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13178
13357
  key: "iridescenceThicknessRange",
13179
13358
  get: /**
13180
13359
  * The range of iridescence thickness, x is minimum, y is maximum.
13181
- * @defaultValue `[100, 400]`.
13360
+ * @defaultValue `[100, 400]`
13182
13361
  */ function get() {
13183
13362
  return this._iridescenceRange;
13184
13363
  },
@@ -13206,6 +13385,67 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13206
13385
  this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
13207
13386
  }
13208
13387
  }
13388
+ },
13389
+ {
13390
+ key: "sheenColor",
13391
+ get: /**
13392
+ * Sheen color.
13393
+ * @defaultValue `[0,0,0]`
13394
+ */ function get() {
13395
+ return this.shaderData.getColor(PBRMaterial._sheenColorProp);
13396
+ },
13397
+ set: function set(value) {
13398
+ var sheenColor = this.shaderData.getColor(PBRMaterial._sheenColorProp);
13399
+ if (value !== sheenColor) {
13400
+ sheenColor.copyFrom(value);
13401
+ }
13402
+ }
13403
+ },
13404
+ {
13405
+ key: "sheenRoughness",
13406
+ get: /**
13407
+ * Sheen roughness, from 0.0 to 1.0.
13408
+ * @defaultValue `0.0`
13409
+ */ function get() {
13410
+ return this.shaderData.getFloat(PBRMaterial._sheenRoughnessProp);
13411
+ },
13412
+ set: function set(value) {
13413
+ value = Math.max(0, Math.min(1, value));
13414
+ this.shaderData.setFloat(PBRMaterial._sheenRoughnessProp, value);
13415
+ }
13416
+ },
13417
+ {
13418
+ key: "sheenColorTexture",
13419
+ get: /**
13420
+ * Sheen color texture, multiply ‘sheenColor’.
13421
+ */ function get() {
13422
+ return this.shaderData.getTexture(PBRMaterial._sheenTextureProp);
13423
+ },
13424
+ set: function set(value) {
13425
+ this.shaderData.setTexture(PBRMaterial._sheenTextureProp, value);
13426
+ if (value) {
13427
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
13428
+ } else {
13429
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
13430
+ }
13431
+ }
13432
+ },
13433
+ {
13434
+ key: "sheenRoughnessTexture",
13435
+ get: /**
13436
+ * Sheen roughness texture.
13437
+ * @remarks Use alpha channel, and multiply 'sheenRoughness'.
13438
+ */ function get() {
13439
+ return this.shaderData.getTexture(PBRMaterial._sheenRoughnessTextureProp);
13440
+ },
13441
+ set: function set(value) {
13442
+ this.shaderData.setTexture(PBRMaterial._sheenRoughnessTextureProp, value);
13443
+ if (value) {
13444
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
13445
+ } else {
13446
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
13447
+ }
13448
+ }
13209
13449
  }
13210
13450
  ]);
13211
13451
  return PBRMaterial;
@@ -13219,6 +13459,10 @@ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_Anisotro
13219
13459
  PBRMaterial._iridescenceInfoProp = ShaderProperty.getByName("material_IridescenceInfo");
13220
13460
  PBRMaterial._iridescenceThicknessTextureProp = ShaderProperty.getByName("material_IridescenceThicknessTexture");
13221
13461
  PBRMaterial._iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture");
13462
+ PBRMaterial._sheenColorProp = ShaderProperty.getByName("material_SheenColor");
13463
+ PBRMaterial._sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness");
13464
+ PBRMaterial._sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
13465
+ PBRMaterial._sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture");
13222
13466
 
13223
13467
  /**
13224
13468
  * PBR (Specular-Glossiness Workflow) Material.
@@ -14018,8 +14262,7 @@ var BlendShapeFrameDirty = /*#__PURE__*/ function(BlendShapeFrameDirty) {
14018
14262
  var mesh = this._mesh;
14019
14263
  if (mesh) {
14020
14264
  var localBounds = mesh.bounds;
14021
- var worldMatrix = this._entity.transform.worldMatrix;
14022
- BoundingBox.transform(localBounds, worldMatrix, worldBounds);
14265
+ BoundingBox.transform(localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
14023
14266
  } else {
14024
14267
  worldBounds.min.set(0, 0, 0);
14025
14268
  worldBounds.max.set(0, 0, 0);
@@ -16918,12 +17161,18 @@ var ComponentCloner = /*#__PURE__*/ function() {
16918
17161
  */ var Entity = /*#__PURE__*/ function(EngineObject) {
16919
17162
  _inherits(Entity, EngineObject);
16920
17163
  function Entity(engine, name) {
17164
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
17165
+ components[_key - 2] = arguments[_key];
17166
+ }
16921
17167
  var _this;
16922
- _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
17168
+ _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
16923
17169
  _this._invModelMatrix = new Matrix();
16924
17170
  _this.name = name;
16925
- _this.transform = _this.addComponent(Transform);
16926
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
17171
+ for(var i = 0, n = components.length; i < n; i++){
17172
+ _this.addComponent(components[i]);
17173
+ }
17174
+ !_this._transform && _this.addComponent(Transform);
17175
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
16927
17176
  return _this;
16928
17177
  }
16929
17178
  var _proto = Entity.prototype;
@@ -16941,6 +17190,12 @@ var ComponentCloner = /*#__PURE__*/ function() {
16941
17190
  this
16942
17191
  ], args));
16943
17192
  this._components.push(component);
17193
+ // @todo: temporary solution
17194
+ if (_instanceof(component, Transform)) {
17195
+ var transform = this._transform;
17196
+ this._transform = component;
17197
+ transform == null ? void 0 : transform.destroy();
17198
+ }
16944
17199
  component._setActive(true, ActiveChangeFlag.All);
16945
17200
  return component;
16946
17201
  };
@@ -17084,7 +17339,8 @@ var ComponentCloner = /*#__PURE__*/ function() {
17084
17339
  * @param name - The child entity's name
17085
17340
  * @returns The child entity
17086
17341
  */ _proto.createChild = function createChild(name) {
17087
- var child = new Entity(this.engine, name);
17342
+ var transform = this._transform;
17343
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
17088
17344
  child.layer = this.layer;
17089
17345
  child.parent = this;
17090
17346
  return child;
@@ -17113,13 +17369,20 @@ var ComponentCloner = /*#__PURE__*/ function() {
17113
17369
  return cloneEntity;
17114
17370
  };
17115
17371
  /**
17372
+ * Listen for changes in the world pose of this `Entity`.
17373
+ * @returns Change flag
17374
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
17375
+ return this._updateFlagManager.createFlag(BoolUpdateFlag);
17376
+ };
17377
+ /**
17116
17378
  * @internal
17117
17379
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
17118
17380
  this._isTemplate = true;
17119
17381
  this._templateResource = templateResource;
17120
17382
  };
17121
17383
  _proto._createCloneEntity = function _createCloneEntity() {
17122
- var cloneEntity = new Entity(this._engine, this.name);
17384
+ var transform = this._transform;
17385
+ var cloneEntity = transform ? new Entity(this.engine, this.name, transform.constructor) : new Entity(this.engine, this.name);
17123
17386
  var templateResource = this._templateResource;
17124
17387
  if (templateResource) {
17125
17388
  cloneEntity._templateResource = templateResource;
@@ -17127,11 +17390,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
17127
17390
  }
17128
17391
  cloneEntity.layer = this.layer;
17129
17392
  cloneEntity._isActive = this._isActive;
17130
- var cloneTransform = cloneEntity.transform;
17131
- var _this = this, srcTransform = _this.transform;
17132
- cloneTransform.position = srcTransform.position;
17133
- cloneTransform.rotation = srcTransform.rotation;
17134
- cloneTransform.scale = srcTransform.scale;
17393
+ cloneEntity.transform._copyFrom(this.transform);
17135
17394
  var srcChildren = this._children;
17136
17395
  for(var i = 0, n = srcChildren.length; i < n; i++){
17137
17396
  cloneEntity.addChild(srcChildren[i]._createCloneEntity());
@@ -17431,6 +17690,14 @@ var ComponentCloner = /*#__PURE__*/ function() {
17431
17690
  return entity;
17432
17691
  };
17433
17692
  _create_class(Entity, [
17693
+ {
17694
+ key: "transform",
17695
+ get: /**
17696
+ * The transform of this entity.
17697
+ */ function get() {
17698
+ return this._transform;
17699
+ }
17700
+ },
17434
17701
  {
17435
17702
  key: "isActive",
17436
17703
  get: /**
@@ -17680,16 +17947,6 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17680
17947
  var _proto = SkinnedMeshRenderer.prototype;
17681
17948
  /**
17682
17949
  * @internal
17683
- */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
17684
- var worldMatrix = this._transform.worldMatrix;
17685
- if (onlyMVP) {
17686
- this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
17687
- } else {
17688
- this._updateWorldViewRelatedShaderData(context, worldMatrix, batched);
17689
- }
17690
- };
17691
- /**
17692
- * @internal
17693
17950
  */ _proto._onDestroy = function _onDestroy() {
17694
17951
  var _this__jointTexture;
17695
17952
  MeshRenderer.prototype._onDestroy.call(this);
@@ -17765,7 +18022,7 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17765
18022
  var _this_skin;
17766
18023
  var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
17767
18024
  if (rootBone) {
17768
- BoundingBox.transform(this._localBounds, this._transform.worldMatrix, worldBounds);
18025
+ BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
17769
18026
  } else {
17770
18027
  MeshRenderer.prototype._updateBounds.call(this, worldBounds);
17771
18028
  }
@@ -17806,7 +18063,7 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17806
18063
  }
17807
18064
  break;
17808
18065
  case SkinUpdateFlag.RootBoneChanged:
17809
- this._setTransform(value.transform);
18066
+ this._setTransformEntity(value);
17810
18067
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
17811
18068
  break;
17812
18069
  }
@@ -18503,7 +18760,8 @@ PrimitiveChunk.subMeshPool = new ReturnableObjectPool(SubMesh, 10);
18503
18760
  /** Scene. */ AssetType["Scene"] = "Scene";
18504
18761
  /** HDR to cube. */ AssetType["HDR"] = "HDR";
18505
18762
  /** Font. */ AssetType["Font"] = "Font";
18506
- /** Source Font, include ttf otf and woff. */ AssetType["SourceFont"] = "SourceFont";
18763
+ /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
18764
+ /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
18507
18765
  /** Project asset. */ AssetType["Project"] = "project";
18508
18766
  return AssetType;
18509
18767
  }({});
@@ -18893,9 +19151,10 @@ var defaultRetryCount = 1;
18893
19151
  var defaultTimeout = Infinity;
18894
19152
  var defaultInterval = 500;
18895
19153
  /**
18896
- * Web request.
18897
- * @param url - The link
18898
- * @param config - Load configuration
19154
+ * Sends a request to the specified URL and returns a promise for the response.
19155
+ * @param url - The URL to send the request to
19156
+ * @param config - Configuration options for the request
19157
+ * @returns A promise that resolves with the response of type `T`
18899
19158
  */ function request(url, config) {
18900
19159
  if (config === void 0) config = {};
18901
19160
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
@@ -19396,7 +19655,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
19396
19655
  var assetBaseURL = baseUrl;
19397
19656
  if (searchStr) {
19398
19657
  var params = searchStr.split("&");
19399
- for(var i = 0; i < params.length; i++){
19658
+ for(var i = params.length - 1; i >= 0; i--){
19400
19659
  var param = params[i];
19401
19660
  if (param.startsWith("q=")) {
19402
19661
  queryPath = decodeURIComponent(param.split("=")[1]);
@@ -19445,11 +19704,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19445
19704
  Logger.warn("refId:" + refId + " is not find in this._editorResourceConfig.");
19446
19705
  return Promise.resolve(null);
19447
19706
  }
19448
- var remoteUrl = resourceConfig.path;
19449
- var queryPath = new URL(remoteUrl).search;
19450
- var url = resourceConfig.virtualPath + queryPath;
19707
+ var url = resourceConfig.virtualPath;
19451
19708
  if (key) {
19452
- url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key;
19709
+ url += "?q=" + key;
19453
19710
  }
19454
19711
  promise = this.load({
19455
19712
  url: url,
@@ -20111,7 +20368,7 @@ var Collider = /*#__PURE__*/ function(Component) {
20111
20368
  function Collider(entity) {
20112
20369
  var _this;
20113
20370
  _this = Component.call(this, entity) || this, /** @internal */ _this._index = -1, _this._shapes = [];
20114
- _this._updateFlag = _this.entity.transform.registerWorldChangeFlag();
20371
+ _this._updateFlag = entity.registerWorldChangeFlag();
20115
20372
  return _this;
20116
20373
  }
20117
20374
  var _proto = Collider.prototype;
@@ -20125,9 +20382,8 @@ var Collider = /*#__PURE__*/ function(Component) {
20125
20382
  oldCollider.removeShape(shape);
20126
20383
  }
20127
20384
  this._shapes.push(shape);
20128
- shape._collider = this;
20129
- this._nativeCollider.addShape(shape._nativeShape);
20130
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
20385
+ this._addNativeShape(shape);
20386
+ this._handleShapesChanged();
20131
20387
  }
20132
20388
  };
20133
20389
  /**
@@ -20137,9 +20393,8 @@ var Collider = /*#__PURE__*/ function(Component) {
20137
20393
  var index = this._shapes.indexOf(shape);
20138
20394
  if (index !== -1) {
20139
20395
  this._shapes.splice(index, 1);
20140
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
20141
- shape._collider = null;
20142
- this._nativeCollider.removeShape(shape._nativeShape);
20396
+ this._removeNativeShape(shape);
20397
+ this._handleShapesChanged();
20143
20398
  }
20144
20399
  };
20145
20400
  /**
@@ -20147,12 +20402,10 @@ var Collider = /*#__PURE__*/ function(Component) {
20147
20402
  */ _proto.clearShapes = function clearShapes() {
20148
20403
  var shapes = this._shapes;
20149
20404
  for(var i = 0, n = shapes.length; i < n; i++){
20150
- var shape = shapes[i];
20151
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
20152
- shape._destroy();
20153
- this._nativeCollider.removeShape(shape._nativeShape);
20405
+ this._removeNativeShape(shapes[i]);
20154
20406
  }
20155
20407
  shapes.length = 0;
20408
+ this._handleShapesChanged();
20156
20409
  };
20157
20410
  /**
20158
20411
  * @internal
@@ -20173,42 +20426,46 @@ var Collider = /*#__PURE__*/ function(Component) {
20173
20426
  /**
20174
20427
  * @internal
20175
20428
  */ _proto._onEnableInScene = function _onEnableInScene() {
20176
- var physics = this.scene.physics;
20177
- physics._addCollider(this);
20178
- var shapes = this.shapes;
20179
- for(var i = 0, n = shapes.length; i < n; i++){
20180
- physics._addColliderShape(shapes[i]);
20181
- }
20429
+ this.scene.physics._addCollider(this);
20182
20430
  };
20183
20431
  /**
20184
20432
  * @internal
20185
20433
  */ _proto._onDisableInScene = function _onDisableInScene() {
20186
- var physics = this.scene.physics;
20187
- physics._removeCollider(this);
20188
- var shapes = this.shapes;
20189
- for(var i = 0, n = shapes.length; i < n; i++){
20190
- physics._removeColliderShape(shapes[i]);
20191
- }
20434
+ this.scene.physics._removeCollider(this);
20192
20435
  };
20193
20436
  /**
20194
20437
  * @internal
20195
20438
  */ _proto._cloneTo = function _cloneTo(target) {
20196
- var shapes = target._shapes;
20197
- for(var i = 0, n = shapes.length; i < n; i++){
20198
- target._addPhysicsShape(shapes[i]);
20439
+ target._syncNative();
20440
+ };
20441
+ /**
20442
+ * @internal
20443
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {};
20444
+ _proto._syncNative = function _syncNative() {
20445
+ for(var i = 0, n = this.shapes.length; i < n; i++){
20446
+ this._addNativeShape(this.shapes[i]);
20199
20447
  }
20200
20448
  };
20201
20449
  /**
20202
20450
  * @internal
20203
20451
  */ _proto._onDestroy = function _onDestroy() {
20204
20452
  Component.prototype._onDestroy.call(this);
20205
- this.clearShapes();
20453
+ var shapes = this._shapes;
20454
+ for(var i = 0, n = shapes.length; i < n; i++){
20455
+ var shape = shapes[i];
20456
+ this._removeNativeShape(shape);
20457
+ shape._destroy();
20458
+ }
20459
+ shapes.length = 0;
20206
20460
  this._nativeCollider.destroy();
20207
20461
  };
20208
- _proto._addPhysicsShape = function _addPhysicsShape(shape) {
20462
+ _proto._addNativeShape = function _addNativeShape(shape) {
20209
20463
  shape._collider = this;
20210
20464
  this._nativeCollider.addShape(shape._nativeShape);
20211
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
20465
+ };
20466
+ _proto._removeNativeShape = function _removeNativeShape(shape) {
20467
+ shape._collider = null;
20468
+ this._nativeCollider.removeShape(shape._nativeShape);
20212
20469
  };
20213
20470
  _create_class(Collider, [
20214
20471
  {
@@ -20245,13 +20502,12 @@ var Collision = function Collision() {
20245
20502
  * A physics scene is a collection of colliders and constraints which can interact.
20246
20503
  */ var PhysicsScene = /*#__PURE__*/ function() {
20247
20504
  function PhysicsScene(scene) {
20248
- var _this = this;
20249
20505
  this._restTime = 0;
20250
20506
  this._fixedTimeStep = 1 / 60;
20251
20507
  this._colliders = new DisorderedArray();
20252
20508
  this._gravity = new Vector3(0, -9.81, 0);
20253
20509
  this._onContactEnter = function(obj1, obj2) {
20254
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20510
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20255
20511
  var shape1 = physicalObjectsMap[obj1];
20256
20512
  var shape2 = physicalObjectsMap[obj2];
20257
20513
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20270,7 +20526,7 @@ var Collision = function Collision() {
20270
20526
  });
20271
20527
  };
20272
20528
  this._onContactExit = function(obj1, obj2) {
20273
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20529
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20274
20530
  var shape1 = physicalObjectsMap[obj1];
20275
20531
  var shape2 = physicalObjectsMap[obj2];
20276
20532
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20289,7 +20545,7 @@ var Collision = function Collision() {
20289
20545
  });
20290
20546
  };
20291
20547
  this._onContactStay = function(obj1, obj2) {
20292
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20548
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20293
20549
  var shape1 = physicalObjectsMap[obj1];
20294
20550
  var shape2 = physicalObjectsMap[obj2];
20295
20551
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20308,7 +20564,7 @@ var Collision = function Collision() {
20308
20564
  });
20309
20565
  };
20310
20566
  this._onTriggerEnter = function(obj1, obj2) {
20311
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20567
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20312
20568
  var shape1 = physicalObjectsMap[obj1];
20313
20569
  var shape2 = physicalObjectsMap[obj2];
20314
20570
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20323,7 +20579,7 @@ var Collision = function Collision() {
20323
20579
  });
20324
20580
  };
20325
20581
  this._onTriggerExit = function(obj1, obj2) {
20326
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20582
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20327
20583
  var shape1 = physicalObjectsMap[obj1];
20328
20584
  var shape2 = physicalObjectsMap[obj2];
20329
20585
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20338,7 +20594,7 @@ var Collision = function Collision() {
20338
20594
  });
20339
20595
  };
20340
20596
  this._onTriggerStay = function(obj1, obj2) {
20341
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20597
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20342
20598
  var shape1 = physicalObjectsMap[obj1];
20343
20599
  var shape2 = physicalObjectsMap[obj2];
20344
20600
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20363,7 +20619,6 @@ var Collision = function Collision() {
20363
20619
  }
20364
20620
  var _proto = PhysicsScene.prototype;
20365
20621
  _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
20366
- var _this = this;
20367
20622
  var hitResult;
20368
20623
  var distance = Number.MAX_VALUE;
20369
20624
  if (typeof distanceOrResult === "number") {
@@ -20381,7 +20636,7 @@ var Collision = function Collision() {
20381
20636
  hitResult = outHitResult;
20382
20637
  }
20383
20638
  var onRaycast = function(obj) {
20384
- var shape = _this._scene.engine._physicalObjectsMap[obj];
20639
+ var shape = Engine._physicalObjectsMap[obj];
20385
20640
  if (!shape) {
20386
20641
  return false;
20387
20642
  }
@@ -20389,7 +20644,7 @@ var Collision = function Collision() {
20389
20644
  };
20390
20645
  if (hitResult != undefined) {
20391
20646
  var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
20392
- var hitShape = _this._scene.engine._physicalObjectsMap[idx];
20647
+ var hitShape = Engine._physicalObjectsMap[idx];
20393
20648
  hitResult.entity = hitShape._collider.entity;
20394
20649
  hitResult.shape = hitShape;
20395
20650
  hitResult.distance = distance;
@@ -20427,22 +20682,6 @@ var Collision = function Collision() {
20427
20682
  }
20428
20683
  };
20429
20684
  /**
20430
- * Add ColliderShape into the manager.
20431
- * @param colliderShape - The Collider Shape.
20432
- * @internal
20433
- */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
20434
- this._scene.engine._physicalObjectsMap[colliderShape.id] = colliderShape;
20435
- this._nativePhysicsScene.addColliderShape(colliderShape._nativeShape);
20436
- };
20437
- /**
20438
- * Remove ColliderShape.
20439
- * @param colliderShape - The Collider Shape.
20440
- * @internal
20441
- */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
20442
- delete this._scene.engine._physicalObjectsMap[colliderShape.id];
20443
- this._nativePhysicsScene.removeColliderShape(colliderShape._nativeShape);
20444
- };
20445
- /**
20446
20685
  * Add collider into the manager.
20447
20686
  * @param collider - StaticCollider or DynamicCollider.
20448
20687
  * @internal
@@ -20585,13 +20824,6 @@ PhysicsScene._collision = new Collision();
20585
20824
  this._updateFlag.flag = true;
20586
20825
  };
20587
20826
  /**
20588
- * Remove all shape attached.
20589
- */ _proto.clearShapes = function clearShapes() {
20590
- if (this._shapes.length > 0) {
20591
- Collider.prototype.removeShape.call(this, this._shapes[0]);
20592
- }
20593
- };
20594
- /**
20595
20827
  * @internal
20596
20828
  */ _proto._onUpdate = function _onUpdate() {
20597
20829
  if (this._updateFlag.flag) {
@@ -20614,22 +20846,19 @@ PhysicsScene._collision = new Collision();
20614
20846
  /**
20615
20847
  * @internal
20616
20848
  */ _proto._onEnableInScene = function _onEnableInScene() {
20617
- var physics = this.scene.physics;
20618
- physics._addCharacterController(this);
20619
- var shapes = this.shapes;
20620
- for(var i = 0, n = shapes.length; i < n; i++){
20621
- physics._addColliderShape(shapes[i]);
20622
- }
20849
+ this.scene.physics._addCharacterController(this);
20623
20850
  };
20624
20851
  /**
20625
20852
  * @internal
20626
20853
  */ _proto._onDisableInScene = function _onDisableInScene() {
20627
- var physics = this.scene.physics;
20628
- physics._removeCharacterController(this);
20629
- var shapes = this.shapes;
20630
- for(var i = 0, n = shapes.length; i < n; i++){
20631
- physics._removeColliderShape(shapes[i]);
20632
- }
20854
+ this.scene.physics._removeCharacterController(this);
20855
+ };
20856
+ _proto._syncNative = function _syncNative() {
20857
+ Collider.prototype._syncNative.call(this);
20858
+ this._nativeCollider.setStepOffset(this._stepOffset);
20859
+ this._nativeCollider.setNonWalkableMode(this._nonWalkableMode);
20860
+ this._nativeCollider.setUpDirection(this._upDirection);
20861
+ this._nativeCollider.setSlopeLimit(this._slopeLimit);
20633
20862
  };
20634
20863
  _proto._syncWorldPositionFromPhysicalSpace = function _syncWorldPositionFromPhysicalSpace() {
20635
20864
  this._nativeCollider.getWorldPosition(this.entity.transform.worldPosition);
@@ -20641,11 +20870,13 @@ PhysicsScene._collision = new Collision();
20641
20870
  {
20642
20871
  key: "stepOffset",
20643
20872
  get: /**
20644
- * The step offset for the controller.
20873
+ * The step offset for the controller, the value must be greater than or equal to 0.
20874
+ * @remarks Character can overcome obstacle less than the height(stepOffset + contractOffset of the shape).
20645
20875
  */ function get() {
20646
20876
  return this._stepOffset;
20647
20877
  },
20648
20878
  set: function set(value) {
20879
+ value = Math.max(0, value);
20649
20880
  if (this._stepOffset !== value) {
20650
20881
  this._stepOffset = value;
20651
20882
  this._nativeCollider.setStepOffset(value);
@@ -20682,7 +20913,8 @@ PhysicsScene._collision = new Collision();
20682
20913
  {
20683
20914
  key: "slopeLimit",
20684
20915
  get: /**
20685
- * The slope limit for the controller.
20916
+ * The slope limit for the controller, the value is the cosine value of the maximum slope angle.
20917
+ * @defaultValue 0.707(the cosine value of 45 degrees)
20686
20918
  */ function get() {
20687
20919
  return this._slopeLimit;
20688
20920
  },
@@ -20696,6 +20928,9 @@ PhysicsScene._collision = new Collision();
20696
20928
  ]);
20697
20929
  return CharacterController;
20698
20930
  }(Collider);
20931
+ __decorate([
20932
+ deepClone
20933
+ ], CharacterController.prototype, "_upDirection", void 0);
20699
20934
 
20700
20935
  /**
20701
20936
  * A dynamic collider can act with self-defined movement or physical force.
@@ -20703,21 +20938,21 @@ PhysicsScene._collision = new Collision();
20703
20938
  _inherits(DynamicCollider, Collider);
20704
20939
  function DynamicCollider(entity) {
20705
20940
  var _this;
20706
- _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new Vector3(), _this._angularVelocity = new Vector3(), _this._mass = 1.0, _this._centerOfMass = new Vector3(), _this._inertiaTensor = new Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1000, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3;
20941
+ _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new Vector3(), _this._angularVelocity = new Vector3(), _this._mass = 1.0, _this._centerOfMass = new Vector3(), _this._inertiaTensor = new Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
20707
20942
  var transform = _this.entity.transform;
20708
20943
  _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
20709
20944
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
20710
20945
  _this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
20711
- _this._setCenterOfMass = _this._setCenterOfMass.bind(_this);
20712
- _this._setInertiaTensor = _this._setInertiaTensor.bind(_this);
20946
+ _this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
20947
+ _this._handleInertiaTensorChanged = _this._handleInertiaTensorChanged.bind(_this);
20713
20948
  //@ts-ignore
20714
20949
  _this._linearVelocity._onValueChanged = _this._setLinearVelocity;
20715
20950
  //@ts-ignore
20716
20951
  _this._angularVelocity._onValueChanged = _this._setAngularVelocity;
20717
20952
  //@ts-ignore
20718
- _this._centerOfMass._onValueChanged = _this._setCenterOfMass;
20953
+ _this._centerOfMass._onValueChanged = _this._handleCenterOfMassChanged;
20719
20954
  //@ts-ignore
20720
- _this._inertiaTensor._onValueChanged = _this._setInertiaTensor;
20955
+ _this._inertiaTensor._onValueChanged = _this._handleInertiaTensorChanged;
20721
20956
  return _this;
20722
20957
  }
20723
20958
  var _proto = DynamicCollider.prototype;
@@ -20725,16 +20960,16 @@ PhysicsScene._collision = new Collision();
20725
20960
  * Apply a force to the DynamicCollider.
20726
20961
  * @param force - The force make the collider move
20727
20962
  */ _proto.applyForce = function applyForce(force) {
20728
- this._nativeCollider.addForce(force);
20963
+ this._phasedActiveInScene && this._nativeCollider.addForce(force);
20729
20964
  };
20730
20965
  /**
20731
20966
  * Apply a torque to the DynamicCollider.
20732
20967
  * @param torque - The force make the collider rotate
20733
20968
  */ _proto.applyTorque = function applyTorque(torque) {
20734
- this._nativeCollider.addTorque(torque);
20969
+ this._phasedActiveInScene && this._nativeCollider.addTorque(torque);
20735
20970
  };
20736
20971
  _proto.move = function move(positionOrRotation, rotation) {
20737
- this._nativeCollider.move(positionOrRotation, rotation);
20972
+ this._phasedActiveInScene && this._nativeCollider.move(positionOrRotation, rotation);
20738
20973
  };
20739
20974
  /**
20740
20975
  * Forces a collider to sleep at least one frame.
@@ -20742,6 +20977,12 @@ PhysicsScene._collision = new Collision();
20742
20977
  this._nativeCollider.sleep();
20743
20978
  };
20744
20979
  /**
20980
+ * Returns whether the collider is sleeping.
20981
+ * @returns True if the collider is sleeping, false otherwise.
20982
+ */ _proto.isSleeping = function isSleeping() {
20983
+ return this._nativeCollider.isSleeping();
20984
+ };
20985
+ /**
20745
20986
  * Forces a collider to wake up.
20746
20987
  */ _proto.wakeUp = function wakeUp() {
20747
20988
  this._nativeCollider.wakeUp();
@@ -20757,21 +20998,44 @@ PhysicsScene._collision = new Collision();
20757
20998
  /**
20758
20999
  * @internal
20759
21000
  */ _proto._cloneTo = function _cloneTo(target) {
21001
+ target._linearVelocity.copyFrom(this.linearVelocity);
21002
+ target._angularVelocity.copyFrom(this.angularVelocity);
21003
+ target._centerOfMass.copyFrom(this.centerOfMass);
21004
+ target._inertiaTensor.copyFrom(this.inertiaTensor);
20760
21005
  Collider.prototype._cloneTo.call(this, target);
20761
- target.linearDamping = this.linearDamping;
20762
- target.angularDamping = this.angularDamping;
20763
- target.linearVelocity = this.linearVelocity;
20764
- target.angularVelocity = this.angularVelocity;
20765
- target.mass = this.mass;
20766
- target.centerOfMass = this.centerOfMass;
20767
- target.inertiaTensor = this.inertiaTensor;
20768
- target.maxAngularVelocity = this.maxAngularVelocity;
20769
- target.maxDepenetrationVelocity = this.maxDepenetrationVelocity;
20770
- target.sleepThreshold = this.sleepThreshold;
20771
- target.solverIterations = this.solverIterations;
20772
- target.isKinematic = this.isKinematic;
20773
- target.constraints = this.constraints;
20774
- target.collisionDetectionMode = this.collisionDetectionMode;
21006
+ };
21007
+ /**
21008
+ * @internal
21009
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {
21010
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
21011
+ this._setMassAndUpdateInertia();
21012
+ }
21013
+ };
21014
+ _proto._syncNative = function _syncNative() {
21015
+ Collider.prototype._syncNative.call(this);
21016
+ this._nativeCollider.setLinearDamping(this._linearDamping);
21017
+ this._nativeCollider.setAngularDamping(this._angularDamping);
21018
+ this._nativeCollider.setLinearVelocity(this._linearVelocity);
21019
+ this._nativeCollider.setAngularVelocity(this._angularVelocity);
21020
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
21021
+ this._setMassAndUpdateInertia();
21022
+ } else {
21023
+ this._nativeCollider.setMass(this._mass);
21024
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
21025
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21026
+ }
21027
+ this._nativeCollider.setMaxAngularVelocity(this._maxAngularVelocity);
21028
+ this._nativeCollider.setMaxDepenetrationVelocity(this._maxDepenetrationVelocity);
21029
+ this._nativeCollider.setSleepThreshold(this._sleepThreshold);
21030
+ this._nativeCollider.setSolverIterations(this._solverIterations);
21031
+ this._nativeCollider.setIsKinematic(this._isKinematic);
21032
+ this._nativeCollider.setConstraints(this._constraints);
21033
+ this._nativeCollider.setCollisionDetectionMode(this._collisionDetectionMode);
21034
+ };
21035
+ _proto._setMassAndUpdateInertia = function _setMassAndUpdateInertia() {
21036
+ this._nativeCollider.setMassAndUpdateInertia(this._mass);
21037
+ this._automaticCenterOfMass || this._nativeCollider.setCenterOfMass(this._centerOfMass);
21038
+ this._automaticInertiaTensor || this._nativeCollider.setInertiaTensor(this._inertiaTensor);
20775
21039
  };
20776
21040
  _proto._setLinearVelocity = function _setLinearVelocity() {
20777
21041
  this._nativeCollider.setLinearVelocity(this._linearVelocity);
@@ -20779,11 +21043,19 @@ PhysicsScene._collision = new Collision();
20779
21043
  _proto._setAngularVelocity = function _setAngularVelocity() {
20780
21044
  this._nativeCollider.setAngularVelocity(this._angularVelocity);
20781
21045
  };
20782
- _proto._setCenterOfMass = function _setCenterOfMass() {
20783
- this._nativeCollider.setCenterOfMass(this._centerOfMass);
21046
+ _proto._handleCenterOfMassChanged = function _handleCenterOfMassChanged() {
21047
+ if (this._automaticCenterOfMass) {
21048
+ console.warn("The center of mass is automatically calculated, please set automaticCenterOfMass to false if you want to set it manually.");
21049
+ } else {
21050
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
21051
+ }
20784
21052
  };
20785
- _proto._setInertiaTensor = function _setInertiaTensor() {
20786
- this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21053
+ _proto._handleInertiaTensorChanged = function _handleInertiaTensorChanged() {
21054
+ if (this._automaticInertiaTensor) {
21055
+ console.warn("The inertia tensor is automatically calculated, please set automaticInertiaTensor to false if you want to set it manually.");
21056
+ } else {
21057
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21058
+ }
20787
21059
  };
20788
21060
  _create_class(DynamicCollider, [
20789
21061
  {
@@ -20819,6 +21091,11 @@ PhysicsScene._collision = new Collision();
20819
21091
  get: /**
20820
21092
  * The linear velocity vector of the dynamic collider measured in world unit per second.
20821
21093
  */ function get() {
21094
+ //@ts-ignore
21095
+ this._linearVelocity._onValueChanged = null;
21096
+ this._nativeCollider.getLinearVelocity(this._linearVelocity);
21097
+ //@ts-ignore
21098
+ this._linearVelocity._onValueChanged = this._setLinearVelocity;
20822
21099
  return this._linearVelocity;
20823
21100
  },
20824
21101
  set: function set(value) {
@@ -20832,6 +21109,11 @@ PhysicsScene._collision = new Collision();
20832
21109
  get: /**
20833
21110
  * The angular velocity vector of the dynamic collider measured in radians per second.
20834
21111
  */ function get() {
21112
+ //@ts-ignore
21113
+ this._angularVelocity._onValueChanged = null;
21114
+ this._nativeCollider.getAngularVelocity(this._angularVelocity);
21115
+ //@ts-ignore
21116
+ this._angularVelocity._onValueChanged = this._setAngularVelocity;
20835
21117
  return this._angularVelocity;
20836
21118
  },
20837
21119
  set: function set(value) {
@@ -20850,7 +21132,28 @@ PhysicsScene._collision = new Collision();
20850
21132
  set: function set(value) {
20851
21133
  if (this._mass !== value) {
20852
21134
  this._mass = value;
20853
- this._nativeCollider.setMass(value);
21135
+ if (this._automaticInertiaTensor || this._automaticCenterOfMass) {
21136
+ this._setMassAndUpdateInertia();
21137
+ } else {
21138
+ this._nativeCollider.setMass(value);
21139
+ }
21140
+ }
21141
+ }
21142
+ },
21143
+ {
21144
+ key: "automaticCenterOfMass",
21145
+ get: /**
21146
+ * Whether or not to calculate the center of mass automatically, if true, the center of mass will be calculated based on the associated shapes.
21147
+ * @remarks Affected by the position, rotation of the shapes.
21148
+ */ function get() {
21149
+ return this._automaticCenterOfMass;
21150
+ },
21151
+ set: function set(value) {
21152
+ if (this._automaticCenterOfMass !== value) {
21153
+ this._automaticCenterOfMass = value;
21154
+ if (value) {
21155
+ this._setMassAndUpdateInertia();
21156
+ }
20854
21157
  }
20855
21158
  }
20856
21159
  },
@@ -20858,7 +21161,13 @@ PhysicsScene._collision = new Collision();
20858
21161
  key: "centerOfMass",
20859
21162
  get: /**
20860
21163
  * The center of mass relative to the transform's origin.
21164
+ * @remarks The center of mass is automatically calculated, if you want to set it manually, please set automaticCenterOfMass to false.
20861
21165
  */ function get() {
21166
+ // @ts-ignore
21167
+ this._centerOfMass._onValueChanged = null;
21168
+ this._nativeCollider.getCenterOfMass(this._centerOfMass);
21169
+ // @ts-ignore
21170
+ this._centerOfMass._onValueChanged = this._handleCenterOfMassChanged;
20862
21171
  return this._centerOfMass;
20863
21172
  },
20864
21173
  set: function set(value) {
@@ -20867,11 +21176,34 @@ PhysicsScene._collision = new Collision();
20867
21176
  }
20868
21177
  }
20869
21178
  },
21179
+ {
21180
+ key: "automaticInertiaTensor",
21181
+ get: /**
21182
+ * Whether or not to calculate the inertia tensor automatically, if true, the inertia tensor will be calculated based on the associated shapes and mass.
21183
+ * @remarks Affected by the position, rotation of the shapes and the mass of the collider.
21184
+ */ function get() {
21185
+ return this._automaticInertiaTensor;
21186
+ },
21187
+ set: function set(value) {
21188
+ if (this._automaticInertiaTensor !== value) {
21189
+ this._automaticInertiaTensor = value;
21190
+ if (value) {
21191
+ this._setMassAndUpdateInertia();
21192
+ }
21193
+ }
21194
+ }
21195
+ },
20870
21196
  {
20871
21197
  key: "inertiaTensor",
20872
21198
  get: /**
20873
21199
  * The diagonal inertia tensor of mass relative to the center of mass.
21200
+ * @remarks The inertia tensor is automatically calculated, if you want to set it manually, please set automaticInertiaTensor to false.
20874
21201
  */ function get() {
21202
+ // @ts-ignore
21203
+ this._inertiaTensor._onValueChanged = null;
21204
+ this._nativeCollider.getInertiaTensor(this._inertiaTensor);
21205
+ // @ts-ignore
21206
+ this._inertiaTensor._onValueChanged = this._handleInertiaTensorChanged;
20875
21207
  return this._inertiaTensor;
20876
21208
  },
20877
21209
  set: function set(value) {
@@ -20981,21 +21313,12 @@ PhysicsScene._collision = new Collision();
20981
21313
  ]);
20982
21314
  return DynamicCollider;
20983
21315
  }(Collider);
20984
- __decorate([
20985
- ignoreClone
20986
- ], DynamicCollider.prototype, "_linearDamping", void 0);
20987
- __decorate([
20988
- ignoreClone
20989
- ], DynamicCollider.prototype, "_angularDamping", void 0);
20990
21316
  __decorate([
20991
21317
  ignoreClone
20992
21318
  ], DynamicCollider.prototype, "_linearVelocity", void 0);
20993
21319
  __decorate([
20994
21320
  ignoreClone
20995
21321
  ], DynamicCollider.prototype, "_angularVelocity", void 0);
20996
- __decorate([
20997
- ignoreClone
20998
- ], DynamicCollider.prototype, "_mass", void 0);
20999
21322
  __decorate([
21000
21323
  ignoreClone
21001
21324
  ], DynamicCollider.prototype, "_centerOfMass", void 0);
@@ -21004,25 +21327,16 @@ __decorate([
21004
21327
  ], DynamicCollider.prototype, "_inertiaTensor", void 0);
21005
21328
  __decorate([
21006
21329
  ignoreClone
21007
- ], DynamicCollider.prototype, "_maxAngularVelocity", void 0);
21008
- __decorate([
21009
- ignoreClone
21010
- ], DynamicCollider.prototype, "_maxDepenetrationVelocity", void 0);
21011
- __decorate([
21012
- ignoreClone
21013
- ], DynamicCollider.prototype, "_solverIterations", void 0);
21014
- __decorate([
21015
- ignoreClone
21016
- ], DynamicCollider.prototype, "_isKinematic", void 0);
21330
+ ], DynamicCollider.prototype, "_setLinearVelocity", null);
21017
21331
  __decorate([
21018
21332
  ignoreClone
21019
- ], DynamicCollider.prototype, "_constraints", void 0);
21333
+ ], DynamicCollider.prototype, "_setAngularVelocity", null);
21020
21334
  __decorate([
21021
21335
  ignoreClone
21022
- ], DynamicCollider.prototype, "_collisionDetectionMode", void 0);
21336
+ ], DynamicCollider.prototype, "_handleCenterOfMassChanged", null);
21023
21337
  __decorate([
21024
21338
  ignoreClone
21025
- ], DynamicCollider.prototype, "_sleepThreshold", void 0);
21339
+ ], DynamicCollider.prototype, "_handleInertiaTensorChanged", null);
21026
21340
  /**
21027
21341
  * The collision detection mode constants.
21028
21342
  */ var CollisionDetectionMode = /*#__PURE__*/ function(CollisionDetectionMode) {
@@ -21069,9 +21383,9 @@ __decorate([
21069
21383
  * Material class to represent a set of surface properties.
21070
21384
  */ var PhysicsMaterial = /*#__PURE__*/ function() {
21071
21385
  function PhysicsMaterial() {
21072
- this._bounciness = 0.1;
21073
- this._dynamicFriction = 0.1;
21074
- this._staticFriction = 0.1;
21386
+ this._bounciness = 0;
21387
+ this._dynamicFriction = 0.6;
21388
+ this._staticFriction = 0.6;
21075
21389
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
21076
21390
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
21077
21391
  this._nativeMaterial = PhysicsScene._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
@@ -21087,7 +21401,7 @@ __decorate([
21087
21401
  {
21088
21402
  key: "bounciness",
21089
21403
  get: /**
21090
- * The coefficient of bounciness.
21404
+ * The coefficient of bounciness, ranging from 0 to 1.
21091
21405
  */ function get() {
21092
21406
  return this._bounciness;
21093
21407
  },
@@ -21195,22 +21509,96 @@ var Joint = /*#__PURE__*/ function(Component) {
21195
21509
  _inherits(Joint, Component);
21196
21510
  function Joint(entity) {
21197
21511
  var _this;
21198
- _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = 0, _this._torque = 0;
21199
- _this._connectedColliderInfo.localPosition = new Vector3();
21512
+ _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = Infinity, _this._torque = Infinity, _this._automaticConnectedAnchor = true;
21513
+ //@ts-ignore
21514
+ _this._colliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 1);
21515
+ //@ts-ignore
21516
+ _this._connectedColliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 2);
21517
+ _this._onSelfTransformChanged = _this._onSelfTransformChanged.bind(_this);
21518
+ _this._onConnectedTransformChanged = _this._onConnectedTransformChanged.bind(_this);
21519
+ // @ts-ignore
21520
+ entity._updateFlagManager.addListener(_this._onSelfTransformChanged);
21200
21521
  return _this;
21201
21522
  }
21202
21523
  var _proto = Joint.prototype;
21203
21524
  /**
21204
21525
  * @internal
21205
- */ _proto._cloneTo = function _cloneTo(target) {
21206
- target.connectedCollider = this.connectedCollider;
21207
- target.connectedAnchor = this.connectedAnchor;
21208
- target.connectedMassScale = this.connectedMassScale;
21209
- target.connectedInertiaScale = this.connectedInertiaScale;
21210
- target.massScale = this.massScale;
21211
- target.inertiaScale = this.inertiaScale;
21212
- target.breakForce = this.breakForce;
21213
- target.breakTorque = this.breakTorque;
21526
+ */ _proto._onEnableInScene = function _onEnableInScene() {
21527
+ this._createJoint();
21528
+ this._syncNative();
21529
+ };
21530
+ /**
21531
+ * @internal
21532
+ */ _proto._onDisableInScene = function _onDisableInScene() {
21533
+ this._nativeJoint.destroy();
21534
+ this._nativeJoint = null;
21535
+ };
21536
+ _proto._syncNative = function _syncNative() {
21537
+ if (this._nativeJoint) {
21538
+ var _this__connectedColliderInfo_collider;
21539
+ this._nativeJoint.setConnectedCollider(((_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider._nativeCollider) || null);
21540
+ this._updateActualAnchor(1);
21541
+ if (this._automaticConnectedAnchor) {
21542
+ this._calculateConnectedAnchor();
21543
+ } else {
21544
+ this._updateActualAnchor(2);
21545
+ }
21546
+ this._nativeJoint.setConnectedMassScale(this._connectedColliderInfo.massScale);
21547
+ this._nativeJoint.setConnectedInertiaScale(this._connectedColliderInfo.inertiaScale);
21548
+ this._nativeJoint.setMassScale(this._colliderInfo.massScale);
21549
+ this._nativeJoint.setInertiaScale(this._colliderInfo.inertiaScale);
21550
+ this._nativeJoint.setBreakForce(this._force);
21551
+ this._nativeJoint.setBreakTorque(this._torque);
21552
+ }
21553
+ };
21554
+ _proto._calculateConnectedAnchor = function _calculateConnectedAnchor() {
21555
+ var colliderInfo = this._colliderInfo;
21556
+ var connectedColliderInfo = this._connectedColliderInfo;
21557
+ var _this_entity_transform = this.entity.transform, selfPos = _this_entity_transform.worldPosition;
21558
+ var selfActualAnchor = colliderInfo.actualAnchor;
21559
+ var connectedAnchor = connectedColliderInfo.anchor;
21560
+ var connectedActualAnchor = connectedColliderInfo.actualAnchor;
21561
+ var connectedCollider = connectedColliderInfo.collider;
21562
+ if (connectedCollider) {
21563
+ var _connectedCollider_entity_transform = connectedCollider.entity.transform, connectedPos = _connectedCollider_entity_transform.worldPosition, connectedWorldScale = _connectedCollider_entity_transform.lossyWorldScale;
21564
+ Vector3.subtract(selfPos, connectedPos, Joint._tempVector3);
21565
+ Vector3.add(Joint._tempVector3, selfActualAnchor, connectedActualAnchor);
21566
+ Vector3.divide(connectedActualAnchor, connectedWorldScale, connectedAnchor);
21567
+ } else {
21568
+ Vector3.add(selfPos, selfActualAnchor, connectedActualAnchor);
21569
+ connectedAnchor.copyFrom(connectedActualAnchor);
21570
+ }
21571
+ };
21572
+ _proto._onSelfTransformChanged = function _onSelfTransformChanged(type) {
21573
+ if (type & TransformModifyFlags.WorldScale) {
21574
+ this._updateActualAnchor(1);
21575
+ }
21576
+ };
21577
+ _proto._onConnectedTransformChanged = function _onConnectedTransformChanged(type) {
21578
+ if (type & TransformModifyFlags.WorldScale) {
21579
+ this._updateActualAnchor(2);
21580
+ }
21581
+ };
21582
+ _proto._updateActualAnchor = function _updateActualAnchor(flag) {
21583
+ if (flag & 1) {
21584
+ var _this__nativeJoint;
21585
+ var worldScale = this.entity.transform.lossyWorldScale;
21586
+ var selfColliderInfo = this._colliderInfo;
21587
+ Vector3.multiply(selfColliderInfo.anchor, worldScale, selfColliderInfo.actualAnchor);
21588
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAnchor(selfColliderInfo.actualAnchor);
21589
+ }
21590
+ if (flag & 2) {
21591
+ var _this__nativeJoint1;
21592
+ var connectedColliderInfo = this._connectedColliderInfo;
21593
+ var connectedCollider = connectedColliderInfo.collider;
21594
+ if (connectedCollider) {
21595
+ var worldScale1 = connectedCollider.entity.transform.lossyWorldScale;
21596
+ Vector3.multiply(connectedColliderInfo.anchor, worldScale1, connectedColliderInfo.actualAnchor);
21597
+ } else {
21598
+ connectedColliderInfo.actualAnchor.copyFrom(connectedColliderInfo.anchor);
21599
+ }
21600
+ (_this__nativeJoint1 = this._nativeJoint) == null ? void 0 : _this__nativeJoint1.setConnectedAnchor(connectedColliderInfo.actualAnchor);
21601
+ }
21214
21602
  };
21215
21603
  _create_class(Joint, [
21216
21604
  {
@@ -21222,8 +21610,33 @@ var Joint = /*#__PURE__*/ function(Component) {
21222
21610
  },
21223
21611
  set: function set(value) {
21224
21612
  if (this._connectedColliderInfo.collider !== value) {
21613
+ var _this__connectedColliderInfo_collider, _this__nativeJoint;
21614
+ (_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged);
21615
+ value == null ? void 0 : value.entity._updateFlagManager.addListener(this._onConnectedTransformChanged);
21225
21616
  this._connectedColliderInfo.collider = value;
21226
- this._nativeJoint.setConnectedCollider(value._nativeCollider);
21617
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedCollider(value._nativeCollider);
21618
+ if (this._automaticConnectedAnchor) {
21619
+ this._calculateConnectedAnchor();
21620
+ } else {
21621
+ this._updateActualAnchor(2);
21622
+ }
21623
+ }
21624
+ }
21625
+ },
21626
+ {
21627
+ key: "anchor",
21628
+ get: /**
21629
+ * The connected anchor position.
21630
+ * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21631
+ */ function get() {
21632
+ return this._colliderInfo.anchor;
21633
+ },
21634
+ set: function set(value) {
21635
+ var anchor = this._colliderInfo.anchor;
21636
+ if (value !== anchor) {
21637
+ anchor.copyFrom(value);
21638
+ this._updateActualAnchor(1);
21639
+ this._automaticConnectedAnchor && this._calculateConnectedAnchor();
21227
21640
  }
21228
21641
  }
21229
21642
  },
@@ -21233,14 +21646,30 @@ var Joint = /*#__PURE__*/ function(Component) {
21233
21646
  * The connected anchor position.
21234
21647
  * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21235
21648
  */ function get() {
21236
- return this._connectedColliderInfo.localPosition;
21649
+ return this._connectedColliderInfo.anchor;
21237
21650
  },
21238
21651
  set: function set(value) {
21239
- var connectedAnchor = this._connectedColliderInfo.localPosition;
21652
+ if (this.automaticConnectedAnchor) {
21653
+ console.warn("Cannot set connectedAnchor when automaticConnectedAnchor is true.");
21654
+ return;
21655
+ }
21656
+ var connectedAnchor = this._connectedColliderInfo.anchor;
21240
21657
  if (value !== connectedAnchor) {
21241
21658
  connectedAnchor.copyFrom(value);
21659
+ this._updateActualAnchor(2);
21242
21660
  }
21243
- this._nativeJoint.setConnectedAnchor(value);
21661
+ }
21662
+ },
21663
+ {
21664
+ key: "automaticConnectedAnchor",
21665
+ get: /**
21666
+ * Whether or not to calculate the connectedAnchor automatically, if true, the connectedAnchor will be calculated automatically to match the global position of the anchor property.
21667
+ */ function get() {
21668
+ return this._automaticConnectedAnchor;
21669
+ },
21670
+ set: function set(value) {
21671
+ this._automaticConnectedAnchor = value;
21672
+ value && this._calculateConnectedAnchor();
21244
21673
  }
21245
21674
  },
21246
21675
  {
@@ -21252,36 +21681,39 @@ var Joint = /*#__PURE__*/ function(Component) {
21252
21681
  },
21253
21682
  set: function set(value) {
21254
21683
  if (value !== this._connectedColliderInfo.massScale) {
21684
+ var _this__nativeJoint;
21255
21685
  this._connectedColliderInfo.massScale = value;
21256
- this._nativeJoint.setConnectedMassScale(value);
21686
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedMassScale(value);
21257
21687
  }
21258
21688
  }
21259
21689
  },
21260
21690
  {
21261
- key: "connectedInertiaScale",
21691
+ key: "massScale",
21262
21692
  get: /**
21263
- * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
21693
+ * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
21264
21694
  */ function get() {
21265
- return this._connectedColliderInfo.inertiaScale;
21695
+ return this._colliderInfo.massScale;
21266
21696
  },
21267
21697
  set: function set(value) {
21268
- if (value !== this._connectedColliderInfo.inertiaScale) {
21269
- this._connectedColliderInfo.inertiaScale = value;
21270
- this._nativeJoint.setConnectedInertiaScale(value);
21698
+ if (value !== this._colliderInfo.massScale) {
21699
+ var _this__nativeJoint;
21700
+ this._colliderInfo.massScale = value;
21701
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMassScale(value);
21271
21702
  }
21272
21703
  }
21273
21704
  },
21274
21705
  {
21275
- key: "massScale",
21706
+ key: "connectedInertiaScale",
21276
21707
  get: /**
21277
- * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
21708
+ * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
21278
21709
  */ function get() {
21279
- return this._colliderInfo.massScale;
21710
+ return this._connectedColliderInfo.inertiaScale;
21280
21711
  },
21281
21712
  set: function set(value) {
21282
- if (value !== this._colliderInfo.massScale) {
21283
- this._colliderInfo.massScale = value;
21284
- this._nativeJoint.setMassScale(value);
21713
+ if (value !== this._connectedColliderInfo.inertiaScale) {
21714
+ var _this__nativeJoint;
21715
+ this._connectedColliderInfo.inertiaScale = value;
21716
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedInertiaScale(value);
21285
21717
  }
21286
21718
  }
21287
21719
  },
@@ -21294,8 +21726,9 @@ var Joint = /*#__PURE__*/ function(Component) {
21294
21726
  },
21295
21727
  set: function set(value) {
21296
21728
  if (value !== this._colliderInfo.inertiaScale) {
21729
+ var _this__nativeJoint;
21297
21730
  this._colliderInfo.inertiaScale = value;
21298
- this._nativeJoint.setInertiaScale(value);
21731
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setInertiaScale(value);
21299
21732
  }
21300
21733
  }
21301
21734
  },
@@ -21308,8 +21741,9 @@ var Joint = /*#__PURE__*/ function(Component) {
21308
21741
  },
21309
21742
  set: function set(value) {
21310
21743
  if (value !== this._force) {
21744
+ var _this__nativeJoint;
21311
21745
  this._force = value;
21312
- this._nativeJoint.setBreakForce(value);
21746
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakForce(value);
21313
21747
  }
21314
21748
  }
21315
21749
  },
@@ -21322,29 +21756,34 @@ var Joint = /*#__PURE__*/ function(Component) {
21322
21756
  },
21323
21757
  set: function set(value) {
21324
21758
  if (value !== this._torque) {
21759
+ var _this__nativeJoint;
21325
21760
  this._torque = value;
21326
- this._nativeJoint.setBreakTorque(value);
21761
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakTorque(value);
21327
21762
  }
21328
21763
  }
21329
21764
  }
21330
21765
  ]);
21331
21766
  return Joint;
21332
21767
  }(Component);
21768
+ Joint._tempVector3 = new Vector3();
21333
21769
  __decorate([
21334
- ignoreClone
21770
+ deepClone
21335
21771
  ], Joint.prototype, "_colliderInfo", void 0);
21336
21772
  __decorate([
21337
- ignoreClone
21773
+ deepClone
21338
21774
  ], Joint.prototype, "_connectedColliderInfo", void 0);
21339
21775
  __decorate([
21340
21776
  ignoreClone
21341
21777
  ], Joint.prototype, "_nativeJoint", void 0);
21342
21778
  __decorate([
21343
21779
  ignoreClone
21344
- ], Joint.prototype, "_force", void 0);
21780
+ ], Joint.prototype, "_onSelfTransformChanged", null);
21781
+ __decorate([
21782
+ ignoreClone
21783
+ ], Joint.prototype, "_onConnectedTransformChanged", null);
21345
21784
  __decorate([
21346
21785
  ignoreClone
21347
- ], Joint.prototype, "_torque", void 0);
21786
+ ], Joint.prototype, "_updateActualAnchor", null);
21348
21787
  Joint = __decorate([
21349
21788
  dependentComponents(Collider, DependentMode.CheckOnly)
21350
21789
  ], Joint);
@@ -21352,9 +21791,17 @@ Joint = __decorate([
21352
21791
  * @internal
21353
21792
  */ var JointColliderInfo = function JointColliderInfo() {
21354
21793
  this.collider = null;
21355
- this.massScale = 0;
21356
- this.inertiaScale = 0;
21794
+ this.anchor = new Vector3();
21795
+ this.actualAnchor = new Vector3();
21796
+ this.massScale = 1;
21797
+ this.inertiaScale = 1;
21357
21798
  };
21799
+ __decorate([
21800
+ deepClone
21801
+ ], JointColliderInfo.prototype, "anchor", void 0);
21802
+ __decorate([
21803
+ deepClone
21804
+ ], JointColliderInfo.prototype, "actualAnchor", void 0);
21358
21805
 
21359
21806
  /*
21360
21807
  * A fixed joint permits no relative movement between two colliders. ie the colliders are glued together.
@@ -21364,12 +21811,10 @@ Joint = __decorate([
21364
21811
  return Joint.apply(this, arguments) || this;
21365
21812
  }
21366
21813
  var _proto = FixedJoint.prototype;
21367
- /**
21368
- * @internal
21369
- */ _proto._onAwake = function _onAwake() {
21370
- var collider = this._colliderInfo;
21371
- collider.collider = this.entity.getComponent(Collider);
21372
- this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(collider.collider._nativeCollider);
21814
+ _proto._createJoint = function _createJoint() {
21815
+ var colliderInfo = this._colliderInfo;
21816
+ colliderInfo.collider = this.entity.getComponent(Collider);
21817
+ this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
21373
21818
  };
21374
21819
  return FixedJoint;
21375
21820
  }(Joint);
@@ -21389,30 +21834,58 @@ Joint = __decorate([
21389
21834
  * A joint which behaves in a similar way to a hinge or axle.
21390
21835
  */ var HingeJoint = /*#__PURE__*/ function(Joint) {
21391
21836
  _inherits(HingeJoint, Joint);
21392
- function HingeJoint() {
21837
+ function HingeJoint(entity) {
21393
21838
  var _this;
21394
- _this = Joint.apply(this, arguments) || this, _this._axis = new Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false;
21839
+ _this = Joint.call(this, entity) || this, _this._axis = new Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false, _this._angle = 0, _this._velocity = 0;
21840
+ _this._onMotorChanged = _this._onMotorChanged.bind(_this);
21841
+ _this._onLimitsChanged = _this._onLimitsChanged.bind(_this);
21395
21842
  return _this;
21396
21843
  }
21397
21844
  var _proto = HingeJoint.prototype;
21398
21845
  /**
21399
21846
  * @internal
21400
- */ _proto._onAwake = function _onAwake() {
21401
- var collider = this._colliderInfo;
21402
- collider.localPosition = new Vector3();
21403
- collider.collider = this.entity.getComponent(Collider);
21404
- this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(collider.collider._nativeCollider);
21405
- };
21406
- /**
21407
- * @internal
21408
- */ _proto._cloneTo = function _cloneTo(target) {
21409
- target.axis = this.axis;
21410
- target.swingOffset = this.swingOffset;
21411
- target.useLimits = this.useLimits;
21412
- target.useMotor = this.useMotor;
21413
- target.useSpring = this.useSpring;
21414
- target.motor = this.motor;
21415
- target.limits = this.limits;
21847
+ */ _proto._onDisableInScene = function _onDisableInScene() {
21848
+ var nativeJoint = this._nativeJoint;
21849
+ this._angle = nativeJoint.getAngle();
21850
+ this._velocity = nativeJoint.getVelocity();
21851
+ Joint.prototype._onDisableInScene.call(this);
21852
+ };
21853
+ _proto._createJoint = function _createJoint() {
21854
+ var colliderInfo = this._colliderInfo;
21855
+ colliderInfo.collider = this.entity.getComponent(Collider);
21856
+ this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
21857
+ };
21858
+ _proto._syncNative = function _syncNative() {
21859
+ Joint.prototype._syncNative.call(this);
21860
+ var motor = this._jointMotor;
21861
+ this._nativeJoint.setAxis(this._axis);
21862
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, this.useLimits);
21863
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, this.useMotor);
21864
+ if (motor) {
21865
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
21866
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
21867
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
21868
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
21869
+ }
21870
+ };
21871
+ _proto._onMotorChanged = function _onMotorChanged() {
21872
+ var motor = this._jointMotor;
21873
+ if (this._nativeJoint) {
21874
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
21875
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
21876
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
21877
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
21878
+ }
21879
+ };
21880
+ _proto._onLimitsChanged = function _onLimitsChanged() {
21881
+ var limits = this._limits;
21882
+ if (limits && this._nativeJoint) {
21883
+ if (this.useSpring) {
21884
+ this._nativeJoint.setSoftLimit(limits.min, limits.max, limits.stiffness, limits.damping);
21885
+ } else {
21886
+ this._nativeJoint.setHardLimit(limits.min, limits.max, limits.contactDistance);
21887
+ }
21888
+ }
21416
21889
  };
21417
21890
  _create_class(HingeJoint, [
21418
21891
  {
@@ -21425,24 +21898,10 @@ Joint = __decorate([
21425
21898
  set: function set(value) {
21426
21899
  var axis = this._axis;
21427
21900
  if (value !== axis) {
21901
+ var _this__nativeJoint;
21428
21902
  axis.copyFrom(value);
21903
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAxis(axis);
21429
21904
  }
21430
- this._nativeJoint.setAxis(axis);
21431
- }
21432
- },
21433
- {
21434
- key: "swingOffset",
21435
- get: /**
21436
- * The swing offset.
21437
- */ function get() {
21438
- return this._colliderInfo.localPosition;
21439
- },
21440
- set: function set(value) {
21441
- var swingOffset = this._colliderInfo.localPosition;
21442
- if (value !== swingOffset) {
21443
- swingOffset.copyFrom(value);
21444
- }
21445
- this._nativeJoint.setSwingOffset(swingOffset);
21446
21905
  }
21447
21906
  },
21448
21907
  {
@@ -21450,7 +21909,11 @@ Joint = __decorate([
21450
21909
  get: /**
21451
21910
  * The current angle in degrees of the joint relative to its rest position.
21452
21911
  */ function get() {
21453
- return this._nativeJoint.getAngle();
21912
+ var nativeJoint = this._nativeJoint;
21913
+ if (nativeJoint) {
21914
+ this._angle = nativeJoint.getAngle();
21915
+ }
21916
+ return this._angle;
21454
21917
  }
21455
21918
  },
21456
21919
  {
@@ -21458,7 +21921,11 @@ Joint = __decorate([
21458
21921
  get: /**
21459
21922
  * The angular velocity of the joint in degrees per second.
21460
21923
  */ function get() {
21461
- return this._nativeJoint.getVelocity();
21924
+ var nativeJoint = this._nativeJoint;
21925
+ if (nativeJoint) {
21926
+ this._velocity = nativeJoint.getVelocity();
21927
+ }
21928
+ return this._velocity;
21462
21929
  }
21463
21930
  },
21464
21931
  {
@@ -21470,8 +21937,9 @@ Joint = __decorate([
21470
21937
  },
21471
21938
  set: function set(value) {
21472
21939
  if (value !== this.useLimits) {
21940
+ var _this__nativeJoint;
21473
21941
  value ? this._hingeFlags |= HingeJointFlag.LimitEnabled : this._hingeFlags &= ~HingeJointFlag.LimitEnabled;
21474
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
21942
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
21475
21943
  }
21476
21944
  }
21477
21945
  },
@@ -21484,8 +21952,9 @@ Joint = __decorate([
21484
21952
  },
21485
21953
  set: function set(value) {
21486
21954
  if (value !== this.useMotor) {
21955
+ var _this__nativeJoint;
21487
21956
  value ? this._hingeFlags |= HingeJointFlag.DriveEnabled : this._hingeFlags &= ~HingeJointFlag.DriveEnabled;
21488
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
21957
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
21489
21958
  }
21490
21959
  }
21491
21960
  },
@@ -21499,7 +21968,7 @@ Joint = __decorate([
21499
21968
  set: function set(value) {
21500
21969
  if (this._useSpring !== value) {
21501
21970
  this._useSpring = value;
21502
- this.limits = this._limits;
21971
+ this._onLimitsChanged();
21503
21972
  }
21504
21973
  }
21505
21974
  },
@@ -21508,15 +21977,15 @@ Joint = __decorate([
21508
21977
  get: /**
21509
21978
  * The motor will apply a force up to a maximum force to achieve the target velocity in degrees per second.
21510
21979
  */ function get() {
21511
- return this._jointMonitor;
21980
+ return this._jointMotor;
21512
21981
  },
21513
21982
  set: function set(value) {
21514
- if (this._jointMonitor !== value) {
21515
- this._jointMonitor = value;
21516
- this._nativeJoint.setDriveVelocity(value.targetVelocity);
21517
- this._nativeJoint.setDriveForceLimit(value.forceLimit);
21518
- this._nativeJoint.setDriveGearRatio(value.gearRation);
21519
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, value.freeSpin);
21983
+ if (this._jointMotor !== value) {
21984
+ var _this__jointMotor;
21985
+ (_this__jointMotor = this._jointMotor) == null ? void 0 : _this__jointMotor._updateFlagManager.removeListener(this._onMotorChanged);
21986
+ this._jointMotor = value;
21987
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onMotorChanged);
21988
+ this._onMotorChanged();
21520
21989
  }
21521
21990
  }
21522
21991
  },
@@ -21529,12 +21998,11 @@ Joint = __decorate([
21529
21998
  },
21530
21999
  set: function set(value) {
21531
22000
  if (this._limits !== value) {
22001
+ var _this__limits;
22002
+ (_this__limits = this._limits) == null ? void 0 : _this__limits._updateFlagManager.removeListener(this._onLimitsChanged);
21532
22003
  this._limits = value;
21533
- if (this.useSpring) {
21534
- this._nativeJoint.setSoftLimit(value.min, value.max, value.stiffness, value.damping);
21535
- } else {
21536
- this._nativeJoint.setHardLimit(value.min, value.max, value.contactDistance);
21537
- }
22004
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onLimitsChanged);
22005
+ this._onLimitsChanged();
21538
22006
  }
21539
22007
  }
21540
22008
  }
@@ -21542,20 +22010,20 @@ Joint = __decorate([
21542
22010
  return HingeJoint;
21543
22011
  }(Joint);
21544
22012
  __decorate([
21545
- ignoreClone
22013
+ deepClone
21546
22014
  ], HingeJoint.prototype, "_axis", void 0);
21547
22015
  __decorate([
21548
- ignoreClone
21549
- ], HingeJoint.prototype, "_hingeFlags", void 0);
22016
+ deepClone
22017
+ ], HingeJoint.prototype, "_jointMotor", void 0);
21550
22018
  __decorate([
21551
- ignoreClone
21552
- ], HingeJoint.prototype, "_useSpring", void 0);
22019
+ deepClone
22020
+ ], HingeJoint.prototype, "_limits", void 0);
21553
22021
  __decorate([
21554
22022
  ignoreClone
21555
- ], HingeJoint.prototype, "_jointMonitor", void 0);
22023
+ ], HingeJoint.prototype, "_onMotorChanged", null);
21556
22024
  __decorate([
21557
22025
  ignoreClone
21558
- ], HingeJoint.prototype, "_limits", void 0);
22026
+ ], HingeJoint.prototype, "_onLimitsChanged", null);
21559
22027
 
21560
22028
  /**
21561
22029
  * A joint that maintains an upper or lower bound (or both) on the distance between two points on different objects.
@@ -21567,40 +22035,20 @@ __decorate([
21567
22035
  return _this;
21568
22036
  }
21569
22037
  var _proto = SpringJoint.prototype;
21570
- /**
21571
- * @internal
21572
- */ _proto._onAwake = function _onAwake() {
21573
- var collider = this._colliderInfo;
21574
- collider.localPosition = new Vector3();
21575
- collider.collider = this.entity.getComponent(Collider);
21576
- this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(collider.collider._nativeCollider);
21577
- };
21578
- /**
21579
- * @internal
21580
- */ _proto._cloneTo = function _cloneTo(target) {
21581
- target.swingOffset = this.swingOffset;
21582
- target.minDistance = this.minDistance;
21583
- target.maxDistance = this.maxDistance;
21584
- target.tolerance = this.tolerance;
21585
- target.stiffness = this.stiffness;
21586
- target.damping = this.damping;
22038
+ _proto._createJoint = function _createJoint() {
22039
+ var colliderInfo = this._colliderInfo;
22040
+ colliderInfo.collider = this.entity.getComponent(Collider);
22041
+ this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22042
+ };
22043
+ _proto._syncNative = function _syncNative() {
22044
+ Joint.prototype._syncNative.call(this);
22045
+ this._nativeJoint.setMinDistance(this._minDistance);
22046
+ this._nativeJoint.setMaxDistance(this._maxDistance);
22047
+ this._nativeJoint.setTolerance(this._tolerance);
22048
+ this._nativeJoint.setStiffness(this._stiffness);
22049
+ this._nativeJoint.setDamping(this._damping);
21587
22050
  };
21588
22051
  _create_class(SpringJoint, [
21589
- {
21590
- key: "swingOffset",
21591
- get: /**
21592
- * The swing offset.
21593
- */ function get() {
21594
- return this._colliderInfo.localPosition;
21595
- },
21596
- set: function set(value) {
21597
- var swingOffset = this._colliderInfo.localPosition;
21598
- if (value !== swingOffset) {
21599
- swingOffset.copyFrom(value);
21600
- }
21601
- this._nativeJoint.setSwingOffset(value);
21602
- }
21603
- },
21604
22052
  {
21605
22053
  key: "minDistance",
21606
22054
  get: /**
@@ -21610,8 +22058,9 @@ __decorate([
21610
22058
  },
21611
22059
  set: function set(value) {
21612
22060
  if (this._minDistance !== value) {
22061
+ var _this__nativeJoint;
21613
22062
  this._minDistance = value;
21614
- this._nativeJoint.setMinDistance(value);
22063
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMinDistance(value);
21615
22064
  }
21616
22065
  }
21617
22066
  },
@@ -21624,8 +22073,9 @@ __decorate([
21624
22073
  },
21625
22074
  set: function set(value) {
21626
22075
  if (this._maxDistance !== value) {
22076
+ var _this__nativeJoint;
21627
22077
  this._maxDistance = value;
21628
- this._nativeJoint.setMaxDistance(value);
22078
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMaxDistance(value);
21629
22079
  }
21630
22080
  }
21631
22081
  },
@@ -21638,8 +22088,9 @@ __decorate([
21638
22088
  },
21639
22089
  set: function set(value) {
21640
22090
  if (this._tolerance !== value) {
22091
+ var _this__nativeJoint;
21641
22092
  this._tolerance = value;
21642
- this._nativeJoint.setTolerance(value);
22093
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setTolerance(value);
21643
22094
  }
21644
22095
  }
21645
22096
  },
@@ -21652,8 +22103,9 @@ __decorate([
21652
22103
  },
21653
22104
  set: function set(value) {
21654
22105
  if (this._stiffness !== value) {
22106
+ var _this__nativeJoint;
21655
22107
  this._stiffness = value;
21656
- this._nativeJoint.setStiffness(value);
22108
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setStiffness(value);
21657
22109
  }
21658
22110
  }
21659
22111
  },
@@ -21666,8 +22118,9 @@ __decorate([
21666
22118
  },
21667
22119
  set: function set(value) {
21668
22120
  if (this._damping !== value) {
22121
+ var _this__nativeJoint;
21669
22122
  this._damping = value;
21670
- this._nativeJoint.setDamping(value);
22123
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setDamping(value);
21671
22124
  }
21672
22125
  }
21673
22126
  }
@@ -21677,22 +22130,168 @@ __decorate([
21677
22130
 
21678
22131
  /**
21679
22132
  * JointLimits is used to limit the joints angle.
21680
- */ var JointLimits = function JointLimits() {
21681
- /** The upper angular limit (in degrees) of the joint. */ this.max = 0;
21682
- /** The lower angular limit (in degrees) of the joint. */ this.min = 0;
21683
- /** Distance inside the limit value at which the limit will be considered to be active by the solver. */ this.contactDistance = -1;
21684
- /** The spring forces used to reach the target position. */ this.stiffness = 0;
21685
- /** The damper force uses to dampen the spring. */ this.damping = 0;
21686
- };
22133
+ */ var JointLimits = /*#__PURE__*/ function() {
22134
+ function JointLimits() {
22135
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
22136
+ this._max = 0;
22137
+ this._min = 0;
22138
+ this._contactDistance = -1;
22139
+ this._stiffness = 0;
22140
+ this._damping = 0;
22141
+ }
22142
+ _create_class(JointLimits, [
22143
+ {
22144
+ key: "max",
22145
+ get: /**
22146
+ * The upper angular limit (in radians) of the joint.
22147
+ */ function get() {
22148
+ return this._max;
22149
+ },
22150
+ set: function set(value) {
22151
+ if (value < this._min) {
22152
+ throw new Error("Max limit must be greater than min limit");
22153
+ }
22154
+ if (this._max !== value) {
22155
+ this._max = value;
22156
+ this._updateFlagManager.dispatch();
22157
+ }
22158
+ }
22159
+ },
22160
+ {
22161
+ key: "min",
22162
+ get: /**
22163
+ * The lower angular limit (in radians) of the joint.
22164
+ */ function get() {
22165
+ return this._min;
22166
+ },
22167
+ set: function set(value) {
22168
+ if (value > this._max) {
22169
+ throw new Error("Min limit must be less than max limit");
22170
+ }
22171
+ if (this._min !== value) {
22172
+ this._min = value;
22173
+ this._updateFlagManager.dispatch();
22174
+ }
22175
+ }
22176
+ },
22177
+ {
22178
+ key: "contactDistance",
22179
+ get: /**
22180
+ * Distance inside the limit value at which the limit will be considered to be active by the solver.
22181
+ * Default is the lesser of 0.1 radians, and 0.49 * (upperLimit - lowerLimit)
22182
+ */ function get() {
22183
+ if (this._contactDistance === -1) {
22184
+ return Math.min(0.1, 0.49 * (this._max - this._min));
22185
+ }
22186
+ return this._contactDistance;
22187
+ },
22188
+ set: function set(value) {
22189
+ if (this._contactDistance !== value) {
22190
+ this._contactDistance = value;
22191
+ this._updateFlagManager.dispatch();
22192
+ }
22193
+ }
22194
+ },
22195
+ {
22196
+ key: "stiffness",
22197
+ get: /**
22198
+ * The spring forces used to reach the target position.
22199
+ */ function get() {
22200
+ return this._stiffness;
22201
+ },
22202
+ set: function set(value) {
22203
+ if (this._stiffness !== value) {
22204
+ this._stiffness = value;
22205
+ this._updateFlagManager.dispatch();
22206
+ }
22207
+ }
22208
+ },
22209
+ {
22210
+ key: "damping",
22211
+ get: /**
22212
+ * The damper force uses to dampen the spring.
22213
+ */ function get() {
22214
+ return this._damping;
22215
+ },
22216
+ set: function set(value) {
22217
+ if (this._damping !== value) {
22218
+ this._damping = value;
22219
+ this._updateFlagManager.dispatch();
22220
+ }
22221
+ }
22222
+ }
22223
+ ]);
22224
+ return JointLimits;
22225
+ }();
22226
+ __decorate([
22227
+ deepClone
22228
+ ], JointLimits.prototype, "_updateFlagManager", void 0);
21687
22229
 
21688
22230
  /**
21689
22231
  * The JointMotor is used to motorize a joint.
21690
- */ var JointMotor = function JointMotor() {
21691
- /** The motor will apply a force up to force to achieve targetVelocity. */ this.targetVelocity = 0;
21692
- /** The force limit.*/ this.forceLimit = Number.MAX_VALUE;
21693
- /** Gear ration for the motor */ this.gearRation = 1.0;
21694
- /** If freeSpin is enabled the motor will only accelerate but never slow down. */ this.freeSpin = false;
21695
- };
22232
+ */ var JointMotor = /*#__PURE__*/ function() {
22233
+ function JointMotor() {
22234
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
22235
+ this._targetVelocity = 0;
22236
+ this._forceLimit = Number.MAX_VALUE;
22237
+ this._gearRatio = 1.0;
22238
+ this._freeSpin = false;
22239
+ }
22240
+ _create_class(JointMotor, [
22241
+ {
22242
+ key: "targetVelocity",
22243
+ get: /**
22244
+ * The motor will apply a force up to force to achieve targetVelocity.
22245
+ */ function get() {
22246
+ return this._targetVelocity;
22247
+ },
22248
+ set: function set(value) {
22249
+ this._targetVelocity = value;
22250
+ this._updateFlagManager.dispatch();
22251
+ }
22252
+ },
22253
+ {
22254
+ key: "forceLimit",
22255
+ get: /**
22256
+ * The force limit.
22257
+ */ function get() {
22258
+ return this._forceLimit;
22259
+ },
22260
+ set: function set(value) {
22261
+ this._forceLimit = value;
22262
+ this._updateFlagManager.dispatch();
22263
+ }
22264
+ },
22265
+ {
22266
+ key: "gearRatio",
22267
+ get: /**
22268
+ * Gear ration for the motor
22269
+ */ function get() {
22270
+ return this._gearRatio;
22271
+ },
22272
+ set: function set(value) {
22273
+ this._gearRatio = value;
22274
+ this._updateFlagManager.dispatch();
22275
+ }
22276
+ },
22277
+ {
22278
+ key: "freeSpin",
22279
+ get: /**
22280
+ * If freeSpin is enabled the motor will only accelerate but never slow down.
22281
+ */ function get() {
22282
+ return this._freeSpin;
22283
+ },
22284
+ set: function set(value) {
22285
+ this._freeSpin = value;
22286
+ this._updateFlagManager.dispatch();
22287
+ }
22288
+ }
22289
+ ]);
22290
+ return JointMotor;
22291
+ }();
22292
+ __decorate([
22293
+ deepClone
22294
+ ], JointMotor.prototype, "_updateFlagManager", void 0);
21696
22295
 
21697
22296
  /**
21698
22297
  * Abstract class for collider shapes.
@@ -21715,28 +22314,39 @@ __decorate([
21715
22314
  this._rotation._onValueChanged = this._setRotation;
21716
22315
  //@ts-ignore
21717
22316
  this._position._onValueChanged = this._setPosition;
22317
+ Engine._physicalObjectsMap[this._id] = this;
21718
22318
  }
21719
22319
  var _proto = ColliderShape.prototype;
21720
22320
  /**
21721
22321
  * @internal
21722
22322
  */ _proto._cloneTo = function _cloneTo(target) {
21723
- target.contactOffset = this.contactOffset;
21724
- target.rotation = this.rotation;
21725
- target.position = this.position;
21726
- target.isTrigger = this.isTrigger;
21727
- target.material = this.material;
22323
+ target._syncNative();
21728
22324
  };
21729
22325
  /**
21730
22326
  * @internal
21731
22327
  */ _proto._destroy = function _destroy() {
21732
- this._material._destroy();
21733
22328
  this._nativeShape.destroy();
22329
+ this._nativeShape = null;
22330
+ delete Engine._physicalObjectsMap[this._id];
22331
+ };
22332
+ _proto._syncNative = function _syncNative() {
22333
+ var _this__collider;
22334
+ this._nativeShape.setPosition(this._position);
22335
+ this._nativeShape.setRotation(this._rotation);
22336
+ this._nativeShape.setContactOffset(this._contactOffset);
22337
+ this._nativeShape.setIsTrigger(this._isTrigger);
22338
+ this._nativeShape.setMaterial(this._material._nativeMaterial);
22339
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21734
22340
  };
21735
22341
  _proto._setPosition = function _setPosition() {
22342
+ var _this__collider;
21736
22343
  this._nativeShape.setPosition(this._position);
22344
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21737
22345
  };
21738
22346
  _proto._setRotation = function _setRotation() {
22347
+ var _this__collider;
21739
22348
  this._nativeShape.setRotation(this._rotation);
22349
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21740
22350
  };
21741
22351
  _create_class(ColliderShape, [
21742
22352
  {
@@ -21758,11 +22368,12 @@ __decorate([
21758
22368
  {
21759
22369
  key: "contactOffset",
21760
22370
  get: /**
21761
- * Contact offset for this shape.
22371
+ * Contact offset for this shape, the value must be greater than or equal to 0.
21762
22372
  */ function get() {
21763
22373
  return this._contactOffset;
21764
22374
  },
21765
22375
  set: function set(value) {
22376
+ value = Math.max(0, value);
21766
22377
  if (this._contactOffset !== value) {
21767
22378
  this._contactOffset = value;
21768
22379
  this._nativeShape.setContactOffset(value);
@@ -21837,20 +22448,17 @@ __decorate([
21837
22448
  ignoreClone
21838
22449
  ], ColliderShape.prototype, "_id", void 0);
21839
22450
  __decorate([
21840
- ignoreClone
21841
- ], ColliderShape.prototype, "_material", void 0);
21842
- __decorate([
21843
- ignoreClone
21844
- ], ColliderShape.prototype, "_isTrigger", void 0);
21845
- __decorate([
21846
- ignoreClone
22451
+ deepClone
21847
22452
  ], ColliderShape.prototype, "_rotation", void 0);
21848
22453
  __decorate([
21849
- ignoreClone
22454
+ deepClone
21850
22455
  ], ColliderShape.prototype, "_position", void 0);
21851
22456
  __decorate([
21852
22457
  ignoreClone
21853
- ], ColliderShape.prototype, "_contactOffset", void 0);
22458
+ ], ColliderShape.prototype, "_setPosition", null);
22459
+ __decorate([
22460
+ ignoreClone
22461
+ ], ColliderShape.prototype, "_setRotation", null);
21854
22462
 
21855
22463
  /**
21856
22464
  * Physical collider shape for box.
@@ -21860,17 +22468,14 @@ __decorate([
21860
22468
  var _this;
21861
22469
  _this = ColliderShape.call(this) || this, _this._size = new Vector3(1, 1, 1);
21862
22470
  _this._nativeShape = PhysicsScene._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
21863
- _this._setSize = _this._setSize.bind(_this);
21864
22471
  //@ts-ignore
21865
- _this._size._onValueChanged = _this._setSize;
22472
+ _this._size._onValueChanged = _this._setSize.bind(_this);
21866
22473
  return _this;
21867
22474
  }
21868
22475
  var _proto = BoxColliderShape.prototype;
21869
- /**
21870
- * @internal
21871
- */ _proto._cloneTo = function _cloneTo(target) {
21872
- ColliderShape.prototype._cloneTo.call(this, target);
21873
- target.size = this.size;
22476
+ _proto._syncNative = function _syncNative() {
22477
+ ColliderShape.prototype._syncNative.call(this);
22478
+ this._setSize();
21874
22479
  };
21875
22480
  _proto._setSize = function _setSize() {
21876
22481
  this._nativeShape.setSize(this._size);
@@ -21893,8 +22498,11 @@ __decorate([
21893
22498
  return BoxColliderShape;
21894
22499
  }(ColliderShape);
21895
22500
  __decorate([
21896
- ignoreClone
22501
+ deepClone
21897
22502
  ], BoxColliderShape.prototype, "_size", void 0);
22503
+ __decorate([
22504
+ ignoreClone
22505
+ ], BoxColliderShape.prototype, "_setSize", null);
21898
22506
 
21899
22507
  /**
21900
22508
  * Physical collider shape for sphere.
@@ -21907,9 +22515,9 @@ __decorate([
21907
22515
  return _this;
21908
22516
  }
21909
22517
  var _proto = SphereColliderShape.prototype;
21910
- _proto._cloneTo = function _cloneTo(target) {
21911
- ColliderShape.prototype._cloneTo.call(this, target);
21912
- target.radius = this.radius;
22518
+ _proto._syncNative = function _syncNative() {
22519
+ ColliderShape.prototype._syncNative.call(this);
22520
+ this._nativeShape.setRadius(this._radius);
21913
22521
  };
21914
22522
  _create_class(SphereColliderShape, [
21915
22523
  {
@@ -21929,9 +22537,6 @@ __decorate([
21929
22537
  ]);
21930
22538
  return SphereColliderShape;
21931
22539
  }(ColliderShape);
21932
- __decorate([
21933
- ignoreClone
21934
- ], SphereColliderShape.prototype, "_radius", void 0);
21935
22540
 
21936
22541
  /**
21937
22542
  * Physical collider shape plane.
@@ -21957,13 +22562,11 @@ __decorate([
21957
22562
  return _this;
21958
22563
  }
21959
22564
  var _proto = CapsuleColliderShape.prototype;
21960
- /**
21961
- * @internal
21962
- */ _proto._cloneTo = function _cloneTo(target) {
21963
- ColliderShape.prototype._cloneTo.call(this, target);
21964
- target.radius = this.radius;
21965
- target.height = this.height;
21966
- target.upAxis = this.upAxis;
22565
+ _proto._syncNative = function _syncNative() {
22566
+ ColliderShape.prototype._syncNative.call(this);
22567
+ this._nativeShape.setRadius(this._radius);
22568
+ this._nativeShape.setHeight(this._height);
22569
+ this._nativeShape.setUpAxis(this._upAxis);
21967
22570
  };
21968
22571
  _create_class(CapsuleColliderShape, [
21969
22572
  {
@@ -22011,15 +22614,6 @@ __decorate([
22011
22614
  ]);
22012
22615
  return CapsuleColliderShape;
22013
22616
  }(ColliderShape);
22014
- __decorate([
22015
- ignoreClone
22016
- ], CapsuleColliderShape.prototype, "_radius", void 0);
22017
- __decorate([
22018
- ignoreClone
22019
- ], CapsuleColliderShape.prototype, "_height", void 0);
22020
- __decorate([
22021
- ignoreClone
22022
- ], CapsuleColliderShape.prototype, "_upAxis", void 0);
22023
22617
 
22024
22618
  /**
22025
22619
  * Pointer Manager.
@@ -22585,7 +23179,7 @@ ParticleBufferUtils.boundsFloatStride = 8;
22585
23179
  ParticleBufferUtils.boundsTimeOffset = 6;
22586
23180
  ParticleBufferUtils.boundsMaxLifetimeOffset = 7;
22587
23181
 
22588
- var blitFs = "#define GLSLIFY 1\nuniform mediump sampler2D renderer_BlitTexture;\n#ifdef HAS_TEX_LOD\nuniform float renderer_BlitMipLevel;\n#endif\nvarying vec2 v_uv;void main(){\n#ifdef HAS_TEX_LOD\ngl_FragColor=texture2DLodEXT(renderer_BlitTexture,v_uv,renderer_BlitMipLevel);\n#else\ngl_FragColor=texture2D(renderer_BlitTexture,v_uv);\n#endif\n}"; // eslint-disable-line
23182
+ var blitFs = "#define GLSLIFY 1\nuniform mediump sampler2D renderer_BlitTexture;\n#ifdef HAS_TEX_LOD\nuniform float renderer_BlitMipLevel;\n#endif\nvarying vec2 v_uv;void main(){vec2 uv=v_uv;\n#ifdef renderer_FlipYBlitTexture\nuv.y=1.0-uv.y;\n#endif\n#ifdef HAS_TEX_LOD\ngl_FragColor=texture2DLodEXT(renderer_BlitTexture,uv,renderer_BlitMipLevel);\n#else\ngl_FragColor=texture2D(renderer_BlitTexture,uv);\n#endif\n}"; // eslint-disable-line
22589
23183
 
22590
23184
  var blitVs = "#define GLSLIFY 1\nattribute vec4 POSITION_UV;varying vec2 v_uv;void main(){gl_Position=vec4(POSITION_UV.xy,0.0,1.0);v_uv=POSITION_UV.zw;}"; // eslint-disable-line
22591
23185
 
@@ -22859,7 +23453,7 @@ ShaderPool.init();
22859
23453
  _inherits(Engine, EventDispatcher);
22860
23454
  function Engine(canvas, hardwareRenderer, configuration) {
22861
23455
  var _this;
22862
- _this = EventDispatcher.call(this) || this, /** @internal */ _this._physicsInitialized = false, /** @internal */ _this._physicalObjectsMap = {}, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._subRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._textSubRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramPools = [], /** @internal */ _this._fontMap = {}, /** @internal @todo: temporary solution */ _this._macroCollection = new ShaderMacroCollection(), _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._frameInProcess = false, _this._waitingDestroy = false, _this._isDeviceLost = false, _this._waitingGC = false, _this._animate = function() {
23456
+ _this = EventDispatcher.call(this) || this, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._subRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._textSubRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramPools = [], /** @internal */ _this._fontMap = {}, /** @internal @todo: temporary solution */ _this._macroCollection = new ShaderMacroCollection(), _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._frameInProcess = false, _this._waitingDestroy = false, _this._isDeviceLost = false, _this._waitingGC = false, _this._animate = function() {
22863
23457
  if (_this._vSyncCount) {
22864
23458
  var _this_xrManager;
22865
23459
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -23284,6 +23878,7 @@ ShaderPool.init();
23284
23878
  /** @internal */ Engine._gammaMacro = ShaderMacro.getByName("ENGINE_IS_COLORSPACE_GAMMA");
23285
23879
  /** @internal */ Engine._noDepthTextureMacro = ShaderMacro.getByName("ENGINE_NO_DEPTH_TEXTURE");
23286
23880
  /** @internal Conversion of space units to pixel units for 2D. */ Engine._pixelsPerUnit = 100;
23881
+ /** @internal */ Engine._physicalObjectsMap = {};
23287
23882
 
23288
23883
  /**
23289
23884
  * Canvas.
@@ -29663,7 +30258,12 @@ var ParticleStopMode = /*#__PURE__*/ function(ParticleStopMode) {
29663
30258
  };
29664
30259
  _proto._render = function _render(context) {
29665
30260
  var generator = this.generator;
29666
- generator._primitive.instanceCount = generator._getAliveParticleCount();
30261
+ // Don't need to render when no particles
30262
+ var aliveParticleCount = generator._getAliveParticleCount();
30263
+ if (!aliveParticleCount) {
30264
+ return;
30265
+ }
30266
+ generator._primitive.instanceCount = aliveParticleCount;
29667
30267
  var material = this.getMaterial();
29668
30268
  if (!material) {
29669
30269
  return;
@@ -31811,7 +32411,8 @@ __decorate([
31811
32411
  */ _proto._emit = function _emit(time, count) {
31812
32412
  if (this.emission.enabled) {
31813
32413
  // Wait the existing particles to be retired
31814
- if (this.main._maxParticleBuffer < this._currentParticleCount) {
32414
+ var notRetireParticleCount = this._getNotRetiredParticleCount();
32415
+ if (notRetireParticleCount >= this.main.maxParticles) {
31815
32416
  return;
31816
32417
  }
31817
32418
  var position = ParticleGenerator._tempVector30;
@@ -33588,5 +34189,400 @@ var cacheDir = new Vector3();
33588
34189
  return CubeProbe;
33589
34190
  }(Probe);
33590
34191
 
33591
- export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, ClearableObjectPool, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, LayerPathMask, Light, Loader, Logger, MSAASamples, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderPlatformTarget, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, _PostProcessManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
34192
+ /**
34193
+ * Audio Clip.
34194
+ */ var AudioClip = /*#__PURE__*/ function(ReferResource) {
34195
+ _inherits(AudioClip, ReferResource);
34196
+ function AudioClip(engine, name) {
34197
+ if (name === void 0) name = "";
34198
+ var _this;
34199
+ _this = ReferResource.call(this, engine) || this, _this._audioBuffer = null;
34200
+ _this.name = name;
34201
+ return _this;
34202
+ }
34203
+ var _proto = AudioClip.prototype;
34204
+ /**
34205
+ * @internal
34206
+ */ _proto._getAudioSource = function _getAudioSource() {
34207
+ return this._audioBuffer;
34208
+ };
34209
+ /**
34210
+ * @internal
34211
+ */ _proto._setAudioSource = function _setAudioSource(value) {
34212
+ this._audioBuffer = value;
34213
+ };
34214
+ _proto._onDestroy = function _onDestroy() {
34215
+ ReferResource.prototype._onDestroy.call(this);
34216
+ this._audioBuffer = null;
34217
+ this.name = null;
34218
+ };
34219
+ _create_class(AudioClip, [
34220
+ {
34221
+ key: "channels",
34222
+ get: /**
34223
+ * Number of discrete audio channels.
34224
+ */ function get() {
34225
+ return this._audioBuffer.numberOfChannels;
34226
+ }
34227
+ },
34228
+ {
34229
+ key: "sampleRate",
34230
+ get: /**
34231
+ * Sample rate, in samples per second.
34232
+ */ function get() {
34233
+ return this._audioBuffer.sampleRate;
34234
+ }
34235
+ },
34236
+ {
34237
+ key: "duration",
34238
+ get: /**
34239
+ * Duration, in seconds.
34240
+ */ function get() {
34241
+ return this._audioBuffer.duration;
34242
+ }
34243
+ }
34244
+ ]);
34245
+ return AudioClip;
34246
+ }(ReferResource);
34247
+
34248
+ /**
34249
+ * @internal
34250
+ * Audio Manager.
34251
+ */ var AudioManager = /*#__PURE__*/ function() {
34252
+ function AudioManager() {}
34253
+ AudioManager.getContext = function getContext() {
34254
+ var context = AudioManager._context;
34255
+ if (!context) {
34256
+ AudioManager._context = context = new window.AudioContext();
34257
+ // Safari can't resume audio context without element interaction
34258
+ document.addEventListener("pointerdown", AudioManager._tryResume, true);
34259
+ document.addEventListener("touchend", AudioManager._tryResume, true);
34260
+ document.addEventListener("touchstart", AudioManager._tryResume, true);
34261
+ }
34262
+ return context;
34263
+ };
34264
+ AudioManager.getGainNode = function getGainNode() {
34265
+ var gainNode = AudioManager._gainNode;
34266
+ if (!AudioManager._gainNode) {
34267
+ AudioManager._gainNode = gainNode = AudioManager.getContext().createGain();
34268
+ gainNode.connect(AudioManager.getContext().destination);
34269
+ }
34270
+ return gainNode;
34271
+ };
34272
+ AudioManager.isAudioContextRunning = function isAudioContextRunning() {
34273
+ if (AudioManager.getContext().state !== "running") {
34274
+ console.warn("The AudioContext is not running and requires user interaction, such as a click or touch.");
34275
+ return false;
34276
+ }
34277
+ return true;
34278
+ };
34279
+ AudioManager._tryResume = function _tryResume() {
34280
+ if (AudioManager._context.state !== "running") {
34281
+ if (AudioManager._isResuming) {
34282
+ return;
34283
+ }
34284
+ AudioManager._isResuming = true;
34285
+ AudioManager._context.resume().then(function() {
34286
+ AudioManager._isResuming = false;
34287
+ });
34288
+ }
34289
+ };
34290
+ return AudioManager;
34291
+ }();
34292
+ AudioManager._isResuming = false;
34293
+
34294
+ /**
34295
+ * Audio Source Component.
34296
+ */ var AudioSource = /*#__PURE__*/ function(Component) {
34297
+ _inherits(AudioSource, Component);
34298
+ function AudioSource(entity) {
34299
+ var _this;
34300
+ _this = Component.call(this, entity) || this, /** If set to true, the audio component automatically begins to play on startup. */ _this.playOnEnabled = true, _this._isPlaying = false, _this._sourceNode = null, _this._pausedTime = -1, _this._playTime = -1, _this._volume = 1, _this._lastVolume = 1, _this._playbackRate = 1, _this._loop = false;
34301
+ _this._onPlayEnd = _this._onPlayEnd.bind(_this);
34302
+ _this._gainNode = AudioManager.getContext().createGain();
34303
+ _this._gainNode.connect(AudioManager.getGainNode());
34304
+ return _this;
34305
+ }
34306
+ var _proto = AudioSource.prototype;
34307
+ /**
34308
+ * Play the clip.
34309
+ */ _proto.play = function play() {
34310
+ if (!this._canPlay()) {
34311
+ return;
34312
+ }
34313
+ if (this._isPlaying) {
34314
+ return;
34315
+ }
34316
+ var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
34317
+ this._initSourceNode(startTime);
34318
+ this._playTime = AudioManager.getContext().currentTime - startTime;
34319
+ this._pausedTime = -1;
34320
+ this._isPlaying = true;
34321
+ };
34322
+ /**
34323
+ * Stops playing the clip.
34324
+ */ _proto.stop = function stop() {
34325
+ if (this._isPlaying) {
34326
+ this._clearSourceNode();
34327
+ this._isPlaying = false;
34328
+ this._pausedTime = -1;
34329
+ this._playTime = -1;
34330
+ }
34331
+ };
34332
+ /**
34333
+ * Pauses playing the clip.
34334
+ */ _proto.pause = function pause() {
34335
+ if (this._isPlaying) {
34336
+ this._clearSourceNode();
34337
+ this._pausedTime = AudioManager.getContext().currentTime;
34338
+ this._isPlaying = false;
34339
+ }
34340
+ };
34341
+ /**
34342
+ * @internal
34343
+ */ _proto._onEnable = function _onEnable() {
34344
+ this.playOnEnabled && this.play();
34345
+ };
34346
+ /**
34347
+ * @internal
34348
+ */ _proto._onDisable = function _onDisable() {
34349
+ this.pause();
34350
+ };
34351
+ /**
34352
+ * @internal
34353
+ */ _proto._onDestroy = function _onDestroy() {
34354
+ Component.prototype._onDestroy.call(this);
34355
+ this.stop();
34356
+ this.clip = null;
34357
+ };
34358
+ _proto._onPlayEnd = function _onPlayEnd() {
34359
+ this.stop();
34360
+ };
34361
+ _proto._initSourceNode = function _initSourceNode(startTime) {
34362
+ var context = AudioManager.getContext();
34363
+ var sourceNode = context.createBufferSource();
34364
+ sourceNode.buffer = this._clip._getAudioSource();
34365
+ sourceNode.playbackRate.value = this._playbackRate;
34366
+ sourceNode.loop = this._loop;
34367
+ sourceNode.onended = this._onPlayEnd;
34368
+ this._sourceNode = sourceNode;
34369
+ sourceNode.connect(this._gainNode);
34370
+ this._sourceNode.start(0, startTime);
34371
+ };
34372
+ _proto._clearSourceNode = function _clearSourceNode() {
34373
+ this._sourceNode.stop();
34374
+ this._sourceNode.disconnect();
34375
+ this._sourceNode.onended = null;
34376
+ this._sourceNode = null;
34377
+ };
34378
+ _proto._canPlay = function _canPlay() {
34379
+ var _this__clip;
34380
+ var isValidClip = ((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) ? true : false;
34381
+ return isValidClip && AudioManager.isAudioContextRunning();
34382
+ };
34383
+ _create_class(AudioSource, [
34384
+ {
34385
+ key: "clip",
34386
+ get: /**
34387
+ * The audio clip to play.
34388
+ */ function get() {
34389
+ return this._clip;
34390
+ },
34391
+ set: function set(value) {
34392
+ var lastClip = this._clip;
34393
+ if (lastClip !== value) {
34394
+ lastClip && lastClip._addReferCount(-1);
34395
+ value && value._addReferCount(1);
34396
+ this._clip = value;
34397
+ this.stop();
34398
+ }
34399
+ }
34400
+ },
34401
+ {
34402
+ key: "isPlaying",
34403
+ get: /**
34404
+ * Whether the clip playing right now.
34405
+ */ function get() {
34406
+ return this._isPlaying;
34407
+ }
34408
+ },
34409
+ {
34410
+ key: "volume",
34411
+ get: /**
34412
+ * The volume of the audio source, ranging from 0 to 1.
34413
+ * @defaultValue `1`
34414
+ */ function get() {
34415
+ return this._volume;
34416
+ },
34417
+ set: function set(value) {
34418
+ value = Math.min(Math.max(0, value), 1.0);
34419
+ this._volume = value;
34420
+ this._gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
34421
+ }
34422
+ },
34423
+ {
34424
+ key: "playbackRate",
34425
+ get: /**
34426
+ * The playback rate of the audio source.
34427
+ * @defaultValue `1`
34428
+ */ function get() {
34429
+ return this._playbackRate;
34430
+ },
34431
+ set: function set(value) {
34432
+ this._playbackRate = value;
34433
+ if (this._isPlaying) {
34434
+ this._sourceNode.playbackRate.value = this._playbackRate;
34435
+ }
34436
+ }
34437
+ },
34438
+ {
34439
+ key: "mute",
34440
+ get: /**
34441
+ * Mutes or unmute the audio source.
34442
+ * Mute sets volume as 0, unmute restore volume.
34443
+ */ function get() {
34444
+ return this.volume === 0;
34445
+ },
34446
+ set: function set(value) {
34447
+ if (value) {
34448
+ this._lastVolume = this.volume;
34449
+ this.volume = 0;
34450
+ } else {
34451
+ this.volume = this._lastVolume;
34452
+ }
34453
+ }
34454
+ },
34455
+ {
34456
+ key: "loop",
34457
+ get: /**
34458
+ * Whether the audio clip looping.
34459
+ * @defaultValue `false`
34460
+ */ function get() {
34461
+ return this._loop;
34462
+ },
34463
+ set: function set(value) {
34464
+ if (value !== this._loop) {
34465
+ this._loop = value;
34466
+ if (this._isPlaying) {
34467
+ this._sourceNode.loop = this._loop;
34468
+ }
34469
+ }
34470
+ }
34471
+ },
34472
+ {
34473
+ key: "time",
34474
+ get: /**
34475
+ * Playback position in seconds.
34476
+ */ function get() {
34477
+ if (this._isPlaying) {
34478
+ var currentTime = AudioManager.getContext().currentTime;
34479
+ return currentTime - this._playTime;
34480
+ } else {
34481
+ return this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
34482
+ }
34483
+ }
34484
+ }
34485
+ ]);
34486
+ return AudioSource;
34487
+ }(Component);
34488
+ __decorate([
34489
+ ignoreClone
34490
+ ], AudioSource.prototype, "_isPlaying", void 0);
34491
+ __decorate([
34492
+ ignoreClone
34493
+ ], AudioSource.prototype, "_clip", void 0);
34494
+ __decorate([
34495
+ deepClone
34496
+ ], AudioSource.prototype, "_gainNode", void 0);
34497
+ __decorate([
34498
+ ignoreClone
34499
+ ], AudioSource.prototype, "_sourceNode", void 0);
34500
+ __decorate([
34501
+ deepClone
34502
+ ], AudioSource.prototype, "_pausedTime", void 0);
34503
+ __decorate([
34504
+ ignoreClone
34505
+ ], AudioSource.prototype, "_playTime", void 0);
34506
+ __decorate([
34507
+ deepClone
34508
+ ], AudioSource.prototype, "_volume", void 0);
34509
+ __decorate([
34510
+ deepClone
34511
+ ], AudioSource.prototype, "_lastVolume", void 0);
34512
+ __decorate([
34513
+ deepClone
34514
+ ], AudioSource.prototype, "_playbackRate", void 0);
34515
+ __decorate([
34516
+ deepClone
34517
+ ], AudioSource.prototype, "_loop", void 0);
34518
+
34519
+ /**
34520
+ * @internal
34521
+ */ var Polyfill = /*#__PURE__*/ function() {
34522
+ function Polyfill() {}
34523
+ Polyfill.registerPolyfill = function registerPolyfill() {
34524
+ Polyfill._registerMatchAll();
34525
+ };
34526
+ Polyfill._registerMatchAll = function _registerMatchAll() {
34527
+ if (!String.prototype.matchAll) {
34528
+ Logger.info("polyfill String.prototype.matchAll");
34529
+ String.prototype.matchAll = function(pattern) {
34530
+ var flags = pattern.flags;
34531
+ var globalFlagIdx = flags.indexOf("g");
34532
+ if (globalFlagIdx === -1) {
34533
+ throw TypeError("String.prototype.matchAll called with a non-global RegExp argument");
34534
+ }
34535
+ var bindThis = this;
34536
+ return function() {
34537
+ var matchResult, matchFlag, matchPattern, _tmp, _tmp1, _i, index, item;
34538
+ return __generator(this, function(_state) {
34539
+ switch(_state.label){
34540
+ case 0:
34541
+ matchResult = bindThis.match(pattern);
34542
+ if (matchResult == null) return [
34543
+ 2,
34544
+ null
34545
+ ];
34546
+ matchFlag = flags.split("g").join("");
34547
+ matchPattern = new RegExp(pattern.source, matchFlag);
34548
+ _tmp = [];
34549
+ for(_tmp1 in matchResult)_tmp.push(_tmp1);
34550
+ _i = 0;
34551
+ _state.label = 1;
34552
+ case 1:
34553
+ if (!(_i < _tmp.length)) return [
34554
+ 3,
34555
+ 4
34556
+ ];
34557
+ index = _tmp[_i];
34558
+ item = matchResult[index];
34559
+ return [
34560
+ 4,
34561
+ item.match(matchPattern)
34562
+ ];
34563
+ case 2:
34564
+ _state.sent();
34565
+ _state.label = 3;
34566
+ case 3:
34567
+ _i++;
34568
+ return [
34569
+ 3,
34570
+ 1
34571
+ ];
34572
+ case 4:
34573
+ return [
34574
+ 2
34575
+ ];
34576
+ }
34577
+ });
34578
+ }();
34579
+ };
34580
+ }
34581
+ };
34582
+ return Polyfill;
34583
+ }();
34584
+
34585
+ Polyfill.registerPolyfill();
34586
+
34587
+ export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, AudioClip, AudioManager, AudioSource, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, ClearableObjectPool, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, LayerPathMask, Light, Loader, Logger, MSAASamples, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderPlatformTarget, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, _PostProcessManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
33592
34588
  //# sourceMappingURL=module.js.map