@galacean/engine 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/browser.js CHANGED
@@ -5108,6 +5108,97 @@
5108
5108
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5109
5109
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5110
5110
  }
5111
+ function __generator$1(thisArg, body) {
5112
+ var _ = {
5113
+ label: 0,
5114
+ sent: function sent() {
5115
+ if (t[0] & 1) throw t[1];
5116
+ return t[1];
5117
+ },
5118
+ trys: [],
5119
+ ops: []
5120
+ }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
5121
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
5122
+ return this;
5123
+ }), g;
5124
+ function verb(n) {
5125
+ return function(v) {
5126
+ return step([
5127
+ n,
5128
+ v
5129
+ ]);
5130
+ };
5131
+ }
5132
+ function step(op) {
5133
+ if (f) throw new TypeError("Generator is already executing.");
5134
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
5135
+ 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;
5136
+ if (y = 0, t) op = [
5137
+ op[0] & 2,
5138
+ t.value
5139
+ ];
5140
+ switch(op[0]){
5141
+ case 0:
5142
+ case 1:
5143
+ t = op;
5144
+ break;
5145
+ case 4:
5146
+ _.label++;
5147
+ return {
5148
+ value: op[1],
5149
+ done: false
5150
+ };
5151
+ case 5:
5152
+ _.label++;
5153
+ y = op[1];
5154
+ op = [
5155
+ 0
5156
+ ];
5157
+ continue;
5158
+ case 7:
5159
+ op = _.ops.pop();
5160
+ _.trys.pop();
5161
+ continue;
5162
+ default:
5163
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
5164
+ _ = 0;
5165
+ continue;
5166
+ }
5167
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
5168
+ _.label = op[1];
5169
+ break;
5170
+ }
5171
+ if (op[0] === 6 && _.label < t[1]) {
5172
+ _.label = t[1];
5173
+ t = op;
5174
+ break;
5175
+ }
5176
+ if (t && _.label < t[2]) {
5177
+ _.label = t[2];
5178
+ _.ops.push(op);
5179
+ break;
5180
+ }
5181
+ if (t[2]) _.ops.pop();
5182
+ _.trys.pop();
5183
+ continue;
5184
+ }
5185
+ op = body.call(thisArg, _);
5186
+ } catch (e) {
5187
+ op = [
5188
+ 6,
5189
+ e
5190
+ ];
5191
+ y = 0;
5192
+ } finally{
5193
+ f = t = 0;
5194
+ }
5195
+ if (op[0] & 5) throw op[1];
5196
+ return {
5197
+ value: op[0] ? op[1] : void 0,
5198
+ done: true
5199
+ };
5200
+ }
5201
+ }
5111
5202
  typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
5112
5203
  var e = new Error(message);
5113
5204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -10036,11 +10127,13 @@
10036
10127
  /**
10037
10128
  * @internal
10038
10129
  * @todo Should merge when we can delete material render state
10039
- */ _proto._applyRenderQueueByShaderData = function _applyRenderQueueByShaderData(renderStateDataMap, shaderData) {
10130
+ */ _proto._getRenderQueueByShaderData = function _getRenderQueueByShaderData(renderStateDataMap, shaderData) {
10040
10131
  var renderQueueType = renderStateDataMap[RenderStateElementKey.RenderQueueType];
10041
- if (renderQueueType !== undefined) {
10132
+ if (renderQueueType === undefined) {
10133
+ return this.renderQueueType;
10134
+ } else {
10042
10135
  var _shaderData_getFloat;
10043
- this.renderQueueType = (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
10136
+ return (_shaderData_getFloat = shaderData.getFloat(renderQueueType)) != null ? _shaderData_getFloat : RenderQueueType.Opaque;
10044
10137
  }
10045
10138
  };
10046
10139
  _proto._applyStatesByShaderData = function _applyStatesByShaderData(renderStateDataMap, shaderData) {
@@ -10843,12 +10936,18 @@
10843
10936
  /**
10844
10937
  * @internal
10845
10938
  */ ComponentsDependencies._removeCheck = function _removeCheck(entity, type) {
10939
+ var components = entity._components;
10940
+ var n = components.length;
10846
10941
  while(type !== Component){
10942
+ var count = 0;
10943
+ for(var i = 0; i < n; i++){
10944
+ if (_instanceof1$2(components[i], type) && ++count > 1) return;
10945
+ }
10847
10946
  var invDependencies = ComponentsDependencies._invDependenciesMap.get(type);
10848
10947
  if (invDependencies) {
10849
- for(var i = 0, len = invDependencies.length; i < len; i++){
10850
- if (entity.getComponent(invDependencies[i])) {
10851
- throw "Should remove " + invDependencies[i].name + " before adding " + type.name;
10948
+ for(var i1 = 0, len = invDependencies.length; i1 < len; i1++){
10949
+ if (entity.getComponent(invDependencies[i1])) {
10950
+ throw "Should remove " + invDependencies[i1].name + " before remove " + type.name;
10852
10951
  }
10853
10952
  }
10854
10953
  }
@@ -10956,7 +11055,7 @@
10956
11055
  _inherits$2(Transform, Component);
10957
11056
  function Transform(entity) {
10958
11057
  var _this;
10959
- _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188, /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
11058
+ _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._localUniformScaling = true, _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._worldUniformScaling = true, _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 188;
10960
11059
  _this._onPositionChanged = _this._onPositionChanged.bind(_this);
10961
11060
  _this._onWorldPositionChanged = _this._onWorldPositionChanged.bind(_this);
10962
11061
  _this._onRotationChanged = _this._onRotationChanged.bind(_this);
@@ -11104,16 +11203,10 @@
11104
11203
  rotMat.getRotation(this._worldRotationQuaternion);
11105
11204
  };
11106
11205
  /**
11107
- * Register world transform change flag.
11108
- * @returns Change flag
11109
- */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
11110
- return this._updateFlagManager.createFlag(BoolUpdateFlag);
11111
- };
11112
- /**
11113
11206
  * @internal
11114
11207
  */ _proto._parentChange = function _parentChange() {
11115
11208
  this._isParentDirty = true;
11116
- this._updateAllWorldFlag();
11209
+ this._updateAllWorldFlag(444);
11117
11210
  };
11118
11211
  /**
11119
11212
  * @internal
@@ -11124,6 +11217,13 @@
11124
11217
  scale.z < 0 && (isInvert = !isInvert);
11125
11218
  return isInvert;
11126
11219
  };
11220
+ /**
11221
+ * @internal
11222
+ */ _proto._copyFrom = function _copyFrom(transform) {
11223
+ this._position.copyFrom(transform.position);
11224
+ this._rotation.copyFrom(transform.rotation);
11225
+ this._scale.copyFrom(transform.scale);
11226
+ };
11127
11227
  _proto._onDestroy = function _onDestroy() {
11128
11228
  Component.prototype._onDestroy.call(this);
11129
11229
  //@ts-ignore
@@ -11148,10 +11248,10 @@
11148
11248
  */ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
11149
11249
  if (!this._isContainDirtyFlags(132)) {
11150
11250
  this._worldAssociatedChange(132);
11151
- var nodeChildren = this._entity._children;
11152
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11153
- var _nodeChildren_i_transform;
11154
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionFlag();
11251
+ var children = this._entity._children;
11252
+ for(var i = 0, n = children.length; i < n; i++){
11253
+ var _children_i_transform;
11254
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionFlag();
11155
11255
  }
11156
11256
  }
11157
11257
  };
@@ -11160,14 +11260,19 @@
11160
11260
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
11161
11261
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
11162
11262
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
11263
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
11163
11264
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
11164
11265
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
11165
- if (!this._isContainDirtyFlags(152)) {
11166
- this._worldAssociatedChange(152);
11167
- var nodeChildren = this._entity._children;
11168
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11169
- var _nodeChildren_i_transform;
11170
- (_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.
11266
+ var parent = this._getParentTransform();
11267
+ var parentWorldUniformScaling = parent ? parent._getWorldUniformScaling() : true;
11268
+ var flags = parentWorldUniformScaling ? 152 : 184;
11269
+ if (!this._isContainDirtyFlags(flags)) {
11270
+ this._worldAssociatedChange(flags);
11271
+ flags = this._getWorldUniformScaling() ? 156 : 188;
11272
+ var children = this._entity._children;
11273
+ for(var i = 0, n = children.length; i < n; i++){
11274
+ var _children_i_transform;
11275
+ (_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.
11171
11276
  }
11172
11277
  }
11173
11278
  };
@@ -11176,14 +11281,17 @@
11176
11281
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
11177
11282
  * Get worldRotationQuaternion: Will trigger the world rotation (in quaternion) update of itself and all parent entities.
11178
11283
  * Get worldRotation: Will trigger the world rotation(in euler and quaternion) update of itself and world rotation(in quaternion) update of all parent entities.
11284
+ * Get worldScale: Will trigger the scaling update of itself and all parent entities.
11179
11285
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix or worldRotationQuaternion) to be false.
11180
- */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag() {
11181
- if (!this._isContainDirtyFlags(156)) {
11182
- this._worldAssociatedChange(156);
11183
- var nodeChildren = this._entity._children;
11184
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11185
- var _nodeChildren_i_transform;
11186
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndRotationFlag();
11286
+ * @param flags - Dirty flag
11287
+ */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag(flags) {
11288
+ if (!this._isContainDirtyFlags(flags)) {
11289
+ this._worldAssociatedChange(flags);
11290
+ flags = this._getWorldUniformScaling() ? 156 : 188;
11291
+ var children = this._entity._children;
11292
+ for(var i = 0, n = children.length; i < n; i++){
11293
+ var _children_i_transform;
11294
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndRotationFlag(flags);
11187
11295
  }
11188
11296
  }
11189
11297
  };
@@ -11192,13 +11300,15 @@
11192
11300
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
11193
11301
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
11194
11302
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
11195
- */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
11196
- if (!this._isContainDirtyFlags(160)) {
11197
- this._worldAssociatedChange(160);
11198
- var nodeChildren = this._entity._children;
11199
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11200
- var _nodeChildren_i_transform;
11201
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
11303
+ * @param flags - Dirty flag
11304
+ */ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag(flags) {
11305
+ if (!this._isContainDirtyFlags(flags)) {
11306
+ this._worldAssociatedChange(flags);
11307
+ flags |= 4;
11308
+ var children = this._entity._children;
11309
+ for(var i = 0, n = children.length; i < n; i++){
11310
+ var _children_i_transform;
11311
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
11202
11312
  }
11203
11313
  }
11204
11314
  };
@@ -11207,25 +11317,27 @@
11207
11317
  * Get worldPosition: Will trigger the worldMatrix, local position update of itself and the worldMatrix update of all parent entities.
11208
11318
  * Get worldScale: Will trigger the scaling update of itself and all parent entities.
11209
11319
  * In summary, any update of related variables will cause the dirty mark of one of the full process (worldMatrix) to be false.
11210
- */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag() {
11211
- if (!this._isContainDirtyFlags(164)) {
11212
- this._worldAssociatedChange(164);
11213
- var nodeChildren = this._entity._children;
11214
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11215
- var _nodeChildren_i_transform;
11216
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateWorldPositionAndScaleFlag();
11320
+ * @param flags - Dirty flag
11321
+ */ _proto._updateWorldPositionAndScaleFlag = function _updateWorldPositionAndScaleFlag(flags) {
11322
+ if (!this._isContainDirtyFlags(flags)) {
11323
+ this._worldAssociatedChange(flags);
11324
+ var children = this._entity._children;
11325
+ for(var i = 0, n = children.length; i < n; i++){
11326
+ var _children_i_transform;
11327
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateWorldPositionAndScaleFlag(flags);
11217
11328
  }
11218
11329
  }
11219
11330
  };
11220
11331
  /**
11221
11332
  * Update all world transform property dirty flag, the principle is the same as above.
11222
- */ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
11223
- if (!this._isContainDirtyFlags(188)) {
11224
- this._worldAssociatedChange(188);
11225
- var nodeChildren = this._entity._children;
11226
- for(var i = 0, n = nodeChildren.length; i < n; i++){
11227
- var _nodeChildren_i_transform;
11228
- (_nodeChildren_i_transform = nodeChildren[i].transform) == null ? void 0 : _nodeChildren_i_transform._updateAllWorldFlag();
11333
+ * @param flags - Dirty flag
11334
+ */ _proto._updateAllWorldFlag = function _updateAllWorldFlag(flags) {
11335
+ if (!this._isContainDirtyFlags(flags)) {
11336
+ this._worldAssociatedChange(flags);
11337
+ var children = this._entity._children;
11338
+ for(var i = 0, n = children.length; i < n; i++){
11339
+ var _children_i_transform;
11340
+ (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._updateAllWorldFlag(flags);
11229
11341
  }
11230
11342
  }
11231
11343
  };
@@ -11273,7 +11385,7 @@
11273
11385
  };
11274
11386
  _proto._worldAssociatedChange = function _worldAssociatedChange(type) {
11275
11387
  this._dirtyFlag |= type;
11276
- this._updateFlagManager.dispatch(128);
11388
+ this._entity._updateFlagManager.dispatch(type);
11277
11389
  };
11278
11390
  _proto._rotateByQuat = function _rotateByQuat(rotateQuat, relativeToLocal) {
11279
11391
  if (relativeToLocal) {
@@ -11342,8 +11454,36 @@
11342
11454
  this._setDirtyFlagFalse(16);
11343
11455
  };
11344
11456
  _proto._onScaleChanged = function _onScaleChanged() {
11457
+ var _this__scale = this._scale, x = _this__scale.x, y = _this__scale.y, z = _this__scale.z;
11345
11458
  this._setDirtyFlagTrue(64);
11346
- this._updateWorldScaleFlag();
11459
+ var localUniformScaling = x == y && y == z;
11460
+ if (this._localUniformScaling !== localUniformScaling) {
11461
+ this._localUniformScaling = localUniformScaling;
11462
+ this._updateWorldScaleFlag(416);
11463
+ } else {
11464
+ this._updateWorldScaleFlag(160);
11465
+ }
11466
+ };
11467
+ _proto._getWorldUniformScaling = function _getWorldUniformScaling() {
11468
+ if (this._isContainDirtyFlag(256)) {
11469
+ var localUniformScaling = this._localUniformScaling;
11470
+ if (localUniformScaling) {
11471
+ var parent = this._getParentTransform();
11472
+ this._worldUniformScaling = localUniformScaling && (parent ? parent._getWorldUniformScaling() : true);
11473
+ } else {
11474
+ this._worldUniformScaling = false;
11475
+ }
11476
+ this._setDirtyFlagFalse(256);
11477
+ }
11478
+ return this._worldUniformScaling;
11479
+ };
11480
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
11481
+ /**
11482
+ * @deprecated
11483
+ * Listen for changes in the world pose of this `Entity`.
11484
+ * @returns Change flag
11485
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
11486
+ return this.entity._updateFlagManager.createFlag(BoolUpdateFlag);
11347
11487
  };
11348
11488
  _create_class$2(Transform, [
11349
11489
  {
@@ -11510,11 +11650,12 @@
11510
11650
  key: "lossyWorldScale",
11511
11651
  get: /**
11512
11652
  * Local lossy scaling.
11513
- * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has scaling,
11514
- * and the child node has a rotation), the scaling will be tilted. Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3.
11653
+ * @remarks The value obtained may not be correct under certain conditions(for example, the parent node has non-uniform world scaling,
11654
+ * and the child node has a rotation), the scaling will be tilted.
11515
11655
  */ function get() {
11516
11656
  if (this._isContainDirtyFlag(32)) {
11517
11657
  if (this._getParentTransform()) {
11658
+ // Vector3 cannot be used to correctly represent the scaling. Must use Matrix3x3
11518
11659
  var scaleMat = this._getScaleMatrix();
11519
11660
  var e = scaleMat.elements;
11520
11661
  this._lossyWorldScale.set(e[0], e[4], e[8]);
@@ -11542,18 +11683,25 @@
11542
11683
  if (this._localMatrix !== value) {
11543
11684
  this._localMatrix.copyFrom(value);
11544
11685
  }
11686
+ var _this = this, position = _this._position, rotationQuaternion = _this._rotationQuaternion, scale = _this._scale;
11545
11687
  // @ts-ignore
11546
- this._position._onValueChanged = this._rotationQuaternion._onValueChanged = this._scale._onValueChanged = null;
11547
- this._localMatrix.decompose(this._position, this._rotationQuaternion, this._scale);
11688
+ position._onValueChanged = rotationQuaternion._onValueChanged = scale._onValueChanged = null;
11689
+ this._localMatrix.decompose(position, rotationQuaternion, scale);
11548
11690
  // @ts-ignore
11549
- this._position._onValueChanged = this._onPositionChanged;
11691
+ position._onValueChanged = this._onPositionChanged;
11550
11692
  // @ts-ignore
11551
- this._rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
11693
+ rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
11552
11694
  // @ts-ignore
11553
- this._scale._onValueChanged = this._onScaleChanged;
11695
+ scale._onValueChanged = this._onScaleChanged;
11554
11696
  this._setDirtyFlagTrue(1);
11555
11697
  this._setDirtyFlagFalse(64 | 2);
11556
- this._updateAllWorldFlag();
11698
+ var localUniformScaling = scale.x === scale.y && scale.y === scale.z;
11699
+ if (this._localUniformScaling !== localUniformScaling) {
11700
+ this._localUniformScaling = localUniformScaling;
11701
+ this._updateAllWorldFlag(444);
11702
+ } else {
11703
+ this._updateAllWorldFlag(188);
11704
+ }
11557
11705
  }
11558
11706
  },
11559
11707
  {
@@ -11645,6 +11793,9 @@
11645
11793
  __decorate$1([
11646
11794
  deepClone
11647
11795
  ], Transform.prototype, "_scale", void 0);
11796
+ __decorate$1([
11797
+ assignmentClone
11798
+ ], Transform.prototype, "_localUniformScaling", void 0);
11648
11799
  __decorate$1([
11649
11800
  deepClone
11650
11801
  ], Transform.prototype, "_worldPosition", void 0);
@@ -11654,6 +11805,9 @@
11654
11805
  __decorate$1([
11655
11806
  deepClone
11656
11807
  ], Transform.prototype, "_worldRotationQuaternion", void 0);
11808
+ __decorate$1([
11809
+ assignmentClone
11810
+ ], Transform.prototype, "_worldUniformScaling", void 0);
11657
11811
  __decorate$1([
11658
11812
  deepClone
11659
11813
  ], Transform.prototype, "_lossyWorldScale", void 0);
@@ -11678,9 +11832,6 @@
11678
11832
  __decorate$1([
11679
11833
  ignoreClone
11680
11834
  ], Transform.prototype, "_parentTransformCache", void 0);
11681
- __decorate$1([
11682
- ignoreClone
11683
- ], Transform.prototype, "_updateFlagManager", void 0);
11684
11835
  __decorate$1([
11685
11836
  ignoreClone
11686
11837
  ], Transform.prototype, "_onPositionChanged", null);
@@ -11713,12 +11864,18 @@
11713
11864
  TransformModifyFlags[TransformModifyFlags["WorldScale"] = 32] = "WorldScale";
11714
11865
  TransformModifyFlags[TransformModifyFlags["LocalMatrix"] = 64] = "LocalMatrix";
11715
11866
  TransformModifyFlags[TransformModifyFlags["WorldMatrix"] = 128] = "WorldMatrix";
11867
+ /** This is an internal flag used to assist in determining the dispatch
11868
+ * of world scaling dirty flags in the case of non-uniform scaling.
11869
+ */ TransformModifyFlags[TransformModifyFlags["IsWorldUniformScaling"] = 256] = "IsWorldUniformScaling";
11716
11870
  /** WorldMatrix | WorldPosition */ TransformModifyFlags[TransformModifyFlags["WmWp"] = 132] = "WmWp";
11717
11871
  /** WorldMatrix | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWeWq"] = 152] = "WmWeWq";
11872
+ /** WorldMatrix | WorldEuler | WorldQuat | WorldScale*/ TransformModifyFlags[TransformModifyFlags["WmWeWqWs"] = 184] = "WmWeWqWs";
11718
11873
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWpWeWq"] = 156] = "WmWpWeWq";
11719
11874
  /** WorldMatrix | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWs"] = 160] = "WmWs";
11875
+ /** WorldMatrix | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWsWus"] = 416] = "WmWsWus";
11720
11876
  /** WorldMatrix | WorldPosition | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWs"] = 164] = "WmWpWs";
11721
11877
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWs"] = 188] = "WmWpWeWqWs";
11878
+ /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWsWus"] = 444] = "WmWpWeWqWsWus";
11722
11879
  return TransformModifyFlags;
11723
11880
  }({});
11724
11881
  /**
@@ -11771,7 +11928,7 @@
11771
11928
  _this._overrideUpdate = _this.update !== prototype.update;
11772
11929
  _this._addResourceReferCount(_this.shaderData, 1);
11773
11930
  _this._onTransformChanged = _this._onTransformChanged.bind(_this);
11774
- _this._setTransform(entity.transform);
11931
+ _this._setTransformEntity(entity);
11775
11932
  shaderData.enableMacro(Renderer._receiveShadowMacro);
11776
11933
  shaderData.setVector4(Renderer._rendererLayerProperty, _this._rendererLayer);
11777
11934
  return _this;
@@ -11897,7 +12054,7 @@
11897
12054
  * @internal
11898
12055
  */ _proto._onDestroy = function _onDestroy() {
11899
12056
  Component.prototype._onDestroy.call(this);
11900
- this._setTransform(null);
12057
+ this._setTransformEntity(null);
11901
12058
  this._addResourceReferCount(this.shaderData, -1);
11902
12059
  var materials = this._materials;
11903
12060
  for(var i = 0, n = materials.length; i < n; i++){
@@ -11919,7 +12076,7 @@
11919
12076
  /**
11920
12077
  * @internal
11921
12078
  */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
11922
- var worldMatrix = this._transform.worldMatrix;
12079
+ var worldMatrix = this._transformEntity.transform.worldMatrix;
11923
12080
  if (onlyMVP) {
11924
12081
  this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
11925
12082
  } else {
@@ -11958,7 +12115,7 @@
11958
12115
  Matrix.invert(mvMatrix, mvInvMatrix);
11959
12116
  Matrix.invert(worldMatrix, normalMatrix);
11960
12117
  normalMatrix.transpose();
11961
- shaderData.setMatrix(Renderer._localMatrixProperty, this._transform.localMatrix);
12118
+ shaderData.setMatrix(Renderer._localMatrixProperty, this._transformEntity.transform.localMatrix);
11962
12119
  shaderData.setMatrix(Renderer._worldMatrixProperty, worldMatrix);
11963
12120
  shaderData.setMatrix(Renderer._mvMatrixProperty, mvMatrix);
11964
12121
  shaderData.setMatrix(Renderer._mvInvMatrixProperty, mvInvMatrix);
@@ -11977,11 +12134,13 @@
11977
12134
  };
11978
12135
  /**
11979
12136
  * @internal
11980
- */ _proto._setTransform = function _setTransform(transform) {
11981
- var _this__transform;
11982
- (_this__transform = this._transform) == null ? void 0 : _this__transform._updateFlagManager.removeListener(this._onTransformChanged);
11983
- transform == null ? void 0 : transform._updateFlagManager.addListener(this._onTransformChanged);
11984
- this._transform = transform;
12137
+ */ _proto._setTransformEntity = function _setTransformEntity(entity) {
12138
+ var preEntity = this._transformEntity;
12139
+ if (entity !== preEntity) {
12140
+ preEntity == null ? void 0 : preEntity._updateFlagManager.removeListener(this._onTransformChanged);
12141
+ entity == null ? void 0 : entity._updateFlagManager.addListener(this._onTransformChanged);
12142
+ this._transformEntity = entity;
12143
+ }
11985
12144
  };
11986
12145
  /**
11987
12146
  * @internal
@@ -12132,6 +12291,9 @@
12132
12291
  __decorate$1([
12133
12292
  ignoreClone
12134
12293
  ], exports.Renderer.prototype, "_batchedTransformShaderData", void 0);
12294
+ __decorate$1([
12295
+ ignoreClone
12296
+ ], exports.Renderer.prototype, "_transformEntity", void 0);
12135
12297
  __decorate$1([
12136
12298
  ignoreClone
12137
12299
  ], exports.Renderer.prototype, "_overrideUpdate", void 0);
@@ -12144,9 +12306,6 @@
12144
12306
  __decorate$1([
12145
12307
  ignoreClone
12146
12308
  ], exports.Renderer.prototype, "_rendererLayer", void 0);
12147
- __decorate$1([
12148
- ignoreClone
12149
- ], exports.Renderer.prototype, "_transform", void 0);
12150
12309
  __decorate$1([
12151
12310
  deepClone
12152
12311
  ], exports.Renderer.prototype, "_shaderData", void 0);
@@ -13545,11 +13704,13 @@
13545
13704
  * @param viewport - Viewport
13546
13705
  * @param material - The material to use when blitting
13547
13706
  * @param passIndex - Pass index to use of the provided material
13548
- */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex) {
13707
+ * @param flipYOfSource - Whether flip Y axis of source texture
13708
+ */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex, flipYOfSource) {
13549
13709
  if (mipLevel === void 0) mipLevel = 0;
13550
13710
  if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
13551
13711
  if (material === void 0) material = null;
13552
13712
  if (passIndex === void 0) passIndex = 0;
13713
+ if (flipYOfSource === void 0) flipYOfSource = false;
13553
13714
  var basicResources = engine._basicResources;
13554
13715
  var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
13555
13716
  var blitMaterial = material || basicResources.blitMaterial;
@@ -13563,9 +13724,15 @@
13563
13724
  rendererShaderData.setFloat(PipelineUtils._blitMipLevelProperty, mipLevel);
13564
13725
  PipelineUtils._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
13565
13726
  rendererShaderData.setVector4(PipelineUtils._blitTexelSizeProperty, PipelineUtils._texelSize);
13727
+ if (flipYOfSource) {
13728
+ rendererShaderData.enableMacro(PipelineUtils._flipYTextureMacro);
13729
+ } else {
13730
+ rendererShaderData.disableMacro(PipelineUtils._flipYTextureMacro);
13731
+ }
13566
13732
  var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
13567
13733
  var compileMacros = Shader._compileMacros;
13568
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, blitMaterial.shaderData._macroCollection, compileMacros);
13734
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, rendererShaderData._macroCollection, compileMacros);
13735
+ ShaderMacroCollection.unionCollection(compileMacros, blitMaterial.shaderData._macroCollection, compileMacros);
13569
13736
  var program = pass._getShaderProgram(engine, compileMacros);
13570
13737
  program.bind();
13571
13738
  program.groupingOtherUniformBlock();
@@ -13581,6 +13748,7 @@
13581
13748
  PipelineUtils._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
13582
13749
  PipelineUtils._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
13583
13750
  ;
13751
+ PipelineUtils._flipYTextureMacro = ShaderMacro.getByName("renderer_FlipYBlitTexture");
13584
13752
  PipelineUtils._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
13585
13753
  PipelineUtils._texelSize = new Vector4();
13586
13754
  PipelineUtils.defaultViewport = new Vector4(0, 0, 1, 1);
@@ -13676,13 +13844,11 @@
13676
13844
  */ _this.opaqueTextureDownsampling = Downsampling.TwoX, /**
13677
13845
  * Multi-sample anti-aliasing samples when use independent canvas mode.
13678
13846
  *
13679
- * @remarks The `independentCanvasEnabled` property should be `true` to take effect, otherwise it will be invalid.
13847
+ * @remarks It will take effect when `independentCanvasEnabled` property is `true`, otherwise it will be invalid.
13680
13848
  */ _this.msaaSamples = MSAASamples.None, /** @internal */ _this._cameraType = CameraType$1.Normal, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._frustum = new BoundingFrustum(), /** @internal */ _this._virtualCamera = new VirtualCamera(), /** @internal */ _this._replacementShader = null, /** @internal */ _this._replacementSubShaderTag = null, /** @internal */ _this._replacementFailureStrategy = null, /** @internal */ _this._cameraIndex = -1, _this._priority = 0, _this._shaderData = new ShaderData(ShaderDataGroup.Camera), _this._isCustomViewMatrix = false, _this._isCustomProjectionMatrix = false, _this._fieldOfView = 45, _this._orthographicSize = 10, _this._isProjectionDirty = true, _this._isInvProjMatDirty = true, _this._customAspectRatio = undefined, _this._renderTarget = null, _this._depthBufferParams = new Vector4(), _this._opaqueTextureEnabled = false, _this._enableHDR = false, _this._enablePostProcess = false, _this._viewport = new Vector4(0, 0, 1, 1), _this._pixelViewport = new Rect(0, 0, 0, 0), _this._inverseProjectionMatrix = new Matrix(), _this._invViewProjMat = new Matrix();
13681
- var transform = _this.entity.transform;
13682
- _this._transform = transform;
13683
- _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
13684
- _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
13685
- _this._frustumChangeFlag = transform.registerWorldChangeFlag();
13849
+ _this._isViewMatrixDirty = entity.registerWorldChangeFlag();
13850
+ _this._isInvViewProjDirty = entity.registerWorldChangeFlag();
13851
+ _this._frustumChangeFlag = entity.registerWorldChangeFlag();
13686
13852
  _this._renderPipeline = new BasicRenderPipeline(_this);
13687
13853
  _this._addResourceReferCount(_this.shaderData, 1);
13688
13854
  _this._updatePixelViewport();
@@ -13829,7 +13995,7 @@
13829
13995
  var engine = this._engine;
13830
13996
  var context = engine._renderContext;
13831
13997
  var virtualCamera = this._virtualCamera;
13832
- var transform = this.entity.transform;
13998
+ var transform = this._entity.transform;
13833
13999
  Matrix.multiply(this.projectionMatrix, this.viewMatrix, virtualCamera.viewProjectionMatrix);
13834
14000
  virtualCamera.position.copyFrom(transform.worldPosition);
13835
14001
  if (virtualCamera.isOrthographic) {
@@ -13907,7 +14073,6 @@
13907
14073
  this._virtualCamera = null;
13908
14074
  this._shaderData = null;
13909
14075
  this._frustumChangeFlag = null;
13910
- this._transform = null;
13911
14076
  this._isViewMatrixDirty = null;
13912
14077
  this._isInvViewProjDirty = null;
13913
14078
  this._viewport = null;
@@ -13949,7 +14114,7 @@
13949
14114
  };
13950
14115
  _proto._updateShaderData = function _updateShaderData() {
13951
14116
  var shaderData = this.shaderData;
13952
- var transform = this._transform;
14117
+ var transform = this._entity.transform;
13953
14118
  shaderData.setMatrix(Camera._inverseViewMatrixProperty, transform.worldMatrix);
13954
14119
  shaderData.setVector3(Camera._cameraPositionProperty, transform.worldPosition);
13955
14120
  shaderData.setVector3(Camera._cameraForwardProperty, transform.worldForward);
@@ -13964,7 +14129,7 @@
13964
14129
  */ _proto._getInvViewProjMat = function _getInvViewProjMat() {
13965
14130
  if (this._isInvViewProjDirty.flag) {
13966
14131
  this._isInvViewProjDirty.flag = false;
13967
- Matrix.multiply(this._transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
14132
+ Matrix.multiply(this._entity.transform.worldMatrix, this._getInverseProjectionMatrix(), this._invViewProjMat);
13968
14133
  }
13969
14134
  return this._invViewProjMat;
13970
14135
  };
@@ -14011,13 +14176,17 @@
14011
14176
  key: "independentCanvasEnabled",
14012
14177
  get: /**
14013
14178
  * Whether independent canvas is enabled.
14014
- *
14015
14179
  * @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
14016
14180
  */ function get() {
14017
- if (this.enableHDR || this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
14181
+ // Uber pass need internal RT
14182
+ if (this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
14018
14183
  return true;
14019
14184
  }
14020
- return this.opaqueTextureEnabled && !this._renderTarget;
14185
+ if (this.enableHDR || this.opaqueTextureEnabled) {
14186
+ var _this_renderTarget;
14187
+ return this._getInternalColorTextureFormat() !== ((_this_renderTarget = this.renderTarget) == null ? void 0 : _this_renderTarget.getColorTexture(0).format);
14188
+ }
14189
+ return false;
14021
14190
  }
14022
14191
  },
14023
14192
  {
@@ -14159,7 +14328,7 @@
14159
14328
  }
14160
14329
  this._isViewMatrixDirty.flag = false;
14161
14330
  // Ignore scale
14162
- var transform = this._transform;
14331
+ var transform = this._entity.transform;
14163
14332
  Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
14164
14333
  viewMatrix.invert();
14165
14334
  return viewMatrix;
@@ -14277,9 +14446,6 @@
14277
14446
  __decorate$1([
14278
14447
  ignoreClone
14279
14448
  ], exports.Camera.prototype, "_frustumChangeFlag", void 0);
14280
- __decorate$1([
14281
- ignoreClone
14282
- ], exports.Camera.prototype, "_transform", void 0);
14283
14449
  __decorate$1([
14284
14450
  ignoreClone
14285
14451
  ], exports.Camera.prototype, "_isViewMatrixDirty", void 0);
@@ -14460,9 +14626,21 @@
14460
14626
  if (shaderPass.getTagValue(pipelineStageKey) !== pipelineStageTagValue) {
14461
14627
  continue;
14462
14628
  }
14463
- if (!needMaskType) {
14464
- var _shaderPass__renderState;
14465
- if (((_shaderPass__renderState = shaderPass._renderState) != null ? _shaderPass__renderState : renderStates[j]).renderQueueType !== renderQueueType) {
14629
+ var renderState = shaderPass._renderState;
14630
+ if (needMaskType) {
14631
+ // Mask don't care render queue type
14632
+ if (!renderState) {
14633
+ renderState = renderStates[j];
14634
+ }
14635
+ } else {
14636
+ var passQueueType = void 0;
14637
+ if (renderState) {
14638
+ passQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, materialData);
14639
+ } else {
14640
+ renderState = renderStates[j];
14641
+ passQueueType = renderState.renderQueueType;
14642
+ }
14643
+ if (passQueueType !== renderQueueType) {
14466
14644
  continue;
14467
14645
  }
14468
14646
  }
@@ -14517,9 +14695,7 @@
14517
14695
  program.uploadUnGroupTextures();
14518
14696
  }
14519
14697
  }
14520
- var _shaderPass__renderState1;
14521
- var renderState = (_shaderPass__renderState1 = shaderPass._renderState) != null ? _shaderPass__renderState1 : renderStates[j];
14522
- renderState._applyStates(engine, renderer.entity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
14698
+ renderState._applyStates(engine, renderer._transformEntity.transform._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates);
14523
14699
  rhi.drawPrimitive(primitive, subElement.subPrimitive, program);
14524
14700
  }
14525
14701
  }
@@ -15368,6 +15544,8 @@
15368
15544
  function BasicRenderPipeline(camera) {
15369
15545
  this._lastCanvasSize = new Vector2();
15370
15546
  this._internalColorTarget = null;
15547
+ this._canUseBlitFrameBuffer = false;
15548
+ this._shouldGrabColor = false;
15371
15549
  this._camera = camera;
15372
15550
  var engine = camera.engine;
15373
15551
  this._cullingResults = new CullingResults();
@@ -15392,10 +15570,19 @@
15392
15570
  context.rendererUpdateFlag = ContextRendererUpdateFlag.All;
15393
15571
  var camera = this._camera;
15394
15572
  var scene = camera.scene, engine = camera.engine;
15573
+ var rhi = engine._hardwareRenderer;
15395
15574
  var cullingResults = this._cullingResults;
15396
15575
  var sunlight = scene._lightManager._sunlight;
15397
15576
  var depthOnlyPass = this._depthOnlyPass;
15398
15577
  var depthPassEnabled = camera.depthTextureMode === DepthTextureMode.PrePass && depthOnlyPass._supportDepthTexture;
15578
+ var finalClearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
15579
+ var independentCanvasEnabled = camera.independentCanvasEnabled;
15580
+ var msaaSamples = camera.renderTarget ? camera.renderTarget.antiAliasing : camera.msaaSamples;
15581
+ this._shouldGrabColor = independentCanvasEnabled && !(finalClearFlags & CameraClearFlags.Color);
15582
+ // 1. Only support blitFramebuffer in webgl2 context
15583
+ // 2. Can't blit normal FBO to MSAA FBO
15584
+ // 3. Can't blit screen MSAA FBO to normal FBO in mac safari platform and mobile, but mac chrome and firfox is OK
15585
+ this._canUseBlitFrameBuffer = rhi.isWebGL2 && msaaSamples === 1 && (!!camera.renderTarget || !rhi.context.antialias);
15399
15586
  if (scene.castShadows && sunlight && sunlight.shadowType !== ShadowType.None) {
15400
15587
  this._cascadedShadowCasterPass.onRender(context);
15401
15588
  context.rendererUpdateFlag = ContextRendererUpdateFlag.None;
@@ -15415,24 +15602,46 @@
15415
15602
  } else {
15416
15603
  camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
15417
15604
  }
15418
- // Check if need to create internal color texture
15419
- var independentCanvasEnabled = camera.independentCanvasEnabled;
15605
+ // Check if need to create internal color texture or grab texture
15420
15606
  if (independentCanvasEnabled) {
15607
+ var depthFormat;
15608
+ if (camera.renderTarget) {
15609
+ depthFormat = camera.renderTarget._depthFormat;
15610
+ } else if (rhi.context.depth && rhi.context.stencil) {
15611
+ depthFormat = TextureFormat.Depth24Stencil8;
15612
+ } else if (rhi.context.depth) {
15613
+ depthFormat = TextureFormat.Depth24;
15614
+ } else if (rhi.context.stencil) {
15615
+ depthFormat = TextureFormat.Stencil;
15616
+ } else {
15617
+ depthFormat = null;
15618
+ }
15421
15619
  var viewport = camera.pixelViewport;
15422
- var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), TextureFormat.Depth24Stencil8, false, false, camera.msaaSamples, TextureWrapMode$1.Clamp, TextureFilterMode.Bilinear);
15620
+ var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, msaaSamples, TextureWrapMode$1.Clamp, TextureFilterMode.Bilinear);
15621
+ if (!this._canUseBlitFrameBuffer && this._shouldGrabColor) {
15622
+ var _camera_renderTarget;
15623
+ var _camera_renderTarget_getColorTexture_format;
15624
+ 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$1.Clamp, TextureFilterMode.Bilinear);
15625
+ this._grabTexture = grabTexture;
15626
+ }
15423
15627
  this._internalColorTarget = internalColorTarget;
15424
15628
  } else {
15425
15629
  var internalColorTarget1 = this._internalColorTarget;
15630
+ var grabTexture1 = this._grabTexture;
15426
15631
  if (internalColorTarget1) {
15427
15632
  var _internalColorTarget_getColorTexture;
15428
15633
  (_internalColorTarget_getColorTexture = internalColorTarget1.getColorTexture(0)) == null ? void 0 : _internalColorTarget_getColorTexture.destroy(true);
15429
15634
  internalColorTarget1.destroy(true);
15430
15635
  this._internalColorTarget = null;
15431
15636
  }
15637
+ if (grabTexture1) {
15638
+ grabTexture1.destroy(true);
15639
+ this._grabTexture = null;
15640
+ }
15432
15641
  }
15433
- this._drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear);
15642
+ this._drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel);
15434
15643
  };
15435
- _proto._drawRenderPass = function _drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear) {
15644
+ _proto._drawRenderPass = function _drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel) {
15436
15645
  var cullingResults = this._cullingResults;
15437
15646
  var opaqueQueue = cullingResults.opaqueQueue, alphaTestQueue = cullingResults.alphaTestQueue, transparentQueue = cullingResults.transparentQueue;
15438
15647
  var engine = camera.engine, scene = camera.scene;
@@ -15448,18 +15657,37 @@
15448
15657
  context.applyVirtualCamera(camera._virtualCamera, needFlipProjection);
15449
15658
  }
15450
15659
  rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
15451
- var clearFlags = camera.clearFlags & ~(ignoreClear != null ? ignoreClear : CameraClearFlags.None);
15452
15660
  var color = background.solidColor;
15453
- if (clearFlags !== CameraClearFlags.None) {
15454
- rhi.clearRenderTarget(engine, clearFlags, color);
15661
+ if (internalColorTarget && finalClearFlags !== CameraClearFlags.All) {
15662
+ // Can use `blitFramebuffer` API to copy color/depth/stencil buffer from back buffer to internal RT
15663
+ if (this._canUseBlitFrameBuffer) {
15664
+ finalClearFlags !== CameraClearFlags.None && rhi.clearRenderTarget(engine, finalClearFlags, color);
15665
+ rhi.blitInternalRTByBlitFrameBuffer(camera.renderTarget, internalColorTarget, finalClearFlags, camera.viewport);
15666
+ } else {
15667
+ if (!(finalClearFlags & CameraClearFlags.Depth) || !(finalClearFlags & CameraClearFlags.Stencil)) {
15668
+ 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");
15669
+ }
15670
+ if (this._shouldGrabColor) {
15671
+ rhi.clearRenderTarget(engine, CameraClearFlags.DepthStencil);
15672
+ // Copy RT's color buffer to grab texture
15673
+ rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._grabTexture, camera.viewport);
15674
+ // Then blit grab texture to internal RT's color buffer
15675
+ PipelineUtils.blitTexture(engine, this._grabTexture, internalColorTarget, 0, undefined, undefined, undefined, !camera.renderTarget);
15676
+ } else {
15677
+ rhi.clearRenderTarget(engine, CameraClearFlags.All, color);
15678
+ }
15679
+ }
15680
+ rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
15681
+ } else if (finalClearFlags !== CameraClearFlags.None) {
15682
+ rhi.clearRenderTarget(engine, finalClearFlags, color);
15455
15683
  }
15456
15684
  var maskManager = scene._maskManager;
15457
- if (clearFlags & CameraClearFlags.Stencil) {
15685
+ if (finalClearFlags & CameraClearFlags.Stencil) {
15458
15686
  maskManager.hasStencilWritten = false;
15459
15687
  }
15460
15688
  opaqueQueue.render(context, PipelineStage.Forward);
15461
15689
  alphaTestQueue.render(context, PipelineStage.Forward);
15462
- if (clearFlags & CameraClearFlags.Color) {
15690
+ if (finalClearFlags & CameraClearFlags.Color) {
15463
15691
  if (background.mode === BackgroundMode.Sky) {
15464
15692
  background.sky._render(context);
15465
15693
  } else if (background.mode === BackgroundMode.Texture && background.texture) {
@@ -15536,8 +15764,7 @@
15536
15764
  var shaderPass = shaderPasses[i];
15537
15765
  var renderState = shaderPass._renderState;
15538
15766
  if (renderState) {
15539
- renderState._applyRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
15540
- renderQueueType = renderState.renderQueueType;
15767
+ renderQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData);
15541
15768
  } else {
15542
15769
  renderQueueType = renderStates[i].renderQueueType;
15543
15770
  }
@@ -17786,15 +18013,29 @@
17786
18013
  _inherits$2(PBRMaterial, PBRBaseMaterial);
17787
18014
  function PBRMaterial(engine) {
17788
18015
  var _this;
17789
- _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new Vector2(100, 400);
18016
+ _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new Vector2(100, 400), _this._sheenEnabled = false;
17790
18017
  var shaderData = _this.shaderData;
17791
18018
  shaderData.setFloat(PBRMaterial._metallicProp, 1);
17792
18019
  shaderData.setFloat(PBRMaterial._roughnessProp, 1);
17793
18020
  shaderData.setFloat(PBRMaterial._iorProp, 1.5);
17794
18021
  shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
17795
18022
  shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new Vector4(0, 1.3, 100, 400));
18023
+ var sheenColor = new Color(0, 0, 0);
18024
+ shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor);
17796
18025
  // @ts-ignore
17797
18026
  _this._iridescenceRange._onValueChanged = _this._onIridescenceRangeChanged.bind(_this);
18027
+ // @ts-ignore
18028
+ sheenColor._onValueChanged = function() {
18029
+ var enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0;
18030
+ if (enableSheen !== _this._sheenEnabled) {
18031
+ _this._sheenEnabled = enableSheen;
18032
+ if (enableSheen) {
18033
+ _this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
18034
+ } else {
18035
+ _this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
18036
+ }
18037
+ }
18038
+ };
17798
18039
  return _this;
17799
18040
  }
17800
18041
  var _proto = PBRMaterial.prototype;
@@ -17975,7 +18216,7 @@
17975
18216
  key: "iridescenceThicknessRange",
17976
18217
  get: /**
17977
18218
  * The range of iridescence thickness, x is minimum, y is maximum.
17978
- * @defaultValue `[100, 400]`.
18219
+ * @defaultValue `[100, 400]`
17979
18220
  */ function get() {
17980
18221
  return this._iridescenceRange;
17981
18222
  },
@@ -18003,6 +18244,67 @@
18003
18244
  this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
18004
18245
  }
18005
18246
  }
18247
+ },
18248
+ {
18249
+ key: "sheenColor",
18250
+ get: /**
18251
+ * Sheen color.
18252
+ * @defaultValue `[0,0,0]`
18253
+ */ function get() {
18254
+ return this.shaderData.getColor(PBRMaterial._sheenColorProp);
18255
+ },
18256
+ set: function set(value) {
18257
+ var sheenColor = this.shaderData.getColor(PBRMaterial._sheenColorProp);
18258
+ if (value !== sheenColor) {
18259
+ sheenColor.copyFrom(value);
18260
+ }
18261
+ }
18262
+ },
18263
+ {
18264
+ key: "sheenRoughness",
18265
+ get: /**
18266
+ * Sheen roughness, from 0.0 to 1.0.
18267
+ * @defaultValue `0.0`
18268
+ */ function get() {
18269
+ return this.shaderData.getFloat(PBRMaterial._sheenRoughnessProp);
18270
+ },
18271
+ set: function set(value) {
18272
+ value = Math.max(0, Math.min(1, value));
18273
+ this.shaderData.setFloat(PBRMaterial._sheenRoughnessProp, value);
18274
+ }
18275
+ },
18276
+ {
18277
+ key: "sheenColorTexture",
18278
+ get: /**
18279
+ * Sheen color texture, multiply ‘sheenColor’.
18280
+ */ function get() {
18281
+ return this.shaderData.getTexture(PBRMaterial._sheenTextureProp);
18282
+ },
18283
+ set: function set(value) {
18284
+ this.shaderData.setTexture(PBRMaterial._sheenTextureProp, value);
18285
+ if (value) {
18286
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
18287
+ } else {
18288
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_TEXTURE");
18289
+ }
18290
+ }
18291
+ },
18292
+ {
18293
+ key: "sheenRoughnessTexture",
18294
+ get: /**
18295
+ * Sheen roughness texture.
18296
+ * @remarks Use alpha channel, and multiply 'sheenRoughness'.
18297
+ */ function get() {
18298
+ return this.shaderData.getTexture(PBRMaterial._sheenRoughnessTextureProp);
18299
+ },
18300
+ set: function set(value) {
18301
+ this.shaderData.setTexture(PBRMaterial._sheenRoughnessTextureProp, value);
18302
+ if (value) {
18303
+ this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
18304
+ } else {
18305
+ this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
18306
+ }
18307
+ }
18006
18308
  }
18007
18309
  ]);
18008
18310
  return PBRMaterial;
@@ -18016,6 +18318,10 @@
18016
18318
  PBRMaterial._iridescenceInfoProp = ShaderProperty.getByName("material_IridescenceInfo");
18017
18319
  PBRMaterial._iridescenceThicknessTextureProp = ShaderProperty.getByName("material_IridescenceThicknessTexture");
18018
18320
  PBRMaterial._iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture");
18321
+ PBRMaterial._sheenColorProp = ShaderProperty.getByName("material_SheenColor");
18322
+ PBRMaterial._sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness");
18323
+ PBRMaterial._sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
18324
+ PBRMaterial._sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture");
18019
18325
  /**
18020
18326
  * PBR (Specular-Glossiness Workflow) Material.
18021
18327
  */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial) {
@@ -18803,8 +19109,7 @@
18803
19109
  var mesh = this._mesh;
18804
19110
  if (mesh) {
18805
19111
  var localBounds = mesh.bounds;
18806
- var worldMatrix = this._entity.transform.worldMatrix;
18807
- BoundingBox.transform(localBounds, worldMatrix, worldBounds);
19112
+ BoundingBox.transform(localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
18808
19113
  } else {
18809
19114
  worldBounds.min.set(0, 0, 0);
18810
19115
  worldBounds.max.set(0, 0, 0);
@@ -21688,11 +21993,17 @@
21688
21993
  */ var Entity = /*#__PURE__*/ function(EngineObject) {
21689
21994
  _inherits$2(Entity, EngineObject);
21690
21995
  function Entity(engine, name) {
21996
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
21997
+ components[_key - 2] = arguments[_key];
21998
+ }
21691
21999
  var _this;
21692
- _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, _this._invModelMatrix = new Matrix();
22000
+ _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, _this._invModelMatrix = new Matrix();
21693
22001
  _this.name = name;
21694
- _this.transform = _this.addComponent(Transform);
21695
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
22002
+ for(var i = 0, n = components.length; i < n; i++){
22003
+ _this.addComponent(components[i]);
22004
+ }
22005
+ !_this._transform && _this.addComponent(Transform);
22006
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
21696
22007
  return _this;
21697
22008
  }
21698
22009
  var _proto = Entity.prototype;
@@ -21710,6 +22021,12 @@
21710
22021
  this
21711
22022
  ], args));
21712
22023
  this._components.push(component);
22024
+ // @todo: temporary solution
22025
+ if (_instanceof1$2(component, Transform)) {
22026
+ var transform = this._transform;
22027
+ this._transform = component;
22028
+ transform == null ? void 0 : transform.destroy();
22029
+ }
21713
22030
  component._setActive(true, ActiveChangeFlag.All);
21714
22031
  return component;
21715
22032
  };
@@ -21853,7 +22170,8 @@
21853
22170
  * @param name - The child entity's name
21854
22171
  * @returns The child entity
21855
22172
  */ _proto.createChild = function createChild(name) {
21856
- var child = new Entity(this.engine, name);
22173
+ var transform = this._transform;
22174
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
21857
22175
  child.layer = this.layer;
21858
22176
  child.parent = this;
21859
22177
  return child;
@@ -21882,13 +22200,20 @@
21882
22200
  return cloneEntity;
21883
22201
  };
21884
22202
  /**
22203
+ * Listen for changes in the world pose of this `Entity`.
22204
+ * @returns Change flag
22205
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
22206
+ return this._updateFlagManager.createFlag(BoolUpdateFlag);
22207
+ };
22208
+ /**
21885
22209
  * @internal
21886
22210
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
21887
22211
  this._isTemplate = true;
21888
22212
  this._templateResource = templateResource;
21889
22213
  };
21890
22214
  _proto._createCloneEntity = function _createCloneEntity() {
21891
- var cloneEntity = new Entity(this._engine, this.name);
22215
+ var transform = this._transform;
22216
+ var cloneEntity = transform ? new Entity(this.engine, this.name, transform.constructor) : new Entity(this.engine, this.name);
21892
22217
  var templateResource = this._templateResource;
21893
22218
  if (templateResource) {
21894
22219
  cloneEntity._templateResource = templateResource;
@@ -21896,11 +22221,7 @@
21896
22221
  }
21897
22222
  cloneEntity.layer = this.layer;
21898
22223
  cloneEntity._isActive = this._isActive;
21899
- var cloneTransform = cloneEntity.transform;
21900
- var _this = this, srcTransform = _this.transform;
21901
- cloneTransform.position = srcTransform.position;
21902
- cloneTransform.rotation = srcTransform.rotation;
21903
- cloneTransform.scale = srcTransform.scale;
22224
+ cloneEntity.transform._copyFrom(this.transform);
21904
22225
  var srcChildren = this._children;
21905
22226
  for(var i = 0, n = srcChildren.length; i < n; i++){
21906
22227
  cloneEntity.addChild(srcChildren[i]._createCloneEntity());
@@ -22200,6 +22521,14 @@
22200
22521
  return entity;
22201
22522
  };
22202
22523
  _create_class$2(Entity, [
22524
+ {
22525
+ key: "transform",
22526
+ get: /**
22527
+ * The transform of this entity.
22528
+ */ function get() {
22529
+ return this._transform;
22530
+ }
22531
+ },
22203
22532
  {
22204
22533
  key: "isActive",
22205
22534
  get: /**
@@ -22447,16 +22776,6 @@
22447
22776
  var _proto = SkinnedMeshRenderer.prototype;
22448
22777
  /**
22449
22778
  * @internal
22450
- */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
22451
- var worldMatrix = this._transform.worldMatrix;
22452
- if (onlyMVP) {
22453
- this._updateProjectionRelatedShaderData(context, worldMatrix, batched);
22454
- } else {
22455
- this._updateWorldViewRelatedShaderData(context, worldMatrix, batched);
22456
- }
22457
- };
22458
- /**
22459
- * @internal
22460
22779
  */ _proto._onDestroy = function _onDestroy() {
22461
22780
  var _this__jointTexture;
22462
22781
  MeshRenderer.prototype._onDestroy.call(this);
@@ -22532,7 +22851,7 @@
22532
22851
  var _this_skin;
22533
22852
  var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
22534
22853
  if (rootBone) {
22535
- BoundingBox.transform(this._localBounds, this._transform.worldMatrix, worldBounds);
22854
+ BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
22536
22855
  } else {
22537
22856
  MeshRenderer.prototype._updateBounds.call(this, worldBounds);
22538
22857
  }
@@ -22573,7 +22892,7 @@
22573
22892
  }
22574
22893
  break;
22575
22894
  case SkinUpdateFlag.RootBoneChanged:
22576
- this._setTransform(value.transform);
22895
+ this._setTransformEntity(value);
22577
22896
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
22578
22897
  break;
22579
22898
  }
@@ -23261,7 +23580,8 @@
23261
23580
  /** Scene. */ AssetType["Scene"] = "Scene";
23262
23581
  /** HDR to cube. */ AssetType["HDR"] = "HDR";
23263
23582
  /** Font. */ AssetType["Font"] = "Font";
23264
- /** Source Font, include ttf otf and woff. */ AssetType["SourceFont"] = "SourceFont";
23583
+ /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
23584
+ /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
23265
23585
  /** Project asset. */ AssetType["Project"] = "project";
23266
23586
  return AssetType;
23267
23587
  }({});
@@ -23647,9 +23967,10 @@
23647
23967
  var defaultTimeout = Infinity;
23648
23968
  var defaultInterval = 500;
23649
23969
  /**
23650
- * Web request.
23651
- * @param url - The link
23652
- * @param config - Load configuration
23970
+ * Sends a request to the specified URL and returns a promise for the response.
23971
+ * @param url - The URL to send the request to
23972
+ * @param config - Configuration options for the request
23973
+ * @returns A promise that resolves with the response of type `T`
23653
23974
  */ function request(url, config) {
23654
23975
  if (config === void 0) config = {};
23655
23976
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
@@ -24146,7 +24467,7 @@
24146
24467
  var assetBaseURL = baseUrl;
24147
24468
  if (searchStr) {
24148
24469
  var params = searchStr.split("&");
24149
- for(var i = 0; i < params.length; i++){
24470
+ for(var i = params.length - 1; i >= 0; i--){
24150
24471
  var param = params[i];
24151
24472
  if (param.startsWith("q=")) {
24152
24473
  queryPath = decodeURIComponent(param.split("=")[1]);
@@ -24195,11 +24516,9 @@
24195
24516
  Logger.warn("refId:" + refId + " is not find in this._editorResourceConfig.");
24196
24517
  return Promise.resolve(null);
24197
24518
  }
24198
- var remoteUrl = resourceConfig.path;
24199
- var queryPath = new URL(remoteUrl).search;
24200
- var url = resourceConfig.virtualPath + queryPath;
24519
+ var url = resourceConfig.virtualPath;
24201
24520
  if (key) {
24202
- url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key;
24521
+ url += "?q=" + key;
24203
24522
  }
24204
24523
  promise = this.load({
24205
24524
  url: url,
@@ -24853,7 +25172,7 @@
24853
25172
  function Collider(entity) {
24854
25173
  var _this;
24855
25174
  _this = Component.call(this, entity) || this, /** @internal */ _this._index = -1, _this._shapes = [];
24856
- _this._updateFlag = _this.entity.transform.registerWorldChangeFlag();
25175
+ _this._updateFlag = entity.registerWorldChangeFlag();
24857
25176
  return _this;
24858
25177
  }
24859
25178
  var _proto = Collider.prototype;
@@ -24867,9 +25186,8 @@
24867
25186
  oldCollider.removeShape(shape);
24868
25187
  }
24869
25188
  this._shapes.push(shape);
24870
- shape._collider = this;
24871
- this._nativeCollider.addShape(shape._nativeShape);
24872
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
25189
+ this._addNativeShape(shape);
25190
+ this._handleShapesChanged();
24873
25191
  }
24874
25192
  };
24875
25193
  /**
@@ -24879,9 +25197,8 @@
24879
25197
  var index = this._shapes.indexOf(shape);
24880
25198
  if (index !== -1) {
24881
25199
  this._shapes.splice(index, 1);
24882
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
24883
- shape._collider = null;
24884
- this._nativeCollider.removeShape(shape._nativeShape);
25200
+ this._removeNativeShape(shape);
25201
+ this._handleShapesChanged();
24885
25202
  }
24886
25203
  };
24887
25204
  /**
@@ -24889,12 +25206,10 @@
24889
25206
  */ _proto.clearShapes = function clearShapes() {
24890
25207
  var shapes = this._shapes;
24891
25208
  for(var i = 0, n = shapes.length; i < n; i++){
24892
- var shape = shapes[i];
24893
- this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
24894
- shape._destroy();
24895
- this._nativeCollider.removeShape(shape._nativeShape);
25209
+ this._removeNativeShape(shapes[i]);
24896
25210
  }
24897
25211
  shapes.length = 0;
25212
+ this._handleShapesChanged();
24898
25213
  };
24899
25214
  /**
24900
25215
  * @internal
@@ -24915,42 +25230,46 @@
24915
25230
  /**
24916
25231
  * @internal
24917
25232
  */ _proto._onEnableInScene = function _onEnableInScene() {
24918
- var physics = this.scene.physics;
24919
- physics._addCollider(this);
24920
- var shapes = this.shapes;
24921
- for(var i = 0, n = shapes.length; i < n; i++){
24922
- physics._addColliderShape(shapes[i]);
24923
- }
25233
+ this.scene.physics._addCollider(this);
24924
25234
  };
24925
25235
  /**
24926
25236
  * @internal
24927
25237
  */ _proto._onDisableInScene = function _onDisableInScene() {
24928
- var physics = this.scene.physics;
24929
- physics._removeCollider(this);
24930
- var shapes = this.shapes;
24931
- for(var i = 0, n = shapes.length; i < n; i++){
24932
- physics._removeColliderShape(shapes[i]);
24933
- }
25238
+ this.scene.physics._removeCollider(this);
24934
25239
  };
24935
25240
  /**
24936
25241
  * @internal
24937
25242
  */ _proto._cloneTo = function _cloneTo(target) {
24938
- var shapes = target._shapes;
24939
- for(var i = 0, n = shapes.length; i < n; i++){
24940
- target._addPhysicsShape(shapes[i]);
25243
+ target._syncNative();
25244
+ };
25245
+ /**
25246
+ * @internal
25247
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {};
25248
+ _proto._syncNative = function _syncNative() {
25249
+ for(var i = 0, n = this.shapes.length; i < n; i++){
25250
+ this._addNativeShape(this.shapes[i]);
24941
25251
  }
24942
25252
  };
24943
25253
  /**
24944
25254
  * @internal
24945
25255
  */ _proto._onDestroy = function _onDestroy() {
24946
25256
  Component.prototype._onDestroy.call(this);
24947
- this.clearShapes();
25257
+ var shapes = this._shapes;
25258
+ for(var i = 0, n = shapes.length; i < n; i++){
25259
+ var shape = shapes[i];
25260
+ this._removeNativeShape(shape);
25261
+ shape._destroy();
25262
+ }
25263
+ shapes.length = 0;
24948
25264
  this._nativeCollider.destroy();
24949
25265
  };
24950
- _proto._addPhysicsShape = function _addPhysicsShape(shape) {
25266
+ _proto._addNativeShape = function _addNativeShape(shape) {
24951
25267
  shape._collider = this;
24952
25268
  this._nativeCollider.addShape(shape._nativeShape);
24953
- this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
25269
+ };
25270
+ _proto._removeNativeShape = function _removeNativeShape(shape) {
25271
+ shape._collider = null;
25272
+ this._nativeCollider.removeShape(shape._nativeShape);
24954
25273
  };
24955
25274
  _create_class$2(Collider, [
24956
25275
  {
@@ -24984,13 +25303,12 @@
24984
25303
  * A physics scene is a collection of colliders and constraints which can interact.
24985
25304
  */ var PhysicsScene = /*#__PURE__*/ function() {
24986
25305
  function PhysicsScene(scene) {
24987
- var _this = this;
24988
25306
  this._restTime = 0;
24989
25307
  this._fixedTimeStep = 1 / 60;
24990
25308
  this._colliders = new DisorderedArray();
24991
25309
  this._gravity = new Vector3(0, -9.81, 0);
24992
25310
  this._onContactEnter = function(obj1, obj2) {
24993
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25311
+ var physicalObjectsMap = Engine._physicalObjectsMap;
24994
25312
  var shape1 = physicalObjectsMap[obj1];
24995
25313
  var shape2 = physicalObjectsMap[obj2];
24996
25314
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25009,7 +25327,7 @@
25009
25327
  });
25010
25328
  };
25011
25329
  this._onContactExit = function(obj1, obj2) {
25012
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25330
+ var physicalObjectsMap = Engine._physicalObjectsMap;
25013
25331
  var shape1 = physicalObjectsMap[obj1];
25014
25332
  var shape2 = physicalObjectsMap[obj2];
25015
25333
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25028,7 +25346,7 @@
25028
25346
  });
25029
25347
  };
25030
25348
  this._onContactStay = function(obj1, obj2) {
25031
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25349
+ var physicalObjectsMap = Engine._physicalObjectsMap;
25032
25350
  var shape1 = physicalObjectsMap[obj1];
25033
25351
  var shape2 = physicalObjectsMap[obj2];
25034
25352
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25047,7 +25365,7 @@
25047
25365
  });
25048
25366
  };
25049
25367
  this._onTriggerEnter = function(obj1, obj2) {
25050
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25368
+ var physicalObjectsMap = Engine._physicalObjectsMap;
25051
25369
  var shape1 = physicalObjectsMap[obj1];
25052
25370
  var shape2 = physicalObjectsMap[obj2];
25053
25371
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25062,7 +25380,7 @@
25062
25380
  });
25063
25381
  };
25064
25382
  this._onTriggerExit = function(obj1, obj2) {
25065
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25383
+ var physicalObjectsMap = Engine._physicalObjectsMap;
25066
25384
  var shape1 = physicalObjectsMap[obj1];
25067
25385
  var shape2 = physicalObjectsMap[obj2];
25068
25386
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25077,7 +25395,7 @@
25077
25395
  });
25078
25396
  };
25079
25397
  this._onTriggerStay = function(obj1, obj2) {
25080
- var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
25398
+ var physicalObjectsMap = Engine._physicalObjectsMap;
25081
25399
  var shape1 = physicalObjectsMap[obj1];
25082
25400
  var shape2 = physicalObjectsMap[obj2];
25083
25401
  shape1.collider.entity._scripts.forEach(function(element) {
@@ -25102,7 +25420,6 @@
25102
25420
  }
25103
25421
  var _proto = PhysicsScene.prototype;
25104
25422
  _proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
25105
- var _this = this;
25106
25423
  var hitResult;
25107
25424
  var distance = Number.MAX_VALUE;
25108
25425
  if (typeof distanceOrResult === "number") {
@@ -25120,7 +25437,7 @@
25120
25437
  hitResult = outHitResult;
25121
25438
  }
25122
25439
  var onRaycast = function onRaycast(obj) {
25123
- var shape = _this._scene.engine._physicalObjectsMap[obj];
25440
+ var shape = Engine._physicalObjectsMap[obj];
25124
25441
  if (!shape) {
25125
25442
  return false;
25126
25443
  }
@@ -25128,7 +25445,7 @@
25128
25445
  };
25129
25446
  if (hitResult != undefined) {
25130
25447
  var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
25131
- var hitShape = _this._scene.engine._physicalObjectsMap[idx];
25448
+ var hitShape = Engine._physicalObjectsMap[idx];
25132
25449
  hitResult.entity = hitShape._collider.entity;
25133
25450
  hitResult.shape = hitShape;
25134
25451
  hitResult.distance = distance;
@@ -25166,22 +25483,6 @@
25166
25483
  }
25167
25484
  };
25168
25485
  /**
25169
- * Add ColliderShape into the manager.
25170
- * @param colliderShape - The Collider Shape.
25171
- * @internal
25172
- */ _proto._addColliderShape = function _addColliderShape(colliderShape) {
25173
- this._scene.engine._physicalObjectsMap[colliderShape.id] = colliderShape;
25174
- this._nativePhysicsScene.addColliderShape(colliderShape._nativeShape);
25175
- };
25176
- /**
25177
- * Remove ColliderShape.
25178
- * @param colliderShape - The Collider Shape.
25179
- * @internal
25180
- */ _proto._removeColliderShape = function _removeColliderShape(colliderShape) {
25181
- delete this._scene.engine._physicalObjectsMap[colliderShape.id];
25182
- this._nativePhysicsScene.removeColliderShape(colliderShape._nativeShape);
25183
- };
25184
- /**
25185
25486
  * Add collider into the manager.
25186
25487
  * @param collider - StaticCollider or DynamicCollider.
25187
25488
  * @internal
@@ -25322,13 +25623,6 @@
25322
25623
  this._updateFlag.flag = true;
25323
25624
  };
25324
25625
  /**
25325
- * Remove all shape attached.
25326
- */ _proto.clearShapes = function clearShapes() {
25327
- if (this._shapes.length > 0) {
25328
- Collider.prototype.removeShape.call(this, this._shapes[0]);
25329
- }
25330
- };
25331
- /**
25332
25626
  * @internal
25333
25627
  */ _proto._onUpdate = function _onUpdate() {
25334
25628
  if (this._updateFlag.flag) {
@@ -25351,22 +25645,19 @@
25351
25645
  /**
25352
25646
  * @internal
25353
25647
  */ _proto._onEnableInScene = function _onEnableInScene() {
25354
- var physics = this.scene.physics;
25355
- physics._addCharacterController(this);
25356
- var shapes = this.shapes;
25357
- for(var i = 0, n = shapes.length; i < n; i++){
25358
- physics._addColliderShape(shapes[i]);
25359
- }
25648
+ this.scene.physics._addCharacterController(this);
25360
25649
  };
25361
25650
  /**
25362
25651
  * @internal
25363
25652
  */ _proto._onDisableInScene = function _onDisableInScene() {
25364
- var physics = this.scene.physics;
25365
- physics._removeCharacterController(this);
25366
- var shapes = this.shapes;
25367
- for(var i = 0, n = shapes.length; i < n; i++){
25368
- physics._removeColliderShape(shapes[i]);
25369
- }
25653
+ this.scene.physics._removeCharacterController(this);
25654
+ };
25655
+ _proto._syncNative = function _syncNative() {
25656
+ Collider.prototype._syncNative.call(this);
25657
+ this._nativeCollider.setStepOffset(this._stepOffset);
25658
+ this._nativeCollider.setNonWalkableMode(this._nonWalkableMode);
25659
+ this._nativeCollider.setUpDirection(this._upDirection);
25660
+ this._nativeCollider.setSlopeLimit(this._slopeLimit);
25370
25661
  };
25371
25662
  _proto._syncWorldPositionFromPhysicalSpace = function _syncWorldPositionFromPhysicalSpace() {
25372
25663
  this._nativeCollider.getWorldPosition(this.entity.transform.worldPosition);
@@ -25378,11 +25669,13 @@
25378
25669
  {
25379
25670
  key: "stepOffset",
25380
25671
  get: /**
25381
- * The step offset for the controller.
25672
+ * The step offset for the controller, the value must be greater than or equal to 0.
25673
+ * @remarks Character can overcome obstacle less than the height(stepOffset + contractOffset of the shape).
25382
25674
  */ function get() {
25383
25675
  return this._stepOffset;
25384
25676
  },
25385
25677
  set: function set(value) {
25678
+ value = Math.max(0, value);
25386
25679
  if (this._stepOffset !== value) {
25387
25680
  this._stepOffset = value;
25388
25681
  this._nativeCollider.setStepOffset(value);
@@ -25419,7 +25712,8 @@
25419
25712
  {
25420
25713
  key: "slopeLimit",
25421
25714
  get: /**
25422
- * The slope limit for the controller.
25715
+ * The slope limit for the controller, the value is the cosine value of the maximum slope angle.
25716
+ * @defaultValue 0.707(the cosine value of 45 degrees)
25423
25717
  */ function get() {
25424
25718
  return this._slopeLimit;
25425
25719
  },
@@ -25433,27 +25727,30 @@
25433
25727
  ]);
25434
25728
  return CharacterController;
25435
25729
  }(exports.Collider);
25730
+ __decorate$1([
25731
+ deepClone
25732
+ ], CharacterController.prototype, "_upDirection", void 0);
25436
25733
  /**
25437
25734
  * A dynamic collider can act with self-defined movement or physical force.
25438
25735
  */ var DynamicCollider = /*#__PURE__*/ function(Collider) {
25439
25736
  _inherits$2(DynamicCollider, Collider);
25440
25737
  function DynamicCollider(entity) {
25441
25738
  var _this;
25442
- _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new Vector3(), _this._angularVelocity = new Vector3(), _this._mass = 1.0, _this._centerOfMass = new Vector3(), _this._inertiaTensor = new Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1000, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3;
25739
+ _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new Vector3(), _this._angularVelocity = new Vector3(), _this._mass = 1.0, _this._centerOfMass = new Vector3(), _this._inertiaTensor = new Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
25443
25740
  var transform = _this.entity.transform;
25444
25741
  _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
25445
25742
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
25446
25743
  _this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
25447
- _this._setCenterOfMass = _this._setCenterOfMass.bind(_this);
25448
- _this._setInertiaTensor = _this._setInertiaTensor.bind(_this);
25744
+ _this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
25745
+ _this._handleInertiaTensorChanged = _this._handleInertiaTensorChanged.bind(_this);
25449
25746
  //@ts-ignore
25450
25747
  _this._linearVelocity._onValueChanged = _this._setLinearVelocity;
25451
25748
  //@ts-ignore
25452
25749
  _this._angularVelocity._onValueChanged = _this._setAngularVelocity;
25453
25750
  //@ts-ignore
25454
- _this._centerOfMass._onValueChanged = _this._setCenterOfMass;
25751
+ _this._centerOfMass._onValueChanged = _this._handleCenterOfMassChanged;
25455
25752
  //@ts-ignore
25456
- _this._inertiaTensor._onValueChanged = _this._setInertiaTensor;
25753
+ _this._inertiaTensor._onValueChanged = _this._handleInertiaTensorChanged;
25457
25754
  return _this;
25458
25755
  }
25459
25756
  var _proto = DynamicCollider.prototype;
@@ -25461,16 +25758,16 @@
25461
25758
  * Apply a force to the DynamicCollider.
25462
25759
  * @param force - The force make the collider move
25463
25760
  */ _proto.applyForce = function applyForce(force) {
25464
- this._nativeCollider.addForce(force);
25761
+ this._phasedActiveInScene && this._nativeCollider.addForce(force);
25465
25762
  };
25466
25763
  /**
25467
25764
  * Apply a torque to the DynamicCollider.
25468
25765
  * @param torque - The force make the collider rotate
25469
25766
  */ _proto.applyTorque = function applyTorque(torque) {
25470
- this._nativeCollider.addTorque(torque);
25767
+ this._phasedActiveInScene && this._nativeCollider.addTorque(torque);
25471
25768
  };
25472
25769
  _proto.move = function move(positionOrRotation, rotation) {
25473
- this._nativeCollider.move(positionOrRotation, rotation);
25770
+ this._phasedActiveInScene && this._nativeCollider.move(positionOrRotation, rotation);
25474
25771
  };
25475
25772
  /**
25476
25773
  * Forces a collider to sleep at least one frame.
@@ -25478,6 +25775,12 @@
25478
25775
  this._nativeCollider.sleep();
25479
25776
  };
25480
25777
  /**
25778
+ * Returns whether the collider is sleeping.
25779
+ * @returns True if the collider is sleeping, false otherwise.
25780
+ */ _proto.isSleeping = function isSleeping() {
25781
+ return this._nativeCollider.isSleeping();
25782
+ };
25783
+ /**
25481
25784
  * Forces a collider to wake up.
25482
25785
  */ _proto.wakeUp = function wakeUp() {
25483
25786
  this._nativeCollider.wakeUp();
@@ -25493,21 +25796,44 @@
25493
25796
  /**
25494
25797
  * @internal
25495
25798
  */ _proto._cloneTo = function _cloneTo(target) {
25799
+ target._linearVelocity.copyFrom(this.linearVelocity);
25800
+ target._angularVelocity.copyFrom(this.angularVelocity);
25801
+ target._centerOfMass.copyFrom(this.centerOfMass);
25802
+ target._inertiaTensor.copyFrom(this.inertiaTensor);
25496
25803
  Collider.prototype._cloneTo.call(this, target);
25497
- target.linearDamping = this.linearDamping;
25498
- target.angularDamping = this.angularDamping;
25499
- target.linearVelocity = this.linearVelocity;
25500
- target.angularVelocity = this.angularVelocity;
25501
- target.mass = this.mass;
25502
- target.centerOfMass = this.centerOfMass;
25503
- target.inertiaTensor = this.inertiaTensor;
25504
- target.maxAngularVelocity = this.maxAngularVelocity;
25505
- target.maxDepenetrationVelocity = this.maxDepenetrationVelocity;
25506
- target.sleepThreshold = this.sleepThreshold;
25507
- target.solverIterations = this.solverIterations;
25508
- target.isKinematic = this.isKinematic;
25509
- target.constraints = this.constraints;
25510
- target.collisionDetectionMode = this.collisionDetectionMode;
25804
+ };
25805
+ /**
25806
+ * @internal
25807
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {
25808
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
25809
+ this._setMassAndUpdateInertia();
25810
+ }
25811
+ };
25812
+ _proto._syncNative = function _syncNative() {
25813
+ Collider.prototype._syncNative.call(this);
25814
+ this._nativeCollider.setLinearDamping(this._linearDamping);
25815
+ this._nativeCollider.setAngularDamping(this._angularDamping);
25816
+ this._nativeCollider.setLinearVelocity(this._linearVelocity);
25817
+ this._nativeCollider.setAngularVelocity(this._angularVelocity);
25818
+ if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
25819
+ this._setMassAndUpdateInertia();
25820
+ } else {
25821
+ this._nativeCollider.setMass(this._mass);
25822
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
25823
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
25824
+ }
25825
+ this._nativeCollider.setMaxAngularVelocity(this._maxAngularVelocity);
25826
+ this._nativeCollider.setMaxDepenetrationVelocity(this._maxDepenetrationVelocity);
25827
+ this._nativeCollider.setSleepThreshold(this._sleepThreshold);
25828
+ this._nativeCollider.setSolverIterations(this._solverIterations);
25829
+ this._nativeCollider.setIsKinematic(this._isKinematic);
25830
+ this._nativeCollider.setConstraints(this._constraints);
25831
+ this._nativeCollider.setCollisionDetectionMode(this._collisionDetectionMode);
25832
+ };
25833
+ _proto._setMassAndUpdateInertia = function _setMassAndUpdateInertia() {
25834
+ this._nativeCollider.setMassAndUpdateInertia(this._mass);
25835
+ this._automaticCenterOfMass || this._nativeCollider.setCenterOfMass(this._centerOfMass);
25836
+ this._automaticInertiaTensor || this._nativeCollider.setInertiaTensor(this._inertiaTensor);
25511
25837
  };
25512
25838
  _proto._setLinearVelocity = function _setLinearVelocity() {
25513
25839
  this._nativeCollider.setLinearVelocity(this._linearVelocity);
@@ -25515,11 +25841,19 @@
25515
25841
  _proto._setAngularVelocity = function _setAngularVelocity() {
25516
25842
  this._nativeCollider.setAngularVelocity(this._angularVelocity);
25517
25843
  };
25518
- _proto._setCenterOfMass = function _setCenterOfMass() {
25519
- this._nativeCollider.setCenterOfMass(this._centerOfMass);
25844
+ _proto._handleCenterOfMassChanged = function _handleCenterOfMassChanged() {
25845
+ if (this._automaticCenterOfMass) {
25846
+ console.warn("The center of mass is automatically calculated, please set automaticCenterOfMass to false if you want to set it manually.");
25847
+ } else {
25848
+ this._nativeCollider.setCenterOfMass(this._centerOfMass);
25849
+ }
25520
25850
  };
25521
- _proto._setInertiaTensor = function _setInertiaTensor() {
25522
- this._nativeCollider.setInertiaTensor(this._inertiaTensor);
25851
+ _proto._handleInertiaTensorChanged = function _handleInertiaTensorChanged() {
25852
+ if (this._automaticInertiaTensor) {
25853
+ console.warn("The inertia tensor is automatically calculated, please set automaticInertiaTensor to false if you want to set it manually.");
25854
+ } else {
25855
+ this._nativeCollider.setInertiaTensor(this._inertiaTensor);
25856
+ }
25523
25857
  };
25524
25858
  _create_class$2(DynamicCollider, [
25525
25859
  {
@@ -25555,6 +25889,11 @@
25555
25889
  get: /**
25556
25890
  * The linear velocity vector of the dynamic collider measured in world unit per second.
25557
25891
  */ function get() {
25892
+ //@ts-ignore
25893
+ this._linearVelocity._onValueChanged = null;
25894
+ this._nativeCollider.getLinearVelocity(this._linearVelocity);
25895
+ //@ts-ignore
25896
+ this._linearVelocity._onValueChanged = this._setLinearVelocity;
25558
25897
  return this._linearVelocity;
25559
25898
  },
25560
25899
  set: function set(value) {
@@ -25568,6 +25907,11 @@
25568
25907
  get: /**
25569
25908
  * The angular velocity vector of the dynamic collider measured in radians per second.
25570
25909
  */ function get() {
25910
+ //@ts-ignore
25911
+ this._angularVelocity._onValueChanged = null;
25912
+ this._nativeCollider.getAngularVelocity(this._angularVelocity);
25913
+ //@ts-ignore
25914
+ this._angularVelocity._onValueChanged = this._setAngularVelocity;
25571
25915
  return this._angularVelocity;
25572
25916
  },
25573
25917
  set: function set(value) {
@@ -25586,7 +25930,28 @@
25586
25930
  set: function set(value) {
25587
25931
  if (this._mass !== value) {
25588
25932
  this._mass = value;
25589
- this._nativeCollider.setMass(value);
25933
+ if (this._automaticInertiaTensor || this._automaticCenterOfMass) {
25934
+ this._setMassAndUpdateInertia();
25935
+ } else {
25936
+ this._nativeCollider.setMass(value);
25937
+ }
25938
+ }
25939
+ }
25940
+ },
25941
+ {
25942
+ key: "automaticCenterOfMass",
25943
+ get: /**
25944
+ * Whether or not to calculate the center of mass automatically, if true, the center of mass will be calculated based on the associated shapes.
25945
+ * @remarks Affected by the position, rotation of the shapes.
25946
+ */ function get() {
25947
+ return this._automaticCenterOfMass;
25948
+ },
25949
+ set: function set(value) {
25950
+ if (this._automaticCenterOfMass !== value) {
25951
+ this._automaticCenterOfMass = value;
25952
+ if (value) {
25953
+ this._setMassAndUpdateInertia();
25954
+ }
25590
25955
  }
25591
25956
  }
25592
25957
  },
@@ -25594,7 +25959,13 @@
25594
25959
  key: "centerOfMass",
25595
25960
  get: /**
25596
25961
  * The center of mass relative to the transform's origin.
25962
+ * @remarks The center of mass is automatically calculated, if you want to set it manually, please set automaticCenterOfMass to false.
25597
25963
  */ function get() {
25964
+ // @ts-ignore
25965
+ this._centerOfMass._onValueChanged = null;
25966
+ this._nativeCollider.getCenterOfMass(this._centerOfMass);
25967
+ // @ts-ignore
25968
+ this._centerOfMass._onValueChanged = this._handleCenterOfMassChanged;
25598
25969
  return this._centerOfMass;
25599
25970
  },
25600
25971
  set: function set(value) {
@@ -25603,11 +25974,34 @@
25603
25974
  }
25604
25975
  }
25605
25976
  },
25977
+ {
25978
+ key: "automaticInertiaTensor",
25979
+ get: /**
25980
+ * Whether or not to calculate the inertia tensor automatically, if true, the inertia tensor will be calculated based on the associated shapes and mass.
25981
+ * @remarks Affected by the position, rotation of the shapes and the mass of the collider.
25982
+ */ function get() {
25983
+ return this._automaticInertiaTensor;
25984
+ },
25985
+ set: function set(value) {
25986
+ if (this._automaticInertiaTensor !== value) {
25987
+ this._automaticInertiaTensor = value;
25988
+ if (value) {
25989
+ this._setMassAndUpdateInertia();
25990
+ }
25991
+ }
25992
+ }
25993
+ },
25606
25994
  {
25607
25995
  key: "inertiaTensor",
25608
25996
  get: /**
25609
25997
  * The diagonal inertia tensor of mass relative to the center of mass.
25998
+ * @remarks The inertia tensor is automatically calculated, if you want to set it manually, please set automaticInertiaTensor to false.
25610
25999
  */ function get() {
26000
+ // @ts-ignore
26001
+ this._inertiaTensor._onValueChanged = null;
26002
+ this._nativeCollider.getInertiaTensor(this._inertiaTensor);
26003
+ // @ts-ignore
26004
+ this._inertiaTensor._onValueChanged = this._handleInertiaTensorChanged;
25611
26005
  return this._inertiaTensor;
25612
26006
  },
25613
26007
  set: function set(value) {
@@ -25717,21 +26111,12 @@
25717
26111
  ]);
25718
26112
  return DynamicCollider;
25719
26113
  }(exports.Collider);
25720
- __decorate$1([
25721
- ignoreClone
25722
- ], DynamicCollider.prototype, "_linearDamping", void 0);
25723
- __decorate$1([
25724
- ignoreClone
25725
- ], DynamicCollider.prototype, "_angularDamping", void 0);
25726
26114
  __decorate$1([
25727
26115
  ignoreClone
25728
26116
  ], DynamicCollider.prototype, "_linearVelocity", void 0);
25729
26117
  __decorate$1([
25730
26118
  ignoreClone
25731
26119
  ], DynamicCollider.prototype, "_angularVelocity", void 0);
25732
- __decorate$1([
25733
- ignoreClone
25734
- ], DynamicCollider.prototype, "_mass", void 0);
25735
26120
  __decorate$1([
25736
26121
  ignoreClone
25737
26122
  ], DynamicCollider.prototype, "_centerOfMass", void 0);
@@ -25740,25 +26125,16 @@
25740
26125
  ], DynamicCollider.prototype, "_inertiaTensor", void 0);
25741
26126
  __decorate$1([
25742
26127
  ignoreClone
25743
- ], DynamicCollider.prototype, "_maxAngularVelocity", void 0);
25744
- __decorate$1([
25745
- ignoreClone
25746
- ], DynamicCollider.prototype, "_maxDepenetrationVelocity", void 0);
25747
- __decorate$1([
25748
- ignoreClone
25749
- ], DynamicCollider.prototype, "_solverIterations", void 0);
26128
+ ], DynamicCollider.prototype, "_setLinearVelocity", null);
25750
26129
  __decorate$1([
25751
26130
  ignoreClone
25752
- ], DynamicCollider.prototype, "_isKinematic", void 0);
26131
+ ], DynamicCollider.prototype, "_setAngularVelocity", null);
25753
26132
  __decorate$1([
25754
26133
  ignoreClone
25755
- ], DynamicCollider.prototype, "_constraints", void 0);
26134
+ ], DynamicCollider.prototype, "_handleCenterOfMassChanged", null);
25756
26135
  __decorate$1([
25757
26136
  ignoreClone
25758
- ], DynamicCollider.prototype, "_collisionDetectionMode", void 0);
25759
- __decorate$1([
25760
- ignoreClone
25761
- ], DynamicCollider.prototype, "_sleepThreshold", void 0);
26137
+ ], DynamicCollider.prototype, "_handleInertiaTensorChanged", null);
25762
26138
  /**
25763
26139
  * The collision detection mode constants.
25764
26140
  */ var CollisionDetectionMode = /*#__PURE__*/ function(CollisionDetectionMode) {
@@ -25802,9 +26178,9 @@
25802
26178
  * Material class to represent a set of surface properties.
25803
26179
  */ var PhysicsMaterial = /*#__PURE__*/ function() {
25804
26180
  function PhysicsMaterial() {
25805
- this._bounciness = 0.1;
25806
- this._dynamicFriction = 0.1;
25807
- this._staticFriction = 0.1;
26181
+ this._bounciness = 0;
26182
+ this._dynamicFriction = 0.6;
26183
+ this._staticFriction = 0.6;
25808
26184
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
25809
26185
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
25810
26186
  this._nativeMaterial = PhysicsScene._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
@@ -25820,7 +26196,7 @@
25820
26196
  {
25821
26197
  key: "bounciness",
25822
26198
  get: /**
25823
- * The coefficient of bounciness.
26199
+ * The coefficient of bounciness, ranging from 0 to 1.
25824
26200
  */ function get() {
25825
26201
  return this._bounciness;
25826
26202
  },
@@ -25924,22 +26300,96 @@
25924
26300
  _inherits$2(Joint, Component);
25925
26301
  function Joint(entity) {
25926
26302
  var _this;
25927
- _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = 0, _this._torque = 0;
25928
- _this._connectedColliderInfo.localPosition = new Vector3();
26303
+ _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = Infinity, _this._torque = Infinity, _this._automaticConnectedAnchor = true;
26304
+ //@ts-ignore
26305
+ _this._colliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 1);
26306
+ //@ts-ignore
26307
+ _this._connectedColliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 2);
26308
+ _this._onSelfTransformChanged = _this._onSelfTransformChanged.bind(_this);
26309
+ _this._onConnectedTransformChanged = _this._onConnectedTransformChanged.bind(_this);
26310
+ // @ts-ignore
26311
+ entity._updateFlagManager.addListener(_this._onSelfTransformChanged);
25929
26312
  return _this;
25930
26313
  }
25931
26314
  var _proto = Joint.prototype;
25932
26315
  /**
25933
26316
  * @internal
25934
- */ _proto._cloneTo = function _cloneTo(target) {
25935
- target.connectedCollider = this.connectedCollider;
25936
- target.connectedAnchor = this.connectedAnchor;
25937
- target.connectedMassScale = this.connectedMassScale;
25938
- target.connectedInertiaScale = this.connectedInertiaScale;
25939
- target.massScale = this.massScale;
25940
- target.inertiaScale = this.inertiaScale;
25941
- target.breakForce = this.breakForce;
25942
- target.breakTorque = this.breakTorque;
26317
+ */ _proto._onEnableInScene = function _onEnableInScene() {
26318
+ this._createJoint();
26319
+ this._syncNative();
26320
+ };
26321
+ /**
26322
+ * @internal
26323
+ */ _proto._onDisableInScene = function _onDisableInScene() {
26324
+ this._nativeJoint.destroy();
26325
+ this._nativeJoint = null;
26326
+ };
26327
+ _proto._syncNative = function _syncNative() {
26328
+ if (this._nativeJoint) {
26329
+ var _this__connectedColliderInfo_collider;
26330
+ this._nativeJoint.setConnectedCollider(((_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider._nativeCollider) || null);
26331
+ this._updateActualAnchor(1);
26332
+ if (this._automaticConnectedAnchor) {
26333
+ this._calculateConnectedAnchor();
26334
+ } else {
26335
+ this._updateActualAnchor(2);
26336
+ }
26337
+ this._nativeJoint.setConnectedMassScale(this._connectedColliderInfo.massScale);
26338
+ this._nativeJoint.setConnectedInertiaScale(this._connectedColliderInfo.inertiaScale);
26339
+ this._nativeJoint.setMassScale(this._colliderInfo.massScale);
26340
+ this._nativeJoint.setInertiaScale(this._colliderInfo.inertiaScale);
26341
+ this._nativeJoint.setBreakForce(this._force);
26342
+ this._nativeJoint.setBreakTorque(this._torque);
26343
+ }
26344
+ };
26345
+ _proto._calculateConnectedAnchor = function _calculateConnectedAnchor() {
26346
+ var colliderInfo = this._colliderInfo;
26347
+ var connectedColliderInfo = this._connectedColliderInfo;
26348
+ var _this_entity_transform = this.entity.transform, selfPos = _this_entity_transform.worldPosition;
26349
+ var selfActualAnchor = colliderInfo.actualAnchor;
26350
+ var connectedAnchor = connectedColliderInfo.anchor;
26351
+ var connectedActualAnchor = connectedColliderInfo.actualAnchor;
26352
+ var connectedCollider = connectedColliderInfo.collider;
26353
+ if (connectedCollider) {
26354
+ var _connectedCollider_entity_transform = connectedCollider.entity.transform, connectedPos = _connectedCollider_entity_transform.worldPosition, connectedWorldScale = _connectedCollider_entity_transform.lossyWorldScale;
26355
+ Vector3.subtract(selfPos, connectedPos, Joint._tempVector3);
26356
+ Vector3.add(Joint._tempVector3, selfActualAnchor, connectedActualAnchor);
26357
+ Vector3.divide(connectedActualAnchor, connectedWorldScale, connectedAnchor);
26358
+ } else {
26359
+ Vector3.add(selfPos, selfActualAnchor, connectedActualAnchor);
26360
+ connectedAnchor.copyFrom(connectedActualAnchor);
26361
+ }
26362
+ };
26363
+ _proto._onSelfTransformChanged = function _onSelfTransformChanged(type) {
26364
+ if (type & TransformModifyFlags.WorldScale) {
26365
+ this._updateActualAnchor(1);
26366
+ }
26367
+ };
26368
+ _proto._onConnectedTransformChanged = function _onConnectedTransformChanged(type) {
26369
+ if (type & TransformModifyFlags.WorldScale) {
26370
+ this._updateActualAnchor(2);
26371
+ }
26372
+ };
26373
+ _proto._updateActualAnchor = function _updateActualAnchor(flag) {
26374
+ if (flag & 1) {
26375
+ var _this__nativeJoint;
26376
+ var worldScale = this.entity.transform.lossyWorldScale;
26377
+ var selfColliderInfo = this._colliderInfo;
26378
+ Vector3.multiply(selfColliderInfo.anchor, worldScale, selfColliderInfo.actualAnchor);
26379
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAnchor(selfColliderInfo.actualAnchor);
26380
+ }
26381
+ if (flag & 2) {
26382
+ var _this__nativeJoint1;
26383
+ var connectedColliderInfo = this._connectedColliderInfo;
26384
+ var connectedCollider = connectedColliderInfo.collider;
26385
+ if (connectedCollider) {
26386
+ var worldScale1 = connectedCollider.entity.transform.lossyWorldScale;
26387
+ Vector3.multiply(connectedColliderInfo.anchor, worldScale1, connectedColliderInfo.actualAnchor);
26388
+ } else {
26389
+ connectedColliderInfo.actualAnchor.copyFrom(connectedColliderInfo.anchor);
26390
+ }
26391
+ (_this__nativeJoint1 = this._nativeJoint) == null ? void 0 : _this__nativeJoint1.setConnectedAnchor(connectedColliderInfo.actualAnchor);
26392
+ }
25943
26393
  };
25944
26394
  _create_class$2(Joint, [
25945
26395
  {
@@ -25951,8 +26401,33 @@
25951
26401
  },
25952
26402
  set: function set(value) {
25953
26403
  if (this._connectedColliderInfo.collider !== value) {
26404
+ var _this__connectedColliderInfo_collider, _this__nativeJoint;
26405
+ (_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged);
26406
+ value == null ? void 0 : value.entity._updateFlagManager.addListener(this._onConnectedTransformChanged);
25954
26407
  this._connectedColliderInfo.collider = value;
25955
- this._nativeJoint.setConnectedCollider(value._nativeCollider);
26408
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedCollider(value._nativeCollider);
26409
+ if (this._automaticConnectedAnchor) {
26410
+ this._calculateConnectedAnchor();
26411
+ } else {
26412
+ this._updateActualAnchor(2);
26413
+ }
26414
+ }
26415
+ }
26416
+ },
26417
+ {
26418
+ key: "anchor",
26419
+ get: /**
26420
+ * The connected anchor position.
26421
+ * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
26422
+ */ function get() {
26423
+ return this._colliderInfo.anchor;
26424
+ },
26425
+ set: function set(value) {
26426
+ var anchor = this._colliderInfo.anchor;
26427
+ if (value !== anchor) {
26428
+ anchor.copyFrom(value);
26429
+ this._updateActualAnchor(1);
26430
+ this._automaticConnectedAnchor && this._calculateConnectedAnchor();
25956
26431
  }
25957
26432
  }
25958
26433
  },
@@ -25962,14 +26437,30 @@
25962
26437
  * The connected anchor position.
25963
26438
  * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
25964
26439
  */ function get() {
25965
- return this._connectedColliderInfo.localPosition;
26440
+ return this._connectedColliderInfo.anchor;
25966
26441
  },
25967
26442
  set: function set(value) {
25968
- var connectedAnchor = this._connectedColliderInfo.localPosition;
26443
+ if (this.automaticConnectedAnchor) {
26444
+ console.warn("Cannot set connectedAnchor when automaticConnectedAnchor is true.");
26445
+ return;
26446
+ }
26447
+ var connectedAnchor = this._connectedColliderInfo.anchor;
25969
26448
  if (value !== connectedAnchor) {
25970
26449
  connectedAnchor.copyFrom(value);
26450
+ this._updateActualAnchor(2);
25971
26451
  }
25972
- this._nativeJoint.setConnectedAnchor(value);
26452
+ }
26453
+ },
26454
+ {
26455
+ key: "automaticConnectedAnchor",
26456
+ get: /**
26457
+ * 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.
26458
+ */ function get() {
26459
+ return this._automaticConnectedAnchor;
26460
+ },
26461
+ set: function set(value) {
26462
+ this._automaticConnectedAnchor = value;
26463
+ value && this._calculateConnectedAnchor();
25973
26464
  }
25974
26465
  },
25975
26466
  {
@@ -25981,36 +26472,39 @@
25981
26472
  },
25982
26473
  set: function set(value) {
25983
26474
  if (value !== this._connectedColliderInfo.massScale) {
26475
+ var _this__nativeJoint;
25984
26476
  this._connectedColliderInfo.massScale = value;
25985
- this._nativeJoint.setConnectedMassScale(value);
26477
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedMassScale(value);
25986
26478
  }
25987
26479
  }
25988
26480
  },
25989
26481
  {
25990
- key: "connectedInertiaScale",
26482
+ key: "massScale",
25991
26483
  get: /**
25992
- * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
26484
+ * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
25993
26485
  */ function get() {
25994
- return this._connectedColliderInfo.inertiaScale;
26486
+ return this._colliderInfo.massScale;
25995
26487
  },
25996
26488
  set: function set(value) {
25997
- if (value !== this._connectedColliderInfo.inertiaScale) {
25998
- this._connectedColliderInfo.inertiaScale = value;
25999
- this._nativeJoint.setConnectedInertiaScale(value);
26489
+ if (value !== this._colliderInfo.massScale) {
26490
+ var _this__nativeJoint;
26491
+ this._colliderInfo.massScale = value;
26492
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMassScale(value);
26000
26493
  }
26001
26494
  }
26002
26495
  },
26003
26496
  {
26004
- key: "massScale",
26497
+ key: "connectedInertiaScale",
26005
26498
  get: /**
26006
- * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
26499
+ * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
26007
26500
  */ function get() {
26008
- return this._colliderInfo.massScale;
26501
+ return this._connectedColliderInfo.inertiaScale;
26009
26502
  },
26010
26503
  set: function set(value) {
26011
- if (value !== this._colliderInfo.massScale) {
26012
- this._colliderInfo.massScale = value;
26013
- this._nativeJoint.setMassScale(value);
26504
+ if (value !== this._connectedColliderInfo.inertiaScale) {
26505
+ var _this__nativeJoint;
26506
+ this._connectedColliderInfo.inertiaScale = value;
26507
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedInertiaScale(value);
26014
26508
  }
26015
26509
  }
26016
26510
  },
@@ -26023,8 +26517,9 @@
26023
26517
  },
26024
26518
  set: function set(value) {
26025
26519
  if (value !== this._colliderInfo.inertiaScale) {
26520
+ var _this__nativeJoint;
26026
26521
  this._colliderInfo.inertiaScale = value;
26027
- this._nativeJoint.setInertiaScale(value);
26522
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setInertiaScale(value);
26028
26523
  }
26029
26524
  }
26030
26525
  },
@@ -26037,8 +26532,9 @@
26037
26532
  },
26038
26533
  set: function set(value) {
26039
26534
  if (value !== this._force) {
26535
+ var _this__nativeJoint;
26040
26536
  this._force = value;
26041
- this._nativeJoint.setBreakForce(value);
26537
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakForce(value);
26042
26538
  }
26043
26539
  }
26044
26540
  },
@@ -26051,29 +26547,34 @@
26051
26547
  },
26052
26548
  set: function set(value) {
26053
26549
  if (value !== this._torque) {
26550
+ var _this__nativeJoint;
26054
26551
  this._torque = value;
26055
- this._nativeJoint.setBreakTorque(value);
26552
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setBreakTorque(value);
26056
26553
  }
26057
26554
  }
26058
26555
  }
26059
26556
  ]);
26060
26557
  return Joint;
26061
26558
  }(Component);
26559
+ exports.Joint._tempVector3 = new Vector3();
26062
26560
  __decorate$1([
26063
- ignoreClone
26561
+ deepClone
26064
26562
  ], exports.Joint.prototype, "_colliderInfo", void 0);
26065
26563
  __decorate$1([
26066
- ignoreClone
26564
+ deepClone
26067
26565
  ], exports.Joint.prototype, "_connectedColliderInfo", void 0);
26068
26566
  __decorate$1([
26069
26567
  ignoreClone
26070
26568
  ], exports.Joint.prototype, "_nativeJoint", void 0);
26071
26569
  __decorate$1([
26072
26570
  ignoreClone
26073
- ], exports.Joint.prototype, "_force", void 0);
26571
+ ], exports.Joint.prototype, "_onSelfTransformChanged", null);
26074
26572
  __decorate$1([
26075
26573
  ignoreClone
26076
- ], exports.Joint.prototype, "_torque", void 0);
26574
+ ], exports.Joint.prototype, "_onConnectedTransformChanged", null);
26575
+ __decorate$1([
26576
+ ignoreClone
26577
+ ], exports.Joint.prototype, "_updateActualAnchor", null);
26077
26578
  exports.Joint = __decorate$1([
26078
26579
  dependentComponents(exports.Collider, DependentMode.CheckOnly)
26079
26580
  ], exports.Joint);
@@ -26081,9 +26582,17 @@
26081
26582
  * @internal
26082
26583
  */ var JointColliderInfo = function JointColliderInfo() {
26083
26584
  this.collider = null;
26084
- this.massScale = 0;
26085
- this.inertiaScale = 0;
26585
+ this.anchor = new Vector3();
26586
+ this.actualAnchor = new Vector3();
26587
+ this.massScale = 1;
26588
+ this.inertiaScale = 1;
26086
26589
  };
26590
+ __decorate$1([
26591
+ deepClone
26592
+ ], JointColliderInfo.prototype, "anchor", void 0);
26593
+ __decorate$1([
26594
+ deepClone
26595
+ ], JointColliderInfo.prototype, "actualAnchor", void 0);
26087
26596
  /*
26088
26597
  * A fixed joint permits no relative movement between two colliders. ie the colliders are glued together.
26089
26598
  */ var FixedJoint = /*#__PURE__*/ function(Joint) {
@@ -26092,12 +26601,10 @@
26092
26601
  return Joint.apply(this, arguments) || this;
26093
26602
  }
26094
26603
  var _proto = FixedJoint.prototype;
26095
- /**
26096
- * @internal
26097
- */ _proto._onAwake = function _onAwake() {
26098
- var collider = this._colliderInfo;
26099
- collider.collider = this.entity.getComponent(exports.Collider);
26100
- this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(collider.collider._nativeCollider);
26604
+ _proto._createJoint = function _createJoint() {
26605
+ var colliderInfo = this._colliderInfo;
26606
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
26607
+ this._nativeJoint = PhysicsScene._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
26101
26608
  };
26102
26609
  return FixedJoint;
26103
26610
  }(exports.Joint);
@@ -26115,30 +26622,58 @@
26115
26622
  * A joint which behaves in a similar way to a hinge or axle.
26116
26623
  */ var HingeJoint = /*#__PURE__*/ function(Joint) {
26117
26624
  _inherits$2(HingeJoint, Joint);
26118
- function HingeJoint() {
26625
+ function HingeJoint(entity) {
26119
26626
  var _this;
26120
- _this = Joint.apply(this, arguments) || this, _this._axis = new Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false;
26627
+ _this = Joint.call(this, entity) || this, _this._axis = new Vector3(1, 0, 0), _this._hingeFlags = HingeJointFlag.None, _this._useSpring = false, _this._angle = 0, _this._velocity = 0;
26628
+ _this._onMotorChanged = _this._onMotorChanged.bind(_this);
26629
+ _this._onLimitsChanged = _this._onLimitsChanged.bind(_this);
26121
26630
  return _this;
26122
26631
  }
26123
26632
  var _proto = HingeJoint.prototype;
26124
26633
  /**
26125
26634
  * @internal
26126
- */ _proto._onAwake = function _onAwake() {
26127
- var collider = this._colliderInfo;
26128
- collider.localPosition = new Vector3();
26129
- collider.collider = this.entity.getComponent(exports.Collider);
26130
- this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(collider.collider._nativeCollider);
26131
- };
26132
- /**
26133
- * @internal
26134
- */ _proto._cloneTo = function _cloneTo(target) {
26135
- target.axis = this.axis;
26136
- target.swingOffset = this.swingOffset;
26137
- target.useLimits = this.useLimits;
26138
- target.useMotor = this.useMotor;
26139
- target.useSpring = this.useSpring;
26140
- target.motor = this.motor;
26141
- target.limits = this.limits;
26635
+ */ _proto._onDisableInScene = function _onDisableInScene() {
26636
+ var nativeJoint = this._nativeJoint;
26637
+ this._angle = nativeJoint.getAngle();
26638
+ this._velocity = nativeJoint.getVelocity();
26639
+ Joint.prototype._onDisableInScene.call(this);
26640
+ };
26641
+ _proto._createJoint = function _createJoint() {
26642
+ var colliderInfo = this._colliderInfo;
26643
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
26644
+ this._nativeJoint = PhysicsScene._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
26645
+ };
26646
+ _proto._syncNative = function _syncNative() {
26647
+ Joint.prototype._syncNative.call(this);
26648
+ var motor = this._jointMotor;
26649
+ this._nativeJoint.setAxis(this._axis);
26650
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, this.useLimits);
26651
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, this.useMotor);
26652
+ if (motor) {
26653
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
26654
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
26655
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
26656
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
26657
+ }
26658
+ };
26659
+ _proto._onMotorChanged = function _onMotorChanged() {
26660
+ var motor = this._jointMotor;
26661
+ if (this._nativeJoint) {
26662
+ this._nativeJoint.setDriveVelocity(motor.targetVelocity);
26663
+ this._nativeJoint.setDriveForceLimit(motor.forceLimit);
26664
+ this._nativeJoint.setDriveGearRatio(motor.gearRatio);
26665
+ this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, motor.freeSpin);
26666
+ }
26667
+ };
26668
+ _proto._onLimitsChanged = function _onLimitsChanged() {
26669
+ var limits = this._limits;
26670
+ if (limits && this._nativeJoint) {
26671
+ if (this.useSpring) {
26672
+ this._nativeJoint.setSoftLimit(limits.min, limits.max, limits.stiffness, limits.damping);
26673
+ } else {
26674
+ this._nativeJoint.setHardLimit(limits.min, limits.max, limits.contactDistance);
26675
+ }
26676
+ }
26142
26677
  };
26143
26678
  _create_class$2(HingeJoint, [
26144
26679
  {
@@ -26151,24 +26686,10 @@
26151
26686
  set: function set(value) {
26152
26687
  var axis = this._axis;
26153
26688
  if (value !== axis) {
26689
+ var _this__nativeJoint;
26154
26690
  axis.copyFrom(value);
26691
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setAxis(axis);
26155
26692
  }
26156
- this._nativeJoint.setAxis(axis);
26157
- }
26158
- },
26159
- {
26160
- key: "swingOffset",
26161
- get: /**
26162
- * The swing offset.
26163
- */ function get() {
26164
- return this._colliderInfo.localPosition;
26165
- },
26166
- set: function set(value) {
26167
- var swingOffset = this._colliderInfo.localPosition;
26168
- if (value !== swingOffset) {
26169
- swingOffset.copyFrom(value);
26170
- }
26171
- this._nativeJoint.setSwingOffset(swingOffset);
26172
26693
  }
26173
26694
  },
26174
26695
  {
@@ -26176,7 +26697,11 @@
26176
26697
  get: /**
26177
26698
  * The current angle in degrees of the joint relative to its rest position.
26178
26699
  */ function get() {
26179
- return this._nativeJoint.getAngle();
26700
+ var nativeJoint = this._nativeJoint;
26701
+ if (nativeJoint) {
26702
+ this._angle = nativeJoint.getAngle();
26703
+ }
26704
+ return this._angle;
26180
26705
  }
26181
26706
  },
26182
26707
  {
@@ -26184,7 +26709,11 @@
26184
26709
  get: /**
26185
26710
  * The angular velocity of the joint in degrees per second.
26186
26711
  */ function get() {
26187
- return this._nativeJoint.getVelocity();
26712
+ var nativeJoint = this._nativeJoint;
26713
+ if (nativeJoint) {
26714
+ this._velocity = nativeJoint.getVelocity();
26715
+ }
26716
+ return this._velocity;
26188
26717
  }
26189
26718
  },
26190
26719
  {
@@ -26196,8 +26725,9 @@
26196
26725
  },
26197
26726
  set: function set(value) {
26198
26727
  if (value !== this.useLimits) {
26728
+ var _this__nativeJoint;
26199
26729
  value ? this._hingeFlags |= HingeJointFlag.LimitEnabled : this._hingeFlags &= ~HingeJointFlag.LimitEnabled;
26200
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
26730
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.LimitEnabled, value);
26201
26731
  }
26202
26732
  }
26203
26733
  },
@@ -26210,8 +26740,9 @@
26210
26740
  },
26211
26741
  set: function set(value) {
26212
26742
  if (value !== this.useMotor) {
26743
+ var _this__nativeJoint;
26213
26744
  value ? this._hingeFlags |= HingeJointFlag.DriveEnabled : this._hingeFlags &= ~HingeJointFlag.DriveEnabled;
26214
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
26745
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setHingeJointFlag(HingeJointFlag.DriveEnabled, value);
26215
26746
  }
26216
26747
  }
26217
26748
  },
@@ -26225,7 +26756,7 @@
26225
26756
  set: function set(value) {
26226
26757
  if (this._useSpring !== value) {
26227
26758
  this._useSpring = value;
26228
- this.limits = this._limits;
26759
+ this._onLimitsChanged();
26229
26760
  }
26230
26761
  }
26231
26762
  },
@@ -26234,15 +26765,15 @@
26234
26765
  get: /**
26235
26766
  * The motor will apply a force up to a maximum force to achieve the target velocity in degrees per second.
26236
26767
  */ function get() {
26237
- return this._jointMonitor;
26768
+ return this._jointMotor;
26238
26769
  },
26239
26770
  set: function set(value) {
26240
- if (this._jointMonitor !== value) {
26241
- this._jointMonitor = value;
26242
- this._nativeJoint.setDriveVelocity(value.targetVelocity);
26243
- this._nativeJoint.setDriveForceLimit(value.forceLimit);
26244
- this._nativeJoint.setDriveGearRatio(value.gearRation);
26245
- this._nativeJoint.setHingeJointFlag(HingeJointFlag.DriveFreeSpin, value.freeSpin);
26771
+ if (this._jointMotor !== value) {
26772
+ var _this__jointMotor;
26773
+ (_this__jointMotor = this._jointMotor) == null ? void 0 : _this__jointMotor._updateFlagManager.removeListener(this._onMotorChanged);
26774
+ this._jointMotor = value;
26775
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onMotorChanged);
26776
+ this._onMotorChanged();
26246
26777
  }
26247
26778
  }
26248
26779
  },
@@ -26255,12 +26786,11 @@
26255
26786
  },
26256
26787
  set: function set(value) {
26257
26788
  if (this._limits !== value) {
26789
+ var _this__limits;
26790
+ (_this__limits = this._limits) == null ? void 0 : _this__limits._updateFlagManager.removeListener(this._onLimitsChanged);
26258
26791
  this._limits = value;
26259
- if (this.useSpring) {
26260
- this._nativeJoint.setSoftLimit(value.min, value.max, value.stiffness, value.damping);
26261
- } else {
26262
- this._nativeJoint.setHardLimit(value.min, value.max, value.contactDistance);
26263
- }
26792
+ value == null ? void 0 : value._updateFlagManager.addListener(this._onLimitsChanged);
26793
+ this._onLimitsChanged();
26264
26794
  }
26265
26795
  }
26266
26796
  }
@@ -26268,20 +26798,20 @@
26268
26798
  return HingeJoint;
26269
26799
  }(exports.Joint);
26270
26800
  __decorate$1([
26271
- ignoreClone
26801
+ deepClone
26272
26802
  ], HingeJoint.prototype, "_axis", void 0);
26273
26803
  __decorate$1([
26274
- ignoreClone
26275
- ], HingeJoint.prototype, "_hingeFlags", void 0);
26804
+ deepClone
26805
+ ], HingeJoint.prototype, "_jointMotor", void 0);
26276
26806
  __decorate$1([
26277
- ignoreClone
26278
- ], HingeJoint.prototype, "_useSpring", void 0);
26807
+ deepClone
26808
+ ], HingeJoint.prototype, "_limits", void 0);
26279
26809
  __decorate$1([
26280
26810
  ignoreClone
26281
- ], HingeJoint.prototype, "_jointMonitor", void 0);
26811
+ ], HingeJoint.prototype, "_onMotorChanged", null);
26282
26812
  __decorate$1([
26283
26813
  ignoreClone
26284
- ], HingeJoint.prototype, "_limits", void 0);
26814
+ ], HingeJoint.prototype, "_onLimitsChanged", null);
26285
26815
  /**
26286
26816
  * A joint that maintains an upper or lower bound (or both) on the distance between two points on different objects.
26287
26817
  */ var SpringJoint = /*#__PURE__*/ function(Joint) {
@@ -26292,40 +26822,20 @@
26292
26822
  return _this;
26293
26823
  }
26294
26824
  var _proto = SpringJoint.prototype;
26295
- /**
26296
- * @internal
26297
- */ _proto._onAwake = function _onAwake() {
26298
- var collider = this._colliderInfo;
26299
- collider.localPosition = new Vector3();
26300
- collider.collider = this.entity.getComponent(exports.Collider);
26301
- this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(collider.collider._nativeCollider);
26302
- };
26303
- /**
26304
- * @internal
26305
- */ _proto._cloneTo = function _cloneTo(target) {
26306
- target.swingOffset = this.swingOffset;
26307
- target.minDistance = this.minDistance;
26308
- target.maxDistance = this.maxDistance;
26309
- target.tolerance = this.tolerance;
26310
- target.stiffness = this.stiffness;
26311
- target.damping = this.damping;
26825
+ _proto._createJoint = function _createJoint() {
26826
+ var colliderInfo = this._colliderInfo;
26827
+ colliderInfo.collider = this.entity.getComponent(exports.Collider);
26828
+ this._nativeJoint = PhysicsScene._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
26829
+ };
26830
+ _proto._syncNative = function _syncNative() {
26831
+ Joint.prototype._syncNative.call(this);
26832
+ this._nativeJoint.setMinDistance(this._minDistance);
26833
+ this._nativeJoint.setMaxDistance(this._maxDistance);
26834
+ this._nativeJoint.setTolerance(this._tolerance);
26835
+ this._nativeJoint.setStiffness(this._stiffness);
26836
+ this._nativeJoint.setDamping(this._damping);
26312
26837
  };
26313
26838
  _create_class$2(SpringJoint, [
26314
- {
26315
- key: "swingOffset",
26316
- get: /**
26317
- * The swing offset.
26318
- */ function get() {
26319
- return this._colliderInfo.localPosition;
26320
- },
26321
- set: function set(value) {
26322
- var swingOffset = this._colliderInfo.localPosition;
26323
- if (value !== swingOffset) {
26324
- swingOffset.copyFrom(value);
26325
- }
26326
- this._nativeJoint.setSwingOffset(value);
26327
- }
26328
- },
26329
26839
  {
26330
26840
  key: "minDistance",
26331
26841
  get: /**
@@ -26335,8 +26845,9 @@
26335
26845
  },
26336
26846
  set: function set(value) {
26337
26847
  if (this._minDistance !== value) {
26848
+ var _this__nativeJoint;
26338
26849
  this._minDistance = value;
26339
- this._nativeJoint.setMinDistance(value);
26850
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMinDistance(value);
26340
26851
  }
26341
26852
  }
26342
26853
  },
@@ -26349,8 +26860,9 @@
26349
26860
  },
26350
26861
  set: function set(value) {
26351
26862
  if (this._maxDistance !== value) {
26863
+ var _this__nativeJoint;
26352
26864
  this._maxDistance = value;
26353
- this._nativeJoint.setMaxDistance(value);
26865
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setMaxDistance(value);
26354
26866
  }
26355
26867
  }
26356
26868
  },
@@ -26363,8 +26875,9 @@
26363
26875
  },
26364
26876
  set: function set(value) {
26365
26877
  if (this._tolerance !== value) {
26878
+ var _this__nativeJoint;
26366
26879
  this._tolerance = value;
26367
- this._nativeJoint.setTolerance(value);
26880
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setTolerance(value);
26368
26881
  }
26369
26882
  }
26370
26883
  },
@@ -26377,8 +26890,9 @@
26377
26890
  },
26378
26891
  set: function set(value) {
26379
26892
  if (this._stiffness !== value) {
26893
+ var _this__nativeJoint;
26380
26894
  this._stiffness = value;
26381
- this._nativeJoint.setStiffness(value);
26895
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setStiffness(value);
26382
26896
  }
26383
26897
  }
26384
26898
  },
@@ -26391,8 +26905,9 @@
26391
26905
  },
26392
26906
  set: function set(value) {
26393
26907
  if (this._damping !== value) {
26908
+ var _this__nativeJoint;
26394
26909
  this._damping = value;
26395
- this._nativeJoint.setDamping(value);
26910
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setDamping(value);
26396
26911
  }
26397
26912
  }
26398
26913
  }
@@ -26401,21 +26916,167 @@
26401
26916
  }(exports.Joint);
26402
26917
  /**
26403
26918
  * JointLimits is used to limit the joints angle.
26404
- */ var JointLimits = function JointLimits() {
26405
- /** The upper angular limit (in degrees) of the joint. */ this.max = 0;
26406
- /** The lower angular limit (in degrees) of the joint. */ this.min = 0;
26407
- /** Distance inside the limit value at which the limit will be considered to be active by the solver. */ this.contactDistance = -1;
26408
- /** The spring forces used to reach the target position. */ this.stiffness = 0;
26409
- /** The damper force uses to dampen the spring. */ this.damping = 0;
26410
- };
26919
+ */ var JointLimits = /*#__PURE__*/ function() {
26920
+ function JointLimits() {
26921
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
26922
+ this._max = 0;
26923
+ this._min = 0;
26924
+ this._contactDistance = -1;
26925
+ this._stiffness = 0;
26926
+ this._damping = 0;
26927
+ }
26928
+ _create_class$2(JointLimits, [
26929
+ {
26930
+ key: "max",
26931
+ get: /**
26932
+ * The upper angular limit (in radians) of the joint.
26933
+ */ function get() {
26934
+ return this._max;
26935
+ },
26936
+ set: function set(value) {
26937
+ if (value < this._min) {
26938
+ throw new Error("Max limit must be greater than min limit");
26939
+ }
26940
+ if (this._max !== value) {
26941
+ this._max = value;
26942
+ this._updateFlagManager.dispatch();
26943
+ }
26944
+ }
26945
+ },
26946
+ {
26947
+ key: "min",
26948
+ get: /**
26949
+ * The lower angular limit (in radians) of the joint.
26950
+ */ function get() {
26951
+ return this._min;
26952
+ },
26953
+ set: function set(value) {
26954
+ if (value > this._max) {
26955
+ throw new Error("Min limit must be less than max limit");
26956
+ }
26957
+ if (this._min !== value) {
26958
+ this._min = value;
26959
+ this._updateFlagManager.dispatch();
26960
+ }
26961
+ }
26962
+ },
26963
+ {
26964
+ key: "contactDistance",
26965
+ get: /**
26966
+ * Distance inside the limit value at which the limit will be considered to be active by the solver.
26967
+ * Default is the lesser of 0.1 radians, and 0.49 * (upperLimit - lowerLimit)
26968
+ */ function get() {
26969
+ if (this._contactDistance === -1) {
26970
+ return Math.min(0.1, 0.49 * (this._max - this._min));
26971
+ }
26972
+ return this._contactDistance;
26973
+ },
26974
+ set: function set(value) {
26975
+ if (this._contactDistance !== value) {
26976
+ this._contactDistance = value;
26977
+ this._updateFlagManager.dispatch();
26978
+ }
26979
+ }
26980
+ },
26981
+ {
26982
+ key: "stiffness",
26983
+ get: /**
26984
+ * The spring forces used to reach the target position.
26985
+ */ function get() {
26986
+ return this._stiffness;
26987
+ },
26988
+ set: function set(value) {
26989
+ if (this._stiffness !== value) {
26990
+ this._stiffness = value;
26991
+ this._updateFlagManager.dispatch();
26992
+ }
26993
+ }
26994
+ },
26995
+ {
26996
+ key: "damping",
26997
+ get: /**
26998
+ * The damper force uses to dampen the spring.
26999
+ */ function get() {
27000
+ return this._damping;
27001
+ },
27002
+ set: function set(value) {
27003
+ if (this._damping !== value) {
27004
+ this._damping = value;
27005
+ this._updateFlagManager.dispatch();
27006
+ }
27007
+ }
27008
+ }
27009
+ ]);
27010
+ return JointLimits;
27011
+ }();
27012
+ __decorate$1([
27013
+ deepClone
27014
+ ], JointLimits.prototype, "_updateFlagManager", void 0);
26411
27015
  /**
26412
27016
  * The JointMotor is used to motorize a joint.
26413
- */ var JointMotor = function JointMotor() {
26414
- /** The motor will apply a force up to force to achieve targetVelocity. */ this.targetVelocity = 0;
26415
- /** The force limit.*/ this.forceLimit = Number.MAX_VALUE;
26416
- /** Gear ration for the motor */ this.gearRation = 1.0;
26417
- /** If freeSpin is enabled the motor will only accelerate but never slow down. */ this.freeSpin = false;
26418
- };
27017
+ */ var JointMotor = /*#__PURE__*/ function() {
27018
+ function JointMotor() {
27019
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
27020
+ this._targetVelocity = 0;
27021
+ this._forceLimit = Number.MAX_VALUE;
27022
+ this._gearRatio = 1.0;
27023
+ this._freeSpin = false;
27024
+ }
27025
+ _create_class$2(JointMotor, [
27026
+ {
27027
+ key: "targetVelocity",
27028
+ get: /**
27029
+ * The motor will apply a force up to force to achieve targetVelocity.
27030
+ */ function get() {
27031
+ return this._targetVelocity;
27032
+ },
27033
+ set: function set(value) {
27034
+ this._targetVelocity = value;
27035
+ this._updateFlagManager.dispatch();
27036
+ }
27037
+ },
27038
+ {
27039
+ key: "forceLimit",
27040
+ get: /**
27041
+ * The force limit.
27042
+ */ function get() {
27043
+ return this._forceLimit;
27044
+ },
27045
+ set: function set(value) {
27046
+ this._forceLimit = value;
27047
+ this._updateFlagManager.dispatch();
27048
+ }
27049
+ },
27050
+ {
27051
+ key: "gearRatio",
27052
+ get: /**
27053
+ * Gear ration for the motor
27054
+ */ function get() {
27055
+ return this._gearRatio;
27056
+ },
27057
+ set: function set(value) {
27058
+ this._gearRatio = value;
27059
+ this._updateFlagManager.dispatch();
27060
+ }
27061
+ },
27062
+ {
27063
+ key: "freeSpin",
27064
+ get: /**
27065
+ * If freeSpin is enabled the motor will only accelerate but never slow down.
27066
+ */ function get() {
27067
+ return this._freeSpin;
27068
+ },
27069
+ set: function set(value) {
27070
+ this._freeSpin = value;
27071
+ this._updateFlagManager.dispatch();
27072
+ }
27073
+ }
27074
+ ]);
27075
+ return JointMotor;
27076
+ }();
27077
+ __decorate$1([
27078
+ deepClone
27079
+ ], JointMotor.prototype, "_updateFlagManager", void 0);
26419
27080
  /**
26420
27081
  * Abstract class for collider shapes.
26421
27082
  */ var ColliderShape = /*#__PURE__*/ function() {
@@ -26437,28 +27098,39 @@
26437
27098
  this._rotation._onValueChanged = this._setRotation;
26438
27099
  //@ts-ignore
26439
27100
  this._position._onValueChanged = this._setPosition;
27101
+ Engine._physicalObjectsMap[this._id] = this;
26440
27102
  }
26441
27103
  var _proto = ColliderShape.prototype;
26442
27104
  /**
26443
27105
  * @internal
26444
27106
  */ _proto._cloneTo = function _cloneTo(target) {
26445
- target.contactOffset = this.contactOffset;
26446
- target.rotation = this.rotation;
26447
- target.position = this.position;
26448
- target.isTrigger = this.isTrigger;
26449
- target.material = this.material;
27107
+ target._syncNative();
26450
27108
  };
26451
27109
  /**
26452
27110
  * @internal
26453
27111
  */ _proto._destroy = function _destroy() {
26454
- this._material._destroy();
26455
27112
  this._nativeShape.destroy();
27113
+ this._nativeShape = null;
27114
+ delete Engine._physicalObjectsMap[this._id];
27115
+ };
27116
+ _proto._syncNative = function _syncNative() {
27117
+ var _this__collider;
27118
+ this._nativeShape.setPosition(this._position);
27119
+ this._nativeShape.setRotation(this._rotation);
27120
+ this._nativeShape.setContactOffset(this._contactOffset);
27121
+ this._nativeShape.setIsTrigger(this._isTrigger);
27122
+ this._nativeShape.setMaterial(this._material._nativeMaterial);
27123
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
26456
27124
  };
26457
27125
  _proto._setPosition = function _setPosition() {
27126
+ var _this__collider;
26458
27127
  this._nativeShape.setPosition(this._position);
27128
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
26459
27129
  };
26460
27130
  _proto._setRotation = function _setRotation() {
27131
+ var _this__collider;
26461
27132
  this._nativeShape.setRotation(this._rotation);
27133
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
26462
27134
  };
26463
27135
  _create_class$2(ColliderShape, [
26464
27136
  {
@@ -26480,11 +27152,12 @@
26480
27152
  {
26481
27153
  key: "contactOffset",
26482
27154
  get: /**
26483
- * Contact offset for this shape.
27155
+ * Contact offset for this shape, the value must be greater than or equal to 0.
26484
27156
  */ function get() {
26485
27157
  return this._contactOffset;
26486
27158
  },
26487
27159
  set: function set(value) {
27160
+ value = Math.max(0, value);
26488
27161
  if (this._contactOffset !== value) {
26489
27162
  this._contactOffset = value;
26490
27163
  this._nativeShape.setContactOffset(value);
@@ -26559,20 +27232,17 @@
26559
27232
  ignoreClone
26560
27233
  ], ColliderShape.prototype, "_id", void 0);
26561
27234
  __decorate$1([
26562
- ignoreClone
26563
- ], ColliderShape.prototype, "_material", void 0);
26564
- __decorate$1([
26565
- ignoreClone
26566
- ], ColliderShape.prototype, "_isTrigger", void 0);
26567
- __decorate$1([
26568
- ignoreClone
27235
+ deepClone
26569
27236
  ], ColliderShape.prototype, "_rotation", void 0);
26570
27237
  __decorate$1([
26571
- ignoreClone
27238
+ deepClone
26572
27239
  ], ColliderShape.prototype, "_position", void 0);
26573
27240
  __decorate$1([
26574
27241
  ignoreClone
26575
- ], ColliderShape.prototype, "_contactOffset", void 0);
27242
+ ], ColliderShape.prototype, "_setPosition", null);
27243
+ __decorate$1([
27244
+ ignoreClone
27245
+ ], ColliderShape.prototype, "_setRotation", null);
26576
27246
  /**
26577
27247
  * Physical collider shape for box.
26578
27248
  */ var BoxColliderShape = /*#__PURE__*/ function(ColliderShape) {
@@ -26581,17 +27251,14 @@
26581
27251
  var _this;
26582
27252
  _this = ColliderShape.call(this) || this, _this._size = new Vector3(1, 1, 1);
26583
27253
  _this._nativeShape = PhysicsScene._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
26584
- _this._setSize = _this._setSize.bind(_this);
26585
27254
  //@ts-ignore
26586
- _this._size._onValueChanged = _this._setSize;
27255
+ _this._size._onValueChanged = _this._setSize.bind(_this);
26587
27256
  return _this;
26588
27257
  }
26589
27258
  var _proto = BoxColliderShape.prototype;
26590
- /**
26591
- * @internal
26592
- */ _proto._cloneTo = function _cloneTo(target) {
26593
- ColliderShape.prototype._cloneTo.call(this, target);
26594
- target.size = this.size;
27259
+ _proto._syncNative = function _syncNative() {
27260
+ ColliderShape.prototype._syncNative.call(this);
27261
+ this._setSize();
26595
27262
  };
26596
27263
  _proto._setSize = function _setSize() {
26597
27264
  this._nativeShape.setSize(this._size);
@@ -26614,8 +27281,11 @@
26614
27281
  return BoxColliderShape;
26615
27282
  }(ColliderShape);
26616
27283
  __decorate$1([
26617
- ignoreClone
27284
+ deepClone
26618
27285
  ], BoxColliderShape.prototype, "_size", void 0);
27286
+ __decorate$1([
27287
+ ignoreClone
27288
+ ], BoxColliderShape.prototype, "_setSize", null);
26619
27289
  /**
26620
27290
  * Physical collider shape for sphere.
26621
27291
  */ var SphereColliderShape = /*#__PURE__*/ function(ColliderShape) {
@@ -26627,9 +27297,9 @@
26627
27297
  return _this;
26628
27298
  }
26629
27299
  var _proto = SphereColliderShape.prototype;
26630
- _proto._cloneTo = function _cloneTo(target) {
26631
- ColliderShape.prototype._cloneTo.call(this, target);
26632
- target.radius = this.radius;
27300
+ _proto._syncNative = function _syncNative() {
27301
+ ColliderShape.prototype._syncNative.call(this);
27302
+ this._nativeShape.setRadius(this._radius);
26633
27303
  };
26634
27304
  _create_class$2(SphereColliderShape, [
26635
27305
  {
@@ -26649,9 +27319,6 @@
26649
27319
  ]);
26650
27320
  return SphereColliderShape;
26651
27321
  }(ColliderShape);
26652
- __decorate$1([
26653
- ignoreClone
26654
- ], SphereColliderShape.prototype, "_radius", void 0);
26655
27322
  /**
26656
27323
  * Physical collider shape plane.
26657
27324
  */ var PlaneColliderShape = /*#__PURE__*/ function(ColliderShape) {
@@ -26675,13 +27342,11 @@
26675
27342
  return _this;
26676
27343
  }
26677
27344
  var _proto = CapsuleColliderShape.prototype;
26678
- /**
26679
- * @internal
26680
- */ _proto._cloneTo = function _cloneTo(target) {
26681
- ColliderShape.prototype._cloneTo.call(this, target);
26682
- target.radius = this.radius;
26683
- target.height = this.height;
26684
- target.upAxis = this.upAxis;
27345
+ _proto._syncNative = function _syncNative() {
27346
+ ColliderShape.prototype._syncNative.call(this);
27347
+ this._nativeShape.setRadius(this._radius);
27348
+ this._nativeShape.setHeight(this._height);
27349
+ this._nativeShape.setUpAxis(this._upAxis);
26685
27350
  };
26686
27351
  _create_class$2(CapsuleColliderShape, [
26687
27352
  {
@@ -26729,15 +27394,6 @@
26729
27394
  ]);
26730
27395
  return CapsuleColliderShape;
26731
27396
  }(ColliderShape);
26732
- __decorate$1([
26733
- ignoreClone
26734
- ], CapsuleColliderShape.prototype, "_radius", void 0);
26735
- __decorate$1([
26736
- ignoreClone
26737
- ], CapsuleColliderShape.prototype, "_height", void 0);
26738
- __decorate$1([
26739
- ignoreClone
26740
- ], CapsuleColliderShape.prototype, "_upAxis", void 0);
26741
27397
  /**
26742
27398
  * Pointer Manager.
26743
27399
  * @internal
@@ -27295,7 +27951,7 @@
27295
27951
  ParticleBufferUtils.boundsFloatStride = 8;
27296
27952
  ParticleBufferUtils.boundsTimeOffset = 6;
27297
27953
  ParticleBufferUtils.boundsMaxLifetimeOffset = 7;
27298
- 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
27954
+ 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
27299
27955
  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
27300
27956
  var skyProceduralFs = "#define GLSLIFY 1\n#include <common>\nconst float MIE_G=-0.990;const float MIE_G2=0.9801;const float SKY_GROUND_THRESHOLD=0.02;uniform float material_SunSize;uniform float material_SunSizeConvergence;uniform vec4 scene_SunlightColor;uniform vec3 scene_SunlightDirection;varying vec3 v_GroundColor;varying vec3 v_SkyColor;\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_RayDir;\n#else\nvarying float v_SkyGroundFactor;\n#endif\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_SunColor;\n#endif\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n#define LINEAR_2_OUTPUT(color) sqrt(color)\n#endif\nfloat getMiePhase(float eyeCos,float eyeCos2){float temp=1.0+MIE_G2-2.0*MIE_G*eyeCos;temp=pow(temp,pow(material_SunSize,0.65)*10.0);temp=max(temp,1.0e-4);temp=1.5*((1.0-MIE_G2)/(2.0+MIE_G2))*(1.0+eyeCos2)/temp;return temp;}float calcSunAttenuation(vec3 lightPos,vec3 ray){\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nfloat focusedEyeCos=pow(clamp(dot(lightPos,ray),0.0,1.0),material_SunSizeConvergence);return getMiePhase(-focusedEyeCos,focusedEyeCos*focusedEyeCos);\n#else\nvec3 delta=lightPos-ray;float dist=length(delta);float spot=1.0-smoothstep(0.0,material_SunSize,dist);return spot*spot;\n#endif\n}void main(){vec3 col=vec3(0.0,0.0,0.0);\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvec3 ray=normalize(v_Vertex);float y=ray.y/SKY_GROUND_THRESHOLD;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvec3 ray=v_RayDir;float y=ray.y/SKY_GROUND_THRESHOLD;\n#else\nfloat y=v_SkyGroundFactor;\n#endif\ncol=mix(v_SkyColor,v_GroundColor,clamp(y,0.0,1.0));\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nif(y<0.0)col+=v_SunColor*calcSunAttenuation(-scene_SunlightDirection,-ray);\n#endif\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\ncol=LINEAR_2_OUTPUT(col);\n#endif\ngl_FragColor=vec4(col,1.0);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
27301
27957
  var skyProceduralVs = "#define GLSLIFY 1\n#define OUTER_RADIUS 1.025\n#define RAYLEIGH (mix(0.0, 0.0025, pow(material_AtmosphereThickness,2.5)))\n#define MIE 0.0010\n#define SUN_BRIGHTNESS 20.0\n#define MAX_SCATTER 50.0\nconst float SKY_GROUND_THRESHOLD=0.02;const float outerRadius=OUTER_RADIUS;const float outerRadius2=OUTER_RADIUS*OUTER_RADIUS;const float innerRadius=1.0;const float innerRadius2=1.0;const float cameraHeight=0.0001;const float HDSundiskIntensityFactor=15.0;const float simpleSundiskIntensityFactor=27.0;const float sunScale=400.0*SUN_BRIGHTNESS;const float kmESun=MIE*SUN_BRIGHTNESS;const float km4PI=MIE*4.0*3.14159265;const float scale=1.0/(OUTER_RADIUS-1.0);const float scaleDepth=0.25;const float scaleOverScaleDepth=(1.0/(OUTER_RADIUS-1.0))/0.25;const float samples=2.0;const vec3 c_DefaultScatteringWavelength=vec3(0.65,0.57,0.475);const vec3 c_VariableRangeForScatteringWavelength=vec3(0.15,0.15,0.15);attribute vec4 POSITION;uniform mat4 camera_VPMat;uniform vec3 material_SkyTint;uniform vec3 material_GroundTint;uniform float material_Exposure;uniform float material_AtmosphereThickness;uniform vec4 scene_SunlightColor;uniform vec3 scene_SunlightDirection;varying vec3 v_GroundColor;varying vec3 v_SkyColor;\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_RayDir;\n#else\nvarying float v_SkyGroundFactor;\n#endif\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_SunColor;\n#endif\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n#define COLOR_2_GAMMA(color) color\n#define COLOR_2_LINEAR(color) color*color\n#else\n#define GAMMA 2.2\n#define COLOR_2_GAMMA(color) pow(color,vec3(1.0/GAMMA))\n#define COLOR_2_LINEAR(color) color\n#endif\nfloat getRayleighPhase(vec3 light,vec3 ray){float eyeCos=dot(light,ray);return 0.75+0.75*eyeCos*eyeCos;}float scaleAngle(float inCos){float x=1.0-inCos;return 0.25*exp(-0.00287+x*(0.459+x*(3.83+x*(-6.80+x*5.25))));}void main(){gl_Position=camera_VPMat*vec4(POSITION.xyz,1.0);vec3 skyTintInGammaSpace=COLOR_2_GAMMA(material_SkyTint);vec3 scatteringWavelength=mix(c_DefaultScatteringWavelength-c_VariableRangeForScatteringWavelength,c_DefaultScatteringWavelength+c_VariableRangeForScatteringWavelength,vec3(1.0)-skyTintInGammaSpace);vec3 invWavelength=1.0/pow(scatteringWavelength,vec3(4.0));float krESun=RAYLEIGH*SUN_BRIGHTNESS;float kr4PI=RAYLEIGH*4.0*3.14159265;vec3 cameraPos=vec3(0.0,innerRadius+cameraHeight,0.0);vec3 eyeRay=normalize(POSITION.xyz);float far=0.0;vec3 cIn,cOut;if(eyeRay.y>=0.0){far=sqrt(outerRadius2+innerRadius2*eyeRay.y*eyeRay.y-innerRadius2)-innerRadius*eyeRay.y;float height=innerRadius+cameraHeight;float depth=exp(scaleOverScaleDepth*-cameraHeight);float startAngle=dot(eyeRay,cameraPos)/height;float startOffset=depth*scaleAngle(startAngle);float sampleLength=far/samples;float scaledLength=sampleLength*scale;vec3 sampleRay=eyeRay*sampleLength;vec3 samplePoint=cameraPos+sampleRay*0.5;vec3 frontColor=vec3(0.0);{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float lightAngle=dot(-scene_SunlightDirection,samplePoint)/height;float cameraAngle=dot(eyeRay,samplePoint)/height;float scatter=(startOffset+depth*(scaleAngle(lightAngle)-scaleAngle(cameraAngle)));vec3 attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float lightAngle=dot(-scene_SunlightDirection,samplePoint)/height;float cameraAngle=dot(eyeRay,samplePoint)/height;float scatter=(startOffset+depth*(scaleAngle(lightAngle)-scaleAngle(cameraAngle)));vec3 attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}cIn=frontColor*(invWavelength*krESun);cOut=frontColor*kmESun;}else{far=(-cameraHeight)/(min(-0.001,eyeRay.y));vec3 pos=cameraPos+far*eyeRay;float depth=exp((-cameraHeight)*(1.0/scaleDepth));float cameraAngle=dot(-eyeRay,pos);float lightAngle=dot(-scene_SunlightDirection,pos);float cameraScale=scaleAngle(cameraAngle);float lightScale=scaleAngle(lightAngle);float cameraOffset=depth*cameraScale;float temp=lightScale+cameraScale;float sampleLength=far/samples;float scaledLength=sampleLength*scale;vec3 sampleRay=eyeRay*sampleLength;vec3 samplePoint=cameraPos+sampleRay*0.5;vec3 frontColor=vec3(0.0,0.0,0.0);vec3 attenuate;{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float scatter=depth*temp-cameraOffset;attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}cIn=frontColor*(invWavelength*krESun+kmESun);cOut=clamp(attenuate,0.0,1.0);}\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nv_Vertex=-POSITION.xyz;\n#elif defined(MATERIAL_SUN_SIMPLE)\nv_RayDir=-eyeRay;\n#else\nv_SkyGroundFactor=-eyeRay.y/SKY_GROUND_THRESHOLD;\n#endif\nv_GroundColor=material_Exposure*(cIn+COLOR_2_LINEAR(material_GroundTint)*cOut);v_SkyColor=material_Exposure*(cIn*getRayleighPhase(-scene_SunlightDirection,-eyeRay));float lightColorIntensity=clamp(length(scene_SunlightColor.xyz),0.25,1.0);\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nv_SunColor=HDSundiskIntensityFactor*clamp(cOut,0.0,1.0)*scene_SunlightColor.xyz/lightColorIntensity;\n#elif defined(MATERIAL_SUN_SIMPLE)\nv_SunColor=simpleSundiskIntensityFactor*clamp(cOut*sunScale,0.0,1.0)*scene_SunlightColor.xyz/lightColorIntensity;\n#endif\n}"; // eslint-disable-line
@@ -27538,7 +28194,7 @@
27538
28194
  _inherits$2(Engine, EventDispatcher);
27539
28195
  function Engine(canvas, hardwareRenderer, configuration) {
27540
28196
  var _this;
27541
- _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() {
28197
+ _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() {
27542
28198
  if (_this._vSyncCount) {
27543
28199
  var _this_xrManager;
27544
28200
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -27963,6 +28619,7 @@
27963
28619
  /** @internal */ Engine._gammaMacro = ShaderMacro.getByName("ENGINE_IS_COLORSPACE_GAMMA");
27964
28620
  /** @internal */ Engine._noDepthTextureMacro = ShaderMacro.getByName("ENGINE_NO_DEPTH_TEXTURE");
27965
28621
  /** @internal Conversion of space units to pixel units for 2D. */ Engine._pixelsPerUnit = 100;
28622
+ /** @internal */ Engine._physicalObjectsMap = {};
27966
28623
  /**
27967
28624
  * Canvas.
27968
28625
  */ var Canvas = /*#__PURE__*/ function() {
@@ -34244,7 +34901,12 @@
34244
34901
  };
34245
34902
  _proto._render = function _render(context) {
34246
34903
  var generator = this.generator;
34247
- generator._primitive.instanceCount = generator._getAliveParticleCount();
34904
+ // Don't need to render when no particles
34905
+ var aliveParticleCount = generator._getAliveParticleCount();
34906
+ if (!aliveParticleCount) {
34907
+ return;
34908
+ }
34909
+ generator._primitive.instanceCount = aliveParticleCount;
34248
34910
  var material = this.getMaterial();
34249
34911
  if (!material) {
34250
34912
  return;
@@ -36375,7 +37037,8 @@
36375
37037
  */ _proto._emit = function _emit(time, count) {
36376
37038
  if (this.emission.enabled) {
36377
37039
  // Wait the existing particles to be retired
36378
- if (this.main._maxParticleBuffer < this._currentParticleCount) {
37040
+ var notRetireParticleCount = this._getNotRetiredParticleCount();
37041
+ if (notRetireParticleCount >= this.main.maxParticles) {
36379
37042
  return;
36380
37043
  }
36381
37044
  var position = ParticleGenerator._tempVector30;
@@ -38134,6 +38797,396 @@
38134
38797
  };
38135
38798
  return CubeProbe;
38136
38799
  }(Probe);
38800
+ /**
38801
+ * Audio Clip.
38802
+ */ var AudioClip = /*#__PURE__*/ function(ReferResource) {
38803
+ _inherits$2(AudioClip, ReferResource);
38804
+ function AudioClip(engine, name) {
38805
+ if (name === void 0) name = "";
38806
+ var _this;
38807
+ _this = ReferResource.call(this, engine) || this, _this._audioBuffer = null;
38808
+ _this.name = name;
38809
+ return _this;
38810
+ }
38811
+ var _proto = AudioClip.prototype;
38812
+ /**
38813
+ * @internal
38814
+ */ _proto._getAudioSource = function _getAudioSource() {
38815
+ return this._audioBuffer;
38816
+ };
38817
+ /**
38818
+ * @internal
38819
+ */ _proto._setAudioSource = function _setAudioSource(value) {
38820
+ this._audioBuffer = value;
38821
+ };
38822
+ _proto._onDestroy = function _onDestroy() {
38823
+ ReferResource.prototype._onDestroy.call(this);
38824
+ this._audioBuffer = null;
38825
+ this.name = null;
38826
+ };
38827
+ _create_class$2(AudioClip, [
38828
+ {
38829
+ key: "channels",
38830
+ get: /**
38831
+ * Number of discrete audio channels.
38832
+ */ function get() {
38833
+ return this._audioBuffer.numberOfChannels;
38834
+ }
38835
+ },
38836
+ {
38837
+ key: "sampleRate",
38838
+ get: /**
38839
+ * Sample rate, in samples per second.
38840
+ */ function get() {
38841
+ return this._audioBuffer.sampleRate;
38842
+ }
38843
+ },
38844
+ {
38845
+ key: "duration",
38846
+ get: /**
38847
+ * Duration, in seconds.
38848
+ */ function get() {
38849
+ return this._audioBuffer.duration;
38850
+ }
38851
+ }
38852
+ ]);
38853
+ return AudioClip;
38854
+ }(ReferResource);
38855
+ /**
38856
+ * @internal
38857
+ * Audio Manager.
38858
+ */ var AudioManager = /*#__PURE__*/ function() {
38859
+ function AudioManager() {}
38860
+ AudioManager.getContext = function getContext() {
38861
+ var context = AudioManager._context;
38862
+ if (!context) {
38863
+ AudioManager._context = context = new window.AudioContext();
38864
+ // Safari can't resume audio context without element interaction
38865
+ document.addEventListener("pointerdown", AudioManager._tryResume, true);
38866
+ document.addEventListener("touchend", AudioManager._tryResume, true);
38867
+ document.addEventListener("touchstart", AudioManager._tryResume, true);
38868
+ }
38869
+ return context;
38870
+ };
38871
+ AudioManager.getGainNode = function getGainNode() {
38872
+ var gainNode = AudioManager._gainNode;
38873
+ if (!AudioManager._gainNode) {
38874
+ AudioManager._gainNode = gainNode = AudioManager.getContext().createGain();
38875
+ gainNode.connect(AudioManager.getContext().destination);
38876
+ }
38877
+ return gainNode;
38878
+ };
38879
+ AudioManager.isAudioContextRunning = function isAudioContextRunning() {
38880
+ if (AudioManager.getContext().state !== "running") {
38881
+ console.warn("The AudioContext is not running and requires user interaction, such as a click or touch.");
38882
+ return false;
38883
+ }
38884
+ return true;
38885
+ };
38886
+ AudioManager._tryResume = function _tryResume() {
38887
+ if (AudioManager._context.state !== "running") {
38888
+ if (AudioManager._isResuming) {
38889
+ return;
38890
+ }
38891
+ AudioManager._isResuming = true;
38892
+ AudioManager._context.resume().then(function() {
38893
+ AudioManager._isResuming = false;
38894
+ });
38895
+ }
38896
+ };
38897
+ return AudioManager;
38898
+ }();
38899
+ AudioManager._isResuming = false;
38900
+ /**
38901
+ * Audio Source Component.
38902
+ */ var AudioSource = /*#__PURE__*/ function(Component) {
38903
+ _inherits$2(AudioSource, Component);
38904
+ function AudioSource(entity) {
38905
+ var _this;
38906
+ _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;
38907
+ _this._onPlayEnd = _this._onPlayEnd.bind(_this);
38908
+ _this._gainNode = AudioManager.getContext().createGain();
38909
+ _this._gainNode.connect(AudioManager.getGainNode());
38910
+ return _this;
38911
+ }
38912
+ var _proto = AudioSource.prototype;
38913
+ /**
38914
+ * Play the clip.
38915
+ */ _proto.play = function play() {
38916
+ if (!this._canPlay()) {
38917
+ return;
38918
+ }
38919
+ if (this._isPlaying) {
38920
+ return;
38921
+ }
38922
+ var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
38923
+ this._initSourceNode(startTime);
38924
+ this._playTime = AudioManager.getContext().currentTime - startTime;
38925
+ this._pausedTime = -1;
38926
+ this._isPlaying = true;
38927
+ };
38928
+ /**
38929
+ * Stops playing the clip.
38930
+ */ _proto.stop = function stop() {
38931
+ if (this._isPlaying) {
38932
+ this._clearSourceNode();
38933
+ this._isPlaying = false;
38934
+ this._pausedTime = -1;
38935
+ this._playTime = -1;
38936
+ }
38937
+ };
38938
+ /**
38939
+ * Pauses playing the clip.
38940
+ */ _proto.pause = function pause() {
38941
+ if (this._isPlaying) {
38942
+ this._clearSourceNode();
38943
+ this._pausedTime = AudioManager.getContext().currentTime;
38944
+ this._isPlaying = false;
38945
+ }
38946
+ };
38947
+ /**
38948
+ * @internal
38949
+ */ _proto._onEnable = function _onEnable() {
38950
+ this.playOnEnabled && this.play();
38951
+ };
38952
+ /**
38953
+ * @internal
38954
+ */ _proto._onDisable = function _onDisable() {
38955
+ this.pause();
38956
+ };
38957
+ /**
38958
+ * @internal
38959
+ */ _proto._onDestroy = function _onDestroy() {
38960
+ Component.prototype._onDestroy.call(this);
38961
+ this.stop();
38962
+ this.clip = null;
38963
+ };
38964
+ _proto._onPlayEnd = function _onPlayEnd() {
38965
+ this.stop();
38966
+ };
38967
+ _proto._initSourceNode = function _initSourceNode(startTime) {
38968
+ var context = AudioManager.getContext();
38969
+ var sourceNode = context.createBufferSource();
38970
+ sourceNode.buffer = this._clip._getAudioSource();
38971
+ sourceNode.playbackRate.value = this._playbackRate;
38972
+ sourceNode.loop = this._loop;
38973
+ sourceNode.onended = this._onPlayEnd;
38974
+ this._sourceNode = sourceNode;
38975
+ sourceNode.connect(this._gainNode);
38976
+ this._sourceNode.start(0, startTime);
38977
+ };
38978
+ _proto._clearSourceNode = function _clearSourceNode() {
38979
+ this._sourceNode.stop();
38980
+ this._sourceNode.disconnect();
38981
+ this._sourceNode.onended = null;
38982
+ this._sourceNode = null;
38983
+ };
38984
+ _proto._canPlay = function _canPlay() {
38985
+ var _this__clip;
38986
+ var isValidClip = ((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) ? true : false;
38987
+ return isValidClip && AudioManager.isAudioContextRunning();
38988
+ };
38989
+ _create_class$2(AudioSource, [
38990
+ {
38991
+ key: "clip",
38992
+ get: /**
38993
+ * The audio clip to play.
38994
+ */ function get() {
38995
+ return this._clip;
38996
+ },
38997
+ set: function set(value) {
38998
+ var lastClip = this._clip;
38999
+ if (lastClip !== value) {
39000
+ lastClip && lastClip._addReferCount(-1);
39001
+ value && value._addReferCount(1);
39002
+ this._clip = value;
39003
+ this.stop();
39004
+ }
39005
+ }
39006
+ },
39007
+ {
39008
+ key: "isPlaying",
39009
+ get: /**
39010
+ * Whether the clip playing right now.
39011
+ */ function get() {
39012
+ return this._isPlaying;
39013
+ }
39014
+ },
39015
+ {
39016
+ key: "volume",
39017
+ get: /**
39018
+ * The volume of the audio source, ranging from 0 to 1.
39019
+ * @defaultValue `1`
39020
+ */ function get() {
39021
+ return this._volume;
39022
+ },
39023
+ set: function set(value) {
39024
+ value = Math.min(Math.max(0, value), 1.0);
39025
+ this._volume = value;
39026
+ this._gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
39027
+ }
39028
+ },
39029
+ {
39030
+ key: "playbackRate",
39031
+ get: /**
39032
+ * The playback rate of the audio source.
39033
+ * @defaultValue `1`
39034
+ */ function get() {
39035
+ return this._playbackRate;
39036
+ },
39037
+ set: function set(value) {
39038
+ this._playbackRate = value;
39039
+ if (this._isPlaying) {
39040
+ this._sourceNode.playbackRate.value = this._playbackRate;
39041
+ }
39042
+ }
39043
+ },
39044
+ {
39045
+ key: "mute",
39046
+ get: /**
39047
+ * Mutes or unmute the audio source.
39048
+ * Mute sets volume as 0, unmute restore volume.
39049
+ */ function get() {
39050
+ return this.volume === 0;
39051
+ },
39052
+ set: function set(value) {
39053
+ if (value) {
39054
+ this._lastVolume = this.volume;
39055
+ this.volume = 0;
39056
+ } else {
39057
+ this.volume = this._lastVolume;
39058
+ }
39059
+ }
39060
+ },
39061
+ {
39062
+ key: "loop",
39063
+ get: /**
39064
+ * Whether the audio clip looping.
39065
+ * @defaultValue `false`
39066
+ */ function get() {
39067
+ return this._loop;
39068
+ },
39069
+ set: function set(value) {
39070
+ if (value !== this._loop) {
39071
+ this._loop = value;
39072
+ if (this._isPlaying) {
39073
+ this._sourceNode.loop = this._loop;
39074
+ }
39075
+ }
39076
+ }
39077
+ },
39078
+ {
39079
+ key: "time",
39080
+ get: /**
39081
+ * Playback position in seconds.
39082
+ */ function get() {
39083
+ if (this._isPlaying) {
39084
+ var currentTime = AudioManager.getContext().currentTime;
39085
+ return currentTime - this._playTime;
39086
+ } else {
39087
+ return this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
39088
+ }
39089
+ }
39090
+ }
39091
+ ]);
39092
+ return AudioSource;
39093
+ }(Component);
39094
+ __decorate$1([
39095
+ ignoreClone
39096
+ ], AudioSource.prototype, "_isPlaying", void 0);
39097
+ __decorate$1([
39098
+ ignoreClone
39099
+ ], AudioSource.prototype, "_clip", void 0);
39100
+ __decorate$1([
39101
+ deepClone
39102
+ ], AudioSource.prototype, "_gainNode", void 0);
39103
+ __decorate$1([
39104
+ ignoreClone
39105
+ ], AudioSource.prototype, "_sourceNode", void 0);
39106
+ __decorate$1([
39107
+ deepClone
39108
+ ], AudioSource.prototype, "_pausedTime", void 0);
39109
+ __decorate$1([
39110
+ ignoreClone
39111
+ ], AudioSource.prototype, "_playTime", void 0);
39112
+ __decorate$1([
39113
+ deepClone
39114
+ ], AudioSource.prototype, "_volume", void 0);
39115
+ __decorate$1([
39116
+ deepClone
39117
+ ], AudioSource.prototype, "_lastVolume", void 0);
39118
+ __decorate$1([
39119
+ deepClone
39120
+ ], AudioSource.prototype, "_playbackRate", void 0);
39121
+ __decorate$1([
39122
+ deepClone
39123
+ ], AudioSource.prototype, "_loop", void 0);
39124
+ /**
39125
+ * @internal
39126
+ */ var Polyfill = /*#__PURE__*/ function() {
39127
+ function Polyfill() {}
39128
+ Polyfill.registerPolyfill = function registerPolyfill() {
39129
+ Polyfill._registerMatchAll();
39130
+ };
39131
+ Polyfill._registerMatchAll = function _registerMatchAll() {
39132
+ if (!String.prototype.matchAll) {
39133
+ Logger.info("polyfill String.prototype.matchAll");
39134
+ String.prototype.matchAll = function(pattern) {
39135
+ var flags = pattern.flags;
39136
+ var globalFlagIdx = flags.indexOf("g");
39137
+ if (globalFlagIdx === -1) {
39138
+ throw TypeError("String.prototype.matchAll called with a non-global RegExp argument");
39139
+ }
39140
+ var bindThis = this;
39141
+ return function() {
39142
+ var matchResult, matchFlag, matchPattern, _tmp, _tmp1, _i, index, item;
39143
+ return __generator$1(this, function(_state) {
39144
+ switch(_state.label){
39145
+ case 0:
39146
+ matchResult = bindThis.match(pattern);
39147
+ if (matchResult == null) return [
39148
+ 2,
39149
+ null
39150
+ ];
39151
+ matchFlag = flags.split("g").join("");
39152
+ matchPattern = new RegExp(pattern.source, matchFlag);
39153
+ _tmp = [];
39154
+ for(_tmp1 in matchResult)_tmp.push(_tmp1);
39155
+ _i = 0;
39156
+ _state.label = 1;
39157
+ case 1:
39158
+ if (!(_i < _tmp.length)) return [
39159
+ 3,
39160
+ 4
39161
+ ];
39162
+ index = _tmp[_i];
39163
+ item = matchResult[index];
39164
+ return [
39165
+ 4,
39166
+ item.match(matchPattern)
39167
+ ];
39168
+ case 2:
39169
+ _state.sent();
39170
+ _state.label = 3;
39171
+ case 3:
39172
+ _i++;
39173
+ return [
39174
+ 3,
39175
+ 1
39176
+ ];
39177
+ case 4:
39178
+ return [
39179
+ 2
39180
+ ];
39181
+ }
39182
+ });
39183
+ }();
39184
+ };
39185
+ }
39186
+ };
39187
+ return Polyfill;
39188
+ }();
39189
+ Polyfill.registerPolyfill();
38137
39190
 
38138
39191
  var CoreObjects = /*#__PURE__*/Object.freeze({
38139
39192
  __proto__: null,
@@ -38168,6 +39221,9 @@
38168
39221
  AnimatorStateTransition: AnimatorStateTransition,
38169
39222
  AssetPromise: AssetPromise,
38170
39223
  AssetType: AssetType,
39224
+ AudioClip: AudioClip,
39225
+ AudioManager: AudioManager,
39226
+ AudioSource: AudioSource,
38171
39227
  Background: Background,
38172
39228
  BackgroundMode: BackgroundMode,
38173
39229
  BackgroundTextureFillMode: BackgroundTextureFillMode,
@@ -40249,7 +41305,7 @@
40249
41305
  var gl = this._gl;
40250
41306
  var _engine__lastRenderState = engine._lastRenderState, targetBlendState = _engine__lastRenderState.blendState.targetBlendState, depthState = _engine__lastRenderState.depthState, stencilState = _engine__lastRenderState.stencilState;
40251
41307
  var clearFlag = 0;
40252
- if (clearFlags & CameraClearFlags.Color) {
41308
+ if (clearFlags & CameraClearFlags.Color && clearColor) {
40253
41309
  clearFlag |= gl.COLOR_BUFFER_BIT;
40254
41310
  var lc = this._lastClearColor;
40255
41311
  var r = clearColor.r, g = clearColor.g, b = clearColor.b, a = clearColor.a;
@@ -40313,6 +41369,74 @@
40313
41369
  this.viewport(x, y, width, height);
40314
41370
  this.scissor(x, y, width, height);
40315
41371
  };
41372
+ _proto.blitInternalRTByBlitFrameBuffer = function blitInternalRTByBlitFrameBuffer(srcRT, destRT, clearFlags, viewport) {
41373
+ if (!this._isWebGL2) {
41374
+ Logger.warn("WebGL1.0 not support blit frame buffer.");
41375
+ return;
41376
+ }
41377
+ var gl = this._gl;
41378
+ // @ts-ignore
41379
+ var srcFrameBuffer = srcRT ? srcRT._platformRenderTarget._frameBuffer : null;
41380
+ // @ts-ignore
41381
+ var destFrameBuffer = destRT ? destRT._platformRenderTarget._frameBuffer : null;
41382
+ var bufferWidth = this.getMainFrameBufferWidth();
41383
+ var bufferHeight = this.getMainFrameBufferHeight();
41384
+ var srcWidth = srcRT ? srcRT.width : bufferWidth;
41385
+ var srcHeight = srcRT ? srcRT.height : bufferHeight;
41386
+ var blitWidth = destRT.width;
41387
+ var blitHeight = destRT.height;
41388
+ var needFlipY = !srcRT;
41389
+ var needBlitColor = (clearFlags & CameraClearFlags.Color) === 0;
41390
+ var needBlitDepth = (clearFlags & CameraClearFlags.Depth) === 0;
41391
+ var needBlitStencil = (clearFlags & CameraClearFlags.Stencil) === 0;
41392
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, srcFrameBuffer);
41393
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, destFrameBuffer);
41394
+ var blitMask = needBlitColor ? gl.COLOR_BUFFER_BIT : 0;
41395
+ if (needBlitDepth || needBlitStencil) {
41396
+ // @ts-ignore
41397
+ var depthFormat = destRT._depthFormat;
41398
+ if (needBlitDepth) {
41399
+ if (depthFormat === TextureFormat.Depth || depthFormat >= TextureFormat.DepthStencil && depthFormat <= TextureFormat.Depth32Stencil8) {
41400
+ blitMask |= gl.DEPTH_BUFFER_BIT;
41401
+ } else {
41402
+ Logger.warn("Do not clear depth, or set depth format of target which is " + TextureFormat[depthFormat] + " now.");
41403
+ }
41404
+ }
41405
+ if (needBlitStencil) {
41406
+ if (depthFormat === TextureFormat.Stencil || depthFormat === TextureFormat.DepthStencil || depthFormat >= TextureFormat.Depth24Stencil8 || depthFormat >= TextureFormat.Depth32Stencil8) {
41407
+ blitMask |= gl.STENCIL_BUFFER_BIT;
41408
+ } else {
41409
+ Logger.warn("Do not clear stencil, or set stencil format of target which is " + TextureFormat[depthFormat] + " now.");
41410
+ }
41411
+ }
41412
+ }
41413
+ var xStart = viewport.x * srcWidth;
41414
+ var xEnd = xStart + blitWidth;
41415
+ var yStart = needFlipY ? srcHeight - viewport.y * srcHeight : srcHeight - viewport.y * srcHeight - blitHeight;
41416
+ var yEnd = needFlipY ? yStart - blitHeight : yStart + blitHeight;
41417
+ gl.blitFramebuffer(xStart, yStart, xEnd, yEnd, 0, 0, blitWidth, blitHeight, blitMask, gl.NEAREST);
41418
+ };
41419
+ _proto.copyRenderTargetToSubTexture = function copyRenderTargetToSubTexture(srcRT, grabTexture, viewport) {
41420
+ var gl = this._gl;
41421
+ var bufferWidth = this.getMainFrameBufferWidth();
41422
+ var bufferHeight = this.getMainFrameBufferHeight();
41423
+ var srcWidth = srcRT ? srcRT.width : bufferWidth;
41424
+ var srcHeight = srcRT ? srcRT.height : bufferHeight;
41425
+ var copyWidth = grabTexture.width;
41426
+ var copyHeight = grabTexture.height;
41427
+ var flipY = !srcRT;
41428
+ var xStart = viewport.x * srcWidth;
41429
+ var yStart = flipY ? srcHeight - viewport.y * srcHeight - copyHeight : viewport.y * srcHeight;
41430
+ var _srcRT__platformRenderTarget__frameBuffer;
41431
+ // @ts-ignore
41432
+ var frameBuffer = (_srcRT__platformRenderTarget__frameBuffer = srcRT == null ? void 0 : srcRT._platformRenderTarget._frameBuffer) != null ? _srcRT__platformRenderTarget__frameBuffer : null;
41433
+ // @ts-ignore
41434
+ gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
41435
+ // @ts-ignore
41436
+ var glTexture = grabTexture._platformTexture;
41437
+ glTexture._bind();
41438
+ gl.copyTexSubImage2D(glTexture._target, 0, 0, 0, xStart, yStart, copyWidth, copyHeight);
41439
+ };
40316
41440
  _proto.activeTexture = function activeTexture(textureID) {
40317
41441
  if (this._activeTextureID !== textureID) {
40318
41442
  this._gl.activeTexture(textureID);
@@ -40373,6 +41497,7 @@
40373
41497
  if (debugRenderInfo != null) {
40374
41498
  this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
40375
41499
  }
41500
+ this._contextAttributes = gl.getContextAttributes();
40376
41501
  };
40377
41502
  _proto.destroy = function destroy() {
40378
41503
  var webCanvas = this._webCanvas;
@@ -40429,6 +41554,12 @@
40429
41554
  get: function get() {
40430
41555
  return this.capability.canIUseMoreJoints;
40431
41556
  }
41557
+ },
41558
+ {
41559
+ key: "context",
41560
+ get: function get() {
41561
+ return this._contextAttributes;
41562
+ }
40432
41563
  }
40433
41564
  ]);
40434
41565
  return WebGLGraphicDevice;
@@ -42023,32 +43154,18 @@
42023
43154
  var _proto = EnvLoader.prototype;
42024
43155
  _proto.load = function load(item, resourceManager) {
42025
43156
  return new AssetPromise(function(resolve, reject) {
42026
- resourceManager // @ts-ignore
42027
- ._request(item.url, _extends({}, item, {
43157
+ var requestConfig = _extends({}, item, {
42028
43158
  type: "arraybuffer"
42029
- })).then(function(arraybuffer) {
42030
- var _this;
42031
- var shArray = new Float32Array(arraybuffer, 0, 27);
42032
- var shByteLength = 27 * 4;
42033
- var size = (_this = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _this[0];
42034
- var engine = resourceManager.engine;
42035
- var texture = new TextureCube(engine, size);
42036
- texture.filterMode = TextureFilterMode.Trilinear;
42037
- var mipmapCount = texture.mipmapCount;
42038
- var offset = shByteLength + 2;
42039
- for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
42040
- var mipSize = size >> mipLevel;
42041
- for(var face = 0; face < 6; face++){
42042
- var dataSize = mipSize * mipSize * 4;
42043
- var data = new Uint8Array(arraybuffer, offset, dataSize);
42044
- offset += dataSize;
42045
- texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
42046
- }
42047
- }
43159
+ });
43160
+ var engine = resourceManager.engine;
43161
+ resourceManager // @ts-ignore
43162
+ ._request(item.url, requestConfig).then(function(arraybuffer) {
43163
+ var texture = EnvLoader._setTextureByBuffer(engine, arraybuffer);
43164
+ engine.resourceManager.addContentRestorer(new EnvContentRestorer(texture, item.url, requestConfig));
42048
43165
  var ambientLight = new AmbientLight(engine);
42049
43166
  var sh = new SphericalHarmonics3();
42050
43167
  ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
42051
- sh.copyFromArray(shArray);
43168
+ sh.copyFromArray(new Float32Array(arraybuffer, 0, 27));
42052
43169
  ambientLight.diffuseSphericalHarmonics = sh;
42053
43170
  ambientLight.specularTexture = texture;
42054
43171
  ambientLight.specularTextureDecodeRGBM = true;
@@ -42058,6 +43175,27 @@
42058
43175
  });
42059
43176
  });
42060
43177
  };
43178
+ /**
43179
+ * @internal
43180
+ */ EnvLoader._setTextureByBuffer = function _setTextureByBuffer(engine, buffer, texture) {
43181
+ var _this;
43182
+ var shByteLength = 27 * 4;
43183
+ var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
43184
+ texture || (texture = new TextureCube(engine, size));
43185
+ texture.filterMode = TextureFilterMode.Trilinear;
43186
+ var mipmapCount = texture.mipmapCount;
43187
+ var offset = shByteLength + 2;
43188
+ for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
43189
+ var mipSize = size >> mipLevel;
43190
+ for(var face = 0; face < 6; face++){
43191
+ var dataSize = mipSize * mipSize * 4;
43192
+ var data = new Uint8Array(buffer, offset, dataSize);
43193
+ offset += dataSize;
43194
+ texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
43195
+ }
43196
+ }
43197
+ return texture;
43198
+ };
42061
43199
  return EnvLoader;
42062
43200
  }(Loader);
42063
43201
  EnvLoader = __decorate([
@@ -42065,6 +43203,27 @@
42065
43203
  "env"
42066
43204
  ])
42067
43205
  ], EnvLoader);
43206
+ /**
43207
+ * @internal
43208
+ */ var EnvContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
43209
+ _inherits(EnvContentRestorer, ContentRestorer);
43210
+ function EnvContentRestorer(resource, url, requestConfig) {
43211
+ var _this;
43212
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
43213
+ return _this;
43214
+ }
43215
+ var _proto = EnvContentRestorer.prototype;
43216
+ _proto.restoreContent = function restoreContent() {
43217
+ var _this = this;
43218
+ return new AssetPromise(function(resolve, reject) {
43219
+ request(_this.url, _this.requestConfig).then(function(buffer) {
43220
+ EnvLoader._setTextureByBuffer(_this.resource.engine, buffer, _this.resource);
43221
+ resolve(_this.resource);
43222
+ }).catch(reject);
43223
+ });
43224
+ };
43225
+ return EnvContentRestorer;
43226
+ }(ContentRestorer);
42068
43227
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
42069
43228
  try {
42070
43229
  var info = gen[key](arg);
@@ -42473,7 +43632,7 @@
42473
43632
  task.total += 1;
42474
43633
  taskPromise.then(function() {
42475
43634
  _this._setTaskCompleteProgress(++task.loaded, task.total);
42476
- });
43635
+ }, function() {});
42477
43636
  };
42478
43637
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
42479
43638
  var _this = this;
@@ -46713,6 +47872,44 @@
46713
47872
  ""
46714
47873
  ])
46715
47874
  ], TextureCubeLoader);
47875
+ var AudioLoader = /*#__PURE__*/ function(Loader) {
47876
+ _inherits(AudioLoader, Loader);
47877
+ function AudioLoader() {
47878
+ return Loader.apply(this, arguments) || this;
47879
+ }
47880
+ var _proto = AudioLoader.prototype;
47881
+ _proto.load = function load(item, resourceManager) {
47882
+ return new AssetPromise(function(resolve, reject) {
47883
+ var url = item.url;
47884
+ var requestConfig = _extends({}, item, {
47885
+ type: "arraybuffer"
47886
+ });
47887
+ // @ts-ignore
47888
+ resourceManager._request(url, requestConfig).then(function(arrayBuffer) {
47889
+ var audioClip = new AudioClip(resourceManager.engine);
47890
+ AudioManager.getContext().decodeAudioData(arrayBuffer).then(function(result) {
47891
+ // @ts-ignore
47892
+ audioClip._setAudioSource(result);
47893
+ if (url.indexOf("data:") !== 0) {
47894
+ var index = url.lastIndexOf("/");
47895
+ audioClip.name = url.substring(index + 1);
47896
+ }
47897
+ resolve(audioClip);
47898
+ }).catch(function(e) {
47899
+ reject(e);
47900
+ });
47901
+ });
47902
+ });
47903
+ };
47904
+ return AudioLoader;
47905
+ }(Loader);
47906
+ AudioLoader = __decorate([
47907
+ resourceLoader(AssetType.Audio, [
47908
+ "mp3",
47909
+ "ogg",
47910
+ "wav"
47911
+ ])
47912
+ ], AudioLoader);
46716
47913
  var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
46717
47914
  _inherits(ShaderChunkLoader, Loader);
46718
47915
  function ShaderChunkLoader() {
@@ -46750,7 +47947,7 @@
46750
47947
  };
46751
47948
  return ShaderChunkLoader;
46752
47949
  }(Loader);
46753
- ShaderChunkLoader._shaderIncludeRegex = /\s#include\s+"([./][^\\"]+)"/gm;
47950
+ ShaderChunkLoader._shaderIncludeRegex = /#include\s+"([./][^\\"]+)"/gm;
46754
47951
  ShaderChunkLoader = __decorate([
46755
47952
  resourceLoader("ShaderChunk", [
46756
47953
  "glsl"
@@ -47079,6 +48276,36 @@
47079
48276
  KHR_materials_pbrSpecularGlossiness = __decorate([
47080
48277
  registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", GLTFExtensionMode.CreateAndParse)
47081
48278
  ], KHR_materials_pbrSpecularGlossiness);
48279
+ var KHR_materials_sheen = /*#__PURE__*/ function(GLTFExtensionParser) {
48280
+ _inherits(KHR_materials_sheen, GLTFExtensionParser);
48281
+ function KHR_materials_sheen() {
48282
+ return GLTFExtensionParser.apply(this, arguments) || this;
48283
+ }
48284
+ var _proto = KHR_materials_sheen.prototype;
48285
+ _proto.additiveParse = function additiveParse(context, material, schema) {
48286
+ var sheenColorFactor = schema.sheenColorFactor, sheenColorTexture = schema.sheenColorTexture, _schema_sheenRoughnessFactor = schema.sheenRoughnessFactor, sheenRoughnessFactor = _schema_sheenRoughnessFactor === void 0 ? 0 : _schema_sheenRoughnessFactor, sheenRoughnessTexture = schema.sheenRoughnessTexture;
48287
+ if (sheenColorFactor) {
48288
+ material.sheenColor.set(Color.linearToGammaSpace(sheenColorFactor[0]), Color.linearToGammaSpace(sheenColorFactor[1]), Color.linearToGammaSpace(sheenColorFactor[2]), undefined);
48289
+ }
48290
+ material.sheenRoughness = sheenRoughnessFactor;
48291
+ if (sheenColorTexture) {
48292
+ exports.GLTFMaterialParser._checkOtherTextureTransform(sheenColorTexture, "Sheen texture");
48293
+ context.get(GLTFParserType.Texture, sheenColorTexture.index).then(function(texture) {
48294
+ material.sheenColorTexture = texture;
48295
+ });
48296
+ }
48297
+ if (sheenRoughnessTexture) {
48298
+ exports.GLTFMaterialParser._checkOtherTextureTransform(sheenRoughnessTexture, "SheenRoughness texture");
48299
+ context.get(GLTFParserType.Texture, sheenRoughnessTexture.index).then(function(texture) {
48300
+ material.sheenRoughnessTexture = texture;
48301
+ });
48302
+ }
48303
+ };
48304
+ return KHR_materials_sheen;
48305
+ }(GLTFExtensionParser);
48306
+ KHR_materials_sheen = __decorate([
48307
+ registerGLTFExtension("KHR_materials_sheen", GLTFExtensionMode.AdditiveParse)
48308
+ ], KHR_materials_sheen);
47082
48309
  var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
47083
48310
  _inherits(KHR_materials_unlit, GLTFExtensionParser);
47084
48311
  function KHR_materials_unlit() {
@@ -47378,7 +48605,7 @@
47378
48605
  ], EXT_texture_webp);
47379
48606
 
47380
48607
  //@ts-ignore
47381
- var version = "1.4.0-alpha.0";
48608
+ var version = "1.4.0-alpha.1";
47382
48609
  console.log("Galacean engine version: " + version);
47383
48610
  for(var key in CoreObjects){
47384
48611
  Loader.registerClass(key, CoreObjects[key]);
@@ -47404,6 +48631,9 @@
47404
48631
  exports.AnimatorStateTransition = AnimatorStateTransition;
47405
48632
  exports.AssetPromise = AssetPromise;
47406
48633
  exports.AssetType = AssetType;
48634
+ exports.AudioClip = AudioClip;
48635
+ exports.AudioManager = AudioManager;
48636
+ exports.AudioSource = AudioSource;
47407
48637
  exports.Background = Background;
47408
48638
  exports.BackgroundMode = BackgroundMode;
47409
48639
  exports.BackgroundTextureFillMode = BackgroundTextureFillMode;