@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/main.js CHANGED
@@ -98,6 +98,34 @@ function __decorate(decorators, target, key, desc) {
98
98
  return c > 3 && r && Object.defineProperty(target, key, r), r;
99
99
  }
100
100
 
101
+ function __generator(thisArg, body) {
102
+ 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);
103
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
104
+ function verb(n) { return function (v) { return step([n, v]); }; }
105
+ function step(op) {
106
+ if (f) throw new TypeError("Generator is already executing.");
107
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
108
+ 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;
109
+ if (y = 0, t) op = [op[0] & 2, t.value];
110
+ switch (op[0]) {
111
+ case 0: case 1: t = op; break;
112
+ case 4: _.label++; return { value: op[1], done: false };
113
+ case 5: _.label++; y = op[1]; op = [0]; continue;
114
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
115
+ default:
116
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
117
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
118
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
119
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
120
+ if (t[2]) _.ops.pop();
121
+ _.trys.pop(); continue;
122
+ }
123
+ op = body.call(thisArg, _);
124
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
125
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
126
+ }
127
+ }
128
+
101
129
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
102
130
  var e = new Error(message);
103
131
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -5176,11 +5204,13 @@ __decorate([
5176
5204
  /**
5177
5205
  * @internal
5178
5206
  * @todo Should merge when we can delete material render state
5179
- */ _proto._applyRenderQueueByShaderData = function _applyRenderQueueByShaderData(renderStateDataMap, shaderData) {
5207
+ */ _proto._getRenderQueueByShaderData = function _getRenderQueueByShaderData(renderStateDataMap, shaderData) {
5180
5208
  var renderQueueType = renderStateDataMap[RenderStateElementKey.RenderQueueType];
5181
- if (renderQueueType !== undefined) {
5209
+ if (renderQueueType === undefined) {
5210
+ return this.renderQueueType;
5211
+ } else {
5182
5212
  var _shaderData_getFloat;
5183
- this.renderQueueType = (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
5213
+ return (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
5184
5214
  }
5185
5215
  };
5186
5216
  _proto._applyStatesByShaderData = function _applyStatesByShaderData(renderStateDataMap, shaderData) {
@@ -5989,12 +6019,18 @@ __decorate([
5989
6019
  /**
5990
6020
  * @internal
5991
6021
  */ ComponentsDependencies._removeCheck = function _removeCheck(entity, type) {
6022
+ var components = entity._components;
6023
+ var n = components.length;
5992
6024
  while(type !== Component){
6025
+ var count = 0;
6026
+ for(var i = 0; i < n; i++){
6027
+ if (_instanceof(components[i], type) && ++count > 1) return;
6028
+ }
5993
6029
  var invDependencies = ComponentsDependencies._invDependenciesMap.get(type);
5994
6030
  if (invDependencies) {
5995
- for(var i = 0, len = invDependencies.length; i < len; i++){
5996
- if (entity.getComponent(invDependencies[i])) {
5997
- throw "Should remove " + invDependencies[i].name + " before adding " + type.name;
6031
+ for(var i1 = 0, len = invDependencies.length; i1 < len; i1++){
6032
+ if (entity.getComponent(invDependencies[i1])) {
6033
+ throw "Should remove " + invDependencies[i1].name + " before remove " + type.name;
5998
6034
  }
5999
6035
  }
6000
6036
  }
@@ -6105,7 +6141,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
6105
6141
  _inherits(Transform, Component);
6106
6142
  function Transform(entity) {
6107
6143
  var _this;
6108
- _this = Component.call(this, entity) || this, _this._position = new engineMath.Vector3(), _this._rotation = new engineMath.Vector3(), _this._rotationQuaternion = new engineMath.Quaternion(), _this._scale = new engineMath.Vector3(1, 1, 1), _this._worldPosition = new engineMath.Vector3(), _this._worldRotation = new engineMath.Vector3(), _this._worldRotationQuaternion = new engineMath.Quaternion(), _this._lossyWorldScale = new engineMath.Vector3(1, 1, 1), _this._localMatrix = new engineMath.Matrix(), _this._worldMatrix = new engineMath.Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188, /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
6144
+ _this = Component.call(this, entity) || this, _this._position = new engineMath.Vector3(), _this._rotation = new engineMath.Vector3(), _this._rotationQuaternion = new engineMath.Quaternion(), _this._scale = new engineMath.Vector3(1, 1, 1), _this._localUniformScaling = true, _this._worldPosition = new engineMath.Vector3(), _this._worldRotation = new engineMath.Vector3(), _this._worldRotationQuaternion = new engineMath.Quaternion(), _this._worldUniformScaling = true, _this._lossyWorldScale = new engineMath.Vector3(1, 1, 1), _this._localMatrix = new engineMath.Matrix(), _this._worldMatrix = new engineMath.Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188;
6109
6145
  _this._onPositionChanged = _this._onPositionChanged.bind(_this);
6110
6146
  _this._onWorldPositionChanged = _this._onWorldPositionChanged.bind(_this);
6111
6147
  _this._onRotationChanged = _this._onRotationChanged.bind(_this);
@@ -6253,16 +6289,10 @@ function dependentComponents(componentOrComponents, dependentMode) {
6253
6289
  rotMat.getRotation(this._worldRotationQuaternion);
6254
6290
  };
6255
6291
  /**
6256
- * Register world transform change flag.
6257
- * @returns Change flag
6258
- */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
6259
- return this._updateFlagManager.createFlag(BoolUpdateFlag);
6260
- };
6261
- /**
6262
6292
  * @internal
6263
6293
  */ _proto._parentChange = function _parentChange() {
6264
6294
  this._isParentDirty = true;
6265
- this._updateAllWorldFlag();
6295
+ this._updateAllWorldFlag(444);
6266
6296
  };
6267
6297
  /**
6268
6298
  * @internal
@@ -6273,6 +6303,13 @@ function dependentComponents(componentOrComponents, dependentMode) {
6273
6303
  scale.z < 0 && (isInvert = !isInvert);
6274
6304
  return isInvert;
6275
6305
  };
6306
+ /**
6307
+ * @internal
6308
+ */ _proto._copyFrom = function _copyFrom(transform) {
6309
+ this._position.copyFrom(transform.position);
6310
+ this._rotation.copyFrom(transform.rotation);
6311
+ this._scale.copyFrom(transform.scale);
6312
+ };
6276
6313
  _proto._onDestroy = function _onDestroy() {
6277
6314
  Component.prototype._onDestroy.call(this);
6278
6315
  //@ts-ignore
@@ -6297,10 +6334,10 @@ function dependentComponents(componentOrComponents, dependentMode) {
6297
6334
  */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
6298
6335
  if (!this._isContainDirtyFlags(132)) {
6299
6336
  this._worldAssociatedChange(132);
6300
- var nodeChildren = this._entity._children;
6301
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6302
- var _nodeChildren_i_transform;
6303
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionFlag();
6337
+ var children = this._entity._children;
6338
+ for(var i = 0, n = children.length; i < n; i++){
6339
+ var _children_i_transform;
6340
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionFlag();
6304
6341
  }
6305
6342
  }
6306
6343
  };
@@ -6309,14 +6346,19 @@ function dependentComponents(componentOrComponents, dependentMode) {
6309
6346
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6310
6347
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
6311
6348
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
6349
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6312
6350
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
6313
6351
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
6314
- if (!this._isContainDirtyFlags(152)) {
6315
- this._worldAssociatedChange(152);
6316
- var nodeChildren = this._entity._children;
6317
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6318
- var _nodeChildren_i_transform;
6319
- (_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.
6352
+ var parent = this._getParentTransform();
6353
+ var parentWorldUniformScaling = parent ? parent._getWorldUniformScaling() : true;
6354
+ var flags = parentWorldUniformScaling ? 152 : 184;
6355
+ if (!this._isContainDirtyFlags(flags)) {
6356
+ this._worldAssociatedChange(flags);
6357
+ flags = this._getWorldUniformScaling() ? 156 : 188;
6358
+ var children = this._entity._children;
6359
+ for(var i = 0, n = children.length; i < n; i++){
6360
+ var _children_i_transform;
6361
+ (_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.
6320
6362
  }
6321
6363
  }
6322
6364
  };
@@ -6325,14 +6367,17 @@ function dependentComponents(componentOrComponents, dependentMode) {
6325
6367
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6326
6368
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
6327
6369
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
6370
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6328
6371
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
6329
- */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag() {
6330
- if (!this._isContainDirtyFlags(156)) {
6331
- this._worldAssociatedChange(156);
6332
- var nodeChildren = this._entity._children;
6333
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6334
- var _nodeChildren_i_transform;
6335
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndRotationFlag();
6372
+ * @param flags - Dirty flag
6373
+ */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag(flags) {
6374
+ if (!this._isContainDirtyFlags(flags)) {
6375
+ this._worldAssociatedChange(flags);
6376
+ flags = this._getWorldUniformScaling() ? 156 : 188;
6377
+ var children = this._entity._children;
6378
+ for(var i = 0, n = children.length; i < n; i++){
6379
+ var _children_i_transform;
6380
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndRotationFlag(flags);
6336
6381
  }
6337
6382
  }
6338
6383
  };
@@ -6341,13 +6386,15 @@ function dependentComponents(componentOrComponents, dependentMode) {
6341
6386
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6342
6387
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6343
6388
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
6344
- */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
6345
- if (!this._isContainDirtyFlags(160)) {
6346
- this._worldAssociatedChange(160);
6347
- var nodeChildren = this._entity._children;
6348
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6349
- var _nodeChildren_i_transform;
6350
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
6389
+ * @param flags - Dirty flag
6390
+ */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag(flags) {
6391
+ if (!this._isContainDirtyFlags(flags)) {
6392
+ this._worldAssociatedChange(flags);
6393
+ flags |= 4;
6394
+ var children = this._entity._children;
6395
+ for(var i = 0, n = children.length; i < n; i++){
6396
+ var _children_i_transform;
6397
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
6351
6398
  }
6352
6399
  }
6353
6400
  };
@@ -6356,25 +6403,27 @@ function dependentComponents(componentOrComponents, dependentMode) {
6356
6403
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
6357
6404
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
6358
6405
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
6359
- */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag() {
6360
- if (!this._isContainDirtyFlags(164)) {
6361
- this._worldAssociatedChange(164);
6362
- var nodeChildren = this._entity._children;
6363
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6364
- var _nodeChildren_i_transform;
6365
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
6406
+ * @param flags - Dirty flag
6407
+ */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag(flags) {
6408
+ if (!this._isContainDirtyFlags(flags)) {
6409
+ this._worldAssociatedChange(flags);
6410
+ var children = this._entity._children;
6411
+ for(var i = 0, n = children.length; i < n; i++){
6412
+ var _children_i_transform;
6413
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
6366
6414
  }
6367
6415
  }
6368
6416
  };
6369
6417
  /**
6370
6418
  * Update all world transform property dirty flag, the principle is the same as above.
6371
- */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
6372
- if (!this._isContainDirtyFlags(188)) {
6373
- this._worldAssociatedChange(188);
6374
- var nodeChildren = this._entity._children;
6375
- for(var i = 0, n = nodeChildren.length; i < n; i++){
6376
- var _nodeChildren_i_transform;
6377
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateAllWorldFlag();
6419
+ * @param flags - Dirty flag
6420
+ */ _proto._updateAllWorldFlag = function _updateAllWorldFlag(flags) {
6421
+ if (!this._isContainDirtyFlags(flags)) {
6422
+ this._worldAssociatedChange(flags);
6423
+ var children = this._entity._children;
6424
+ for(var i = 0, n = children.length; i < n; i++){
6425
+ var _children_i_transform;
6426
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateAllWorldFlag(flags);
6378
6427
  }
6379
6428
  }
6380
6429
  };
@@ -6422,7 +6471,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
6422
6471
  };
6423
6472
  _proto._worldAssociatedChange = function _worldAssociatedChange(type) {
6424
6473
  this._dirtyFlag |= type;
6425
- this._updateFlagManager.dispatch(128);
6474
+ this._entity._updateFlagManager.dispatch(type);
6426
6475
  };
6427
6476
  _proto._rotateByQuat = function _rotateByQuat(rotateQuat, relativeToLocal) {
6428
6477
  if (relativeToLocal) {
@@ -6491,8 +6540,36 @@ function dependentComponents(componentOrComponents, dependentMode) {
6491
6540
  this._setDirtyFlagFalse(16);
6492
6541
  };
6493
6542
  _proto._onScaleChanged = function _onScaleChanged() {
6543
+ var _this__scale = this._scale, x = _this__scale.x, y = _this__scale.y, z = _this__scale.z;
6494
6544
  this._setDirtyFlagTrue(64);
6495
- this._updateWorldScaleFlag();
6545
+ var localUniformScaling = x == y && y == z;
6546
+ if (this._localUniformScaling !== localUniformScaling) {
6547
+ this._localUniformScaling = localUniformScaling;
6548
+ this._updateWorldScaleFlag(416);
6549
+ } else {
6550
+ this._updateWorldScaleFlag(160);
6551
+ }
6552
+ };
6553
+ _proto._getWorldUniformScaling = function _getWorldUniformScaling() {
6554
+ if (this._isContainDirtyFlag(256)) {
6555
+ var localUniformScaling = this._localUniformScaling;
6556
+ if (localUniformScaling) {
6557
+ var parent = this._getParentTransform();
6558
+ this._worldUniformScaling = localUniformScaling && (parent ? parent._getWorldUniformScaling() : true);
6559
+ } else {
6560
+ this._worldUniformScaling = false;
6561
+ }
6562
+ this._setDirtyFlagFalse(256);
6563
+ }
6564
+ return this._worldUniformScaling;
6565
+ };
6566
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
6567
+ /**
6568
+ * @deprecated
6569
+ * Listen for changes in the world pose of this `Entity`.
6570
+ * @returns Change flag
6571
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
6572
+ return this.entity._updateFlagManager.createFlag(BoolUpdateFlag);
6496
6573
  };
6497
6574
  _create_class(Transform, [
6498
6575
  {
@@ -6659,11 +6736,12 @@ function dependentComponents(componentOrComponents, dependentMode) {
6659
6736
  key: "lossyWorldScale",
6660
6737
  get: /**
6661
6738
  * Local lossy scaling.
6662
- * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has scaling,
6663
- * and the child node has a rotation), the scaling will be tilted. Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3.
6739
+ * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has non-uniform world scaling,
6740
+ * and the child node has a rotation), the scaling will be tilted.
6664
6741
  */ function get() {
6665
6742
  if (this._isContainDirtyFlag(32)) {
6666
6743
  if (this._getParentTransform()) {
6744
+ // Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3
6667
6745
  var scaleMat = this._getScaleMatrix();
6668
6746
  var e = scaleMat.elements;
6669
6747
  this._lossyWorldScale.set(e[0], e[4], e[8]);
@@ -6691,18 +6769,25 @@ function dependentComponents(componentOrComponents, dependentMode) {
6691
6769
  if (this._localMatrix !== value) {
6692
6770
  this._localMatrix.copyFrom(value);
6693
6771
  }
6772
+ var _this = this, position = _this._position, rotationQuaternion = _this._rotationQuaternion, scale = _this._scale;
6694
6773
  // @ts-ignore
6695
- this._position._onValueChanged = this._rotationQuaternion._onValueChanged = this._scale._onValueChanged = null;
6696
- this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
6774
+ position._onValueChanged = rotationQuaternion._onValueChanged = scale._onValueChanged = null;
6775
+ this._localMatrix.decompose(position, rotationQuaternion, scale);
6697
6776
  // @ts-ignore
6698
- this._position._onValueChanged = this._onPositionChanged;
6777
+ position._onValueChanged = this._onPositionChanged;
6699
6778
  // @ts-ignore
6700
- this._rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
6779
+ rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
6701
6780
  // @ts-ignore
6702
- this._scale._onValueChanged = this._onScaleChanged;
6781
+ scale._onValueChanged = this._onScaleChanged;
6703
6782
  this._setDirtyFlagTrue(1);
6704
6783
  this._setDirtyFlagFalse(64 | 2);
6705
- this._updateAllWorldFlag();
6784
+ var localUniformScaling = scale.x === scale.y && scale.y === scale.z;
6785
+ if (this._localUniformScaling !== localUniformScaling) {
6786
+ this._localUniformScaling = localUniformScaling;
6787
+ this._updateAllWorldFlag(444);
6788
+ } else {
6789
+ this._updateAllWorldFlag(188);
6790
+ }
6706
6791
  }
6707
6792
  },
6708
6793
  {
@@ -6794,6 +6879,9 @@ __decorate([
6794
6879
  __decorate([
6795
6880
  deepClone
6796
6881
  ], Transform.prototype, "_scale", void 0);
6882
+ __decorate([
6883
+ assignmentClone
6884
+ ], Transform.prototype, "_localUniformScaling", void 0);
6797
6885
  __decorate([
6798
6886
  deepClone
6799
6887
  ], Transform.prototype, "_worldPosition", void 0);
@@ -6803,6 +6891,9 @@ __decorate([
6803
6891
  __decorate([
6804
6892
  deepClone
6805
6893
  ], Transform.prototype, "_worldRotationQuaternion", void 0);
6894
+ __decorate([
6895
+ assignmentClone
6896
+ ], Transform.prototype, "_worldUniformScaling", void 0);
6806
6897
  __decorate([
6807
6898
  deepClone
6808
6899
  ], Transform.prototype, "_lossyWorldScale", void 0);
@@ -6827,9 +6918,6 @@ __decorate([
6827
6918
  __decorate([
6828
6919
  ignoreClone
6829
6920
  ], Transform.prototype, "_parentTransformCache", void 0);
6830
- __decorate([
6831
- ignoreClone
6832
- ], Transform.prototype, "_updateFlagManager", void 0);
6833
6921
  __decorate([
6834
6922
  ignoreClone
6835
6923
  ], Transform.prototype, "_onPositionChanged", null);
@@ -6862,12 +6950,18 @@ __decorate([
6862
6950
  TransformModifyFlags[TransformModifyFlags["WorldScale"] = 32] = "WorldScale";
6863
6951
  TransformModifyFlags[TransformModifyFlags["LocalMatrix"] = 64] = "LocalMatrix";
6864
6952
  TransformModifyFlags[TransformModifyFlags["WorldMatrix"] = 128] = "WorldMatrix";
6953
+ /** This is an internal flag used to assist in determining the dispatch
6954
+ * of world scaling dirty flags in the case of non-uniform scaling.
6955
+ */ TransformModifyFlags[TransformModifyFlags["IsWorldUniformScaling"] = 256] = "IsWorldUniformScaling";
6865
6956
  /** WorldMatrix | WorldPosition */ TransformModifyFlags[TransformModifyFlags["WmWp"] = 132] = "WmWp";
6866
6957
  /** WorldMatrix | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWeWq"] = 152] = "WmWeWq";
6958
+ /** WorldMatrix | WorldEuler | WorldQuat | WorldScale*/ TransformModifyFlags[TransformModifyFlags["WmWeWqWs"] = 184] = "WmWeWqWs";
6867
6959
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWpWeWq"] = 156] = "WmWpWeWq";
6868
6960
  /** WorldMatrix | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWs"] = 160] = "WmWs";
6961
+ /** WorldMatrix | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWsWus"] = 416] = "WmWsWus";
6869
6962
  /** WorldMatrix | WorldPosition | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWs"] = 164] = "WmWpWs";
6870
6963
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWs"] = 188] = "WmWpWeWqWs";
6964
+ /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWsWus"] = 444] = "WmWpWeWqWsWus";
6871
6965
  return TransformModifyFlags;
6872
6966
  }({});
6873
6967
 
@@ -6922,7 +7016,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
6922
7016
  _this._overrideUpdate = _this.update !== prototype.update;
6923
7017
  _this._addResourceReferCount(_this.shaderData, 1);
6924
7018
  _this._onTransformChanged = _this._onTransformChanged.bind(_this);
6925
- _this._setTransform(entity.transform);
7019
+ _this._setTransformEntity(entity);
6926
7020
  shaderData.enableMacro(Renderer._receiveShadowMacro);
6927
7021
  shaderData.setVector4(Renderer._rendererLayerProperty, _this._rendererLayer);
6928
7022
  return _this;
@@ -7048,7 +7142,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
7048
7142
  * @internal
7049
7143
  */ _proto._onDestroy = function _onDestroy() {
7050
7144
  Component.prototype._onDestroy.call(this);
7051
- this._setTransform(null);
7145
+ this._setTransformEntity(null);
7052
7146
  this._addResourceReferCount(this.shaderData, -1);
7053
7147
  var materials = this._materials;
7054
7148
  for(var i = 0, n = materials.length; i < n; i++){
@@ -7070,7 +7164,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
7070
7164
  /**
7071
7165
  * @internal
7072
7166
  */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
7073
- var worldMatrix = this._transform.worldMatrix;
7167
+ var worldMatrix = this._transformEntity.transform.worldMatrix;
7074
7168
  if (onlyMVP) {
7075
7169
  this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
7076
7170
  } else {
@@ -7109,7 +7203,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
7109
7203
  engineMath.Matrix.invert(mvMatrix, mvInvMatrix);
7110
7204
  engineMath.Matrix.invert(worldMatrix, normalMatrix);
7111
7205
  normalMatrix.transpose();
7112
- shaderData.setMatrix(Renderer._localMatrixProperty, this._transform.localMatrix);
7206
+ shaderData.setMatrix(Renderer._localMatrixProperty, this._transformEntity.transform.localMatrix);
7113
7207
  shaderData.setMatrix(Renderer._worldMatrixProperty, worldMatrix);
7114
7208
  shaderData.setMatrix(Renderer._mvMatrixProperty, mvMatrix);
7115
7209
  shaderData.setMatrix(Renderer._mvInvMatrixProperty, mvInvMatrix);
@@ -7128,11 +7222,13 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
7128
7222
  };
7129
7223
  /**
7130
7224
  * @internal
7131
- */ _proto._setTransform = function _setTransform(transform) {
7132
- var _this__transform;
7133
- (_this__transform = this._transform) == null ? void 0 : _this__transform._updateFlagManager.removeListener(this._onTransformChanged);
7134
- transform == null ? void 0 : transform._updateFlagManager.addListener(this._onTransformChanged);
7135
- this._transform = transform;
7225
+ */ _proto._setTransformEntity = function _setTransformEntity(entity) {
7226
+ var preEntity = this._transformEntity;
7227
+ if (entity !== preEntity) {
7228
+ preEntity == null ? void 0 : preEntity._updateFlagManager.removeListener(this._onTransformChanged);
7229
+ entity == null ? void 0 : entity._updateFlagManager.addListener(this._onTransformChanged);
7230
+ this._transformEntity = entity;
7231
+ }
7136
7232
  };
7137
7233
  /**
7138
7234
  * @internal
@@ -7283,6 +7379,9 @@ __decorate([
7283
7379
  __decorate([
7284
7380
  ignoreClone
7285
7381
  ], exports.Renderer.prototype, "_batchedTransformShaderData", void 0);
7382
+ __decorate([
7383
+ ignoreClone
7384
+ ], exports.Renderer.prototype, "_transformEntity", void 0);
7286
7385
  __decorate([
7287
7386
  ignoreClone
7288
7387
  ], exports.Renderer.prototype, "_overrideUpdate", void 0);
@@ -7295,9 +7394,6 @@ __decorate([
7295
7394
  __decorate([
7296
7395
  ignoreClone
7297
7396
  ], exports.Renderer.prototype, "_rendererLayer", void 0);
7298
- __decorate([
7299
- ignoreClone
7300
- ], exports.Renderer.prototype, "_transform", void 0);
7301
7397
  __decorate([
7302
7398
  deepClone
7303
7399
  ], exports.Renderer.prototype, "_shaderData", void 0);
@@ -8705,11 +8801,13 @@ __decorate([
8705
8801
  * @param viewport - Viewport
8706
8802
  * @param material - The material to use when blitting
8707
8803
  * @param passIndex - Pass index to use of the provided material
8708
- */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex) {
8804
+ * @param flipYOfSource - Whether flip Y axis of source texture
8805
+ */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex, flipYOfSource) {
8709
8806
  if (mipLevel === void 0) mipLevel = 0;
8710
8807
  if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
8711
8808
  if (material === void 0) material = null;
8712
8809
  if (passIndex === void 0) passIndex = 0;
8810
+ if (flipYOfSource === void 0) flipYOfSource = false;
8713
8811
  var basicResources = engine._basicResources;
8714
8812
  var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
8715
8813
  var blitMaterial = material || basicResources.blitMaterial;
@@ -8723,9 +8821,15 @@ __decorate([
8723
8821
  rendererShaderData.setFloat(PipelineUtils._blitMipLevelProperty, mipLevel);
8724
8822
  PipelineUtils._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
8725
8823
  rendererShaderData.setVector4(PipelineUtils._blitTexelSizeProperty, PipelineUtils._texelSize);
8824
+ if (flipYOfSource) {
8825
+ rendererShaderData.enableMacro(PipelineUtils._flipYTextureMacro);
8826
+ } else {
8827
+ rendererShaderData.disableMacro(PipelineUtils._flipYTextureMacro);
8828
+ }
8726
8829
  var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
8727
8830
  var compileMacros = Shader._compileMacros;
8728
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, blitMaterial.shaderData._macroCollection, compileMacros);
8831
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, rendererShaderData._macroCollection, compileMacros);
8832
+ ShaderMacroCollection.unionCollection(compileMacros, blitMaterial.shaderData._macroCollection, compileMacros);
8729
8833
  var program = pass._getShaderProgram(engine, compileMacros);
8730
8834
  program.bind();
8731
8835
  program.groupingOtherUniformBlock();
@@ -8741,6 +8845,7 @@ PipelineUtils._blitTextureProperty = ShaderProperty.getByName("renderer_BlitText
8741
8845
  PipelineUtils._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
8742
8846
  PipelineUtils._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
8743
8847
  ;
8848
+ PipelineUtils._flipYTextureMacro = ShaderMacro.getByName("renderer_FlipYBlitTexture");
8744
8849
  PipelineUtils._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
8745
8850
  PipelineUtils._texelSize = new engineMath.Vector4();
8746
8851
  PipelineUtils.defaultViewport = new engineMath.Vector4(0, 0, 1, 1);
@@ -8845,13 +8950,11 @@ exports.Camera = /*#__PURE__*/ function(Component) {
8845
8950
  */ _this.opaqueTextureDownsampling = Downsampling.TwoX, /**
8846
8951
  * Multi-sample anti-aliasing samples when use independent canvas mode.
8847
8952
  *
8848
- * @remarks The `independentCanvasEnabled` property should be `true` to take effect, otherwise it will be invalid.
8953
+ * @remarks It will take effect when `independentCanvasEnabled` property is `true`, otherwise it will be invalid.
8849
8954
  */ _this.msaaSamples = MSAASamples.None, /** @internal */ _this._cameraType = CameraType.Normal, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._frustum = new engineMath.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 engineMath.Vector4(), _this._opaqueTextureEnabled = false, _this._enableHDR = false, _this._enablePostProcess = false, _this._viewport = new engineMath.Vector4(0, 0, 1, 1), _this._pixelViewport = new engineMath.Rect(0, 0, 0, 0), _this._inverseProjectionMatrix = new engineMath.Matrix(), _this._invViewProjMat = new engineMath.Matrix();
8850
- var transform = _this.entity.transform;
8851
- _this._transform = transform;
8852
- _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
8853
- _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
8854
- _this._frustumChangeFlag = transform.registerWorldChangeFlag();
8955
+ _this._isViewMatrixDirty = entity.registerWorldChangeFlag();
8956
+ _this._isInvViewProjDirty = entity.registerWorldChangeFlag();
8957
+ _this._frustumChangeFlag = entity.registerWorldChangeFlag();
8855
8958
  _this._renderPipeline = new BasicRenderPipeline(_this);
8856
8959
  _this._addResourceReferCount(_this.shaderData, 1);
8857
8960
  _this._updatePixelViewport();
@@ -8998,7 +9101,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
8998
9101
  var engine = this._engine;
8999
9102
  var context = engine._renderContext;
9000
9103
  var virtualCamera = this._virtualCamera;
9001
- var transform = this.entity.transform;
9104
+ var transform = this._entity.transform;
9002
9105
  engineMath.Matrix.multiply(this.projectionMatrix, this.viewMatrix, virtualCamera.viewProjectionMatrix);
9003
9106
  virtualCamera.position.copyFrom(transform.worldPosition);
9004
9107
  if (virtualCamera.isOrthographic) {
@@ -9076,7 +9179,6 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9076
9179
  this._virtualCamera = null;
9077
9180
  this._shaderData = null;
9078
9181
  this._frustumChangeFlag = null;
9079
- this._transform = null;
9080
9182
  this._isViewMatrixDirty = null;
9081
9183
  this._isInvViewProjDirty = null;
9082
9184
  this._viewport = null;
@@ -9118,7 +9220,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9118
9220
  };
9119
9221
  _proto._updateShaderData = function _updateShaderData() {
9120
9222
  var shaderData = this.shaderData;
9121
- var transform = this._transform;
9223
+ var transform = this._entity.transform;
9122
9224
  shaderData.setMatrix(Camera._inverseViewMatrixProperty, transform.worldMatrix);
9123
9225
  shaderData.setVector3(Camera._cameraPositionProperty, transform.worldPosition);
9124
9226
  shaderData.setVector3(Camera._cameraForwardProperty, transform.worldForward);
@@ -9133,7 +9235,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9133
9235
  */ _proto._getInvViewProjMat = function _getInvViewProjMat() {
9134
9236
  if (this._isInvViewProjDirty.flag) {
9135
9237
  this._isInvViewProjDirty.flag = false;
9136
- engineMath.Matrix.multiply(this._transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
9238
+ engineMath.Matrix.multiply(this._entity.transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
9137
9239
  }
9138
9240
  return this._invViewProjMat;
9139
9241
  };
@@ -9180,13 +9282,17 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9180
9282
  key: "independentCanvasEnabled",
9181
9283
  get: /**
9182
9284
  * Whether independent canvas is enabled.
9183
- *
9184
9285
  * @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
9185
9286
  */ function get() {
9186
- if (this.enableHDR || this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
9287
+ // Uber pass need internal RT
9288
+ if (this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
9187
9289
  return true;
9188
9290
  }
9189
- return this.opaqueTextureEnabled && !this._renderTarget;
9291
+ if (this.enableHDR || this.opaqueTextureEnabled) {
9292
+ var _this_renderTarget;
9293
+ return this._getInternalColorTextureFormat() !== ((_this_renderTarget = this.renderTarget) == null ? void 0 : _this_renderTarget.getColorTexture(0).format);
9294
+ }
9295
+ return false;
9190
9296
  }
9191
9297
  },
9192
9298
  {
@@ -9328,7 +9434,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9328
9434
  }
9329
9435
  this._isViewMatrixDirty.flag = false;
9330
9436
  // Ignore scale
9331
- var transform = this._transform;
9437
+ var transform = this._entity.transform;
9332
9438
  engineMath.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
9333
9439
  viewMatrix.invert();
9334
9440
  return viewMatrix;
@@ -9446,9 +9552,6 @@ __decorate([
9446
9552
  __decorate([
9447
9553
  ignoreClone
9448
9554
  ], exports.Camera.prototype, "_frustumChangeFlag", void 0);
9449
- __decorate([
9450
- ignoreClone
9451
- ], exports.Camera.prototype, "_transform", void 0);
9452
9555
  __decorate([
9453
9556
  ignoreClone
9454
9557
  ], exports.Camera.prototype, "_isViewMatrixDirty", void 0);
@@ -9635,9 +9738,21 @@ RenderContext._flipYViewProjectionMatrix = new engineMath.Matrix();
9635
9738
  if (shaderPass.getTagValue(pipelineStageKey) !== pipelineStageTagValue) {
9636
9739
  continue;
9637
9740
  }
9638
- if (!needMaskType) {
9639
- var _shaderPass__renderState;
9640
- if (((_shaderPass__renderState = shaderPass._renderState) != null ? _shaderPass__renderState : renderStates[j]).renderQueueType !== renderQueueType) {
9741
+ var renderState = shaderPass._renderState;
9742
+ if (needMaskType) {
9743
+ // Mask don't care render queue type
9744
+ if (!renderState) {
9745
+ renderState = renderStates[j];
9746
+ }
9747
+ } else {
9748
+ var passQueueType = void 0;
9749
+ if (renderState) {
9750
+ passQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, materialData);
9751
+ } else {
9752
+ renderState = renderStates[j];
9753
+ passQueueType = renderState.renderQueueType;
9754
+ }
9755
+ if (passQueueType !== renderQueueType) {
9641
9756
  continue;
9642
9757
  }
9643
9758
  }
@@ -9692,9 +9807,7 @@ RenderContext._flipYViewProjectionMatrix = new engineMath.Matrix();
9692
9807
  program.uploadUnGroupTextures();
9693
9808
  }
9694
9809
  }
9695
- var _shaderPass__renderState1;
9696
- var renderState = (_shaderPass__renderState1 = shaderPass._renderState) != null ? _shaderPass__renderState1 : renderStates[j];
9697
- renderState._applyStates(engine, renderer.entity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
9810
+ renderState._applyStates(engine, renderer._transformEntity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
9698
9811
  rhi.drawPrimitive(primitive, subElement.subPrimitive, program);
9699
9812
  }
9700
9813
  }
@@ -10554,6 +10667,8 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10554
10667
  function BasicRenderPipeline(camera) {
10555
10668
  this._lastCanvasSize = new engineMath.Vector2();
10556
10669
  this._internalColorTarget = null;
10670
+ this._canUseBlitFrameBuffer = false;
10671
+ this._shouldGrabColor = false;
10557
10672
  this._camera = camera;
10558
10673
  var engine = camera.engine;
10559
10674
  this._cullingResults = new CullingResults();
@@ -10578,10 +10693,19 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10578
10693
  context.rendererUpdateFlag = ContextRendererUpdateFlag.All;
10579
10694
  var camera = this._camera;
10580
10695
  var scene = camera.scene, engine = camera.engine;
10696
+ var rhi = engine._hardwareRenderer;
10581
10697
  var cullingResults = this._cullingResults;
10582
10698
  var sunlight = scene._lightManager._sunlight;
10583
10699
  var depthOnlyPass = this._depthOnlyPass;
10584
10700
  var depthPassEnabled = camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
10701
+ var finalClearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
10702
+ var independentCanvasEnabled = camera.independentCanvasEnabled;
10703
+ var msaaSamples = camera.renderTarget ? camera.renderTarget.antiAliasing : camera.msaaSamples;
10704
+ this._shouldGrabColor = independentCanvasEnabled && !(finalClearFlags & CameraClearFlags.Color);
10705
+ // 1. Only support blitFramebuffer in webgl2 context
10706
+ // 2. Can't blit normal FBO to MSAA FBO
10707
+ // 3. Can't blit screen MSAA FBO to normal FBO in mac safari platform and mobile, but mac chrome and firfox is OK
10708
+ this._canUseBlitFrameBuffer = rhi.isWebGL2 && msaaSamples === 1 && (!!camera.renderTarget || !rhi.context.antialias);
10585
10709
  if (scene.castShadows && sunlight && sunlight.shadowType !== ShadowType.None) {
10586
10710
  this._cascadedShadowCasterPass.onRender(context);
10587
10711
  context.rendererUpdateFlag = ContextRendererUpdateFlag.None;
@@ -10601,24 +10725,46 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10601
10725
  } else {
10602
10726
  camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
10603
10727
  }
10604
- // Check if need to create internal color texture
10605
- var independentCanvasEnabled = camera.independentCanvasEnabled;
10728
+ // Check if need to create internal color texture or grab texture
10606
10729
  if (independentCanvasEnabled) {
10730
+ var depthFormat;
10731
+ if (camera.renderTarget) {
10732
+ depthFormat = camera.renderTarget._depthFormat;
10733
+ } else if (rhi.context.depth && rhi.context.stencil) {
10734
+ depthFormat = TextureFormat.Depth24Stencil8;
10735
+ } else if (rhi.context.depth) {
10736
+ depthFormat = TextureFormat.Depth24;
10737
+ } else if (rhi.context.stencil) {
10738
+ depthFormat = TextureFormat.Stencil;
10739
+ } else {
10740
+ depthFormat = null;
10741
+ }
10607
10742
  var viewport = camera.pixelViewport;
10608
- var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), TextureFormat.Depth24Stencil8, false, false, camera.msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
10743
+ var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
10744
+ if (!this._canUseBlitFrameBuffer && this._shouldGrabColor) {
10745
+ var _camera_renderTarget;
10746
+ var _camera_renderTarget_getColorTexture_format;
10747
+ 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);
10748
+ this._grabTexture = grabTexture;
10749
+ }
10609
10750
  this._internalColorTarget = internalColorTarget;
10610
10751
  } else {
10611
10752
  var internalColorTarget1 = this._internalColorTarget;
10753
+ var grabTexture1 = this._grabTexture;
10612
10754
  if (internalColorTarget1) {
10613
10755
  var _internalColorTarget_getColorTexture;
10614
10756
  (_internalColorTarget_getColorTexture = internalColorTarget1.getColorTexture(0)) == null ? void 0 : _internalColorTarget_getColorTexture.destroy(true);
10615
10757
  internalColorTarget1.destroy(true);
10616
10758
  this._internalColorTarget = null;
10617
10759
  }
10760
+ if (grabTexture1) {
10761
+ grabTexture1.destroy(true);
10762
+ this._grabTexture = null;
10763
+ }
10618
10764
  }
10619
- this._drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear);
10765
+ this._drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel);
10620
10766
  };
10621
- _proto._drawRenderPass = function _drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear) {
10767
+ _proto._drawRenderPass = function _drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel) {
10622
10768
  var cullingResults = this._cullingResults;
10623
10769
  var opaqueQueue = cullingResults.opaqueQueue, alphaTestQueue = cullingResults.alphaTestQueue, transparentQueue = cullingResults.transparentQueue;
10624
10770
  var engine = camera.engine, scene = camera.scene;
@@ -10634,18 +10780,38 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10634
10780
  context.applyVirtualCamera(camera._virtualCamera, needFlipProjection);
10635
10781
  }
10636
10782
  rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
10637
- var clearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
10638
10783
  var color = background.solidColor;
10639
- if (clearFlags !== CameraClearFlags.None) {
10640
- rhi.clearRenderTarget(engine, clearFlags, color);
10784
+ if (internalColorTarget && finalClearFlags !== CameraClearFlags.All) {
10785
+ // Can use `blitFramebuffer` API to copy color/depth/stencil buffer from back buffer to internal RT
10786
+ if (this._canUseBlitFrameBuffer) {
10787
+ finalClearFlags !== CameraClearFlags.None && rhi.clearRenderTarget(engine, finalClearFlags, color);
10788
+ rhi.blitInternalRTByBlitFrameBuffer(camera.renderTarget, internalColorTarget, finalClearFlags, camera.viewport);
10789
+ } else {
10790
+ if (!(finalClearFlags & CameraClearFlags.Depth) || !(finalClearFlags & CameraClearFlags.Stencil)) {
10791
+ 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");
10792
+ }
10793
+ if (this._shouldGrabColor) {
10794
+ rhi.clearRenderTarget(engine, CameraClearFlags.DepthStencil);
10795
+ // Copy RT's color buffer to grab texture
10796
+ rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._grabTexture, camera.viewport);
10797
+ // Then blit grab texture to internal RT's color buffer
10798
+ PipelineUtils.blitTexture(engine, this._grabTexture, internalColorTarget, 0, undefined, undefined, undefined, // Only flip Y axis in webgl context
10799
+ !camera.renderTarget);
10800
+ } else {
10801
+ rhi.clearRenderTarget(engine, CameraClearFlags.All, color);
10802
+ }
10803
+ }
10804
+ rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
10805
+ } else if (finalClearFlags !== CameraClearFlags.None) {
10806
+ rhi.clearRenderTarget(engine, finalClearFlags, color);
10641
10807
  }
10642
10808
  var maskManager = scene._maskManager;
10643
- if (clearFlags & CameraClearFlags.Stencil) {
10809
+ if (finalClearFlags & CameraClearFlags.Stencil) {
10644
10810
  maskManager.hasStencilWritten = false;
10645
10811
  }
10646
10812
  opaqueQueue.render(context, PipelineStage.Forward);
10647
10813
  alphaTestQueue.render(context, PipelineStage.Forward);
10648
- if (clearFlags & CameraClearFlags.Color) {
10814
+ if (finalClearFlags & CameraClearFlags.Color) {
10649
10815
  if (background.mode === BackgroundMode.Sky) {
10650
10816
  background.sky._render(context);
10651
10817
  } else if (background.mode === BackgroundMode.Texture && background.texture) {
@@ -10722,8 +10888,7 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10722
10888
  var shaderPass = shaderPasses[i];
10723
10889
  var renderState = shaderPass._renderState;
10724
10890
  if (renderState) {
10725
- renderState._applyRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
10726
- renderQueueType = renderState.renderQueueType;
10891
+ renderQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
10727
10892
  } else {
10728
10893
  renderQueueType = renderStates[i].renderQueueType;
10729
10894
  }
@@ -12993,15 +13158,29 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
12993
13158
  _inherits(PBRMaterial, PBRBaseMaterial);
12994
13159
  function PBRMaterial(engine) {
12995
13160
  var _this;
12996
- _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new engineMath.Vector2(100, 400);
13161
+ _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new engineMath.Vector2(100, 400), _this._sheenEnabled = false;
12997
13162
  var shaderData = _this.shaderData;
12998
13163
  shaderData.setFloat(PBRMaterial._metallicProp, 1);
12999
13164
  shaderData.setFloat(PBRMaterial._roughnessProp, 1);
13000
13165
  shaderData.setFloat(PBRMaterial._iorProp, 1.5);
13001
13166
  shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new engineMath.Vector3(1, 0, 0));
13002
13167
  shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new engineMath.Vector4(0, 1.3, 100, 400));
13168
+ var sheenColor = new engineMath.Color(0, 0, 0);
13169
+ shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor);
13003
13170
  // @ts-ignore
13004
13171
  _this._iridescenceRange._onValueChanged = _this._onIridescenceRangeChanged.bind(_this);
13172
+ // @ts-ignore
13173
+ sheenColor._onValueChanged = function() {
13174
+ var enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0;
13175
+ if (enableSheen !== _this._sheenEnabled) {
13176
+ _this._sheenEnabled = enableSheen;
13177
+ if (enableSheen) {
13178
+ _this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
13179
+ } else {
13180
+ _this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
13181
+ }
13182
+ }
13183
+ };
13005
13184
  return _this;
13006
13185
  }
13007
13186
  var _proto = PBRMaterial.prototype;
@@ -13182,7 +13361,7 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13182
13361
  key: "iridescenceThicknessRange",
13183
13362
  get: /**
13184
13363
  * The range of iridescence thickness, x is minimum, y is maximum.
13185
- * @defaultValue `[100, 400]`.
13364
+ * @defaultValue `[100, 400]`
13186
13365
  */ function get() {
13187
13366
  return this._iridescenceRange;
13188
13367
  },
@@ -13210,6 +13389,67 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13210
13389
  this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
13211
13390
  }
13212
13391
  }
13392
+ },
13393
+ {
13394
+ key: "sheenColor",
13395
+ get: /**
13396
+ * Sheen color.
13397
+ * @defaultValue `[0,0,0]`
13398
+ */ function get() {
13399
+ return this.shaderData.getColor(PBRMaterial._sheenColorProp);
13400
+ },
13401
+ set: function set(value) {
13402
+ var sheenColor = this.shaderData.getColor(PBRMaterial._sheenColorProp);
13403
+ if (value !== sheenColor) {
13404
+ sheenColor.copyFrom(value);
13405
+ }
13406
+ }
13407
+ },
13408
+ {
13409
+ key: "sheenRoughness",
13410
+ get: /**
13411
+ * Sheen roughness, from 0.0 to 1.0.
13412
+ * @defaultValue `0.0`
13413
+ */ function get() {
13414
+ return this.shaderData.getFloat(PBRMaterial._sheenRoughnessProp);
13415
+ },
13416
+ set: function set(value) {
13417
+ value = Math.max(0, Math.min(1, value));
13418
+ this.shaderData.setFloat(PBRMaterial._sheenRoughnessProp, value);
13419
+ }
13420
+ },
13421
+ {
13422
+ key: "sheenColorTexture",
13423
+ get: /**
13424
+ * Sheen color texture, multiply ‘sheenColor’.
13425
+ */ function get() {
13426
+ return this.shaderData.getTexture(PBRMaterial._sheenTextureProp);
13427
+ },
13428
+ set: function set(value) {
13429
+ this.shaderData.setTexture(PBRMaterial._sheenTextureProp, value);
13430
+ if (value) {
13431
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
13432
+ } else {
13433
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
13434
+ }
13435
+ }
13436
+ },
13437
+ {
13438
+ key: "sheenRoughnessTexture",
13439
+ get: /**
13440
+ * Sheen roughness texture.
13441
+ * @remarks Use alpha channel, and multiply 'sheenRoughness'.
13442
+ */ function get() {
13443
+ return this.shaderData.getTexture(PBRMaterial._sheenRoughnessTextureProp);
13444
+ },
13445
+ set: function set(value) {
13446
+ this.shaderData.setTexture(PBRMaterial._sheenRoughnessTextureProp, value);
13447
+ if (value) {
13448
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
13449
+ } else {
13450
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
13451
+ }
13452
+ }
13213
13453
  }
13214
13454
  ]);
13215
13455
  return PBRMaterial;
@@ -13223,6 +13463,10 @@ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_Anisotro
13223
13463
  PBRMaterial._iridescenceInfoProp = ShaderProperty.getByName("material_IridescenceInfo");
13224
13464
  PBRMaterial._iridescenceThicknessTextureProp = ShaderProperty.getByName("material_IridescenceThicknessTexture");
13225
13465
  PBRMaterial._iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture");
13466
+ PBRMaterial._sheenColorProp = ShaderProperty.getByName("material_SheenColor");
13467
+ PBRMaterial._sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness");
13468
+ PBRMaterial._sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
13469
+ PBRMaterial._sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture");
13226
13470
 
13227
13471
  /**
13228
13472
  * PBR (Specular-Glossiness Workflow) Material.
@@ -14022,8 +14266,7 @@ var BlendShapeFrameDirty = /*#__PURE__*/ function(BlendShapeFrameDirty) {
14022
14266
  var mesh = this._mesh;
14023
14267
  if (mesh) {
14024
14268
  var localBounds = mesh.bounds;
14025
- var worldMatrix = this._entity.transform.worldMatrix;
14026
- engineMath.BoundingBox.transform(localBounds, worldMatrix, worldBounds);
14269
+ engineMath.BoundingBox.transform(localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
14027
14270
  } else {
14028
14271
  worldBounds.min.set(0, 0, 0);
14029
14272
  worldBounds.max.set(0, 0, 0);
@@ -16922,12 +17165,18 @@ var ComponentCloner = /*#__PURE__*/ function() {
16922
17165
  */ var Entity = /*#__PURE__*/ function(EngineObject) {
16923
17166
  _inherits(Entity, EngineObject);
16924
17167
  function Entity(engine, name) {
17168
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
17169
+ components[_key - 2] = arguments[_key];
17170
+ }
16925
17171
  var _this;
16926
- _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----------------------------------------------------------------
17172
+ _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----------------------------------------------------------------
16927
17173
  _this._invModelMatrix = new engineMath.Matrix();
16928
17174
  _this.name = name;
16929
- _this.transform = _this.addComponent(Transform);
16930
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
17175
+ for(var i = 0, n = components.length; i < n; i++){
17176
+ _this.addComponent(components[i]);
17177
+ }
17178
+ !_this._transform && _this.addComponent(Transform);
17179
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
16931
17180
  return _this;
16932
17181
  }
16933
17182
  var _proto = Entity.prototype;
@@ -16945,6 +17194,12 @@ var ComponentCloner = /*#__PURE__*/ function() {
16945
17194
  this
16946
17195
  ], args));
16947
17196
  this._components.push(component);
17197
+ // @todo: temporary solution
17198
+ if (_instanceof(component, Transform)) {
17199
+ var transform = this._transform;
17200
+ this._transform = component;
17201
+ transform == null ? void 0 : transform.destroy();
17202
+ }
16948
17203
  component._setActive(true, ActiveChangeFlag.All);
16949
17204
  return component;
16950
17205
  };
@@ -17088,7 +17343,8 @@ var ComponentCloner = /*#__PURE__*/ function() {
17088
17343
  * @param name - The child entity's name
17089
17344
  * @returns The child entity
17090
17345
  */ _proto.createChild = function createChild(name) {
17091
- var child = new Entity(this.engine, name);
17346
+ var transform = this._transform;
17347
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
17092
17348
  child.layer = this.layer;
17093
17349
  child.parent = this;
17094
17350
  return child;
@@ -17117,13 +17373,20 @@ var ComponentCloner = /*#__PURE__*/ function() {
17117
17373
  return cloneEntity;
17118
17374
  };
17119
17375
  /**
17376
+ * Listen for changes in the world pose of this `Entity`.
17377
+ * @returns Change flag
17378
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
17379
+ return this._updateFlagManager.createFlag(BoolUpdateFlag);
17380
+ };
17381
+ /**
17120
17382
  * @internal
17121
17383
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
17122
17384
  this._isTemplate = true;
17123
17385
  this._templateResource = templateResource;
17124
17386
  };
17125
17387
  _proto._createCloneEntity = function _createCloneEntity() {
17126
- var cloneEntity = new Entity(this._engine, this.name);
17388
+ var transform = this._transform;
17389
+ var cloneEntity = transform ? new Entity(this.engine, this.name, transform.constructor) : new Entity(this.engine, this.name);
17127
17390
  var templateResource = this._templateResource;
17128
17391
  if (templateResource) {
17129
17392
  cloneEntity._templateResource = templateResource;
@@ -17131,11 +17394,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
17131
17394
  }
17132
17395
  cloneEntity.layer = this.layer;
17133
17396
  cloneEntity._isActive = this._isActive;
17134
- var cloneTransform = cloneEntity.transform;
17135
- var _this = this, srcTransform = _this.transform;
17136
- cloneTransform.position = srcTransform.position;
17137
- cloneTransform.rotation = srcTransform.rotation;
17138
- cloneTransform.scale = srcTransform.scale;
17397
+ cloneEntity.transform._copyFrom(this.transform);
17139
17398
  var srcChildren = this._children;
17140
17399
  for(var i = 0, n = srcChildren.length; i < n; i++){
17141
17400
  cloneEntity.addChild(srcChildren[i]._createCloneEntity());
@@ -17435,6 +17694,14 @@ var ComponentCloner = /*#__PURE__*/ function() {
17435
17694
  return entity;
17436
17695
  };
17437
17696
  _create_class(Entity, [
17697
+ {
17698
+ key: "transform",
17699
+ get: /**
17700
+ * The transform of this entity.
17701
+ */ function get() {
17702
+ return this._transform;
17703
+ }
17704
+ },
17438
17705
  {
17439
17706
  key: "isActive",
17440
17707
  get: /**
@@ -17684,16 +17951,6 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17684
17951
  var _proto = SkinnedMeshRenderer.prototype;
17685
17952
  /**
17686
17953
  * @internal
17687
- */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
17688
- var worldMatrix = this._transform.worldMatrix;
17689
- if (onlyMVP) {
17690
- this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
17691
- } else {
17692
- this._updateWorldViewRelatedShaderData(context, worldMatrix, batched);
17693
- }
17694
- };
17695
- /**
17696
- * @internal
17697
17954
  */ _proto._onDestroy = function _onDestroy() {
17698
17955
  var _this__jointTexture;
17699
17956
  MeshRenderer.prototype._onDestroy.call(this);
@@ -17769,7 +18026,7 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17769
18026
  var _this_skin;
17770
18027
  var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
17771
18028
  if (rootBone) {
17772
- engineMath.BoundingBox.transform(this._localBounds, this._transform.worldMatrix, worldBounds);
18029
+ engineMath.BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
17773
18030
  } else {
17774
18031
  MeshRenderer.prototype._updateBounds.call(this, worldBounds);
17775
18032
  }
@@ -17810,7 +18067,7 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
17810
18067
  }
17811
18068
  break;
17812
18069
  case SkinUpdateFlag.RootBoneChanged:
17813
- this._setTransform(value.transform);
18070
+ this._setTransformEntity(value);
17814
18071
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
17815
18072
  break;
17816
18073
  }
@@ -18507,7 +18764,8 @@ PrimitiveChunk.subMeshPool = new ReturnableObjectPool(SubMesh, 10);
18507
18764
  /** Scene. */ AssetType["Scene"] = "Scene";
18508
18765
  /** HDR to cube. */ AssetType["HDR"] = "HDR";
18509
18766
  /** Font. */ AssetType["Font"] = "Font";
18510
- /** Source Font, include ttf otf and woff. */ AssetType["SourceFont"] = "SourceFont";
18767
+ /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
18768
+ /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
18511
18769
  /** Project asset. */ AssetType["Project"] = "project";
18512
18770
  return AssetType;
18513
18771
  }({});
@@ -18897,9 +19155,10 @@ var defaultRetryCount = 1;
18897
19155
  var defaultTimeout = Infinity;
18898
19156
  var defaultInterval = 500;
18899
19157
  /**
18900
- * Web request.
18901
- * @param url - The link
18902
- * @param config - Load configuration
19158
+ * Sends a request to the specified URL and returns a promise for the response.
19159
+ * @param url - The URL to send the request to
19160
+ * @param config - Configuration options for the request
19161
+ * @returns A promise that resolves with the response of type `T`
18903
19162
  */ function request(url, config) {
18904
19163
  if (config === void 0) config = {};
18905
19164
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
@@ -19400,7 +19659,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
19400
19659
  var assetBaseURL = baseUrl;
19401
19660
  if (searchStr) {
19402
19661
  var params = searchStr.split("&");
19403
- for(var i = 0; i < params.length; i++){
19662
+ for(var i = params.length - 1; i >= 0; i--){
19404
19663
  var param = params[i];
19405
19664
  if (param.startsWith("q=")) {
19406
19665
  queryPath = decodeURIComponent(param.split("=")[1]);
@@ -19449,11 +19708,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19449
19708
  Logger.warn("refId:" + refId + " is not find in this._editorResourceConfig.");
19450
19709
  return Promise.resolve(null);
19451
19710
  }
19452
- var remoteUrl = resourceConfig.path;
19453
- var queryPath = new URL(remoteUrl).search;
19454
- var url = resourceConfig.virtualPath + queryPath;
19711
+ var url = resourceConfig.virtualPath;
19455
19712
  if (key) {
19456
- url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key;
19713
+ url += "?q=" + key;
19457
19714
  }
19458
19715
  promise = this.load({
19459
19716
  url: url,
@@ -20115,7 +20372,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
20115
20372
  function Collider(entity) {
20116
20373
  var _this;
20117
20374
  _this = Component.call(this, entity) || this, /** @internal */ _this._index = -1, _this._shapes = [];
20118
- _this._updateFlag = _this.entity.transform.registerWorldChangeFlag();
20375
+ _this._updateFlag = entity.registerWorldChangeFlag();
20119
20376
  return _this;
20120
20377
  }
20121
20378
  var _proto = Collider.prototype;
@@ -20129,9 +20386,8 @@ exports.Collider = /*#__PURE__*/ function(Component) {
20129
20386
  oldCollider.removeShape(shape);
20130
20387
  }
20131
20388
  this._shapes.push(shape);
20132
- shape._collider = this;
20133
- this._nativeCollider.addShape(shape._nativeShape);
20134
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
20389
+ this._addNativeShape(shape);
20390
+ this._handleShapesChanged();
20135
20391
  }
20136
20392
  };
20137
20393
  /**
@@ -20141,9 +20397,8 @@ exports.Collider = /*#__PURE__*/ function(Component) {
20141
20397
  var index = this._shapes.indexOf(shape);
20142
20398
  if (index !== -1) {
20143
20399
  this._shapes.splice(index, 1);
20144
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
20145
- shape._collider = null;
20146
- this._nativeCollider.removeShape(shape._nativeShape);
20400
+ this._removeNativeShape(shape);
20401
+ this._handleShapesChanged();
20147
20402
  }
20148
20403
  };
20149
20404
  /**
@@ -20151,12 +20406,10 @@ exports.Collider = /*#__PURE__*/ function(Component) {
20151
20406
  */ _proto.clearShapes = function clearShapes() {
20152
20407
  var shapes = this._shapes;
20153
20408
  for(var i = 0, n = shapes.length; i < n; i++){
20154
- var shape = shapes[i];
20155
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
20156
- shape._destroy();
20157
- this._nativeCollider.removeShape(shape._nativeShape);
20409
+ this._removeNativeShape(shapes[i]);
20158
20410
  }
20159
20411
  shapes.length = 0;
20412
+ this._handleShapesChanged();
20160
20413
  };
20161
20414
  /**
20162
20415
  * @internal
@@ -20177,42 +20430,46 @@ exports.Collider = /*#__PURE__*/ function(Component) {
20177
20430
  /**
20178
20431
  * @internal
20179
20432
  */ _proto._onEnableInScene = function _onEnableInScene() {
20180
- var physics = this.scene.physics;
20181
- physics._addCollider(this);
20182
- var shapes = this.shapes;
20183
- for(var i = 0, n = shapes.length; i < n; i++){
20184
- physics._addColliderShape(shapes[i]);
20185
- }
20433
+ this.scene.physics._addCollider(this);
20186
20434
  };
20187
20435
  /**
20188
20436
  * @internal
20189
20437
  */ _proto._onDisableInScene = function _onDisableInScene() {
20190
- var physics = this.scene.physics;
20191
- physics._removeCollider(this);
20192
- var shapes = this.shapes;
20193
- for(var i = 0, n = shapes.length; i < n; i++){
20194
- physics._removeColliderShape(shapes[i]);
20195
- }
20438
+ this.scene.physics._removeCollider(this);
20196
20439
  };
20197
20440
  /**
20198
20441
  * @internal
20199
20442
  */ _proto._cloneTo = function _cloneTo(target) {
20200
- var shapes = target._shapes;
20201
- for(var i = 0, n = shapes.length; i < n; i++){
20202
- target._addPhysicsShape(shapes[i]);
20443
+ target._syncNative();
20444
+ };
20445
+ /**
20446
+ * @internal
20447
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {};
20448
+ _proto._syncNative = function _syncNative() {
20449
+ for(var i = 0, n = this.shapes.length; i < n; i++){
20450
+ this._addNativeShape(this.shapes[i]);
20203
20451
  }
20204
20452
  };
20205
20453
  /**
20206
20454
  * @internal
20207
20455
  */ _proto._onDestroy = function _onDestroy() {
20208
20456
  Component.prototype._onDestroy.call(this);
20209
- this.clearShapes();
20457
+ var shapes = this._shapes;
20458
+ for(var i = 0, n = shapes.length; i < n; i++){
20459
+ var shape = shapes[i];
20460
+ this._removeNativeShape(shape);
20461
+ shape._destroy();
20462
+ }
20463
+ shapes.length = 0;
20210
20464
  this._nativeCollider.destroy();
20211
20465
  };
20212
- _proto._addPhysicsShape = function _addPhysicsShape(shape) {
20466
+ _proto._addNativeShape = function _addNativeShape(shape) {
20213
20467
  shape._collider = this;
20214
20468
  this._nativeCollider.addShape(shape._nativeShape);
20215
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
20469
+ };
20470
+ _proto._removeNativeShape = function _removeNativeShape(shape) {
20471
+ shape._collider = null;
20472
+ this._nativeCollider.removeShape(shape._nativeShape);
20216
20473
  };
20217
20474
  _create_class(Collider, [
20218
20475
  {
@@ -20249,13 +20506,12 @@ var Collision = function Collision() {
20249
20506
  * A physics scene is a collection of colliders and constraints which can interact.
20250
20507
  */ var PhysicsScene = /*#__PURE__*/ function() {
20251
20508
  function PhysicsScene(scene) {
20252
- var _this = this;
20253
20509
  this._restTime = 0;
20254
20510
  this._fixedTimeStep = 1 / 60;
20255
20511
  this._colliders = new DisorderedArray();
20256
20512
  this._gravity = new engineMath.Vector3(0, -9.81, 0);
20257
20513
  this._onContactEnter = function(obj1, obj2) {
20258
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20514
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20259
20515
  var shape1 = physicalObjectsMap[obj1];
20260
20516
  var shape2 = physicalObjectsMap[obj2];
20261
20517
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20274,7 +20530,7 @@ var Collision = function Collision() {
20274
20530
  });
20275
20531
  };
20276
20532
  this._onContactExit = function(obj1, obj2) {
20277
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20533
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20278
20534
  var shape1 = physicalObjectsMap[obj1];
20279
20535
  var shape2 = physicalObjectsMap[obj2];
20280
20536
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20293,7 +20549,7 @@ var Collision = function Collision() {
20293
20549
  });
20294
20550
  };
20295
20551
  this._onContactStay = function(obj1, obj2) {
20296
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20552
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20297
20553
  var shape1 = physicalObjectsMap[obj1];
20298
20554
  var shape2 = physicalObjectsMap[obj2];
20299
20555
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20312,7 +20568,7 @@ var Collision = function Collision() {
20312
20568
  });
20313
20569
  };
20314
20570
  this._onTriggerEnter = function(obj1, obj2) {
20315
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20571
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20316
20572
  var shape1 = physicalObjectsMap[obj1];
20317
20573
  var shape2 = physicalObjectsMap[obj2];
20318
20574
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20327,7 +20583,7 @@ var Collision = function Collision() {
20327
20583
  });
20328
20584
  };
20329
20585
  this._onTriggerExit = function(obj1, obj2) {
20330
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20586
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20331
20587
  var shape1 = physicalObjectsMap[obj1];
20332
20588
  var shape2 = physicalObjectsMap[obj2];
20333
20589
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20342,7 +20598,7 @@ var Collision = function Collision() {
20342
20598
  });
20343
20599
  };
20344
20600
  this._onTriggerStay = function(obj1, obj2) {
20345
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
20601
+ var physicalObjectsMap = Engine._physicalObjectsMap;
20346
20602
  var shape1 = physicalObjectsMap[obj1];
20347
20603
  var shape2 = physicalObjectsMap[obj2];
20348
20604
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -20367,7 +20623,6 @@ var Collision = function Collision() {
20367
20623
  }
20368
20624
  var _proto = PhysicsScene.prototype;
20369
20625
  _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
20370
- var _this = this;
20371
20626
  var hitResult;
20372
20627
  var distance = Number.MAX_VALUE;
20373
20628
  if (typeof distanceOrResult === "number") {
@@ -20385,7 +20640,7 @@ var Collision = function Collision() {
20385
20640
  hitResult = outHitResult;
20386
20641
  }
20387
20642
  var onRaycast = function(obj) {
20388
- var shape = _this._scene.engine._physicalObjectsMap[obj];
20643
+ var shape = Engine._physicalObjectsMap[obj];
20389
20644
  if (!shape) {
20390
20645
  return false;
20391
20646
  }
@@ -20393,7 +20648,7 @@ var Collision = function Collision() {
20393
20648
  };
20394
20649
  if (hitResult != undefined) {
20395
20650
  var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
20396
- var hitShape = _this._scene.engine._physicalObjectsMap[idx];
20651
+ var hitShape = Engine._physicalObjectsMap[idx];
20397
20652
  hitResult.entity = hitShape._collider.entity;
20398
20653
  hitResult.shape = hitShape;
20399
20654
  hitResult.distance = distance;
@@ -20431,22 +20686,6 @@ var Collision = function Collision() {
20431
20686
  }
20432
20687
  };
20433
20688
  /**
20434
- * Add ColliderShape into the manager.
20435
- * @param colliderShape - The Collider Shape.
20436
- * @internal
20437
- */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
20438
- this._scene.engine._physicalObjectsMap[colliderShape.id] = colliderShape;
20439
- this._nativePhysicsScene.addColliderShape(colliderShape._nativeShape);
20440
- };
20441
- /**
20442
- * Remove ColliderShape.
20443
- * @param colliderShape - The Collider Shape.
20444
- * @internal
20445
- */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
20446
- delete this._scene.engine._physicalObjectsMap[colliderShape.id];
20447
- this._nativePhysicsScene.removeColliderShape(colliderShape._nativeShape);
20448
- };
20449
- /**
20450
20689
  * Add collider into the manager.
20451
20690
  * @param collider - StaticCollider or DynamicCollider.
20452
20691
  * @internal
@@ -20589,13 +20828,6 @@ PhysicsScene._collision = new Collision();
20589
20828
  this._updateFlag.flag = true;
20590
20829
  };
20591
20830
  /**
20592
- * Remove all shape attached.
20593
- */ _proto.clearShapes = function clearShapes() {
20594
- if (this._shapes.length > 0) {
20595
- Collider.prototype.removeShape.call(this, this._shapes[0]);
20596
- }
20597
- };
20598
- /**
20599
20831
  * @internal
20600
20832
  */ _proto._onUpdate = function _onUpdate() {
20601
20833
  if (this._updateFlag.flag) {
@@ -20618,22 +20850,19 @@ PhysicsScene._collision = new Collision();
20618
20850
  /**
20619
20851
  * @internal
20620
20852
  */ _proto._onEnableInScene = function _onEnableInScene() {
20621
- var physics = this.scene.physics;
20622
- physics._addCharacterController(this);
20623
- var shapes = this.shapes;
20624
- for(var i = 0, n = shapes.length; i < n; i++){
20625
- physics._addColliderShape(shapes[i]);
20626
- }
20853
+ this.scene.physics._addCharacterController(this);
20627
20854
  };
20628
20855
  /**
20629
20856
  * @internal
20630
20857
  */ _proto._onDisableInScene = function _onDisableInScene() {
20631
- var physics = this.scene.physics;
20632
- physics._removeCharacterController(this);
20633
- var shapes = this.shapes;
20634
- for(var i = 0, n = shapes.length; i < n; i++){
20635
- physics._removeColliderShape(shapes[i]);
20636
- }
20858
+ this.scene.physics._removeCharacterController(this);
20859
+ };
20860
+ _proto._syncNative = function _syncNative() {
20861
+ Collider.prototype._syncNative.call(this);
20862
+ this._nativeCollider.setStepOffset(this._stepOffset);
20863
+ this._nativeCollider.setNonWalkableMode(this._nonWalkableMode);
20864
+ this._nativeCollider.setUpDirection(this._upDirection);
20865
+ this._nativeCollider.setSlopeLimit(this._slopeLimit);
20637
20866
  };
20638
20867
  _proto._syncWorldPositionFromPhysicalSpace = function _syncWorldPositionFromPhysicalSpace() {
20639
20868
  this._nativeCollider.getWorldPosition(this.entity.transform.worldPosition);
@@ -20645,11 +20874,13 @@ PhysicsScene._collision = new Collision();
20645
20874
  {
20646
20875
  key: "stepOffset",
20647
20876
  get: /**
20648
- * The step offset for the controller.
20877
+ * The step offset for the controller, the value must be greater than or equal to 0.
20878
+ * @remarks Character can overcome obstacle less than the height(stepOffset + contractOffset of the shape).
20649
20879
  */ function get() {
20650
20880
  return this._stepOffset;
20651
20881
  },
20652
20882
  set: function set(value) {
20883
+ value = Math.max(0, value);
20653
20884
  if (this._stepOffset !== value) {
20654
20885
  this._stepOffset = value;
20655
20886
  this._nativeCollider.setStepOffset(value);
@@ -20686,7 +20917,8 @@ PhysicsScene._collision = new Collision();
20686
20917
  {
20687
20918
  key: "slopeLimit",
20688
20919
  get: /**
20689
- * The slope limit for the controller.
20920
+ * The slope limit for the controller, the value is the cosine value of the maximum slope angle.
20921
+ * @defaultValue 0.707(the cosine value of 45 degrees)
20690
20922
  */ function get() {
20691
20923
  return this._slopeLimit;
20692
20924
  },
@@ -20700,6 +20932,9 @@ PhysicsScene._collision = new Collision();
20700
20932
  ]);
20701
20933
  return CharacterController;
20702
20934
  }(exports.Collider);
20935
+ __decorate([
20936
+ deepClone
20937
+ ], CharacterController.prototype, "_upDirection", void 0);
20703
20938
 
20704
20939
  /**
20705
20940
  * A dynamic collider can act with self-defined movement or physical force.
@@ -20707,21 +20942,21 @@ PhysicsScene._collision = new Collision();
20707
20942
  _inherits(DynamicCollider, Collider);
20708
20943
  function DynamicCollider(entity) {
20709
20944
  var _this;
20710
- _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new engineMath.Vector3(), _this._angularVelocity = new engineMath.Vector3(), _this._mass = 1.0, _this._centerOfMass = new engineMath.Vector3(), _this._inertiaTensor = new engineMath.Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1000, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3;
20945
+ _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new engineMath.Vector3(), _this._angularVelocity = new engineMath.Vector3(), _this._mass = 1.0, _this._centerOfMass = new engineMath.Vector3(), _this._inertiaTensor = new engineMath.Vector3(1, 1, 1), _this._maxAngularVelocity = 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;
20711
20946
  var transform = _this.entity.transform;
20712
20947
  _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
20713
20948
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
20714
20949
  _this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
20715
- _this._setCenterOfMass = _this._setCenterOfMass.bind(_this);
20716
- _this._setInertiaTensor = _this._setInertiaTensor.bind(_this);
20950
+ _this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
20951
+ _this._handleInertiaTensorChanged = _this._handleInertiaTensorChanged.bind(_this);
20717
20952
  //@ts-ignore
20718
20953
  _this._linearVelocity._onValueChanged = _this._setLinearVelocity;
20719
20954
  //@ts-ignore
20720
20955
  _this._angularVelocity._onValueChanged = _this._setAngularVelocity;
20721
20956
  //@ts-ignore
20722
- _this._centerOfMass._onValueChanged = _this._setCenterOfMass;
20957
+ _this._centerOfMass._onValueChanged = _this._handleCenterOfMassChanged;
20723
20958
  //@ts-ignore
20724
- _this._inertiaTensor._onValueChanged = _this._setInertiaTensor;
20959
+ _this._inertiaTensor._onValueChanged = _this._handleInertiaTensorChanged;
20725
20960
  return _this;
20726
20961
  }
20727
20962
  var _proto = DynamicCollider.prototype;
@@ -20729,16 +20964,16 @@ PhysicsScene._collision = new Collision();
20729
20964
  * Apply a force to the DynamicCollider.
20730
20965
  * @param force - The force make the collider move
20731
20966
  */ _proto.applyForce = function applyForce(force) {
20732
- this._nativeCollider.addForce(force);
20967
+ this._phasedActiveInScene && this._nativeCollider.addForce(force);
20733
20968
  };
20734
20969
  /**
20735
20970
  * Apply a torque to the DynamicCollider.
20736
20971
  * @param torque - The force make the collider rotate
20737
20972
  */ _proto.applyTorque = function applyTorque(torque) {
20738
- this._nativeCollider.addTorque(torque);
20973
+ this._phasedActiveInScene && this._nativeCollider.addTorque(torque);
20739
20974
  };
20740
20975
  _proto.move = function move(positionOrRotation, rotation) {
20741
- this._nativeCollider.move(positionOrRotation, rotation);
20976
+ this._phasedActiveInScene && this._nativeCollider.move(positionOrRotation, rotation);
20742
20977
  };
20743
20978
  /**
20744
20979
  * Forces a collider to sleep at least one frame.
@@ -20746,6 +20981,12 @@ PhysicsScene._collision = new Collision();
20746
20981
  this._nativeCollider.sleep();
20747
20982
  };
20748
20983
  /**
20984
+ * Returns whether the collider is sleeping.
20985
+ * @returns True if the collider is sleeping, false otherwise.
20986
+ */ _proto.isSleeping = function isSleeping() {
20987
+ return this._nativeCollider.isSleeping();
20988
+ };
20989
+ /**
20749
20990
  * Forces a collider to wake up.
20750
20991
  */ _proto.wakeUp = function wakeUp() {
20751
20992
  this._nativeCollider.wakeUp();
@@ -20761,21 +21002,44 @@ PhysicsScene._collision = new Collision();
20761
21002
  /**
20762
21003
  * @internal
20763
21004
  */ _proto._cloneTo = function _cloneTo(target) {
21005
+ target._linearVelocity.copyFrom(this.linearVelocity);
21006
+ target._angularVelocity.copyFrom(this.angularVelocity);
21007
+ target._centerOfMass.copyFrom(this.centerOfMass);
21008
+ target._inertiaTensor.copyFrom(this.inertiaTensor);
20764
21009
  Collider.prototype._cloneTo.call(this, target);
20765
- target.linearDamping = this.linearDamping;
20766
- target.angularDamping = this.angularDamping;
20767
- target.linearVelocity = this.linearVelocity;
20768
- target.angularVelocity = this.angularVelocity;
20769
- target.mass = this.mass;
20770
- target.centerOfMass = this.centerOfMass;
20771
- target.inertiaTensor = this.inertiaTensor;
20772
- target.maxAngularVelocity = this.maxAngularVelocity;
20773
- target.maxDepenetrationVelocity = this.maxDepenetrationVelocity;
20774
- target.sleepThreshold = this.sleepThreshold;
20775
- target.solverIterations = this.solverIterations;
20776
- target.isKinematic = this.isKinematic;
20777
- target.constraints = this.constraints;
20778
- target.collisionDetectionMode = this.collisionDetectionMode;
21010
+ };
21011
+ /**
21012
+ * @internal
21013
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {
21014
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
21015
+ this._setMassAndUpdateInertia();
21016
+ }
21017
+ };
21018
+ _proto._syncNative = function _syncNative() {
21019
+ Collider.prototype._syncNative.call(this);
21020
+ this._nativeCollider.setLinearDamping(this._linearDamping);
21021
+ this._nativeCollider.setAngularDamping(this._angularDamping);
21022
+ this._nativeCollider.setLinearVelocity(this._linearVelocity);
21023
+ this._nativeCollider.setAngularVelocity(this._angularVelocity);
21024
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
21025
+ this._setMassAndUpdateInertia();
21026
+ } else {
21027
+ this._nativeCollider.setMass(this._mass);
21028
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
21029
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21030
+ }
21031
+ this._nativeCollider.setMaxAngularVelocity(this._maxAngularVelocity);
21032
+ this._nativeCollider.setMaxDepenetrationVelocity(this._maxDepenetrationVelocity);
21033
+ this._nativeCollider.setSleepThreshold(this._sleepThreshold);
21034
+ this._nativeCollider.setSolverIterations(this._solverIterations);
21035
+ this._nativeCollider.setIsKinematic(this._isKinematic);
21036
+ this._nativeCollider.setConstraints(this._constraints);
21037
+ this._nativeCollider.setCollisionDetectionMode(this._collisionDetectionMode);
21038
+ };
21039
+ _proto._setMassAndUpdateInertia = function _setMassAndUpdateInertia() {
21040
+ this._nativeCollider.setMassAndUpdateInertia(this._mass);
21041
+ this._automaticCenterOfMass || this._nativeCollider.setCenterOfMass(this._centerOfMass);
21042
+ this._automaticInertiaTensor || this._nativeCollider.setInertiaTensor(this._inertiaTensor);
20779
21043
  };
20780
21044
  _proto._setLinearVelocity = function _setLinearVelocity() {
20781
21045
  this._nativeCollider.setLinearVelocity(this._linearVelocity);
@@ -20783,11 +21047,19 @@ PhysicsScene._collision = new Collision();
20783
21047
  _proto._setAngularVelocity = function _setAngularVelocity() {
20784
21048
  this._nativeCollider.setAngularVelocity(this._angularVelocity);
20785
21049
  };
20786
- _proto._setCenterOfMass = function _setCenterOfMass() {
20787
- this._nativeCollider.setCenterOfMass(this._centerOfMass);
21050
+ _proto._handleCenterOfMassChanged = function _handleCenterOfMassChanged() {
21051
+ if (this._automaticCenterOfMass) {
21052
+ console.warn("The center of mass is automatically calculated, please set automaticCenterOfMass to false if you want to set it manually.");
21053
+ } else {
21054
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
21055
+ }
20788
21056
  };
20789
- _proto._setInertiaTensor = function _setInertiaTensor() {
20790
- this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21057
+ _proto._handleInertiaTensorChanged = function _handleInertiaTensorChanged() {
21058
+ if (this._automaticInertiaTensor) {
21059
+ console.warn("The inertia tensor is automatically calculated, please set automaticInertiaTensor to false if you want to set it manually.");
21060
+ } else {
21061
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
21062
+ }
20791
21063
  };
20792
21064
  _create_class(DynamicCollider, [
20793
21065
  {
@@ -20823,6 +21095,11 @@ PhysicsScene._collision = new Collision();
20823
21095
  get: /**
20824
21096
  * The linear velocity vector of the dynamic collider measured in world unit per second.
20825
21097
  */ function get() {
21098
+ //@ts-ignore
21099
+ this._linearVelocity._onValueChanged = null;
21100
+ this._nativeCollider.getLinearVelocity(this._linearVelocity);
21101
+ //@ts-ignore
21102
+ this._linearVelocity._onValueChanged = this._setLinearVelocity;
20826
21103
  return this._linearVelocity;
20827
21104
  },
20828
21105
  set: function set(value) {
@@ -20836,6 +21113,11 @@ PhysicsScene._collision = new Collision();
20836
21113
  get: /**
20837
21114
  * The angular velocity vector of the dynamic collider measured in radians per second.
20838
21115
  */ function get() {
21116
+ //@ts-ignore
21117
+ this._angularVelocity._onValueChanged = null;
21118
+ this._nativeCollider.getAngularVelocity(this._angularVelocity);
21119
+ //@ts-ignore
21120
+ this._angularVelocity._onValueChanged = this._setAngularVelocity;
20839
21121
  return this._angularVelocity;
20840
21122
  },
20841
21123
  set: function set(value) {
@@ -20854,7 +21136,28 @@ PhysicsScene._collision = new Collision();
20854
21136
  set: function set(value) {
20855
21137
  if (this._mass !== value) {
20856
21138
  this._mass = value;
20857
- this._nativeCollider.setMass(value);
21139
+ if (this._automaticInertiaTensor || this._automaticCenterOfMass) {
21140
+ this._setMassAndUpdateInertia();
21141
+ } else {
21142
+ this._nativeCollider.setMass(value);
21143
+ }
21144
+ }
21145
+ }
21146
+ },
21147
+ {
21148
+ key: "automaticCenterOfMass",
21149
+ get: /**
21150
+ * Whether or not to calculate the center of mass automatically, if true, the center of mass will be calculated based on the associated shapes.
21151
+ * @remarks Affected by the position, rotation of the shapes.
21152
+ */ function get() {
21153
+ return this._automaticCenterOfMass;
21154
+ },
21155
+ set: function set(value) {
21156
+ if (this._automaticCenterOfMass !== value) {
21157
+ this._automaticCenterOfMass = value;
21158
+ if (value) {
21159
+ this._setMassAndUpdateInertia();
21160
+ }
20858
21161
  }
20859
21162
  }
20860
21163
  },
@@ -20862,7 +21165,13 @@ PhysicsScene._collision = new Collision();
20862
21165
  key: "centerOfMass",
20863
21166
  get: /**
20864
21167
  * The center of mass relative to the transform's origin.
21168
+ * @remarks The center of mass is automatically calculated, if you want to set it manually, please set automaticCenterOfMass to false.
20865
21169
  */ function get() {
21170
+ // @ts-ignore
21171
+ this._centerOfMass._onValueChanged = null;
21172
+ this._nativeCollider.getCenterOfMass(this._centerOfMass);
21173
+ // @ts-ignore
21174
+ this._centerOfMass._onValueChanged = this._handleCenterOfMassChanged;
20866
21175
  return this._centerOfMass;
20867
21176
  },
20868
21177
  set: function set(value) {
@@ -20871,11 +21180,34 @@ PhysicsScene._collision = new Collision();
20871
21180
  }
20872
21181
  }
20873
21182
  },
21183
+ {
21184
+ key: "automaticInertiaTensor",
21185
+ get: /**
21186
+ * Whether or not to calculate the inertia tensor automatically, if true, the inertia tensor will be calculated based on the associated shapes and mass.
21187
+ * @remarks Affected by the position, rotation of the shapes and the mass of the collider.
21188
+ */ function get() {
21189
+ return this._automaticInertiaTensor;
21190
+ },
21191
+ set: function set(value) {
21192
+ if (this._automaticInertiaTensor !== value) {
21193
+ this._automaticInertiaTensor = value;
21194
+ if (value) {
21195
+ this._setMassAndUpdateInertia();
21196
+ }
21197
+ }
21198
+ }
21199
+ },
20874
21200
  {
20875
21201
  key: "inertiaTensor",
20876
21202
  get: /**
20877
21203
  * The diagonal inertia tensor of mass relative to the center of mass.
21204
+ * @remarks The inertia tensor is automatically calculated, if you want to set it manually, please set automaticInertiaTensor to false.
20878
21205
  */ function get() {
21206
+ // @ts-ignore
21207
+ this._inertiaTensor._onValueChanged = null;
21208
+ this._nativeCollider.getInertiaTensor(this._inertiaTensor);
21209
+ // @ts-ignore
21210
+ this._inertiaTensor._onValueChanged = this._handleInertiaTensorChanged;
20879
21211
  return this._inertiaTensor;
20880
21212
  },
20881
21213
  set: function set(value) {
@@ -20985,21 +21317,12 @@ PhysicsScene._collision = new Collision();
20985
21317
  ]);
20986
21318
  return DynamicCollider;
20987
21319
  }(exports.Collider);
20988
- __decorate([
20989
- ignoreClone
20990
- ], DynamicCollider.prototype, "_linearDamping", void 0);
20991
- __decorate([
20992
- ignoreClone
20993
- ], DynamicCollider.prototype, "_angularDamping", void 0);
20994
21320
  __decorate([
20995
21321
  ignoreClone
20996
21322
  ], DynamicCollider.prototype, "_linearVelocity", void 0);
20997
21323
  __decorate([
20998
21324
  ignoreClone
20999
21325
  ], DynamicCollider.prototype, "_angularVelocity", void 0);
21000
- __decorate([
21001
- ignoreClone
21002
- ], DynamicCollider.prototype, "_mass", void 0);
21003
21326
  __decorate([
21004
21327
  ignoreClone
21005
21328
  ], DynamicCollider.prototype, "_centerOfMass", void 0);
@@ -21008,25 +21331,16 @@ __decorate([
21008
21331
  ], DynamicCollider.prototype, "_inertiaTensor", void 0);
21009
21332
  __decorate([
21010
21333
  ignoreClone
21011
- ], DynamicCollider.prototype, "_maxAngularVelocity", void 0);
21012
- __decorate([
21013
- ignoreClone
21014
- ], DynamicCollider.prototype, "_maxDepenetrationVelocity", void 0);
21015
- __decorate([
21016
- ignoreClone
21017
- ], DynamicCollider.prototype, "_solverIterations", void 0);
21018
- __decorate([
21019
- ignoreClone
21020
- ], DynamicCollider.prototype, "_isKinematic", void 0);
21334
+ ], DynamicCollider.prototype, "_setLinearVelocity", null);
21021
21335
  __decorate([
21022
21336
  ignoreClone
21023
- ], DynamicCollider.prototype, "_constraints", void 0);
21337
+ ], DynamicCollider.prototype, "_setAngularVelocity", null);
21024
21338
  __decorate([
21025
21339
  ignoreClone
21026
- ], DynamicCollider.prototype, "_collisionDetectionMode", void 0);
21340
+ ], DynamicCollider.prototype, "_handleCenterOfMassChanged", null);
21027
21341
  __decorate([
21028
21342
  ignoreClone
21029
- ], DynamicCollider.prototype, "_sleepThreshold", void 0);
21343
+ ], DynamicCollider.prototype, "_handleInertiaTensorChanged", null);
21030
21344
  /**
21031
21345
  * The collision detection mode constants.
21032
21346
  */ var CollisionDetectionMode = /*#__PURE__*/ function(CollisionDetectionMode) {
@@ -21073,9 +21387,9 @@ __decorate([
21073
21387
  * Material class to represent a set of surface properties.
21074
21388
  */ var PhysicsMaterial = /*#__PURE__*/ function() {
21075
21389
  function PhysicsMaterial() {
21076
- this._bounciness = 0.1;
21077
- this._dynamicFriction = 0.1;
21078
- this._staticFriction = 0.1;
21390
+ this._bounciness = 0;
21391
+ this._dynamicFriction = 0.6;
21392
+ this._staticFriction = 0.6;
21079
21393
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
21080
21394
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
21081
21395
  this._nativeMaterial = PhysicsScene._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
@@ -21091,7 +21405,7 @@ __decorate([
21091
21405
  {
21092
21406
  key: "bounciness",
21093
21407
  get: /**
21094
- * The coefficient of bounciness.
21408
+ * The coefficient of bounciness, ranging from 0 to 1.
21095
21409
  */ function get() {
21096
21410
  return this._bounciness;
21097
21411
  },
@@ -21199,22 +21513,96 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21199
21513
  _inherits(Joint, Component);
21200
21514
  function Joint(entity) {
21201
21515
  var _this;
21202
- _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = 0, _this._torque = 0;
21203
- _this._connectedColliderInfo.localPosition = new engineMath.Vector3();
21516
+ _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = Infinity, _this._torque = Infinity, _this._automaticConnectedAnchor = true;
21517
+ //@ts-ignore
21518
+ _this._colliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 1);
21519
+ //@ts-ignore
21520
+ _this._connectedColliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 2);
21521
+ _this._onSelfTransformChanged = _this._onSelfTransformChanged.bind(_this);
21522
+ _this._onConnectedTransformChanged = _this._onConnectedTransformChanged.bind(_this);
21523
+ // @ts-ignore
21524
+ entity._updateFlagManager.addListener(_this._onSelfTransformChanged);
21204
21525
  return _this;
21205
21526
  }
21206
21527
  var _proto = Joint.prototype;
21207
21528
  /**
21208
21529
  * @internal
21209
- */ _proto._cloneTo = function _cloneTo(target) {
21210
- target.connectedCollider = this.connectedCollider;
21211
- target.connectedAnchor = this.connectedAnchor;
21212
- target.connectedMassScale = this.connectedMassScale;
21213
- target.connectedInertiaScale = this.connectedInertiaScale;
21214
- target.massScale = this.massScale;
21215
- target.inertiaScale = this.inertiaScale;
21216
- target.breakForce = this.breakForce;
21217
- target.breakTorque = this.breakTorque;
21530
+ */ _proto._onEnableInScene = function _onEnableInScene() {
21531
+ this._createJoint();
21532
+ this._syncNative();
21533
+ };
21534
+ /**
21535
+ * @internal
21536
+ */ _proto._onDisableInScene = function _onDisableInScene() {
21537
+ this._nativeJoint.destroy();
21538
+ this._nativeJoint = null;
21539
+ };
21540
+ _proto._syncNative = function _syncNative() {
21541
+ if (this._nativeJoint) {
21542
+ var _this__connectedColliderInfo_collider;
21543
+ this._nativeJoint.setConnectedCollider(((_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider._nativeCollider) || null);
21544
+ this._updateActualAnchor(1);
21545
+ if (this._automaticConnectedAnchor) {
21546
+ this._calculateConnectedAnchor();
21547
+ } else {
21548
+ this._updateActualAnchor(2);
21549
+ }
21550
+ this._nativeJoint.setConnectedMassScale(this._connectedColliderInfo.massScale);
21551
+ this._nativeJoint.setConnectedInertiaScale(this._connectedColliderInfo.inertiaScale);
21552
+ this._nativeJoint.setMassScale(this._colliderInfo.massScale);
21553
+ this._nativeJoint.setInertiaScale(this._colliderInfo.inertiaScale);
21554
+ this._nativeJoint.setBreakForce(this._force);
21555
+ this._nativeJoint.setBreakTorque(this._torque);
21556
+ }
21557
+ };
21558
+ _proto._calculateConnectedAnchor = function _calculateConnectedAnchor() {
21559
+ var colliderInfo = this._colliderInfo;
21560
+ var connectedColliderInfo = this._connectedColliderInfo;
21561
+ var _this_entity_transform = this.entity.transform, selfPos = _this_entity_transform.worldPosition;
21562
+ var selfActualAnchor = colliderInfo.actualAnchor;
21563
+ var connectedAnchor = connectedColliderInfo.anchor;
21564
+ var connectedActualAnchor = connectedColliderInfo.actualAnchor;
21565
+ var connectedCollider = connectedColliderInfo.collider;
21566
+ if (connectedCollider) {
21567
+ var _connectedCollider_entity_transform = connectedCollider.entity.transform, connectedPos = _connectedCollider_entity_transform.worldPosition, connectedWorldScale = _connectedCollider_entity_transform.lossyWorldScale;
21568
+ engineMath.Vector3.subtract(selfPos, connectedPos, Joint._tempVector3);
21569
+ engineMath.Vector3.add(Joint._tempVector3, selfActualAnchor, connectedActualAnchor);
21570
+ engineMath.Vector3.divide(connectedActualAnchor, connectedWorldScale, connectedAnchor);
21571
+ } else {
21572
+ engineMath.Vector3.add(selfPos, selfActualAnchor, connectedActualAnchor);
21573
+ connectedAnchor.copyFrom(connectedActualAnchor);
21574
+ }
21575
+ };
21576
+ _proto._onSelfTransformChanged = function _onSelfTransformChanged(type) {
21577
+ if (type & TransformModifyFlags.WorldScale) {
21578
+ this._updateActualAnchor(1);
21579
+ }
21580
+ };
21581
+ _proto._onConnectedTransformChanged = function _onConnectedTransformChanged(type) {
21582
+ if (type & TransformModifyFlags.WorldScale) {
21583
+ this._updateActualAnchor(2);
21584
+ }
21585
+ };
21586
+ _proto._updateActualAnchor = function _updateActualAnchor(flag) {
21587
+ if (flag & 1) {
21588
+ var _this__nativeJoint;
21589
+ var worldScale = this.entity.transform.lossyWorldScale;
21590
+ var selfColliderInfo = this._colliderInfo;
21591
+ engineMath.Vector3.multiply(selfColliderInfo.anchor, worldScale, selfColliderInfo.actualAnchor);
21592
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAnchor(selfColliderInfo.actualAnchor);
21593
+ }
21594
+ if (flag & 2) {
21595
+ var _this__nativeJoint1;
21596
+ var connectedColliderInfo = this._connectedColliderInfo;
21597
+ var connectedCollider = connectedColliderInfo.collider;
21598
+ if (connectedCollider) {
21599
+ var worldScale1 = connectedCollider.entity.transform.lossyWorldScale;
21600
+ engineMath.Vector3.multiply(connectedColliderInfo.anchor, worldScale1, connectedColliderInfo.actualAnchor);
21601
+ } else {
21602
+ connectedColliderInfo.actualAnchor.copyFrom(connectedColliderInfo.anchor);
21603
+ }
21604
+ (_this__nativeJoint1 = this._nativeJoint) == null ? void 0 : _this__nativeJoint1.setConnectedAnchor(connectedColliderInfo.actualAnchor);
21605
+ }
21218
21606
  };
21219
21607
  _create_class(Joint, [
21220
21608
  {
@@ -21226,8 +21614,33 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21226
21614
  },
21227
21615
  set: function set(value) {
21228
21616
  if (this._connectedColliderInfo.collider !== value) {
21617
+ var _this__connectedColliderInfo_collider, _this__nativeJoint;
21618
+ (_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged);
21619
+ value == null ? void 0 : value.entity._updateFlagManager.addListener(this._onConnectedTransformChanged);
21229
21620
  this._connectedColliderInfo.collider = value;
21230
- this._nativeJoint.setConnectedCollider(value._nativeCollider);
21621
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedCollider(value._nativeCollider);
21622
+ if (this._automaticConnectedAnchor) {
21623
+ this._calculateConnectedAnchor();
21624
+ } else {
21625
+ this._updateActualAnchor(2);
21626
+ }
21627
+ }
21628
+ }
21629
+ },
21630
+ {
21631
+ key: "anchor",
21632
+ get: /**
21633
+ * The connected anchor position.
21634
+ * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21635
+ */ function get() {
21636
+ return this._colliderInfo.anchor;
21637
+ },
21638
+ set: function set(value) {
21639
+ var anchor = this._colliderInfo.anchor;
21640
+ if (value !== anchor) {
21641
+ anchor.copyFrom(value);
21642
+ this._updateActualAnchor(1);
21643
+ this._automaticConnectedAnchor && this._calculateConnectedAnchor();
21231
21644
  }
21232
21645
  }
21233
21646
  },
@@ -21237,14 +21650,30 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21237
21650
  * The connected anchor position.
21238
21651
  * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21239
21652
  */ function get() {
21240
- return this._connectedColliderInfo.localPosition;
21653
+ return this._connectedColliderInfo.anchor;
21241
21654
  },
21242
21655
  set: function set(value) {
21243
- var connectedAnchor = this._connectedColliderInfo.localPosition;
21656
+ if (this.automaticConnectedAnchor) {
21657
+ console.warn("Cannot set connectedAnchor when automaticConnectedAnchor is true.");
21658
+ return;
21659
+ }
21660
+ var connectedAnchor = this._connectedColliderInfo.anchor;
21244
21661
  if (value !== connectedAnchor) {
21245
21662
  connectedAnchor.copyFrom(value);
21663
+ this._updateActualAnchor(2);
21246
21664
  }
21247
- this._nativeJoint.setConnectedAnchor(value);
21665
+ }
21666
+ },
21667
+ {
21668
+ key: "automaticConnectedAnchor",
21669
+ get: /**
21670
+ * 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.
21671
+ */ function get() {
21672
+ return this._automaticConnectedAnchor;
21673
+ },
21674
+ set: function set(value) {
21675
+ this._automaticConnectedAnchor = value;
21676
+ value && this._calculateConnectedAnchor();
21248
21677
  }
21249
21678
  },
21250
21679
  {
@@ -21256,36 +21685,39 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21256
21685
  },
21257
21686
  set: function set(value) {
21258
21687
  if (value !== this._connectedColliderInfo.massScale) {
21688
+ var _this__nativeJoint;
21259
21689
  this._connectedColliderInfo.massScale = value;
21260
- this._nativeJoint.setConnectedMassScale(value);
21690
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedMassScale(value);
21261
21691
  }
21262
21692
  }
21263
21693
  },
21264
21694
  {
21265
- key: "connectedInertiaScale",
21695
+ key: "massScale",
21266
21696
  get: /**
21267
- * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
21697
+ * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
21268
21698
  */ function get() {
21269
- return this._connectedColliderInfo.inertiaScale;
21699
+ return this._colliderInfo.massScale;
21270
21700
  },
21271
21701
  set: function set(value) {
21272
- if (value !== this._connectedColliderInfo.inertiaScale) {
21273
- this._connectedColliderInfo.inertiaScale = value;
21274
- this._nativeJoint.setConnectedInertiaScale(value);
21702
+ if (value !== this._colliderInfo.massScale) {
21703
+ var _this__nativeJoint;
21704
+ this._colliderInfo.massScale = value;
21705
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMassScale(value);
21275
21706
  }
21276
21707
  }
21277
21708
  },
21278
21709
  {
21279
- key: "massScale",
21710
+ key: "connectedInertiaScale",
21280
21711
  get: /**
21281
- * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
21712
+ * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
21282
21713
  */ function get() {
21283
- return this._colliderInfo.massScale;
21714
+ return this._connectedColliderInfo.inertiaScale;
21284
21715
  },
21285
21716
  set: function set(value) {
21286
- if (value !== this._colliderInfo.massScale) {
21287
- this._colliderInfo.massScale = value;
21288
- this._nativeJoint.setMassScale(value);
21717
+ if (value !== this._connectedColliderInfo.inertiaScale) {
21718
+ var _this__nativeJoint;
21719
+ this._connectedColliderInfo.inertiaScale = value;
21720
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedInertiaScale(value);
21289
21721
  }
21290
21722
  }
21291
21723
  },
@@ -21298,8 +21730,9 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21298
21730
  },
21299
21731
  set: function set(value) {
21300
21732
  if (value !== this._colliderInfo.inertiaScale) {
21733
+ var _this__nativeJoint;
21301
21734
  this._colliderInfo.inertiaScale = value;
21302
- this._nativeJoint.setInertiaScale(value);
21735
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setInertiaScale(value);
21303
21736
  }
21304
21737
  }
21305
21738
  },
@@ -21312,8 +21745,9 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21312
21745
  },
21313
21746
  set: function set(value) {
21314
21747
  if (value !== this._force) {
21748
+ var _this__nativeJoint;
21315
21749
  this._force = value;
21316
- this._nativeJoint.setBreakForce(value);
21750
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakForce(value);
21317
21751
  }
21318
21752
  }
21319
21753
  },
@@ -21326,29 +21760,34 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21326
21760
  },
21327
21761
  set: function set(value) {
21328
21762
  if (value !== this._torque) {
21763
+ var _this__nativeJoint;
21329
21764
  this._torque = value;
21330
- this._nativeJoint.setBreakTorque(value);
21765
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakTorque(value);
21331
21766
  }
21332
21767
  }
21333
21768
  }
21334
21769
  ]);
21335
21770
  return Joint;
21336
21771
  }(Component);
21772
+ exports.Joint._tempVector3 = new engineMath.Vector3();
21337
21773
  __decorate([
21338
- ignoreClone
21774
+ deepClone
21339
21775
  ], exports.Joint.prototype, "_colliderInfo", void 0);
21340
21776
  __decorate([
21341
- ignoreClone
21777
+ deepClone
21342
21778
  ], exports.Joint.prototype, "_connectedColliderInfo", void 0);
21343
21779
  __decorate([
21344
21780
  ignoreClone
21345
21781
  ], exports.Joint.prototype, "_nativeJoint", void 0);
21346
21782
  __decorate([
21347
21783
  ignoreClone
21348
- ], exports.Joint.prototype, "_force", void 0);
21784
+ ], exports.Joint.prototype, "_onSelfTransformChanged", null);
21785
+ __decorate([
21786
+ ignoreClone
21787
+ ], exports.Joint.prototype, "_onConnectedTransformChanged", null);
21349
21788
  __decorate([
21350
21789
  ignoreClone
21351
- ], exports.Joint.prototype, "_torque", void 0);
21790
+ ], exports.Joint.prototype, "_updateActualAnchor", null);
21352
21791
  exports.Joint = __decorate([
21353
21792
  dependentComponents(exports.Collider, DependentMode.CheckOnly)
21354
21793
  ], exports.Joint);
@@ -21356,9 +21795,17 @@ exports.Joint = __decorate([
21356
21795
  * @internal
21357
21796
  */ var JointColliderInfo = function JointColliderInfo() {
21358
21797
  this.collider = null;
21359
- this.massScale = 0;
21360
- this.inertiaScale = 0;
21798
+ this.anchor = new engineMath.Vector3();
21799
+ this.actualAnchor = new engineMath.Vector3();
21800
+ this.massScale = 1;
21801
+ this.inertiaScale = 1;
21361
21802
  };
21803
+ __decorate([
21804
+ deepClone
21805
+ ], JointColliderInfo.prototype, "anchor", void 0);
21806
+ __decorate([
21807
+ deepClone
21808
+ ], JointColliderInfo.prototype, "actualAnchor", void 0);
21362
21809
 
21363
21810
  /*
21364
21811
  * A fixed joint permits no relative movement between two colliders. ie the colliders are glued together.
@@ -21368,12 +21815,10 @@ exports.Joint = __decorate([
21368
21815
  return Joint.apply(this, arguments) || this;
21369
21816
  }
21370
21817
  var _proto = FixedJoint.prototype;
21371
- /**
21372
- * @internal
21373
- */ _proto._onAwake = function _onAwake() {
21374
- var collider = this._colliderInfo;
21375
- collider.collider = this.entity.getComponent(exports.Collider);
21376
- this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(collider.collider._nativeCollider);
21818
+ _proto._createJoint = function _createJoint() {
21819
+ var colliderInfo = this._colliderInfo;
21820
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
21821
+ this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
21377
21822
  };
21378
21823
  return FixedJoint;
21379
21824
  }(exports.Joint);
@@ -21393,30 +21838,58 @@ exports.Joint = __decorate([
21393
21838
  * A joint which behaves in a similar way to a hinge or axle.
21394
21839
  */ var HingeJoint = /*#__PURE__*/ function(Joint) {
21395
21840
  _inherits(HingeJoint, Joint);
21396
- function HingeJoint() {
21841
+ function HingeJoint(entity) {
21397
21842
  var _this;
21398
- _this = Joint.apply(this, arguments) || this, _this._axis = new engineMath.Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false;
21843
+ _this = Joint.call(this, entity) || this, _this._axis = new engineMath.Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false, _this._angle = 0, _this._velocity = 0;
21844
+ _this._onMotorChanged = _this._onMotorChanged.bind(_this);
21845
+ _this._onLimitsChanged = _this._onLimitsChanged.bind(_this);
21399
21846
  return _this;
21400
21847
  }
21401
21848
  var _proto = HingeJoint.prototype;
21402
21849
  /**
21403
21850
  * @internal
21404
- */ _proto._onAwake = function _onAwake() {
21405
- var collider = this._colliderInfo;
21406
- collider.localPosition = new engineMath.Vector3();
21407
- collider.collider = this.entity.getComponent(exports.Collider);
21408
- this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(collider.collider._nativeCollider);
21409
- };
21410
- /**
21411
- * @internal
21412
- */ _proto._cloneTo = function _cloneTo(target) {
21413
- target.axis = this.axis;
21414
- target.swingOffset = this.swingOffset;
21415
- target.useLimits = this.useLimits;
21416
- target.useMotor = this.useMotor;
21417
- target.useSpring = this.useSpring;
21418
- target.motor = this.motor;
21419
- target.limits = this.limits;
21851
+ */ _proto._onDisableInScene = function _onDisableInScene() {
21852
+ var nativeJoint = this._nativeJoint;
21853
+ this._angle = nativeJoint.getAngle();
21854
+ this._velocity = nativeJoint.getVelocity();
21855
+ Joint.prototype._onDisableInScene.call(this);
21856
+ };
21857
+ _proto._createJoint = function _createJoint() {
21858
+ var colliderInfo = this._colliderInfo;
21859
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
21860
+ this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
21861
+ };
21862
+ _proto._syncNative = function _syncNative() {
21863
+ Joint.prototype._syncNative.call(this);
21864
+ var motor = this._jointMotor;
21865
+ this._nativeJoint.setAxis(this._axis);
21866
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, this.useLimits);
21867
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, this.useMotor);
21868
+ if (motor) {
21869
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
21870
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
21871
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
21872
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
21873
+ }
21874
+ };
21875
+ _proto._onMotorChanged = function _onMotorChanged() {
21876
+ var motor = this._jointMotor;
21877
+ if (this._nativeJoint) {
21878
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
21879
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
21880
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
21881
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
21882
+ }
21883
+ };
21884
+ _proto._onLimitsChanged = function _onLimitsChanged() {
21885
+ var limits = this._limits;
21886
+ if (limits && this._nativeJoint) {
21887
+ if (this.useSpring) {
21888
+ this._nativeJoint.setSoftLimit(limits.min, limits.max, limits.stiffness, limits.damping);
21889
+ } else {
21890
+ this._nativeJoint.setHardLimit(limits.min, limits.max, limits.contactDistance);
21891
+ }
21892
+ }
21420
21893
  };
21421
21894
  _create_class(HingeJoint, [
21422
21895
  {
@@ -21429,24 +21902,10 @@ exports.Joint = __decorate([
21429
21902
  set: function set(value) {
21430
21903
  var axis = this._axis;
21431
21904
  if (value !== axis) {
21905
+ var _this__nativeJoint;
21432
21906
  axis.copyFrom(value);
21907
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAxis(axis);
21433
21908
  }
21434
- this._nativeJoint.setAxis(axis);
21435
- }
21436
- },
21437
- {
21438
- key: "swingOffset",
21439
- get: /**
21440
- * The swing offset.
21441
- */ function get() {
21442
- return this._colliderInfo.localPosition;
21443
- },
21444
- set: function set(value) {
21445
- var swingOffset = this._colliderInfo.localPosition;
21446
- if (value !== swingOffset) {
21447
- swingOffset.copyFrom(value);
21448
- }
21449
- this._nativeJoint.setSwingOffset(swingOffset);
21450
21909
  }
21451
21910
  },
21452
21911
  {
@@ -21454,7 +21913,11 @@ exports.Joint = __decorate([
21454
21913
  get: /**
21455
21914
  * The current angle in degrees of the joint relative to its rest position.
21456
21915
  */ function get() {
21457
- return this._nativeJoint.getAngle();
21916
+ var nativeJoint = this._nativeJoint;
21917
+ if (nativeJoint) {
21918
+ this._angle = nativeJoint.getAngle();
21919
+ }
21920
+ return this._angle;
21458
21921
  }
21459
21922
  },
21460
21923
  {
@@ -21462,7 +21925,11 @@ exports.Joint = __decorate([
21462
21925
  get: /**
21463
21926
  * The angular velocity of the joint in degrees per second.
21464
21927
  */ function get() {
21465
- return this._nativeJoint.getVelocity();
21928
+ var nativeJoint = this._nativeJoint;
21929
+ if (nativeJoint) {
21930
+ this._velocity = nativeJoint.getVelocity();
21931
+ }
21932
+ return this._velocity;
21466
21933
  }
21467
21934
  },
21468
21935
  {
@@ -21474,8 +21941,9 @@ exports.Joint = __decorate([
21474
21941
  },
21475
21942
  set: function set(value) {
21476
21943
  if (value !== this.useLimits) {
21944
+ var _this__nativeJoint;
21477
21945
  value ? this._hingeFlags |= HingeJointFlag.LimitEnabled : this._hingeFlags &= ~HingeJointFlag.LimitEnabled;
21478
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
21946
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
21479
21947
  }
21480
21948
  }
21481
21949
  },
@@ -21488,8 +21956,9 @@ exports.Joint = __decorate([
21488
21956
  },
21489
21957
  set: function set(value) {
21490
21958
  if (value !== this.useMotor) {
21959
+ var _this__nativeJoint;
21491
21960
  value ? this._hingeFlags |= HingeJointFlag.DriveEnabled : this._hingeFlags &= ~HingeJointFlag.DriveEnabled;
21492
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
21961
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
21493
21962
  }
21494
21963
  }
21495
21964
  },
@@ -21503,7 +21972,7 @@ exports.Joint = __decorate([
21503
21972
  set: function set(value) {
21504
21973
  if (this._useSpring !== value) {
21505
21974
  this._useSpring = value;
21506
- this.limits = this._limits;
21975
+ this._onLimitsChanged();
21507
21976
  }
21508
21977
  }
21509
21978
  },
@@ -21512,15 +21981,15 @@ exports.Joint = __decorate([
21512
21981
  get: /**
21513
21982
  * The motor will apply a force up to a maximum force to achieve the target velocity in degrees per second.
21514
21983
  */ function get() {
21515
- return this._jointMonitor;
21984
+ return this._jointMotor;
21516
21985
  },
21517
21986
  set: function set(value) {
21518
- if (this._jointMonitor !== value) {
21519
- this._jointMonitor = value;
21520
- this._nativeJoint.setDriveVelocity(value.targetVelocity);
21521
- this._nativeJoint.setDriveForceLimit(value.forceLimit);
21522
- this._nativeJoint.setDriveGearRatio(value.gearRation);
21523
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, value.freeSpin);
21987
+ if (this._jointMotor !== value) {
21988
+ var _this__jointMotor;
21989
+ (_this__jointMotor = this._jointMotor) == null ? void 0 : _this__jointMotor._updateFlagManager.removeListener(this._onMotorChanged);
21990
+ this._jointMotor = value;
21991
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onMotorChanged);
21992
+ this._onMotorChanged();
21524
21993
  }
21525
21994
  }
21526
21995
  },
@@ -21533,12 +22002,11 @@ exports.Joint = __decorate([
21533
22002
  },
21534
22003
  set: function set(value) {
21535
22004
  if (this._limits !== value) {
22005
+ var _this__limits;
22006
+ (_this__limits = this._limits) == null ? void 0 : _this__limits._updateFlagManager.removeListener(this._onLimitsChanged);
21536
22007
  this._limits = value;
21537
- if (this.useSpring) {
21538
- this._nativeJoint.setSoftLimit(value.min, value.max, value.stiffness, value.damping);
21539
- } else {
21540
- this._nativeJoint.setHardLimit(value.min, value.max, value.contactDistance);
21541
- }
22008
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onLimitsChanged);
22009
+ this._onLimitsChanged();
21542
22010
  }
21543
22011
  }
21544
22012
  }
@@ -21546,20 +22014,20 @@ exports.Joint = __decorate([
21546
22014
  return HingeJoint;
21547
22015
  }(exports.Joint);
21548
22016
  __decorate([
21549
- ignoreClone
22017
+ deepClone
21550
22018
  ], HingeJoint.prototype, "_axis", void 0);
21551
22019
  __decorate([
21552
- ignoreClone
21553
- ], HingeJoint.prototype, "_hingeFlags", void 0);
22020
+ deepClone
22021
+ ], HingeJoint.prototype, "_jointMotor", void 0);
21554
22022
  __decorate([
21555
- ignoreClone
21556
- ], HingeJoint.prototype, "_useSpring", void 0);
22023
+ deepClone
22024
+ ], HingeJoint.prototype, "_limits", void 0);
21557
22025
  __decorate([
21558
22026
  ignoreClone
21559
- ], HingeJoint.prototype, "_jointMonitor", void 0);
22027
+ ], HingeJoint.prototype, "_onMotorChanged", null);
21560
22028
  __decorate([
21561
22029
  ignoreClone
21562
- ], HingeJoint.prototype, "_limits", void 0);
22030
+ ], HingeJoint.prototype, "_onLimitsChanged", null);
21563
22031
 
21564
22032
  /**
21565
22033
  * A joint that maintains an upper or lower bound (or both) on the distance between two points on different objects.
@@ -21571,40 +22039,20 @@ __decorate([
21571
22039
  return _this;
21572
22040
  }
21573
22041
  var _proto = SpringJoint.prototype;
21574
- /**
21575
- * @internal
21576
- */ _proto._onAwake = function _onAwake() {
21577
- var collider = this._colliderInfo;
21578
- collider.localPosition = new engineMath.Vector3();
21579
- collider.collider = this.entity.getComponent(exports.Collider);
21580
- this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(collider.collider._nativeCollider);
21581
- };
21582
- /**
21583
- * @internal
21584
- */ _proto._cloneTo = function _cloneTo(target) {
21585
- target.swingOffset = this.swingOffset;
21586
- target.minDistance = this.minDistance;
21587
- target.maxDistance = this.maxDistance;
21588
- target.tolerance = this.tolerance;
21589
- target.stiffness = this.stiffness;
21590
- target.damping = this.damping;
22042
+ _proto._createJoint = function _createJoint() {
22043
+ var colliderInfo = this._colliderInfo;
22044
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
22045
+ this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
22046
+ };
22047
+ _proto._syncNative = function _syncNative() {
22048
+ Joint.prototype._syncNative.call(this);
22049
+ this._nativeJoint.setMinDistance(this._minDistance);
22050
+ this._nativeJoint.setMaxDistance(this._maxDistance);
22051
+ this._nativeJoint.setTolerance(this._tolerance);
22052
+ this._nativeJoint.setStiffness(this._stiffness);
22053
+ this._nativeJoint.setDamping(this._damping);
21591
22054
  };
21592
22055
  _create_class(SpringJoint, [
21593
- {
21594
- key: "swingOffset",
21595
- get: /**
21596
- * The swing offset.
21597
- */ function get() {
21598
- return this._colliderInfo.localPosition;
21599
- },
21600
- set: function set(value) {
21601
- var swingOffset = this._colliderInfo.localPosition;
21602
- if (value !== swingOffset) {
21603
- swingOffset.copyFrom(value);
21604
- }
21605
- this._nativeJoint.setSwingOffset(value);
21606
- }
21607
- },
21608
22056
  {
21609
22057
  key: "minDistance",
21610
22058
  get: /**
@@ -21614,8 +22062,9 @@ __decorate([
21614
22062
  },
21615
22063
  set: function set(value) {
21616
22064
  if (this._minDistance !== value) {
22065
+ var _this__nativeJoint;
21617
22066
  this._minDistance = value;
21618
- this._nativeJoint.setMinDistance(value);
22067
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMinDistance(value);
21619
22068
  }
21620
22069
  }
21621
22070
  },
@@ -21628,8 +22077,9 @@ __decorate([
21628
22077
  },
21629
22078
  set: function set(value) {
21630
22079
  if (this._maxDistance !== value) {
22080
+ var _this__nativeJoint;
21631
22081
  this._maxDistance = value;
21632
- this._nativeJoint.setMaxDistance(value);
22082
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMaxDistance(value);
21633
22083
  }
21634
22084
  }
21635
22085
  },
@@ -21642,8 +22092,9 @@ __decorate([
21642
22092
  },
21643
22093
  set: function set(value) {
21644
22094
  if (this._tolerance !== value) {
22095
+ var _this__nativeJoint;
21645
22096
  this._tolerance = value;
21646
- this._nativeJoint.setTolerance(value);
22097
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setTolerance(value);
21647
22098
  }
21648
22099
  }
21649
22100
  },
@@ -21656,8 +22107,9 @@ __decorate([
21656
22107
  },
21657
22108
  set: function set(value) {
21658
22109
  if (this._stiffness !== value) {
22110
+ var _this__nativeJoint;
21659
22111
  this._stiffness = value;
21660
- this._nativeJoint.setStiffness(value);
22112
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setStiffness(value);
21661
22113
  }
21662
22114
  }
21663
22115
  },
@@ -21670,8 +22122,9 @@ __decorate([
21670
22122
  },
21671
22123
  set: function set(value) {
21672
22124
  if (this._damping !== value) {
22125
+ var _this__nativeJoint;
21673
22126
  this._damping = value;
21674
- this._nativeJoint.setDamping(value);
22127
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setDamping(value);
21675
22128
  }
21676
22129
  }
21677
22130
  }
@@ -21681,22 +22134,168 @@ __decorate([
21681
22134
 
21682
22135
  /**
21683
22136
  * JointLimits is used to limit the joints angle.
21684
- */ var JointLimits = function JointLimits() {
21685
- /** The upper angular limit (in degrees) of the joint. */ this.max = 0;
21686
- /** The lower angular limit (in degrees) of the joint. */ this.min = 0;
21687
- /** Distance inside the limit value at which the limit will be considered to be active by the solver. */ this.contactDistance = -1;
21688
- /** The spring forces used to reach the target position. */ this.stiffness = 0;
21689
- /** The damper force uses to dampen the spring. */ this.damping = 0;
21690
- };
22137
+ */ var JointLimits = /*#__PURE__*/ function() {
22138
+ function JointLimits() {
22139
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
22140
+ this._max = 0;
22141
+ this._min = 0;
22142
+ this._contactDistance = -1;
22143
+ this._stiffness = 0;
22144
+ this._damping = 0;
22145
+ }
22146
+ _create_class(JointLimits, [
22147
+ {
22148
+ key: "max",
22149
+ get: /**
22150
+ * The upper angular limit (in radians) of the joint.
22151
+ */ function get() {
22152
+ return this._max;
22153
+ },
22154
+ set: function set(value) {
22155
+ if (value < this._min) {
22156
+ throw new Error("Max limit must be greater than min limit");
22157
+ }
22158
+ if (this._max !== value) {
22159
+ this._max = value;
22160
+ this._updateFlagManager.dispatch();
22161
+ }
22162
+ }
22163
+ },
22164
+ {
22165
+ key: "min",
22166
+ get: /**
22167
+ * The lower angular limit (in radians) of the joint.
22168
+ */ function get() {
22169
+ return this._min;
22170
+ },
22171
+ set: function set(value) {
22172
+ if (value > this._max) {
22173
+ throw new Error("Min limit must be less than max limit");
22174
+ }
22175
+ if (this._min !== value) {
22176
+ this._min = value;
22177
+ this._updateFlagManager.dispatch();
22178
+ }
22179
+ }
22180
+ },
22181
+ {
22182
+ key: "contactDistance",
22183
+ get: /**
22184
+ * Distance inside the limit value at which the limit will be considered to be active by the solver.
22185
+ * Default is the lesser of 0.1 radians, and 0.49 * (upperLimit - lowerLimit)
22186
+ */ function get() {
22187
+ if (this._contactDistance === -1) {
22188
+ return Math.min(0.1, 0.49 * (this._max - this._min));
22189
+ }
22190
+ return this._contactDistance;
22191
+ },
22192
+ set: function set(value) {
22193
+ if (this._contactDistance !== value) {
22194
+ this._contactDistance = value;
22195
+ this._updateFlagManager.dispatch();
22196
+ }
22197
+ }
22198
+ },
22199
+ {
22200
+ key: "stiffness",
22201
+ get: /**
22202
+ * The spring forces used to reach the target position.
22203
+ */ function get() {
22204
+ return this._stiffness;
22205
+ },
22206
+ set: function set(value) {
22207
+ if (this._stiffness !== value) {
22208
+ this._stiffness = value;
22209
+ this._updateFlagManager.dispatch();
22210
+ }
22211
+ }
22212
+ },
22213
+ {
22214
+ key: "damping",
22215
+ get: /**
22216
+ * The damper force uses to dampen the spring.
22217
+ */ function get() {
22218
+ return this._damping;
22219
+ },
22220
+ set: function set(value) {
22221
+ if (this._damping !== value) {
22222
+ this._damping = value;
22223
+ this._updateFlagManager.dispatch();
22224
+ }
22225
+ }
22226
+ }
22227
+ ]);
22228
+ return JointLimits;
22229
+ }();
22230
+ __decorate([
22231
+ deepClone
22232
+ ], JointLimits.prototype, "_updateFlagManager", void 0);
21691
22233
 
21692
22234
  /**
21693
22235
  * The JointMotor is used to motorize a joint.
21694
- */ var JointMotor = function JointMotor() {
21695
- /** The motor will apply a force up to force to achieve targetVelocity. */ this.targetVelocity = 0;
21696
- /** The force limit.*/ this.forceLimit = Number.MAX_VALUE;
21697
- /** Gear ration for the motor */ this.gearRation = 1.0;
21698
- /** If freeSpin is enabled the motor will only accelerate but never slow down. */ this.freeSpin = false;
21699
- };
22236
+ */ var JointMotor = /*#__PURE__*/ function() {
22237
+ function JointMotor() {
22238
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
22239
+ this._targetVelocity = 0;
22240
+ this._forceLimit = Number.MAX_VALUE;
22241
+ this._gearRatio = 1.0;
22242
+ this._freeSpin = false;
22243
+ }
22244
+ _create_class(JointMotor, [
22245
+ {
22246
+ key: "targetVelocity",
22247
+ get: /**
22248
+ * The motor will apply a force up to force to achieve targetVelocity.
22249
+ */ function get() {
22250
+ return this._targetVelocity;
22251
+ },
22252
+ set: function set(value) {
22253
+ this._targetVelocity = value;
22254
+ this._updateFlagManager.dispatch();
22255
+ }
22256
+ },
22257
+ {
22258
+ key: "forceLimit",
22259
+ get: /**
22260
+ * The force limit.
22261
+ */ function get() {
22262
+ return this._forceLimit;
22263
+ },
22264
+ set: function set(value) {
22265
+ this._forceLimit = value;
22266
+ this._updateFlagManager.dispatch();
22267
+ }
22268
+ },
22269
+ {
22270
+ key: "gearRatio",
22271
+ get: /**
22272
+ * Gear ration for the motor
22273
+ */ function get() {
22274
+ return this._gearRatio;
22275
+ },
22276
+ set: function set(value) {
22277
+ this._gearRatio = value;
22278
+ this._updateFlagManager.dispatch();
22279
+ }
22280
+ },
22281
+ {
22282
+ key: "freeSpin",
22283
+ get: /**
22284
+ * If freeSpin is enabled the motor will only accelerate but never slow down.
22285
+ */ function get() {
22286
+ return this._freeSpin;
22287
+ },
22288
+ set: function set(value) {
22289
+ this._freeSpin = value;
22290
+ this._updateFlagManager.dispatch();
22291
+ }
22292
+ }
22293
+ ]);
22294
+ return JointMotor;
22295
+ }();
22296
+ __decorate([
22297
+ deepClone
22298
+ ], JointMotor.prototype, "_updateFlagManager", void 0);
21700
22299
 
21701
22300
  /**
21702
22301
  * Abstract class for collider shapes.
@@ -21719,28 +22318,39 @@ __decorate([
21719
22318
  this._rotation._onValueChanged = this._setRotation;
21720
22319
  //@ts-ignore
21721
22320
  this._position._onValueChanged = this._setPosition;
22321
+ Engine._physicalObjectsMap[this._id] = this;
21722
22322
  }
21723
22323
  var _proto = ColliderShape.prototype;
21724
22324
  /**
21725
22325
  * @internal
21726
22326
  */ _proto._cloneTo = function _cloneTo(target) {
21727
- target.contactOffset = this.contactOffset;
21728
- target.rotation = this.rotation;
21729
- target.position = this.position;
21730
- target.isTrigger = this.isTrigger;
21731
- target.material = this.material;
22327
+ target._syncNative();
21732
22328
  };
21733
22329
  /**
21734
22330
  * @internal
21735
22331
  */ _proto._destroy = function _destroy() {
21736
- this._material._destroy();
21737
22332
  this._nativeShape.destroy();
22333
+ this._nativeShape = null;
22334
+ delete Engine._physicalObjectsMap[this._id];
22335
+ };
22336
+ _proto._syncNative = function _syncNative() {
22337
+ var _this__collider;
22338
+ this._nativeShape.setPosition(this._position);
22339
+ this._nativeShape.setRotation(this._rotation);
22340
+ this._nativeShape.setContactOffset(this._contactOffset);
22341
+ this._nativeShape.setIsTrigger(this._isTrigger);
22342
+ this._nativeShape.setMaterial(this._material._nativeMaterial);
22343
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21738
22344
  };
21739
22345
  _proto._setPosition = function _setPosition() {
22346
+ var _this__collider;
21740
22347
  this._nativeShape.setPosition(this._position);
22348
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21741
22349
  };
21742
22350
  _proto._setRotation = function _setRotation() {
22351
+ var _this__collider;
21743
22352
  this._nativeShape.setRotation(this._rotation);
22353
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
21744
22354
  };
21745
22355
  _create_class(ColliderShape, [
21746
22356
  {
@@ -21762,11 +22372,12 @@ __decorate([
21762
22372
  {
21763
22373
  key: "contactOffset",
21764
22374
  get: /**
21765
- * Contact offset for this shape.
22375
+ * Contact offset for this shape, the value must be greater than or equal to 0.
21766
22376
  */ function get() {
21767
22377
  return this._contactOffset;
21768
22378
  },
21769
22379
  set: function set(value) {
22380
+ value = Math.max(0, value);
21770
22381
  if (this._contactOffset !== value) {
21771
22382
  this._contactOffset = value;
21772
22383
  this._nativeShape.setContactOffset(value);
@@ -21841,20 +22452,17 @@ __decorate([
21841
22452
  ignoreClone
21842
22453
  ], ColliderShape.prototype, "_id", void 0);
21843
22454
  __decorate([
21844
- ignoreClone
21845
- ], ColliderShape.prototype, "_material", void 0);
21846
- __decorate([
21847
- ignoreClone
21848
- ], ColliderShape.prototype, "_isTrigger", void 0);
21849
- __decorate([
21850
- ignoreClone
22455
+ deepClone
21851
22456
  ], ColliderShape.prototype, "_rotation", void 0);
21852
22457
  __decorate([
21853
- ignoreClone
22458
+ deepClone
21854
22459
  ], ColliderShape.prototype, "_position", void 0);
21855
22460
  __decorate([
21856
22461
  ignoreClone
21857
- ], ColliderShape.prototype, "_contactOffset", void 0);
22462
+ ], ColliderShape.prototype, "_setPosition", null);
22463
+ __decorate([
22464
+ ignoreClone
22465
+ ], ColliderShape.prototype, "_setRotation", null);
21858
22466
 
21859
22467
  /**
21860
22468
  * Physical collider shape for box.
@@ -21864,17 +22472,14 @@ __decorate([
21864
22472
  var _this;
21865
22473
  _this = ColliderShape.call(this) || this, _this._size = new engineMath.Vector3(1, 1, 1);
21866
22474
  _this._nativeShape = PhysicsScene._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
21867
- _this._setSize = _this._setSize.bind(_this);
21868
22475
  //@ts-ignore
21869
- _this._size._onValueChanged = _this._setSize;
22476
+ _this._size._onValueChanged = _this._setSize.bind(_this);
21870
22477
  return _this;
21871
22478
  }
21872
22479
  var _proto = BoxColliderShape.prototype;
21873
- /**
21874
- * @internal
21875
- */ _proto._cloneTo = function _cloneTo(target) {
21876
- ColliderShape.prototype._cloneTo.call(this, target);
21877
- target.size = this.size;
22480
+ _proto._syncNative = function _syncNative() {
22481
+ ColliderShape.prototype._syncNative.call(this);
22482
+ this._setSize();
21878
22483
  };
21879
22484
  _proto._setSize = function _setSize() {
21880
22485
  this._nativeShape.setSize(this._size);
@@ -21897,8 +22502,11 @@ __decorate([
21897
22502
  return BoxColliderShape;
21898
22503
  }(ColliderShape);
21899
22504
  __decorate([
21900
- ignoreClone
22505
+ deepClone
21901
22506
  ], BoxColliderShape.prototype, "_size", void 0);
22507
+ __decorate([
22508
+ ignoreClone
22509
+ ], BoxColliderShape.prototype, "_setSize", null);
21902
22510
 
21903
22511
  /**
21904
22512
  * Physical collider shape for sphere.
@@ -21911,9 +22519,9 @@ __decorate([
21911
22519
  return _this;
21912
22520
  }
21913
22521
  var _proto = SphereColliderShape.prototype;
21914
- _proto._cloneTo = function _cloneTo(target) {
21915
- ColliderShape.prototype._cloneTo.call(this, target);
21916
- target.radius = this.radius;
22522
+ _proto._syncNative = function _syncNative() {
22523
+ ColliderShape.prototype._syncNative.call(this);
22524
+ this._nativeShape.setRadius(this._radius);
21917
22525
  };
21918
22526
  _create_class(SphereColliderShape, [
21919
22527
  {
@@ -21933,9 +22541,6 @@ __decorate([
21933
22541
  ]);
21934
22542
  return SphereColliderShape;
21935
22543
  }(ColliderShape);
21936
- __decorate([
21937
- ignoreClone
21938
- ], SphereColliderShape.prototype, "_radius", void 0);
21939
22544
 
21940
22545
  /**
21941
22546
  * Physical collider shape plane.
@@ -21961,13 +22566,11 @@ __decorate([
21961
22566
  return _this;
21962
22567
  }
21963
22568
  var _proto = CapsuleColliderShape.prototype;
21964
- /**
21965
- * @internal
21966
- */ _proto._cloneTo = function _cloneTo(target) {
21967
- ColliderShape.prototype._cloneTo.call(this, target);
21968
- target.radius = this.radius;
21969
- target.height = this.height;
21970
- target.upAxis = this.upAxis;
22569
+ _proto._syncNative = function _syncNative() {
22570
+ ColliderShape.prototype._syncNative.call(this);
22571
+ this._nativeShape.setRadius(this._radius);
22572
+ this._nativeShape.setHeight(this._height);
22573
+ this._nativeShape.setUpAxis(this._upAxis);
21971
22574
  };
21972
22575
  _create_class(CapsuleColliderShape, [
21973
22576
  {
@@ -22015,15 +22618,6 @@ __decorate([
22015
22618
  ]);
22016
22619
  return CapsuleColliderShape;
22017
22620
  }(ColliderShape);
22018
- __decorate([
22019
- ignoreClone
22020
- ], CapsuleColliderShape.prototype, "_radius", void 0);
22021
- __decorate([
22022
- ignoreClone
22023
- ], CapsuleColliderShape.prototype, "_height", void 0);
22024
- __decorate([
22025
- ignoreClone
22026
- ], CapsuleColliderShape.prototype, "_upAxis", void 0);
22027
22621
 
22028
22622
  /**
22029
22623
  * Pointer Manager.
@@ -22589,7 +23183,7 @@ ParticleBufferUtils.boundsFloatStride = 8;
22589
23183
  ParticleBufferUtils.boundsTimeOffset = 6;
22590
23184
  ParticleBufferUtils.boundsMaxLifetimeOffset = 7;
22591
23185
 
22592
- 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
23186
+ 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
22593
23187
 
22594
23188
  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
22595
23189
 
@@ -22863,7 +23457,7 @@ ShaderPool.init();
22863
23457
  _inherits(Engine, EventDispatcher);
22864
23458
  function Engine(canvas, hardwareRenderer, configuration) {
22865
23459
  var _this;
22866
- _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() {
23460
+ _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() {
22867
23461
  if (_this._vSyncCount) {
22868
23462
  var _this_xrManager;
22869
23463
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -23288,6 +23882,7 @@ ShaderPool.init();
23288
23882
  /** @internal */ Engine._gammaMacro = ShaderMacro.getByName("ENGINE_IS_COLORSPACE_GAMMA");
23289
23883
  /** @internal */ Engine._noDepthTextureMacro = ShaderMacro.getByName("ENGINE_NO_DEPTH_TEXTURE");
23290
23884
  /** @internal Conversion of space units to pixel units for 2D. */ Engine._pixelsPerUnit = 100;
23885
+ /** @internal */ Engine._physicalObjectsMap = {};
23291
23886
 
23292
23887
  /**
23293
23888
  * Canvas.
@@ -29667,7 +30262,12 @@ var ParticleStopMode = /*#__PURE__*/ function(ParticleStopMode) {
29667
30262
  };
29668
30263
  _proto._render = function _render(context) {
29669
30264
  var generator = this.generator;
29670
- generator._primitive.instanceCount = generator._getAliveParticleCount();
30265
+ // Don't need to render when no particles
30266
+ var aliveParticleCount = generator._getAliveParticleCount();
30267
+ if (!aliveParticleCount) {
30268
+ return;
30269
+ }
30270
+ generator._primitive.instanceCount = aliveParticleCount;
29671
30271
  var material = this.getMaterial();
29672
30272
  if (!material) {
29673
30273
  return;
@@ -31815,7 +32415,8 @@ __decorate([
31815
32415
  */ _proto._emit = function _emit(time, count) {
31816
32416
  if (this.emission.enabled) {
31817
32417
  // Wait the existing particles to be retired
31818
- if (this.main._maxParticleBuffer < this._currentParticleCount) {
32418
+ var notRetireParticleCount = this._getNotRetiredParticleCount();
32419
+ if (notRetireParticleCount >= this.main.maxParticles) {
31819
32420
  return;
31820
32421
  }
31821
32422
  var position = ParticleGenerator._tempVector30;
@@ -33592,6 +34193,401 @@ var cacheDir = new engineMath.Vector3();
33592
34193
  return CubeProbe;
33593
34194
  }(Probe);
33594
34195
 
34196
+ /**
34197
+ * Audio Clip.
34198
+ */ var AudioClip = /*#__PURE__*/ function(ReferResource) {
34199
+ _inherits(AudioClip, ReferResource);
34200
+ function AudioClip(engine, name) {
34201
+ if (name === void 0) name = "";
34202
+ var _this;
34203
+ _this = ReferResource.call(this, engine) || this, _this._audioBuffer = null;
34204
+ _this.name = name;
34205
+ return _this;
34206
+ }
34207
+ var _proto = AudioClip.prototype;
34208
+ /**
34209
+ * @internal
34210
+ */ _proto._getAudioSource = function _getAudioSource() {
34211
+ return this._audioBuffer;
34212
+ };
34213
+ /**
34214
+ * @internal
34215
+ */ _proto._setAudioSource = function _setAudioSource(value) {
34216
+ this._audioBuffer = value;
34217
+ };
34218
+ _proto._onDestroy = function _onDestroy() {
34219
+ ReferResource.prototype._onDestroy.call(this);
34220
+ this._audioBuffer = null;
34221
+ this.name = null;
34222
+ };
34223
+ _create_class(AudioClip, [
34224
+ {
34225
+ key: "channels",
34226
+ get: /**
34227
+ * Number of discrete audio channels.
34228
+ */ function get() {
34229
+ return this._audioBuffer.numberOfChannels;
34230
+ }
34231
+ },
34232
+ {
34233
+ key: "sampleRate",
34234
+ get: /**
34235
+ * Sample rate, in samples per second.
34236
+ */ function get() {
34237
+ return this._audioBuffer.sampleRate;
34238
+ }
34239
+ },
34240
+ {
34241
+ key: "duration",
34242
+ get: /**
34243
+ * Duration, in seconds.
34244
+ */ function get() {
34245
+ return this._audioBuffer.duration;
34246
+ }
34247
+ }
34248
+ ]);
34249
+ return AudioClip;
34250
+ }(ReferResource);
34251
+
34252
+ /**
34253
+ * @internal
34254
+ * Audio Manager.
34255
+ */ var AudioManager = /*#__PURE__*/ function() {
34256
+ function AudioManager() {}
34257
+ AudioManager.getContext = function getContext() {
34258
+ var context = AudioManager._context;
34259
+ if (!context) {
34260
+ AudioManager._context = context = new window.AudioContext();
34261
+ // Safari can't resume audio context without element interaction
34262
+ document.addEventListener("pointerdown", AudioManager._tryResume, true);
34263
+ document.addEventListener("touchend", AudioManager._tryResume, true);
34264
+ document.addEventListener("touchstart", AudioManager._tryResume, true);
34265
+ }
34266
+ return context;
34267
+ };
34268
+ AudioManager.getGainNode = function getGainNode() {
34269
+ var gainNode = AudioManager._gainNode;
34270
+ if (!AudioManager._gainNode) {
34271
+ AudioManager._gainNode = gainNode = AudioManager.getContext().createGain();
34272
+ gainNode.connect(AudioManager.getContext().destination);
34273
+ }
34274
+ return gainNode;
34275
+ };
34276
+ AudioManager.isAudioContextRunning = function isAudioContextRunning() {
34277
+ if (AudioManager.getContext().state !== "running") {
34278
+ console.warn("The AudioContext is not running and requires user interaction, such as a click or touch.");
34279
+ return false;
34280
+ }
34281
+ return true;
34282
+ };
34283
+ AudioManager._tryResume = function _tryResume() {
34284
+ if (AudioManager._context.state !== "running") {
34285
+ if (AudioManager._isResuming) {
34286
+ return;
34287
+ }
34288
+ AudioManager._isResuming = true;
34289
+ AudioManager._context.resume().then(function() {
34290
+ AudioManager._isResuming = false;
34291
+ });
34292
+ }
34293
+ };
34294
+ return AudioManager;
34295
+ }();
34296
+ AudioManager._isResuming = false;
34297
+
34298
+ /**
34299
+ * Audio Source Component.
34300
+ */ var AudioSource = /*#__PURE__*/ function(Component) {
34301
+ _inherits(AudioSource, Component);
34302
+ function AudioSource(entity) {
34303
+ var _this;
34304
+ _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;
34305
+ _this._onPlayEnd = _this._onPlayEnd.bind(_this);
34306
+ _this._gainNode = AudioManager.getContext().createGain();
34307
+ _this._gainNode.connect(AudioManager.getGainNode());
34308
+ return _this;
34309
+ }
34310
+ var _proto = AudioSource.prototype;
34311
+ /**
34312
+ * Play the clip.
34313
+ */ _proto.play = function play() {
34314
+ if (!this._canPlay()) {
34315
+ return;
34316
+ }
34317
+ if (this._isPlaying) {
34318
+ return;
34319
+ }
34320
+ var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
34321
+ this._initSourceNode(startTime);
34322
+ this._playTime = AudioManager.getContext().currentTime - startTime;
34323
+ this._pausedTime = -1;
34324
+ this._isPlaying = true;
34325
+ };
34326
+ /**
34327
+ * Stops playing the clip.
34328
+ */ _proto.stop = function stop() {
34329
+ if (this._isPlaying) {
34330
+ this._clearSourceNode();
34331
+ this._isPlaying = false;
34332
+ this._pausedTime = -1;
34333
+ this._playTime = -1;
34334
+ }
34335
+ };
34336
+ /**
34337
+ * Pauses playing the clip.
34338
+ */ _proto.pause = function pause() {
34339
+ if (this._isPlaying) {
34340
+ this._clearSourceNode();
34341
+ this._pausedTime = AudioManager.getContext().currentTime;
34342
+ this._isPlaying = false;
34343
+ }
34344
+ };
34345
+ /**
34346
+ * @internal
34347
+ */ _proto._onEnable = function _onEnable() {
34348
+ this.playOnEnabled && this.play();
34349
+ };
34350
+ /**
34351
+ * @internal
34352
+ */ _proto._onDisable = function _onDisable() {
34353
+ this.pause();
34354
+ };
34355
+ /**
34356
+ * @internal
34357
+ */ _proto._onDestroy = function _onDestroy() {
34358
+ Component.prototype._onDestroy.call(this);
34359
+ this.stop();
34360
+ this.clip = null;
34361
+ };
34362
+ _proto._onPlayEnd = function _onPlayEnd() {
34363
+ this.stop();
34364
+ };
34365
+ _proto._initSourceNode = function _initSourceNode(startTime) {
34366
+ var context = AudioManager.getContext();
34367
+ var sourceNode = context.createBufferSource();
34368
+ sourceNode.buffer = this._clip._getAudioSource();
34369
+ sourceNode.playbackRate.value = this._playbackRate;
34370
+ sourceNode.loop = this._loop;
34371
+ sourceNode.onended = this._onPlayEnd;
34372
+ this._sourceNode = sourceNode;
34373
+ sourceNode.connect(this._gainNode);
34374
+ this._sourceNode.start(0, startTime);
34375
+ };
34376
+ _proto._clearSourceNode = function _clearSourceNode() {
34377
+ this._sourceNode.stop();
34378
+ this._sourceNode.disconnect();
34379
+ this._sourceNode.onended = null;
34380
+ this._sourceNode = null;
34381
+ };
34382
+ _proto._canPlay = function _canPlay() {
34383
+ var _this__clip;
34384
+ var isValidClip = ((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) ? true : false;
34385
+ return isValidClip && AudioManager.isAudioContextRunning();
34386
+ };
34387
+ _create_class(AudioSource, [
34388
+ {
34389
+ key: "clip",
34390
+ get: /**
34391
+ * The audio clip to play.
34392
+ */ function get() {
34393
+ return this._clip;
34394
+ },
34395
+ set: function set(value) {
34396
+ var lastClip = this._clip;
34397
+ if (lastClip !== value) {
34398
+ lastClip && lastClip._addReferCount(-1);
34399
+ value && value._addReferCount(1);
34400
+ this._clip = value;
34401
+ this.stop();
34402
+ }
34403
+ }
34404
+ },
34405
+ {
34406
+ key: "isPlaying",
34407
+ get: /**
34408
+ * Whether the clip playing right now.
34409
+ */ function get() {
34410
+ return this._isPlaying;
34411
+ }
34412
+ },
34413
+ {
34414
+ key: "volume",
34415
+ get: /**
34416
+ * The volume of the audio source, ranging from 0 to 1.
34417
+ * @defaultValue `1`
34418
+ */ function get() {
34419
+ return this._volume;
34420
+ },
34421
+ set: function set(value) {
34422
+ value = Math.min(Math.max(0, value), 1.0);
34423
+ this._volume = value;
34424
+ this._gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
34425
+ }
34426
+ },
34427
+ {
34428
+ key: "playbackRate",
34429
+ get: /**
34430
+ * The playback rate of the audio source.
34431
+ * @defaultValue `1`
34432
+ */ function get() {
34433
+ return this._playbackRate;
34434
+ },
34435
+ set: function set(value) {
34436
+ this._playbackRate = value;
34437
+ if (this._isPlaying) {
34438
+ this._sourceNode.playbackRate.value = this._playbackRate;
34439
+ }
34440
+ }
34441
+ },
34442
+ {
34443
+ key: "mute",
34444
+ get: /**
34445
+ * Mutes or unmute the audio source.
34446
+ * Mute sets volume as 0, unmute restore volume.
34447
+ */ function get() {
34448
+ return this.volume === 0;
34449
+ },
34450
+ set: function set(value) {
34451
+ if (value) {
34452
+ this._lastVolume = this.volume;
34453
+ this.volume = 0;
34454
+ } else {
34455
+ this.volume = this._lastVolume;
34456
+ }
34457
+ }
34458
+ },
34459
+ {
34460
+ key: "loop",
34461
+ get: /**
34462
+ * Whether the audio clip looping.
34463
+ * @defaultValue `false`
34464
+ */ function get() {
34465
+ return this._loop;
34466
+ },
34467
+ set: function set(value) {
34468
+ if (value !== this._loop) {
34469
+ this._loop = value;
34470
+ if (this._isPlaying) {
34471
+ this._sourceNode.loop = this._loop;
34472
+ }
34473
+ }
34474
+ }
34475
+ },
34476
+ {
34477
+ key: "time",
34478
+ get: /**
34479
+ * Playback position in seconds.
34480
+ */ function get() {
34481
+ if (this._isPlaying) {
34482
+ var currentTime = AudioManager.getContext().currentTime;
34483
+ return currentTime - this._playTime;
34484
+ } else {
34485
+ return this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
34486
+ }
34487
+ }
34488
+ }
34489
+ ]);
34490
+ return AudioSource;
34491
+ }(Component);
34492
+ __decorate([
34493
+ ignoreClone
34494
+ ], AudioSource.prototype, "_isPlaying", void 0);
34495
+ __decorate([
34496
+ ignoreClone
34497
+ ], AudioSource.prototype, "_clip", void 0);
34498
+ __decorate([
34499
+ deepClone
34500
+ ], AudioSource.prototype, "_gainNode", void 0);
34501
+ __decorate([
34502
+ ignoreClone
34503
+ ], AudioSource.prototype, "_sourceNode", void 0);
34504
+ __decorate([
34505
+ deepClone
34506
+ ], AudioSource.prototype, "_pausedTime", void 0);
34507
+ __decorate([
34508
+ ignoreClone
34509
+ ], AudioSource.prototype, "_playTime", void 0);
34510
+ __decorate([
34511
+ deepClone
34512
+ ], AudioSource.prototype, "_volume", void 0);
34513
+ __decorate([
34514
+ deepClone
34515
+ ], AudioSource.prototype, "_lastVolume", void 0);
34516
+ __decorate([
34517
+ deepClone
34518
+ ], AudioSource.prototype, "_playbackRate", void 0);
34519
+ __decorate([
34520
+ deepClone
34521
+ ], AudioSource.prototype, "_loop", void 0);
34522
+
34523
+ /**
34524
+ * @internal
34525
+ */ var Polyfill = /*#__PURE__*/ function() {
34526
+ function Polyfill() {}
34527
+ Polyfill.registerPolyfill = function registerPolyfill() {
34528
+ Polyfill._registerMatchAll();
34529
+ };
34530
+ Polyfill._registerMatchAll = function _registerMatchAll() {
34531
+ if (!String.prototype.matchAll) {
34532
+ Logger.info("polyfill String.prototype.matchAll");
34533
+ String.prototype.matchAll = function(pattern) {
34534
+ var flags = pattern.flags;
34535
+ var globalFlagIdx = flags.indexOf("g");
34536
+ if (globalFlagIdx === -1) {
34537
+ throw TypeError("String.prototype.matchAll called with a non-global RegExp argument");
34538
+ }
34539
+ var bindThis = this;
34540
+ return function() {
34541
+ var matchResult, matchFlag, matchPattern, _tmp, _tmp1, _i, index, item;
34542
+ return __generator(this, function(_state) {
34543
+ switch(_state.label){
34544
+ case 0:
34545
+ matchResult = bindThis.match(pattern);
34546
+ if (matchResult == null) return [
34547
+ 2,
34548
+ null
34549
+ ];
34550
+ matchFlag = flags.split("g").join("");
34551
+ matchPattern = new RegExp(pattern.source, matchFlag);
34552
+ _tmp = [];
34553
+ for(_tmp1 in matchResult)_tmp.push(_tmp1);
34554
+ _i = 0;
34555
+ _state.label = 1;
34556
+ case 1:
34557
+ if (!(_i < _tmp.length)) return [
34558
+ 3,
34559
+ 4
34560
+ ];
34561
+ index = _tmp[_i];
34562
+ item = matchResult[index];
34563
+ return [
34564
+ 4,
34565
+ item.match(matchPattern)
34566
+ ];
34567
+ case 2:
34568
+ _state.sent();
34569
+ _state.label = 3;
34570
+ case 3:
34571
+ _i++;
34572
+ return [
34573
+ 3,
34574
+ 1
34575
+ ];
34576
+ case 4:
34577
+ return [
34578
+ 2
34579
+ ];
34580
+ }
34581
+ });
34582
+ }();
34583
+ };
34584
+ }
34585
+ };
34586
+ return Polyfill;
34587
+ }();
34588
+
34589
+ Polyfill.registerPolyfill();
34590
+
33595
34591
  exports.AmbientLight = AmbientLight;
33596
34592
  exports.AnimationClip = AnimationClip;
33597
34593
  exports.AnimationClipCurveBinding = AnimationClipCurveBinding;
@@ -33611,6 +34607,9 @@ exports.AnimatorStateMachine = AnimatorStateMachine;
33611
34607
  exports.AnimatorStateTransition = AnimatorStateTransition;
33612
34608
  exports.AssetPromise = AssetPromise;
33613
34609
  exports.AssetType = AssetType;
34610
+ exports.AudioClip = AudioClip;
34611
+ exports.AudioManager = AudioManager;
34612
+ exports.AudioSource = AudioSource;
33614
34613
  exports.Background = Background;
33615
34614
  exports.BackgroundMode = BackgroundMode;
33616
34615
  exports.BackgroundTextureFillMode = BackgroundTextureFillMode;