@galacean/engine-core 2.0.0-alpha.37 → 2.0.0-alpha.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -3848,7 +3848,7 @@ TiledSpriteAssembler = __decorate([
3848
3848
  sprite.name === name && outSprites.push(sprite);
3849
3849
  }
3850
3850
  } else {
3851
- console.warn("The name of the sprite you want to find is not exit in SpriteAtlas.");
3851
+ console.warn("There is no sprite named " + name + " in the atlas.");
3852
3852
  }
3853
3853
  return outSprites;
3854
3854
  };
@@ -6059,6 +6059,9 @@ __decorate([
6059
6059
  __decorate([
6060
6060
  ignoreClone
6061
6061
  ], Transform.prototype, "_isParentDirty", void 0);
6062
+ __decorate([
6063
+ ignoreClone
6064
+ ], Transform.prototype, "_parentTransformCache", void 0);
6062
6065
  __decorate([
6063
6066
  ignoreClone
6064
6067
  ], Transform.prototype, "_dirtyFlag", void 0);
@@ -17071,9 +17074,10 @@ var ComponentCloner = /*#__PURE__*/ function() {
17071
17074
  };
17072
17075
  /**
17073
17076
  * Get the components which match the type of the entity and it's children.
17077
+ * @remarks The components are returned in depth-first pre-order: the entity itself first, then each child's subtree in sibling order.
17074
17078
  * @param type - The component type
17075
17079
  * @param results - The components collection
17076
- * @returns The components collection which match the type
17080
+ * @returns The components collection which match the type
17077
17081
  */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
17078
17082
  results.length = 0;
17079
17083
  this._getComponentsInChildren(type, results);
@@ -17378,14 +17382,16 @@ var ComponentCloner = /*#__PURE__*/ function() {
17378
17382
  }
17379
17383
  };
17380
17384
  _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
17381
- for(var i = this._components.length - 1; i >= 0; i--){
17382
- var component = this._components[i];
17385
+ var components = this._components;
17386
+ for(var i = 0, n = components.length; i < n; i++){
17387
+ var component = components[i];
17383
17388
  if (_instanceof(component, type)) {
17384
17389
  results.push(component);
17385
17390
  }
17386
17391
  }
17387
- for(var i1 = this._children.length - 1; i1 >= 0; i1--){
17388
- this._children[i1]._getComponentsInChildren(type, results);
17392
+ var children = this._children;
17393
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
17394
+ children[i1]._getComponentsInChildren(type, results);
17389
17395
  }
17390
17396
  };
17391
17397
  _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
@@ -18609,7 +18615,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
18609
18615
  this._graphicResourcePool = Object.create(null);
18610
18616
  this._contentRestorerPool = Object.create(null);
18611
18617
  this._subAssetPromiseCallbacks = {};
18612
- this.//-----------------Editor temp solution-----------------
18618
+ this.// Virtual resource mapping
18613
18619
  /** @internal */ _objectPool = Object.create(null);
18614
18620
  this./** @internal */ _virtualPathResourceMap = Object.create(null);
18615
18621
  }
@@ -18723,21 +18729,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
18723
18729
  };
18724
18730
  /**
18725
18731
  * @internal
18726
- */ _proto._onSubAssetFail = function _onSubAssetFail(assetBaseURL, assetSubPath, value) {
18727
- var _this__subAssetPromiseCallbacks_assetBaseURL;
18728
- var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
18729
- if (subPromiseCallback) {
18730
- subPromiseCallback.reject(value);
18731
- } else {
18732
- var // Pending
18733
- _this__subAssetPromiseCallbacks, _assetBaseURL;
18734
- ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
18735
- rejectedValue: value
18736
- };
18737
- }
18738
- };
18739
- /**
18740
- * @internal
18741
18732
  */ _proto._addAsset = function _addAsset(path, asset) {
18742
18733
  this._assetPool[asset.instanceId] = path;
18743
18734
  this._assetUrlPool[path] = asset;
@@ -18817,37 +18808,39 @@ var MultiExecutor = /*#__PURE__*/ function() {
18817
18808
  this._contentRestorerPool = null;
18818
18809
  this._loadingPromises = null;
18819
18810
  };
18820
- _proto._assignDefaultOptions = function _assignDefaultOptions(assetInfo) {
18821
- var _assetInfo_type;
18822
- assetInfo.type = (_assetInfo_type = assetInfo.type) != null ? _assetInfo_type : ResourceManager._getTypeByUrl(assetInfo.url);
18811
+ _proto._resolveLoadItemOptions = function _resolveLoadItemOptions(assetInfo, virtualResourceEntry) {
18812
+ var _assetInfo;
18813
+ var _virtualResourceEntry_type, _ref;
18814
+ assetInfo.type = (_ref = (_virtualResourceEntry_type = virtualResourceEntry == null ? void 0 : virtualResourceEntry.type) != null ? _virtualResourceEntry_type : assetInfo.type) != null ? _ref : ResourceManager._getTypeByUrl(assetInfo.url);
18823
18815
  if (assetInfo.type === undefined) {
18824
18816
  throw "asset type should be specified: " + assetInfo.url;
18825
18817
  }
18818
+ var _params;
18819
+ (_params = (_assetInfo = assetInfo).params) != null ? _params : _assetInfo.params = virtualResourceEntry == null ? void 0 : virtualResourceEntry.params;
18826
18820
  var _assetInfo_retryCount;
18827
18821
  assetInfo.retryCount = (_assetInfo_retryCount = assetInfo.retryCount) != null ? _assetInfo_retryCount : this.retryCount;
18828
18822
  var _assetInfo_timeout;
18829
18823
  assetInfo.timeout = (_assetInfo_timeout = assetInfo.timeout) != null ? _assetInfo_timeout : this.timeout;
18830
18824
  var _assetInfo_retryInterval;
18831
18825
  assetInfo.retryInterval = (_assetInfo_retryInterval = assetInfo.retryInterval) != null ? _assetInfo_retryInterval : this.retryInterval;
18832
- var _assetInfo_url;
18833
- assetInfo.url = (_assetInfo_url = assetInfo.url) != null ? _assetInfo_url : assetInfo.urls.join(",");
18834
- return assetInfo;
18835
18826
  };
18836
18827
  _proto._loadSingleItem = function _loadSingleItem(itemOrURL) {
18837
18828
  var _this = this;
18838
- var item = this._assignDefaultOptions(typeof itemOrURL === "string" ? {
18829
+ var item = typeof itemOrURL === "string" ? {
18839
18830
  url: itemOrURL
18840
- } : itemOrURL);
18841
- var url = item.url;
18842
- // Not absolute and base url is set
18843
- if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
18831
+ } : itemOrURL;
18832
+ var _item_url;
18833
+ item.url = (_item_url = item.url) != null ? _item_url : item.urls.join(",");
18844
18834
  // Parse url
18845
- var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18835
+ var _this__parseURL = this._parseURL(item.url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18846
18836
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
18847
18837
  // Get remote asset base url
18848
- var remoteConfig = this._virtualPathResourceMap[assetBaseURL];
18849
- var _remoteConfig_path;
18850
- var remoteAssetBaseURL = (_remoteConfig_path = remoteConfig == null ? void 0 : remoteConfig.path) != null ? _remoteConfig_path : assetBaseURL;
18838
+ var virtualResourceEntry = this._virtualPathResourceMap[assetBaseURL];
18839
+ this._resolveLoadItemOptions(item, virtualResourceEntry);
18840
+ // Not absolute and base url is set
18841
+ item.url = !Utils.isAbsoluteUrl(assetBaseURL) && this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, assetBaseURL) : assetBaseURL;
18842
+ var _virtualResourceEntry_path;
18843
+ var remoteAssetBaseURL = (_virtualResourceEntry_path = virtualResourceEntry == null ? void 0 : virtualResourceEntry.path) != null ? _virtualResourceEntry_path : item.url;
18851
18844
  // Check cache
18852
18845
  var cacheObject = this._assetUrlPool[remoteAssetBaseURL];
18853
18846
  if (cacheObject) {
@@ -18881,25 +18874,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
18881
18874
  if (!loader) {
18882
18875
  throw "loader not found: " + item.type;
18883
18876
  }
18884
- var subpackageName = remoteConfig == null ? void 0 : remoteConfig.subpackageName;
18877
+ var subpackageName = virtualResourceEntry == null ? void 0 : virtualResourceEntry.subpackageName;
18885
18878
  // Check sub asset
18886
18879
  if (queryPath) {
18887
18880
  // Check whether load main asset
18888
- var mainPromise = loadingPromises[remoteAssetBaseURL] || this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName);
18889
- mainPromise.catch(function(e) {
18890
- _this._onSubAssetFail(remoteAssetBaseURL, queryPath, e);
18891
- });
18892
- return this._createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, queryPath);
18881
+ var mainPromise = loadingPromises[remoteAssetBaseURL] || this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName);
18882
+ return this._createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, queryPath, mainPromise);
18893
18883
  }
18894
- return this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName);
18884
+ return this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName);
18895
18885
  };
18896
18886
  // For adapter mini-game platform
18897
- _proto._loadSubpackageAndMainAsset = function _loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName) {
18898
- return this._loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL);
18887
+ _proto._loadSubpackageAndMainAsset = function _loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName) {
18888
+ return this._loadMainAsset(loader, item, remoteAssetBaseURL);
18899
18889
  };
18900
- _proto._loadMainAsset = function _loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL) {
18890
+ _proto._loadMainAsset = function _loadMainAsset(loader, item, remoteAssetBaseURL) {
18901
18891
  var _this = this;
18902
- item.url = assetBaseURL;
18903
18892
  var loadingPromises = this._loadingPromises;
18904
18893
  var promise = loader.load(item, this);
18905
18894
  loadingPromises[remoteAssetBaseURL] = promise;
@@ -18915,30 +18904,33 @@ var MultiExecutor = /*#__PURE__*/ function() {
18915
18904
  });
18916
18905
  return promise;
18917
18906
  };
18918
- _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, assetSubPath) {
18907
+ _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, assetSubPath, mainPromise) {
18919
18908
  var _this = this;
18920
18909
  var _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
18921
18910
  var loadingPromises = this._loadingPromises;
18922
18911
  var subPromiseCallback = (_this__subAssetPromiseCallbacks_remoteAssetBaseURL = this._subAssetPromiseCallbacks[remoteAssetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_remoteAssetBaseURL[assetSubPath];
18923
18912
  var resolvedValue = subPromiseCallback == null ? void 0 : subPromiseCallback.resolvedValue;
18924
- var rejectedValue = subPromiseCallback == null ? void 0 : subPromiseCallback.rejectedValue;
18925
- // Already resolved or rejected
18926
- if (resolvedValue || rejectedValue) {
18927
- return new AssetPromise(function(resolve, reject) {
18928
- if (resolvedValue) {
18929
- resolve(resolvedValue);
18930
- } else if (rejectedValue) {
18931
- reject(rejectedValue);
18932
- }
18933
- });
18913
+ // Already resolved
18914
+ if (resolvedValue) {
18915
+ return AssetPromise.resolve(resolvedValue);
18934
18916
  }
18935
18917
  // Pending
18936
- var promise = new AssetPromise(function(resolve, reject) {
18918
+ var promise = new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
18937
18919
  var _this__subAssetPromiseCallbacks, _remoteAssetBaseURL;
18938
18920
  ((_this__subAssetPromiseCallbacks = _this._subAssetPromiseCallbacks)[_remoteAssetBaseURL = remoteAssetBaseURL] || (_this__subAssetPromiseCallbacks[_remoteAssetBaseURL] = {}))[assetSubPath] = {
18939
18921
  resolve: resolve,
18940
18922
  reject: reject
18941
18923
  };
18924
+ // A loader may finish the main asset before its eager sub-asset notification reaches this callback.
18925
+ // Always resolve from the completed main asset as the authoritative fallback so callback cleanup cannot
18926
+ // strand a sub-asset request.
18927
+ mainPromise.onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(resource) {
18928
+ try {
18929
+ resolve(_this._getResolveResource(resource, _this._parseQueryPath(assetSubPath)));
18930
+ } catch (error) {
18931
+ reject(error);
18932
+ }
18933
+ }, reject);
18942
18934
  });
18943
18935
  loadingPromises[remoteAssetURL] = promise;
18944
18936
  promise.then(function() {
@@ -18962,7 +18954,10 @@ var MultiExecutor = /*#__PURE__*/ function() {
18962
18954
  if (paths) {
18963
18955
  for(var i = 0, n = paths.length; i < n; i++){
18964
18956
  var path = paths[i];
18965
- subResource = subResource[path];
18957
+ subResource = subResource == null ? void 0 : subResource[path];
18958
+ if (subResource === undefined) {
18959
+ throw new Error("Sub-asset path does not exist: " + paths.join("."));
18960
+ }
18966
18961
  }
18967
18962
  }
18968
18963
  return subResource;
@@ -19008,6 +19003,16 @@ var MultiExecutor = /*#__PURE__*/ function() {
19008
19003
  delete this._subAssetPromiseCallbacks[assetBaseURL];
19009
19004
  };
19010
19005
  /**
19006
+ * Register virtual asset paths and their load descriptors.
19007
+ * @remarks References inside runtime scenes and Prefabs can keep stable virtual paths while the backing URLs
19008
+ * are generated dynamically, such as object URLs created from a resource package.
19009
+ */ _proto.registerVirtualResources = function registerVirtualResources(resources) {
19010
+ var _this = this;
19011
+ resources.forEach(function(resource) {
19012
+ _this._virtualPathResourceMap[resource.virtualPath] = resource;
19013
+ });
19014
+ };
19015
+ /**
19011
19016
  * @internal
19012
19017
  * @beta Just for internal editor, not recommended for developers.
19013
19018
  */ _proto.getResourceByRef = function getResourceByRef(ref) {
@@ -19026,10 +19031,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19026
19031
  return AssetPromise.resolve(null);
19027
19032
  }
19028
19033
  var loadUrl = key ? url + "?q=" + key : url;
19034
+ // type and params omitted: resolved from the virtualPath map, the single source of truth
19029
19035
  var promise = this.load({
19030
- url: loadUrl,
19031
- type: mapped.type,
19032
- params: mapped.params
19036
+ url: loadUrl
19033
19037
  });
19034
19038
  return isClone ? promise.then(function(item) {
19035
19039
  return item.clone();
@@ -19037,18 +19041,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
19037
19041
  };
19038
19042
  /**
19039
19043
  * @internal
19040
- * @beta Just for internal editor, not recommended for developers.
19041
- */ _proto.initVirtualResources = function initVirtualResources(config) {
19042
- var _this = this;
19043
- config.forEach(function(element) {
19044
- _this._virtualPathResourceMap[element.virtualPath] = element;
19045
- if (element.dependentAssetMap) {
19046
- _this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
19047
- }
19048
- });
19049
- };
19050
- /**
19051
- * @internal
19052
19044
  */ ResourceManager._addLoader = function _addLoader(type, loader, extNames) {
19053
19045
  this._loaders[type] = loader;
19054
19046
  for(var i = 0, len = extNames.length; i < len; i++){
@@ -20436,6 +20428,13 @@ __decorate([
20436
20428
  this._phasedActiveInScene && this._nativeCollider.addForce(force);
20437
20429
  };
20438
20430
  /**
20431
+ * Apply a force to the DynamicCollider at a given position in world space.
20432
+ * @param force - The force to apply, in world space
20433
+ * @param position - The position where the force is applied, in world space
20434
+ */ _proto.applyForceAtPosition = function applyForceAtPosition(force, position) {
20435
+ this._phasedActiveInScene && this._nativeCollider.addForceAtPosition(force, position);
20436
+ };
20437
+ /**
20439
20438
  * Apply a torque to the DynamicCollider.
20440
20439
  * @param torque - The force make the collider rotate
20441
20440
  */ _proto.applyTorque = function applyTorque(torque) {
@@ -26788,6 +26787,7 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
26788
26787
  depthOnlyPass.release();
26789
26788
  camera.shaderData.setTexture(Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
26790
26789
  }
26790
+ var pool = engine._renderTargetPool;
26791
26791
  // Check if need to create internal color texture or grab texture
26792
26792
  if (independentCanvasEnabled) {
26793
26793
  var depthFormat;
@@ -26803,26 +26803,12 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
26803
26803
  depthFormat = null;
26804
26804
  }
26805
26805
  var viewport = camera.pixelViewport;
26806
- var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, !camera.enableHDR, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26806
+ this._internalColorTarget = pool.allocateRenderTarget(viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, !camera.enableHDR, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26807
26807
  if (this._shouldCopyBackgroundColor) {
26808
26808
  var _camera_renderTarget;
26809
26809
  var colorTexture = (_camera_renderTarget = camera.renderTarget) == null ? void 0 : _camera_renderTarget.getColorTexture(0);
26810
26810
  var _colorTexture_format, _colorTexture_isSRGBColorSpace;
26811
- var copyBackgroundTexture = PipelineUtils.recreateTextureIfNeeded(engine, this._copyBackgroundTexture, viewport.width, viewport.height, (_colorTexture_format = colorTexture == null ? void 0 : colorTexture.format) != null ? _colorTexture_format : TextureFormat.R8G8B8A8, false, (_colorTexture_isSRGBColorSpace = colorTexture == null ? void 0 : colorTexture.isSRGBColorSpace) != null ? _colorTexture_isSRGBColorSpace : false, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26812
- this._copyBackgroundTexture = copyBackgroundTexture;
26813
- }
26814
- this._internalColorTarget = internalColorTarget;
26815
- } else {
26816
- var internalColorTarget1 = this._internalColorTarget;
26817
- var copyBackgroundTexture1 = this._copyBackgroundTexture;
26818
- var pool = engine._renderTargetPool;
26819
- if (internalColorTarget1) {
26820
- pool.freeRenderTarget(internalColorTarget1);
26821
- this._internalColorTarget = null;
26822
- }
26823
- if (copyBackgroundTexture1) {
26824
- pool.freeTexture(copyBackgroundTexture1);
26825
- this._copyBackgroundTexture = null;
26811
+ this._copyBackgroundTexture = pool.allocateTexture(viewport.width, viewport.height, (_colorTexture_format = colorTexture == null ? void 0 : colorTexture.format) != null ? _colorTexture_format : TextureFormat.R8G8B8A8, false, (_colorTexture_isSRGBColorSpace = colorTexture == null ? void 0 : colorTexture.isSRGBColorSpace) != null ? _colorTexture_isSRGBColorSpace : false, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26826
26812
  }
26827
26813
  }
26828
26814
  // Scalable ambient obscurance pass
@@ -26835,6 +26821,15 @@ CascadedShadowCasterPass._tempMatrix0 = new Matrix();
26835
26821
  this._saoPass.release();
26836
26822
  }
26837
26823
  this._drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel);
26824
+ // Return the per-frame leases so the next camera with matching shape can reuse them
26825
+ if (this._internalColorTarget) {
26826
+ pool.freeRenderTarget(this._internalColorTarget);
26827
+ this._internalColorTarget = null;
26828
+ }
26829
+ if (this._copyBackgroundTexture) {
26830
+ pool.freeTexture(this._copyBackgroundTexture);
26831
+ this._copyBackgroundTexture = null;
26832
+ }
26838
26833
  };
26839
26834
  _proto._drawRenderPass = function _drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel) {
26840
26835
  var cullingResults = this._cullingResults;
@@ -27168,7 +27163,9 @@ var OverlayCamera = function OverlayCamera() {
27168
27163
  _inherits(Engine, EventDispatcher);
27169
27164
  function Engine(canvas, hardwareRenderer, configuration) {
27170
27165
  var _this;
27171
- _this = EventDispatcher.call(this) || this, /** @internal */ _this._renderingStatistics = new RenderingStatistics(), /** @internal */ _this._isDeviceLost = false, /** @internal */ _this._frameInProcess = false, /** @internal */ _this._pendingDestroyObjects = [], /** @internal */ _this._processingPendingDestroys = false, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._textRenderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramMaps = [], /** @internal */ _this._fontMap = {}, /** @internal */ _this._macroCollection = new ShaderMacroCollection(), /** @internal */ _this._postProcessPassNeedRefresh = false, _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._waitingDestroy = false, _this._waitingGC = false, _this._postProcessPasses = new Array(), _this._activePostProcessPasses = new Array(), _this._animate = function() {
27166
+ _this = EventDispatcher.call(this) || this, /** @internal */ _this._renderingStatistics = new RenderingStatistics(), /** @internal */ _this._isDeviceLost = false, /** @internal */ _this._frameInProcess = false, /** @internal */ _this._pendingDestroyObjects = [], /** @internal */ _this._processingPendingDestroys = false, /** @internal */ _this._physicsInitialized = false, /** @internal */ _this._lastRenderState = new RenderState(), /** @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /** @internal */ _this._textRenderElementPool = new ClearableObjectPool(RenderElement), /** @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /** @internal */ _this._renderContext = new RenderContext(), /** @internal */ _this._renderCount = 0, /** @internal */ _this._shaderProgramMaps = [], /** @internal */ _this._fontMap = {}, /** @internal */ _this._macroCollection = new ShaderMacroCollection(), /** @internal */ _this._postProcessPassNeedRefresh = false, _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._waitingDestroy = false, _this._waitingGC = false, _this._postProcessPasses = new Array(), _this._activePostProcessPasses = new Array(), _this._onCanvasResize = function() {
27167
+ return _this._renderTargetPool.gc();
27168
+ }, _this._animate = function() {
27172
27169
  if (_this._vSyncCount) {
27173
27170
  var _this_xrManager;
27174
27171
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -27189,6 +27186,7 @@ var OverlayCamera = function OverlayCamera() {
27189
27186
  _this._textDefaultFont.isGCIgnored = true;
27190
27187
  _this._batcherManager = new BatcherManager(_this);
27191
27188
  _this._renderTargetPool = new RenderTargetPool(_this);
27189
+ canvas._sizeUpdateFlagManager.addListener(_this._onCanvasResize);
27192
27190
  _this.inputManager = new InputManager(_this, configuration.input);
27193
27191
  var xrDevice = configuration.xrDevice;
27194
27192
  if (xrDevice) {
@@ -27246,6 +27244,7 @@ var OverlayCamera = function OverlayCamera() {
27246
27244
  * Update the engine loop manually. If you call engine.run(), you generally don't need to call this function.
27247
27245
  */ _proto.update = function update() {
27248
27246
  var _this_xrManager;
27247
+ this._canvas._pumpPendingResolution();
27249
27248
  var time = this._time;
27250
27249
  time._update();
27251
27250
  var deltaTime = time.deltaTime;
@@ -27392,6 +27391,8 @@ var OverlayCamera = function OverlayCamera() {
27392
27391
  var _this_xrManager;
27393
27392
  this._destroyed = true;
27394
27393
  this._waitingDestroy = false;
27394
+ this._canvas._sizeUpdateFlagManager.removeListener(this._onCanvasResize);
27395
+ this._canvas._destroy();
27395
27396
  this._sceneManager._destroyAllScene();
27396
27397
  this._resourceManager._destroy();
27397
27398
  this.inputManager._destroy();
@@ -27688,40 +27689,57 @@ var OverlayCamera = function OverlayCamera() {
27688
27689
  /** @internal */ Engine._physicalObjectsMap = {};
27689
27690
 
27690
27691
  /**
27691
- * Canvas.
27692
+ * The canvas the engine renders to; owns the render-buffer resolution.
27692
27693
  */ var Canvas = /*#__PURE__*/ function() {
27693
27694
  function Canvas() {
27694
- /* @internal */ this._sizeUpdateFlagManager = new UpdateFlagManager();
27695
+ /**
27696
+ * @internal
27697
+ */ this._sizeUpdateFlagManager = new UpdateFlagManager();
27698
+ this._width = 0;
27699
+ this._height = 0;
27695
27700
  }
27701
+ var _proto = Canvas.prototype;
27702
+ /**
27703
+ * Lock the render buffer to an explicit resolution and stop following the display size.
27704
+ * @param width - Render buffer width in pixels
27705
+ * @param height - Render buffer height in pixels
27706
+ *
27707
+ * @throws
27708
+ * Throw an error if width or height is not a positive finite number.
27709
+ */ _proto.setResolution = function setResolution(width, height) {
27710
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
27711
+ throw new Error("Canvas.setResolution: invalid size " + width + "x" + height);
27712
+ }
27713
+ this._exitAutoResolution();
27714
+ this._setResolution(Math.round(width), Math.round(height));
27715
+ };
27716
+ _proto._setResolution = function _setResolution(width, height) {
27717
+ if (this._width !== width || this._height !== height) {
27718
+ this._width = width;
27719
+ this._height = height;
27720
+ this._onResolutionChanged(width, height);
27721
+ this._sizeUpdateFlagManager.dispatch();
27722
+ }
27723
+ };
27724
+ /**
27725
+ * @internal
27726
+ */ _proto._pumpPendingResolution = function _pumpPendingResolution() {};
27727
+ _proto._exitAutoResolution = function _exitAutoResolution() {};
27696
27728
  _create_class(Canvas, [
27697
27729
  {
27698
27730
  key: "width",
27699
27731
  get: /**
27700
- * The width of the canvas.
27732
+ * The width component of the canvas resolution, in pixels.
27701
27733
  */ function get() {
27702
27734
  return this._width;
27703
- },
27704
- set: function set(value) {
27705
- if (this._width !== value) {
27706
- this._width = value;
27707
- this._onWidthChanged(value);
27708
- this._sizeUpdateFlagManager.dispatch();
27709
- }
27710
27735
  }
27711
27736
  },
27712
27737
  {
27713
27738
  key: "height",
27714
27739
  get: /**
27715
- *The height of the canvas.
27740
+ * The height component of the canvas resolution, in pixels.
27716
27741
  */ function get() {
27717
27742
  return this._height;
27718
- },
27719
- set: function set(value) {
27720
- if (this._height !== value) {
27721
- this._height = value;
27722
- this._onHeightChange(value);
27723
- this._sizeUpdateFlagManager.dispatch();
27724
- }
27725
27743
  }
27726
27744
  }
27727
27745
  ]);
@@ -27732,11 +27750,11 @@ var OverlayCamera = function OverlayCamera() {
27732
27750
  * The manager of the components.
27733
27751
  */ var ComponentsManager = /*#__PURE__*/ function() {
27734
27752
  function ComponentsManager() {
27735
- /* @internal */ this._cameraNeedSorting = false;
27753
+ /** @internal */ this._cameraNeedSorting = false;
27736
27754
  /** @internal */ this._activeCameras = new DisorderedArray();
27737
27755
  /** @internal */ this._renderers = new DisorderedArray();
27738
27756
  /** @internal */ this._overlayCanvases = new DisorderedArray();
27739
- /* @internal */ this._overlayCanvasesSortingDirty = false;
27757
+ /** @internal */ this._overlayCanvasesSortingDirty = false;
27740
27758
  /** @internal */ this._canvases = new DisorderedArray();
27741
27759
  // Script
27742
27760
  this._onStartScripts = new DisorderedArray();
@@ -28955,7 +28973,7 @@ AmbientOcclusion._enableMacro = ShaderMacro.getByName("SCENE_ENABLE_AMBIENT_OCCL
28955
28973
  * @remarks
28956
28974
  * Darkens areas where objects are close together to simulate natural light blocking,
28957
28975
  * such as corners, crevices, and contact points between surfaces.
28958
- */ _this.ambientOcclusion = new AmbientOcclusion(_this), /* @internal */ _this._lightManager = new LightManager(), /* @internal */ _this._componentsManager = new ComponentsManager(), /** @internal */ _this._maskManager = new MaskManager(), /** @internal */ _this._isActiveInEngine = false, /** @internal */ _this._rootEntities = [], _this._background = new Background(_this._engine), _this._shaderData = new ShaderData(ShaderDataGroup.Scene), _this._shadowCascades = ShadowCascadesMode.NoCascades, _this._fogMode = FogMode.None, _this._fogColor = new Color(0.21404114048223255, 0.21404114048223255, 0.21404114048223255, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
28976
+ */ _this.ambientOcclusion = new AmbientOcclusion(_this), /** @internal */ _this._lightManager = new LightManager(), /** @internal */ _this._componentsManager = new ComponentsManager(), /** @internal */ _this._maskManager = new MaskManager(), /** @internal */ _this._isActiveInEngine = false, /** @internal */ _this._rootEntities = [], _this._background = new Background(_this._engine), _this._shaderData = new ShaderData(ShaderDataGroup.Scene), _this._shadowCascades = ShadowCascadesMode.NoCascades, _this._fogMode = FogMode.None, _this._fogColor = new Color(0.21404114048223255, 0.21404114048223255, 0.21404114048223255, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
28959
28977
  _this.name = name || "";
28960
28978
  var shaderData = _this.shaderData;
28961
28979
  shaderData._addReferCount(1);
@@ -29726,7 +29744,7 @@ var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
29726
29744
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29727
29745
  signalArgs[_key] = arguments[_key];
29728
29746
  }
29729
- return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
29747
+ return (_target = target)[methodName].apply(_target, [].concat(signalArgs, args));
29730
29748
  } : function() {
29731
29749
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29732
29750
  signalArgs[_key] = arguments[_key];
@@ -30160,7 +30178,7 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30160
30178
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
30161
30179
  function AnimationClipCurveBinding() {
30162
30180
  /** The index of the component that is animated. */ this.typeIndex = 0;
30163
- this._tempCurveOwner = {};
30181
+ this._tempCurveOwner = new WeakMap();
30164
30182
  }
30165
30183
  var _proto = AnimationClipCurveBinding.prototype;
30166
30184
  /**
@@ -30186,11 +30204,12 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30186
30204
  /**
30187
30205
  * @internal
30188
30206
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity, component) {
30189
- var instanceId = entity.instanceId;
30190
- if (!this._tempCurveOwner[instanceId]) {
30191
- this._tempCurveOwner[instanceId] = this._createCurveOwner(entity, component);
30207
+ var owner = this._tempCurveOwner.get(entity);
30208
+ if (!owner) {
30209
+ owner = this._createCurveOwner(entity, component);
30210
+ this._tempCurveOwner.set(entity, owner);
30192
30211
  }
30193
- return this._tempCurveOwner[instanceId];
30212
+ return owner;
30194
30213
  };
30195
30214
  return AnimationClipCurveBinding;
30196
30215
  }();
@@ -30272,11 +30291,10 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30272
30291
  this._length = 0;
30273
30292
  };
30274
30293
  /**
30275
- * @internal
30276
30294
  * Samples an animation at a given time.
30277
30295
  * @param entity - The animated entity
30278
30296
  * @param time - The time to sample an animation
30279
- */ _proto._sampleAnimation = function _sampleAnimation(entity, time) {
30297
+ */ _proto.sampleAnimation = function sampleAnimation(entity, time) {
30280
30298
  var _this = this, curveBindings = _this._curveBindings;
30281
30299
  var components = AnimationCurveOwner._components;
30282
30300
  for(var i = curveBindings.length - 1; i >= 0; i--){
@@ -31451,12 +31469,6 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31451
31469
  return LayerState;
31452
31470
  }({});
31453
31471
 
31454
- /**
31455
- * @internal
31456
- */ var AnimationEventHandler = function AnimationEventHandler() {
31457
- this.handlers = [];
31458
- };
31459
-
31460
31472
  /**
31461
31473
  * Animation wrap mode.
31462
31474
  */ var WrapMode = /*#__PURE__*/ function(WrapMode) {
@@ -31465,6 +31477,12 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31465
31477
  return WrapMode;
31466
31478
  }({});
31467
31479
 
31480
+ /**
31481
+ * @internal
31482
+ */ var AnimationEventHandler = function AnimationEventHandler() {
31483
+ this.handlers = [];
31484
+ };
31485
+
31468
31486
  /**
31469
31487
  * @internal
31470
31488
  */ var AnimatorStatePlayData = /*#__PURE__*/ function() {
@@ -31505,19 +31523,21 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31505
31523
  this.playedTime += deltaTime;
31506
31524
  var instance = this.instance;
31507
31525
  var state = instance._state;
31526
+ var clipLength = state.clip.length;
31527
+ var clipStartTime = state.clipStartTime;
31508
31528
  var time = this.playedTime + this.offsetFrameTime;
31509
- var duration = state._getDuration();
31529
+ var duration = (state.clipEndTime - clipStartTime) * clipLength;
31510
31530
  this.playState = AnimatorStatePlayState.Playing;
31511
31531
  if (instance.wrapMode === WrapMode.Loop) {
31512
31532
  time = duration ? time % duration : 0;
31513
- } else {
31514
- if (Math.abs(time) >= duration) {
31515
- time = time < 0 ? -duration : duration;
31516
- this.playState = AnimatorStatePlayState.Finished;
31517
- }
31533
+ } else if (time >= duration || time <= -duration) {
31534
+ time = time < 0 ? -duration : duration;
31535
+ this.playState = AnimatorStatePlayState.Finished;
31536
+ }
31537
+ if (time < 0) {
31538
+ time += duration;
31518
31539
  }
31519
- time < 0 && (time += duration);
31520
- this.clipTime = time + state.clipStartTime * state.clip.length;
31540
+ this.clipTime = time + clipStartTime * clipLength;
31521
31541
  if (this._changedOrientation) {
31522
31542
  !this.isForward && this._correctTime();
31523
31543
  this._changedOrientation = false;
@@ -31530,6 +31550,26 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31530
31550
  this.clipTime = state.clipEndTime * state.clip.length;
31531
31551
  }
31532
31552
  };
31553
+ _create_class(AnimatorStatePlayData, [
31554
+ {
31555
+ key: "state",
31556
+ get: function get() {
31557
+ return this.instance._state;
31558
+ }
31559
+ },
31560
+ {
31561
+ key: "speed",
31562
+ get: function get() {
31563
+ return this.instance.speed;
31564
+ }
31565
+ },
31566
+ {
31567
+ key: "wrapMode",
31568
+ get: function get() {
31569
+ return this.instance.wrapMode;
31570
+ }
31571
+ }
31572
+ ]);
31533
31573
  return AnimatorStatePlayData;
31534
31574
  }();
31535
31575
 
@@ -31708,8 +31748,8 @@ function _type_of(obj) {
31708
31748
  * @internal
31709
31749
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
31710
31750
  function AnimatorLayerData() {
31711
- this.curveOwnerPool = Object.create(null);
31712
- this.animatorStateDataMap = new WeakMap();
31751
+ this.curveOwnerPool = new WeakMap();
31752
+ this.animatorStateDataMap = new Map();
31713
31753
  this.instanceMap = new WeakMap();
31714
31754
  this.srcPlayData = null;
31715
31755
  this.destPlayData = null;
@@ -31728,15 +31768,6 @@ function _type_of(obj) {
31728
31768
  }
31729
31769
  return instance;
31730
31770
  };
31731
- _proto.completeCrossFade = function completeCrossFade() {
31732
- this.srcPlayData = this.destPlayData;
31733
- this.destPlayData = null;
31734
- this.crossFadeTransition = null;
31735
- };
31736
- _proto.clearCrossFadeSlot = function clearCrossFadeSlot() {
31737
- this.destPlayData = null;
31738
- this.crossFadeTransition = null;
31739
- };
31740
31771
  _proto.resetCurrentCheckIndex = function resetCurrentCheckIndex() {
31741
31772
  this.layer.stateMachine._entryTransitionCollection.needResetCurrentCheckIndex = true;
31742
31773
  this.layer.stateMachine._anyStateTransitionCollection.needResetCurrentCheckIndex = true;
@@ -31760,7 +31791,7 @@ function _type_of(obj) {
31760
31791
  _inherits(Animator, Component);
31761
31792
  function Animator(entity) {
31762
31793
  var _this;
31763
- _this = Component.call(this, entity) || this, /** Culling mode of this Animator. */ _this.cullingMode = AnimatorCullingMode.None, /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0, /** @internal */ _this._playFrameCount = -1, /** @internal */ _this._onUpdateIndex = -1, _this._updateMark = 0, _this._animatorLayersData = new Array(), _this._curveOwnerPool = Object.create(null), _this._parametersValueMap = Object.create(null), _this._tempAnimatorStateInfo = {
31794
+ _this = Component.call(this, entity) || this, /** Culling mode of this Animator. */ _this.cullingMode = AnimatorCullingMode.None, /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0, /** Whether the Animator sends AnimationEvent callbacks. */ _this.fireEvents = true, /** @internal */ _this._playFrameCount = -1, /** @internal */ _this._onUpdateIndex = -1, _this._updateMark = 0, _this._animatorLayersData = new Array(), _this._curveOwnerPool = new WeakMap(), _this._parametersValueMap = Object.create(null), _this._tempAnimatorStateInfo = {
31764
31795
  layerIndex: -1,
31765
31796
  state: null
31766
31797
  }, _this._controlledRenderers = new Array();
@@ -31943,16 +31974,21 @@ function _type_of(obj) {
31943
31974
  /**
31944
31975
  * @internal
31945
31976
  */ _proto._reset = function _reset() {
31946
- var _this = this, animationCurveOwners = _this._curveOwnerPool;
31947
- for(var instanceId in animationCurveOwners){
31948
- var propertyOwners = animationCurveOwners[instanceId];
31949
- for(var property in propertyOwners){
31950
- var owner = propertyOwners[property];
31951
- owner.revertDefaultValue();
31977
+ var layersData = this._animatorLayersData;
31978
+ for(var i = 0, n = layersData.length; i < n; i++){
31979
+ var layerData = layersData[i];
31980
+ if (!layerData) continue;
31981
+ for(var _iterator = _create_for_of_iterator_helper_loose(layerData.animatorStateDataMap.values()), _step; !(_step = _iterator()).done;){
31982
+ var stateData = _step.value;
31983
+ var layerOwners = stateData.curveLayerOwner;
31984
+ for(var k = 0, l = layerOwners.length; k < l; k++){
31985
+ var _layerOwners_k_curveOwner, _layerOwners_k;
31986
+ (_layerOwners_k = layerOwners[k]) == null ? void 0 : (_layerOwners_k_curveOwner = _layerOwners_k.curveOwner) == null ? void 0 : _layerOwners_k_curveOwner.revertDefaultValue();
31987
+ }
31952
31988
  }
31953
31989
  }
31954
31990
  this._animatorLayersData.length = 0;
31955
- this._curveOwnerPool = Object.create(null);
31991
+ this._curveOwnerPool = new WeakMap();
31956
31992
  this._parametersValueMap = Object.create(null);
31957
31993
  if (this._controllerUpdateFlag) {
31958
31994
  this._controllerUpdateFlag.flag = false;
@@ -31975,6 +32011,7 @@ function _type_of(obj) {
31975
32011
  };
31976
32012
  _proto._onDestroy = function _onDestroy() {
31977
32013
  Component.prototype._onDestroy.call(this);
32014
+ this._reset();
31978
32015
  var controller = this._animatorController;
31979
32016
  if (controller) {
31980
32017
  var _this__controllerUpdateFlag;
@@ -31988,7 +32025,8 @@ function _type_of(obj) {
31988
32025
  if (!state) {
31989
32026
  return;
31990
32027
  }
31991
- var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
32028
+ var animatorLayerData = this._getAnimatorLayerData(playLayerIndex);
32029
+ var manuallyTransition = animatorLayerData.manuallyTransition;
31992
32030
  manuallyTransition.duration = duration;
31993
32031
  manuallyTransition.offset = normalizedTimeOffset;
31994
32032
  manuallyTransition.isFixedDuration = isFixedDuration;
@@ -32043,20 +32081,30 @@ function _type_of(obj) {
32043
32081
  var relativePath = curve.relativePath;
32044
32082
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
32045
32083
  if (targetEntity) {
32046
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
32084
+ var _layerPropertyOwners, _property;
32047
32085
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
32048
32086
  components.length = 0;
32049
32087
  if (!component) {
32050
32088
  continue;
32051
32089
  }
32052
32090
  var property = curve.property;
32053
- var instanceId = component.instanceId;
32054
- // Get owner
32055
- var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
32056
- var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
32057
- // Get layer owner
32058
- var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
32059
- var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
32091
+ // Key owner lookup by Component identity instead of instanceId.
32092
+ var propertyOwners = curveOwnerPool.get(component);
32093
+ if (!propertyOwners) {
32094
+ propertyOwners = Object.create(null);
32095
+ curveOwnerPool.set(component, propertyOwners);
32096
+ }
32097
+ var owner = propertyOwners[property];
32098
+ if (!owner) {
32099
+ owner = curve._createCurveOwner(targetEntity, component);
32100
+ propertyOwners[property] = owner;
32101
+ }
32102
+ var layerPropertyOwners = layerCurveOwnerPool.get(component);
32103
+ if (!layerPropertyOwners) {
32104
+ layerPropertyOwners = Object.create(null);
32105
+ layerCurveOwnerPool.set(component, layerPropertyOwners);
32106
+ }
32107
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property = property] || (_layerPropertyOwners[_property] = curve._createCurveLayerOwner(owner));
32060
32108
  if (mask && mask.pathMasks.length) {
32061
32109
  var _mask_getPathMask;
32062
32110
  var _mask_getPathMask_active;
@@ -32070,8 +32118,6 @@ function _type_of(obj) {
32070
32118
  }
32071
32119
  };
32072
32120
  _proto._ensureEventHandlers = function _ensureEventHandlers(state, animatorStateData) {
32073
- // state._updateFlagManager dispatches on both clip-swap and clip-events-mutation,
32074
- // so its version covers every input that affects eventHandlers binding
32075
32121
  var stateVersion = state._updateFlagManager.version;
32076
32122
  var scriptsVersion = this._entity._scriptsVersion;
32077
32123
  if (animatorStateData.eventsBuiltVersion === stateVersion && animatorStateData.eventsBuiltScriptsVersion === scriptsVersion) {
@@ -32195,8 +32241,8 @@ function _type_of(obj) {
32195
32241
  };
32196
32242
  _proto._updatePlayingState = function _updatePlayingState(layerData, weight, additive, deltaTime, aniUpdate) {
32197
32243
  var srcPlayData = layerData.srcPlayData;
32198
- var state = srcPlayData.instance._state;
32199
- var playSpeed = srcPlayData.instance.speed * this.speed;
32244
+ var state = srcPlayData.state;
32245
+ var playSpeed = srcPlayData.speed * this.speed;
32200
32246
  var playDeltaTime = playSpeed * deltaTime;
32201
32247
  srcPlayData.updateOrientation(playDeltaTime);
32202
32248
  var lastClipTime = srcPlayData.clipTime, lastPlayState = srcPlayData.playState;
@@ -32240,14 +32286,13 @@ function _type_of(obj) {
32240
32286
  this._evaluatePlayingState(srcPlayData, weight, additive, aniUpdate);
32241
32287
  this._fireAnimationEventsAndCallScripts(layerData.layerIndex, srcPlayData, state, lastClipTime, lastPlayState, playCostTime);
32242
32288
  if (transition) {
32243
- // Remove speed factor, use actual cost time. Per-instance speed=0 means the source
32244
- // state is paused, so it consumes no time — pass deltaTime through to the destination.
32289
+ // Remove speed factor, use actual cost time
32245
32290
  var remainDeltaTime = playSpeed === 0 ? deltaTime : deltaTime - playCostTime / playSpeed;
32246
32291
  remainDeltaTime > 0 && this._updateState(layerData, remainDeltaTime, aniUpdate);
32247
32292
  }
32248
32293
  };
32249
32294
  _proto._evaluatePlayingState = function _evaluatePlayingState(playData, weight, additive, aniUpdate) {
32250
- var curveBindings = playData.instance.clip._curveBindings;
32295
+ var curveBindings = playData.state.clip._curveBindings;
32251
32296
  var finished = playData.playState === AnimatorStatePlayState.Finished;
32252
32297
  if (aniUpdate || finished) {
32253
32298
  var curveLayerOwner = playData.stateData.curveLayerOwner;
@@ -32270,14 +32315,14 @@ function _type_of(obj) {
32270
32315
  _proto._updateCrossFadeState = function _updateCrossFadeState(layerData, weight, additive, deltaTime, aniUpdate) {
32271
32316
  var srcPlayData = layerData.srcPlayData, destPlayData = layerData.destPlayData, layerIndex = layerData.layerIndex;
32272
32317
  var speed = this.speed;
32273
- var srcState = srcPlayData.instance._state;
32274
- var destState = destPlayData.instance._state;
32318
+ var srcState = srcPlayData.state;
32319
+ var destState = destPlayData.state;
32275
32320
  var transitionDuration = layerData.crossFadeTransition._getFixedDuration();
32276
32321
  if (this._tryCrossFadeInterrupt(layerData, transitionDuration, destState, deltaTime, aniUpdate)) {
32277
32322
  return;
32278
32323
  }
32279
- var srcPlaySpeed = srcPlayData.instance.speed * speed;
32280
- var dstPlaySpeed = destPlayData.instance.speed * speed;
32324
+ var srcPlaySpeed = srcPlayData.speed * speed;
32325
+ var dstPlaySpeed = destPlayData.speed * speed;
32281
32326
  var dstPlayDeltaTime = dstPlaySpeed * deltaTime;
32282
32327
  srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
32283
32328
  destPlayData.updateOrientation(dstPlayDeltaTime);
@@ -32320,8 +32365,8 @@ function _type_of(obj) {
32320
32365
  };
32321
32366
  _proto._evaluateCrossFadeState = function _evaluateCrossFadeState(layerData, srcPlayData, destPlayData, weight, crossWeight, additive, aniUpdate) {
32322
32367
  var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
32323
- var _srcPlayData_instance_clip = srcPlayData.instance.clip, srcCurves = _srcPlayData_instance_clip._curveBindings;
32324
- var destState = destPlayData.instance._state;
32368
+ var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
32369
+ var destState = destPlayData.state;
32325
32370
  var _destState_clip = destState.clip, destCurves = _destState_clip._curveBindings;
32326
32371
  var finished = destPlayData.playState === AnimatorStatePlayState.Finished;
32327
32372
  if (aniUpdate || finished) {
@@ -32340,12 +32385,12 @@ function _type_of(obj) {
32340
32385
  };
32341
32386
  _proto._updateCrossFadeFromPoseState = function _updateCrossFadeFromPoseState(layerData, weight, additive, deltaTime, aniUpdate) {
32342
32387
  var destPlayData = layerData.destPlayData;
32343
- var state = destPlayData.instance._state;
32388
+ var state = destPlayData.state;
32344
32389
  var transitionDuration = layerData.crossFadeTransition._getFixedDuration();
32345
32390
  if (this._tryCrossFadeInterrupt(layerData, transitionDuration, state, deltaTime, aniUpdate)) {
32346
32391
  return;
32347
32392
  }
32348
- var playSpeed = destPlayData.instance.speed * this.speed;
32393
+ var playSpeed = destPlayData.speed * this.speed;
32349
32394
  var playDeltaTime = playSpeed * deltaTime;
32350
32395
  destPlayData.updateOrientation(playDeltaTime);
32351
32396
  var lastDestClipTime = destPlayData.clipTime, lastPlayState = destPlayData.playState;
@@ -32382,7 +32427,7 @@ function _type_of(obj) {
32382
32427
  };
32383
32428
  _proto._evaluateCrossFadeFromPoseState = function _evaluateCrossFadeFromPoseState(layerData, destPlayData, weight, crossWeight, additive, aniUpdate) {
32384
32429
  var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
32385
- var state = destPlayData.instance._state;
32430
+ var state = destPlayData.state;
32386
32431
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
32387
32432
  var destClipTime = destPlayData.clipTime, playState = destPlayData.playState;
32388
32433
  var finished = playState === AnimatorStatePlayState.Finished;
@@ -32394,7 +32439,7 @@ function _type_of(obj) {
32394
32439
  if (!owner) continue;
32395
32440
  var curveIndex = layerOwner.crossDestCurveIndex;
32396
32441
  this._checkRevertOwner(owner, additive);
32397
- var value = layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, additive);
32442
+ var value = owner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, additive);
32398
32443
  aniUpdate && owner.applyValue(value, weight, additive);
32399
32444
  finished && layerOwner.saveFinalValue();
32400
32445
  }
@@ -32402,8 +32447,8 @@ function _type_of(obj) {
32402
32447
  };
32403
32448
  _proto._updateFinishedState = function _updateFinishedState(layerData, weight, additive, deltaTime, aniUpdate) {
32404
32449
  var playData = layerData.srcPlayData;
32405
- var state = playData.instance._state;
32406
- var actualSpeed = playData.instance.speed * this.speed;
32450
+ var state = playData.state;
32451
+ var actualSpeed = playData.speed * this.speed;
32407
32452
  var actualDeltaTime = actualSpeed * deltaTime;
32408
32453
  playData.updateOrientation(actualDeltaTime);
32409
32454
  var clipTime = playData.clipTime, isForward = playData.isForward;
@@ -32421,7 +32466,7 @@ function _type_of(obj) {
32421
32466
  return;
32422
32467
  }
32423
32468
  var curveLayerOwner = playData.stateData.curveLayerOwner;
32424
- var _playData_instance_clip = playData.instance.clip, curveBindings = _playData_instance_clip._curveBindings;
32469
+ var _playData_state_clip = playData.state.clip, curveBindings = _playData_state_clip._curveBindings;
32425
32470
  for(var i = curveBindings.length - 1; i >= 0; i--){
32426
32471
  var layerOwner = curveLayerOwner[i];
32427
32472
  var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
@@ -32437,12 +32482,14 @@ function _type_of(obj) {
32437
32482
  } else {
32438
32483
  layerData.layerState = LayerState.Playing;
32439
32484
  }
32440
- layerData.completeCrossFade();
32485
+ layerData.srcPlayData = destPlayData;
32486
+ layerData.destPlayData = null;
32487
+ layerData.crossFadeTransition = null;
32441
32488
  };
32442
32489
  _proto._preparePlayOwner = function _preparePlayOwner(layerData, playState) {
32443
32490
  if (layerData.layerState === LayerState.Playing) {
32444
32491
  var srcPlayData = layerData.srcPlayData;
32445
- if (srcPlayData.instance._state !== playState) {
32492
+ if (srcPlayData.state !== playState) {
32446
32493
  var curveLayerOwner = srcPlayData.stateData.curveLayerOwner;
32447
32494
  for(var i = curveLayerOwner.length - 1; i >= 0; i--){
32448
32495
  var _curveLayerOwner_i;
@@ -32457,17 +32504,17 @@ function _type_of(obj) {
32457
32504
  }
32458
32505
  };
32459
32506
  _proto._applyStateTransitions = function _applyStateTransitions(layerData, isForward, playData, transitionCollection, lastClipTime, clipTime, deltaTime, aniUpdate) {
32460
- var state = playData.instance._state;
32461
- var clipDuration = state.clip.length;
32507
+ var state = playData.state;
32462
32508
  var targetTransition = null;
32463
- var startTime = state.clipStartTime * clipDuration;
32464
- var endTime = state.clipEndTime * clipDuration;
32465
32509
  if (transitionCollection.noExitTimeCount) {
32466
32510
  targetTransition = this._checkNoExitTimeTransitions(layerData, transitionCollection, aniUpdate);
32467
32511
  if (targetTransition) {
32468
32512
  return targetTransition;
32469
32513
  }
32470
32514
  }
32515
+ var clipDuration = state.clip.length;
32516
+ var startTime = state.clipStartTime * clipDuration;
32517
+ var endTime = state.clipEndTime * clipDuration;
32471
32518
  if (isForward) {
32472
32519
  if (lastClipTime + deltaTime >= endTime) {
32473
32520
  targetTransition = this._checkSubTransition(layerData, state, transitionCollection, lastClipTime, endTime, aniUpdate);
@@ -32574,9 +32621,8 @@ function _type_of(obj) {
32574
32621
  var playData = animatorLayerData.getOrCreateInstance(state)._playData;
32575
32622
  playData.reset(animatorStateData, state._getClipActualEndTime() * normalizedTimeOffset);
32576
32623
  animatorLayerData.srcPlayData = playData;
32577
- // Drop any dangling cross-fade slot from a previously-interrupted crossFade
32578
- // so a later crossFade(B) isn't wrongly no-op'd by the active-dest guard.
32579
- animatorLayerData.clearCrossFadeSlot();
32624
+ animatorLayerData.destPlayData = null;
32625
+ animatorLayerData.crossFadeTransition = null;
32580
32626
  animatorLayerData.resetCurrentCheckIndex();
32581
32627
  return true;
32582
32628
  };
@@ -32660,9 +32706,7 @@ function _type_of(obj) {
32660
32706
  return false;
32661
32707
  }
32662
32708
  var animatorLayerData = this._getAnimatorLayerData(layerIndex);
32663
- // Self/active-dest cross-fade is a no-op: each state has one persistent
32664
- // instance per layer, so a second concurrent fade has nowhere to live.
32665
- if (((_animatorLayerData_srcPlayData = animatorLayerData.srcPlayData) == null ? void 0 : _animatorLayerData_srcPlayData.instance._state) === crossState || ((_animatorLayerData_destPlayData = animatorLayerData.destPlayData) == null ? void 0 : _animatorLayerData_destPlayData.instance._state) === crossState) {
32709
+ if (((_animatorLayerData_srcPlayData = animatorLayerData.srcPlayData) == null ? void 0 : _animatorLayerData_srcPlayData.state) === crossState || ((_animatorLayerData_destPlayData = animatorLayerData.destPlayData) == null ? void 0 : _animatorLayerData_destPlayData.state) === crossState) {
32666
32710
  return false;
32667
32711
  }
32668
32712
  var animatorStateData = this._getAnimatorStateData(crossState, animatorLayerData, layerIndex);
@@ -32694,23 +32738,27 @@ function _type_of(obj) {
32694
32738
  return true;
32695
32739
  };
32696
32740
  _proto._fireAnimationEvents = function _fireAnimationEvents(playData, eventHandlers, lastClipTime, deltaTime) {
32697
- var isForward = playData.isForward, clipTime = playData.clipTime;
32698
- var state = playData.instance._state;
32741
+ var state = playData.state, isForward = playData.isForward, clipTime = playData.clipTime, wrapMode = playData.wrapMode;
32699
32742
  var startTime = state._getClipActualStartTime();
32700
32743
  var endTime = state._getClipActualEndTime();
32744
+ var canWrap = wrapMode === WrapMode.Loop;
32701
32745
  if (isForward) {
32702
32746
  if (lastClipTime + deltaTime >= endTime) {
32703
32747
  this._fireSubAnimationEvents(playData, eventHandlers, lastClipTime, endTime);
32704
- playData.currentEventIndex = 0;
32705
- this._fireSubAnimationEvents(playData, eventHandlers, startTime, clipTime);
32748
+ if (canWrap) {
32749
+ playData.currentEventIndex = 0;
32750
+ this._fireSubAnimationEvents(playData, eventHandlers, startTime, clipTime);
32751
+ }
32706
32752
  } else {
32707
32753
  this._fireSubAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
32708
32754
  }
32709
32755
  } else {
32710
32756
  if (lastClipTime + deltaTime <= startTime) {
32711
32757
  this._fireBackwardSubAnimationEvents(playData, eventHandlers, lastClipTime, startTime);
32712
- playData.currentEventIndex = eventHandlers.length - 1;
32713
- this._fireBackwardSubAnimationEvents(playData, eventHandlers, endTime, clipTime);
32758
+ if (canWrap) {
32759
+ playData.currentEventIndex = eventHandlers.length - 1;
32760
+ this._fireBackwardSubAnimationEvents(playData, eventHandlers, endTime, clipTime);
32761
+ }
32714
32762
  } else {
32715
32763
  this._fireBackwardSubAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
32716
32764
  }
@@ -32726,8 +32774,10 @@ function _type_of(obj) {
32726
32774
  }
32727
32775
  var handlers = eventHandler.handlers;
32728
32776
  if (time >= lastClipTime) {
32729
- for(var j = handlers.length - 1; j >= 0; j--){
32730
- handlers[j](parameter);
32777
+ if (this.fireEvents) {
32778
+ for(var j = handlers.length - 1; j >= 0; j--){
32779
+ handlers[j](parameter);
32780
+ }
32731
32781
  }
32732
32782
  playState.currentEventIndex = Math.min(eventIndex + 1, n - 1);
32733
32783
  }
@@ -32743,8 +32793,10 @@ function _type_of(obj) {
32743
32793
  }
32744
32794
  if (time <= lastClipTime) {
32745
32795
  var handlers = eventHandler.handlers;
32746
- for(var j = handlers.length - 1; j >= 0; j--){
32747
- handlers[j](parameter);
32796
+ if (this.fireEvents) {
32797
+ for(var j = handlers.length - 1; j >= 0; j--){
32798
+ handlers[j](parameter);
32799
+ }
32748
32800
  }
32749
32801
  playState.currentEventIndex = Math.max(eventIndex - 1, 0);
32750
32802
  }
@@ -32775,9 +32827,6 @@ function _type_of(obj) {
32775
32827
  owner.updateMark = this._updateMark;
32776
32828
  };
32777
32829
  _proto._fireAnimationEventsAndCallScripts = function _fireAnimationEventsAndCallScripts(layerIndex, playData, state, lastClipTime, lastPlayState, deltaTime) {
32778
- // Re-check whether the clip events/scripts changed since the last build —
32779
- // play()/crossFade() entry points already ensure on enter, but addEvent()
32780
- // or addComponent(Script) after play() must also flow through.
32781
32830
  this._ensureEventHandlers(state, playData.stateData);
32782
32831
  var eventHandlers = playData.stateData.eventHandlers;
32783
32832
  eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, deltaTime);
@@ -32845,6 +32894,9 @@ Animator._tempScripts = [];
32845
32894
  __decorate([
32846
32895
  assignmentClone
32847
32896
  ], Animator.prototype, "speed", void 0);
32897
+ __decorate([
32898
+ assignmentClone
32899
+ ], Animator.prototype, "fireEvents", void 0);
32848
32900
  __decorate([
32849
32901
  assignmentClone
32850
32902
  ], Animator.prototype, "_animatorController", void 0);
@@ -32916,7 +32968,10 @@ function _assert_this_initialized(self) {
32916
32968
  /** @internal */ _this._parametersMap = {},
32917
32969
  /** @internal */ _this._layers = [],
32918
32970
  /** @internal */ _this._layersMap = {},
32919
- _this._updateFlagManager = new UpdateFlagManager()
32971
+ _this._updateFlagManager = new UpdateFlagManager(),
32972
+ _this._onStatesInvalidate = function() {
32973
+ return _this._updateFlagManager.dispatch();
32974
+ }
32920
32975
  ][0];
32921
32976
  return _assert_this_initialized(_this);
32922
32977
  }
@@ -32971,6 +33026,7 @@ function _assert_this_initialized(self) {
32971
33026
  */ _proto.addLayer = function addLayer(layer) {
32972
33027
  this._layers.push(layer);
32973
33028
  this._layersMap[layer.name] = layer;
33029
+ layer._setStatesInvalidateCallback(this._onStatesInvalidate);
32974
33030
  layer._setEngine(this._engine);
32975
33031
  this._updateFlagManager.dispatch();
32976
33032
  };
@@ -32980,13 +33036,18 @@ function _assert_this_initialized(self) {
32980
33036
  */ _proto.removeLayer = function removeLayer(layerIndex) {
32981
33037
  var theLayer = this.layers[layerIndex];
32982
33038
  this._layers.splice(layerIndex, 1);
33039
+ theLayer._setStatesInvalidateCallback(null);
32983
33040
  delete this._layersMap[theLayer.name];
32984
33041
  this._updateFlagManager.dispatch();
32985
33042
  };
32986
33043
  /**
32987
33044
  * Clear layers.
32988
33045
  */ _proto.clearLayers = function clearLayers() {
32989
- this._layers.length = 0;
33046
+ var _this = this, layers = _this._layers;
33047
+ for(var i = 0, n = layers.length; i < n; i++){
33048
+ layers[i]._setStatesInvalidateCallback(null);
33049
+ }
33050
+ layers.length = 0;
32990
33051
  for(var name in this._layersMap){
32991
33052
  delete this._layersMap[name];
32992
33053
  }
@@ -33002,7 +33063,9 @@ function _assert_this_initialized(self) {
33002
33063
  */ _proto._setEngine = function _setEngine(engine) {
33003
33064
  var _this = this, layers = _this._layers;
33004
33065
  for(var i = 0, n = layers.length; i < n; i++){
33005
- layers[i]._setEngine(engine);
33066
+ var layer = layers[i];
33067
+ layer._setStatesInvalidateCallback(this._onStatesInvalidate);
33068
+ layer._setEngine(engine);
33006
33069
  }
33007
33070
  };
33008
33071
  _proto._addParameter = function _addParameter(name, defaultValue, isTrigger) {
@@ -33389,6 +33452,7 @@ function _assert_this_initialized(self) {
33389
33452
  */ var AnimatorStateMachine = /*#__PURE__*/ function() {
33390
33453
  function AnimatorStateMachine() {
33391
33454
  /** The list of states. */ this.states = [];
33455
+ this._onStatesInvalidate = null;
33392
33456
  /**
33393
33457
  * The state will be played automatically.
33394
33458
  * @remarks When the Animator's AnimatorController changed or the Animator's onEnable be triggered. Cleared to `null` if the state is removed via `removeState`.
@@ -33425,6 +33489,7 @@ function _assert_this_initialized(self) {
33425
33489
  if (this.defaultState === state) {
33426
33490
  this.defaultState = null;
33427
33491
  }
33492
+ this._onStatesInvalidate == null ? void 0 : this._onStatesInvalidate.call(this);
33428
33493
  }
33429
33494
  };
33430
33495
  /**
@@ -33484,6 +33549,11 @@ function _assert_this_initialized(self) {
33484
33549
  states[i]._setEngine(engine);
33485
33550
  }
33486
33551
  };
33552
+ /**
33553
+ * @internal
33554
+ */ _proto._setStatesInvalidateCallback = function _setStatesInvalidateCallback(onStatesInvalidate) {
33555
+ this._onStatesInvalidate = onStatesInvalidate;
33556
+ };
33487
33557
  _create_class(AnimatorStateMachine, [
33488
33558
  {
33489
33559
  key: "entryTransitions",
@@ -33512,14 +33582,43 @@ function _assert_this_initialized(self) {
33512
33582
  this.name = name;
33513
33583
  this./** The blending weight that the layers has. It is not taken into account for the first layer. */ weight = 1.0;
33514
33584
  this./** The blending mode used by the layer. It is not taken into account for the first layer. */ blendingMode = AnimatorLayerBlendingMode.Override;
33515
- this.stateMachine = new AnimatorStateMachine();
33585
+ this._onStatesInvalidate = null;
33586
+ this._stateMachine = new AnimatorStateMachine();
33516
33587
  }
33517
33588
  var _proto = AnimatorControllerLayer.prototype;
33518
33589
  /**
33519
33590
  * @internal
33520
33591
  */ _proto._setEngine = function _setEngine(engine) {
33521
- this.stateMachine._setEngine(engine);
33592
+ this._engine = engine;
33593
+ this._stateMachine._setEngine(engine);
33522
33594
  };
33595
+ /**
33596
+ * @internal
33597
+ */ _proto._setStatesInvalidateCallback = function _setStatesInvalidateCallback(onStatesInvalidate) {
33598
+ this._onStatesInvalidate = onStatesInvalidate;
33599
+ this._stateMachine._setStatesInvalidateCallback(onStatesInvalidate);
33600
+ };
33601
+ _create_class(AnimatorControllerLayer, [
33602
+ {
33603
+ key: "stateMachine",
33604
+ get: /**
33605
+ * The state machine for the layer.
33606
+ */ function get() {
33607
+ return this._stateMachine;
33608
+ },
33609
+ set: function set(value) {
33610
+ var lastStateMachine = this._stateMachine;
33611
+ if (lastStateMachine === value) {
33612
+ return;
33613
+ }
33614
+ lastStateMachine._setStatesInvalidateCallback(null);
33615
+ this._stateMachine = value;
33616
+ value._setStatesInvalidateCallback(this._onStatesInvalidate);
33617
+ this._engine && value._setEngine(this._engine);
33618
+ this._onStatesInvalidate == null ? void 0 : this._onStatesInvalidate.call(this);
33619
+ }
33620
+ }
33621
+ ]);
33523
33622
  return AnimatorControllerLayer;
33524
33623
  }();
33525
33624
 
@@ -35121,6 +35220,7 @@ __decorate([
35121
35220
  /**
35122
35221
  * @internal
35123
35222
  */ _proto._getMax = function _getMax() {
35223
+ var minMaxRange = ParticleCompositeCurve._minMaxRange;
35124
35224
  switch(this.mode){
35125
35225
  case ParticleCurveMode.Constant:
35126
35226
  return this.constantMax;
@@ -35128,17 +35228,18 @@ __decorate([
35128
35228
  return Math.max(this.constantMin, this.constantMax);
35129
35229
  case ParticleCurveMode.Curve:
35130
35230
  var _this_curveMax;
35131
- return this._getMaxKeyValue((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys);
35231
+ this._getKeyMinMax((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys, minMaxRange);
35232
+ return minMaxRange.y;
35132
35233
  case ParticleCurveMode.TwoCurves:
35133
35234
  var _this_curveMin, _this_curveMax1;
35134
- var min = this._getMaxKeyValue((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys);
35135
- var max = this._getMaxKeyValue((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys);
35136
- return min > max ? min : max;
35235
+ this._getKeyMinMax((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys, minMaxRange);
35236
+ var maxCurveMin = minMaxRange.y;
35237
+ this._getKeyMinMax((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys, minMaxRange);
35238
+ return maxCurveMin > minMaxRange.y ? maxCurveMin : minMaxRange.y;
35137
35239
  }
35138
35240
  };
35139
35241
  /**
35140
35242
  * @internal
35141
-
35142
35243
  */ _proto._getMinMax = function _getMinMax(out) {
35143
35244
  switch(this.mode){
35144
35245
  case ParticleCurveMode.Constant:
@@ -35148,23 +35249,40 @@ __decorate([
35148
35249
  out.set(Math.min(this.constantMin, this.constantMax), Math.max(this.constantMin, this.constantMax));
35149
35250
  break;
35150
35251
  case ParticleCurveMode.Curve:
35151
- var _this_curveMax, _this_curveMax1;
35152
- out.set(this._getMinKeyValue((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys), this._getMaxKeyValue((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys));
35252
+ var _this_curveMax;
35253
+ this._getKeyMinMax((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys, out);
35153
35254
  break;
35154
35255
  case ParticleCurveMode.TwoCurves:
35155
- var _this_curveMax2, _this_curveMin, _this_curveMax3, _this_curveMin1;
35156
- var minCurveMax = this._getMinKeyValue((_this_curveMax2 = this.curveMax) == null ? void 0 : _this_curveMax2.keys);
35157
- var minCurveMin = this._getMinKeyValue((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys);
35158
- var maxCurveMax = this._getMaxKeyValue((_this_curveMax3 = this.curveMax) == null ? void 0 : _this_curveMax3.keys);
35159
- var maxCurveMin = this._getMaxKeyValue((_this_curveMin1 = this.curveMin) == null ? void 0 : _this_curveMin1.keys);
35160
- var min = minCurveMax < minCurveMin ? minCurveMax : minCurveMin;
35161
- var max = maxCurveMax > maxCurveMin ? maxCurveMax : maxCurveMin;
35162
- out.set(min, max);
35256
+ var _this_curveMin, _this_curveMax1;
35257
+ this._getKeyMinMax((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys, out);
35258
+ var minCurveMin = out.x;
35259
+ var maxCurveMin = out.y;
35260
+ this._getKeyMinMax((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys, out);
35261
+ var minCurveMax = out.x;
35262
+ var maxCurveMax = out.y;
35263
+ out.set(minCurveMax < minCurveMin ? minCurveMax : minCurveMin, maxCurveMax > maxCurveMin ? maxCurveMax : maxCurveMin);
35163
35264
  break;
35164
35265
  }
35165
35266
  };
35166
35267
  /**
35167
35268
  * @internal
35269
+ */ _proto._isZero = function _isZero() {
35270
+ var minMax = ParticleCompositeCurve._minMaxRange;
35271
+ this._getMinMax(minMax);
35272
+ return minMax.x === 0 && minMax.y === 0;
35273
+ };
35274
+ /**
35275
+ * @internal
35276
+ */ _proto._isCurveMode = function _isCurveMode() {
35277
+ return this._mode === ParticleCurveMode.Curve || this._mode === ParticleCurveMode.TwoCurves;
35278
+ };
35279
+ /**
35280
+ * @internal
35281
+ */ _proto._isRandomMode = function _isRandomMode() {
35282
+ return this._mode === ParticleCurveMode.TwoConstants || this._mode === ParticleCurveMode.TwoCurves;
35283
+ };
35284
+ /**
35285
+ * @internal
35168
35286
  */ _proto._registerOnValueChanged = function _registerOnValueChanged(listener) {
35169
35287
  this._updateManager.addListener(listener);
35170
35288
  };
@@ -35173,31 +35291,20 @@ __decorate([
35173
35291
  */ _proto._unRegisterOnValueChanged = function _unRegisterOnValueChanged(listener) {
35174
35292
  this._updateManager.removeListener(listener);
35175
35293
  };
35176
- _proto._getMaxKeyValue = function _getMaxKeyValue(keys) {
35177
- var max = undefined;
35178
- var _keys_length;
35179
- var count = (_keys_length = keys == null ? void 0 : keys.length) != null ? _keys_length : 0;
35180
- if (count > 0) {
35181
- max = keys[0].value;
35182
- for(var i = 1; i < count; i++){
35183
- var value = keys[i].value;
35184
- max = Math.max(max, value);
35185
- }
35186
- }
35187
- return max;
35188
- };
35189
- _proto._getMinKeyValue = function _getMinKeyValue(keys) {
35294
+ _proto._getKeyMinMax = function _getKeyMinMax(keys, out) {
35190
35295
  var min = undefined;
35296
+ var max = undefined;
35191
35297
  var _keys_length;
35192
35298
  var count = (_keys_length = keys == null ? void 0 : keys.length) != null ? _keys_length : 0;
35193
35299
  if (count > 0) {
35194
- min = keys[0].value;
35300
+ min = max = keys[0].value;
35195
35301
  for(var i = 1; i < count; i++){
35196
35302
  var value = keys[i].value;
35197
35303
  min = Math.min(min, value);
35304
+ max = Math.max(max, value);
35198
35305
  }
35199
35306
  }
35200
- return min;
35307
+ out.set(min != null ? min : 0, max != null ? max : 0);
35201
35308
  };
35202
35309
  _proto._onCurveChange = function _onCurveChange(lastValue, value) {
35203
35310
  var dispatch = this._updateDispatch;
@@ -35303,6 +35410,7 @@ __decorate([
35303
35410
  ]);
35304
35411
  return ParticleCompositeCurve;
35305
35412
  }();
35413
+ ParticleCompositeCurve._minMaxRange = new Vector2();
35306
35414
  __decorate([
35307
35415
  ignoreClone
35308
35416
  ], ParticleCompositeCurve.prototype, "_updateManager", void 0);
@@ -37640,10 +37748,20 @@ __decorate([
37640
37748
  _inherits(VelocityOverLifetimeModule, ParticleGeneratorModule);
37641
37749
  function VelocityOverLifetimeModule(generator) {
37642
37750
  var _this;
37643
- _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._velocityRand = new Rand(0, ParticleRandomSubSeeds.VelocityOverLifetime), _this._velocityMinConstant = new Vector3(), _this._velocityMaxConstant = new Vector3(), _this._space = ParticleSimulationSpace.Local;
37751
+ _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._velocityRand = new Rand(0, ParticleRandomSubSeeds.VelocityOverLifetime), _this._velocityMinConstant = new Vector3(), _this._velocityMaxConstant = new Vector3(), _this._orbitalMinConstant = new Vector3(), _this._orbitalConstant = new Vector3(), _this._offset = new Vector3(), _this._space = ParticleSimulationSpace.Local, _this._onTransformFeedbackDirty = function() {
37752
+ return _this._generator._setTransformFeedback();
37753
+ };
37644
37754
  _this.velocityX = new ParticleCompositeCurve(0);
37645
37755
  _this.velocityY = new ParticleCompositeCurve(0);
37646
37756
  _this.velocityZ = new ParticleCompositeCurve(0);
37757
+ _this.orbitalX = new ParticleCompositeCurve(0);
37758
+ _this.orbitalY = new ParticleCompositeCurve(0);
37759
+ _this.orbitalZ = new ParticleCompositeCurve(0);
37760
+ _this.radial = new ParticleCompositeCurve(0);
37761
+ // @ts-ignore
37762
+ _this._offset._onValueChanged = function() {
37763
+ return _this._generator._renderer._onGeneratorParamsChanged();
37764
+ };
37647
37765
  return _this;
37648
37766
  }
37649
37767
  var _proto = VelocityOverLifetimeModule.prototype;
@@ -37652,6 +37770,10 @@ __decorate([
37652
37770
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
37653
37771
  var velocityMacro = null;
37654
37772
  var isRandomModeMacro = null;
37773
+ var orbitalMacro = null;
37774
+ var orbitalRandomModeMacro = null;
37775
+ var radialMacro = null;
37776
+ var radialRandomModeMacro = null;
37655
37777
  if (this.enabled) {
37656
37778
  var velocityX = this.velocityX;
37657
37779
  var velocityY = this.velocityY;
@@ -37681,15 +37803,111 @@ __decorate([
37681
37803
  }
37682
37804
  }
37683
37805
  shaderData.setInt(VelocityOverLifetimeModule._spaceProperty, this.space);
37806
+ var needTransformFeedback = this._needTransformFeedback();
37807
+ var orbitalActive = needTransformFeedback && this._isOrbitalActive();
37808
+ var radialActive = needTransformFeedback && this._isRadialActive();
37809
+ if (orbitalActive) {
37810
+ var orbitalX = this._orbitalX;
37811
+ var orbitalY = this._orbitalY;
37812
+ var orbitalZ = this._orbitalZ;
37813
+ var isOrbitalRandomCurveMode = orbitalX.mode === ParticleCurveMode.TwoCurves && orbitalY.mode === ParticleCurveMode.TwoCurves && orbitalZ.mode === ParticleCurveMode.TwoCurves;
37814
+ if (isOrbitalRandomCurveMode || orbitalX.mode === ParticleCurveMode.Curve && orbitalY.mode === ParticleCurveMode.Curve && orbitalZ.mode === ParticleCurveMode.Curve) {
37815
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveXProperty, orbitalX.curveMax._getTypeArray());
37816
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveYProperty, orbitalY.curveMax._getTypeArray());
37817
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveZProperty, orbitalZ.curveMax._getTypeArray());
37818
+ orbitalMacro = VelocityOverLifetimeModule._orbitalCurveModeMacro;
37819
+ if (isOrbitalRandomCurveMode) {
37820
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveXProperty, orbitalX.curveMin._getTypeArray());
37821
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveYProperty, orbitalY.curveMin._getTypeArray());
37822
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveZProperty, orbitalZ.curveMin._getTypeArray());
37823
+ orbitalRandomModeMacro = VelocityOverLifetimeModule._orbitalRandomModeMacro;
37824
+ }
37825
+ } else {
37826
+ this._orbitalConstant.set(orbitalX.constantMax, orbitalY.constantMax, orbitalZ.constantMax);
37827
+ shaderData.setVector3(VelocityOverLifetimeModule._orbitalMaxConstantProperty, this._orbitalConstant);
37828
+ orbitalMacro = VelocityOverLifetimeModule._orbitalConstantModeMacro;
37829
+ if (orbitalX.mode === ParticleCurveMode.TwoConstants && orbitalY.mode === ParticleCurveMode.TwoConstants && orbitalZ.mode === ParticleCurveMode.TwoConstants) {
37830
+ this._orbitalMinConstant.set(orbitalX.constantMin, orbitalY.constantMin, orbitalZ.constantMin);
37831
+ shaderData.setVector3(VelocityOverLifetimeModule._orbitalMinConstantProperty, this._orbitalMinConstant);
37832
+ orbitalRandomModeMacro = VelocityOverLifetimeModule._orbitalRandomModeMacro;
37833
+ }
37834
+ }
37835
+ }
37836
+ if (radialActive) {
37837
+ var radial = this._radial;
37838
+ var isRadialRandomMode = radial._isRandomMode();
37839
+ if (radial._isCurveMode()) {
37840
+ shaderData.setFloatArray(VelocityOverLifetimeModule._radialMaxCurveProperty, radial.curveMax._getTypeArray());
37841
+ radialMacro = VelocityOverLifetimeModule._radialCurveModeMacro;
37842
+ if (isRadialRandomMode) {
37843
+ shaderData.setFloatArray(VelocityOverLifetimeModule._radialMinCurveProperty, radial.curveMin._getTypeArray());
37844
+ radialRandomModeMacro = VelocityOverLifetimeModule._radialRandomModeMacro;
37845
+ }
37846
+ } else {
37847
+ shaderData.setFloat(VelocityOverLifetimeModule._radialMaxConstantProperty, radial.constantMax);
37848
+ radialMacro = VelocityOverLifetimeModule._radialConstantModeMacro;
37849
+ if (isRadialRandomMode) {
37850
+ shaderData.setFloat(VelocityOverLifetimeModule._radialMinConstantProperty, radial.constantMin);
37851
+ radialRandomModeMacro = VelocityOverLifetimeModule._radialRandomModeMacro;
37852
+ }
37853
+ }
37854
+ }
37855
+ if (orbitalActive || radialActive) {
37856
+ shaderData.setVector3(VelocityOverLifetimeModule._offsetProperty, this._offset);
37857
+ }
37684
37858
  }
37685
37859
  this._velocityMacro = this._enableMacro(shaderData, this._velocityMacro, velocityMacro);
37686
37860
  this._randomModeMacro = this._enableMacro(shaderData, this._randomModeMacro, isRandomModeMacro);
37861
+ this._orbitalMacro = this._enableMacro(shaderData, this._orbitalMacro, orbitalMacro);
37862
+ this._orbitalRandomModeMacro = this._enableMacro(shaderData, this._orbitalRandomModeMacro, orbitalRandomModeMacro);
37863
+ this._radialMacro = this._enableMacro(shaderData, this._radialMacro, radialMacro);
37864
+ this._radialRandomModeMacro = this._enableMacro(shaderData, this._radialRandomModeMacro, radialRandomModeMacro);
37687
37865
  };
37688
37866
  /**
37689
37867
  * @internal
37690
37868
  */ _proto._resetRandomSeed = function _resetRandomSeed(seed) {
37691
37869
  this._velocityRand.reset(seed, ParticleRandomSubSeeds.VelocityOverLifetime);
37692
37870
  };
37871
+ /**
37872
+ * @internal
37873
+ */ _proto._needTransformFeedback = function _needTransformFeedback() {
37874
+ if (!this._enabled || !this._generator._renderer.engine._hardwareRenderer.isWebGL2) {
37875
+ return false;
37876
+ }
37877
+ return this._isOrbitalActive() || this._isRadialActive();
37878
+ };
37879
+ /**
37880
+ * @internal
37881
+ */ _proto._isOrbitalActive = function _isOrbitalActive() {
37882
+ return !(this._orbitalX._isZero() && this._orbitalY._isZero() && this._orbitalZ._isZero());
37883
+ };
37884
+ /**
37885
+ * @internal
37886
+ */ _proto._isRadialActive = function _isRadialActive() {
37887
+ return !this._radial._isZero();
37888
+ };
37889
+ /**
37890
+ * @internal
37891
+ */ _proto._isRandomMode = function _isRandomMode() {
37892
+ var velocityX = this.velocityX;
37893
+ var velocityY = this.velocityY;
37894
+ var velocityZ = this.velocityZ;
37895
+ var isLinearRandomMode = velocityX.mode === ParticleCurveMode.TwoConstants && velocityY.mode === ParticleCurveMode.TwoConstants && velocityZ.mode === ParticleCurveMode.TwoConstants || velocityX.mode === ParticleCurveMode.TwoCurves && velocityY.mode === ParticleCurveMode.TwoCurves && velocityZ.mode === ParticleCurveMode.TwoCurves;
37896
+ if (!this._needTransformFeedback()) {
37897
+ return isLinearRandomMode;
37898
+ }
37899
+ var orbitalX = this._orbitalX;
37900
+ var orbitalY = this._orbitalY;
37901
+ var orbitalZ = this._orbitalZ;
37902
+ var isOrbitalRandomMode = orbitalX.mode === ParticleCurveMode.TwoConstants && orbitalY.mode === ParticleCurveMode.TwoConstants && orbitalZ.mode === ParticleCurveMode.TwoConstants || orbitalX.mode === ParticleCurveMode.TwoCurves && orbitalY.mode === ParticleCurveMode.TwoCurves && orbitalZ.mode === ParticleCurveMode.TwoCurves;
37903
+ return isLinearRandomMode || isOrbitalRandomMode || this._radial._isRandomMode();
37904
+ };
37905
+ _proto._onOrbitalRadialChange = function _onOrbitalRadialChange(lastValue, value) {
37906
+ this._onCompositeCurveChange(lastValue, value);
37907
+ lastValue == null ? void 0 : lastValue._unRegisterOnValueChanged(this._onTransformFeedbackDirty);
37908
+ value == null ? void 0 : value._registerOnValueChanged(this._onTransformFeedbackDirty);
37909
+ this._generator._setTransformFeedback();
37910
+ };
37693
37911
  _create_class(VelocityOverLifetimeModule, [
37694
37912
  {
37695
37913
  key: "velocityX",
@@ -37736,6 +37954,84 @@ __decorate([
37736
37954
  }
37737
37955
  }
37738
37956
  },
37957
+ {
37958
+ key: "orbitalX",
37959
+ get: /**
37960
+ * Orbital velocity (radians/second) around the x axis of the system.
37961
+ * @remarks Requires WebGL2.
37962
+ */ function get() {
37963
+ return this._orbitalX;
37964
+ },
37965
+ set: function set(value) {
37966
+ var lastValue = this._orbitalX;
37967
+ if (value !== lastValue) {
37968
+ this._orbitalX = value;
37969
+ this._onOrbitalRadialChange(lastValue, value);
37970
+ }
37971
+ }
37972
+ },
37973
+ {
37974
+ key: "orbitalY",
37975
+ get: /**
37976
+ * Orbital velocity (radians/second) around the y axis of the system.
37977
+ * @remarks Requires WebGL2.
37978
+ */ function get() {
37979
+ return this._orbitalY;
37980
+ },
37981
+ set: function set(value) {
37982
+ var lastValue = this._orbitalY;
37983
+ if (value !== lastValue) {
37984
+ this._orbitalY = value;
37985
+ this._onOrbitalRadialChange(lastValue, value);
37986
+ }
37987
+ }
37988
+ },
37989
+ {
37990
+ key: "orbitalZ",
37991
+ get: /**
37992
+ * Orbital velocity (radians/second) around the z axis of the system.
37993
+ * @remarks Requires WebGL2.
37994
+ */ function get() {
37995
+ return this._orbitalZ;
37996
+ },
37997
+ set: function set(value) {
37998
+ var lastValue = this._orbitalZ;
37999
+ if (value !== lastValue) {
38000
+ this._orbitalZ = value;
38001
+ this._onOrbitalRadialChange(lastValue, value);
38002
+ }
38003
+ }
38004
+ },
38005
+ {
38006
+ key: "radial",
38007
+ get: /**
38008
+ * Radial velocity moving particles away from (or towards) the center.
38009
+ * @remarks Requires WebGL2.
38010
+ */ function get() {
38011
+ return this._radial;
38012
+ },
38013
+ set: function set(value) {
38014
+ var lastValue = this._radial;
38015
+ if (value !== lastValue) {
38016
+ this._radial = value;
38017
+ this._onOrbitalRadialChange(lastValue, value);
38018
+ }
38019
+ }
38020
+ },
38021
+ {
38022
+ key: "centerOffset",
38023
+ get: /**
38024
+ * The center offset of orbital/radial motion from the particle system origin.
38025
+ */ function get() {
38026
+ return this._offset;
38027
+ },
38028
+ set: function set(value) {
38029
+ var offset = this._offset;
38030
+ if (value !== offset) {
38031
+ offset.copyFrom(value);
38032
+ }
38033
+ }
38034
+ },
37739
38035
  {
37740
38036
  key: "space",
37741
38037
  get: /**
@@ -37758,6 +38054,7 @@ __decorate([
37758
38054
  set: function set(value) {
37759
38055
  if (value !== this._enabled) {
37760
38056
  this._enabled = value;
38057
+ this._generator._setTransformFeedback();
37761
38058
  this._generator._renderer._onGeneratorParamsChanged();
37762
38059
  }
37763
38060
  }
@@ -37777,6 +38074,25 @@ VelocityOverLifetimeModule._maxGradientXProperty = ShaderProperty.getByName("ren
37777
38074
  VelocityOverLifetimeModule._maxGradientYProperty = ShaderProperty.getByName("renderer_VOLMaxGradientY");
37778
38075
  VelocityOverLifetimeModule._maxGradientZProperty = ShaderProperty.getByName("renderer_VOLMaxGradientZ");
37779
38076
  VelocityOverLifetimeModule._spaceProperty = ShaderProperty.getByName("renderer_VOLSpace");
38077
+ VelocityOverLifetimeModule._orbitalConstantModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_CONSTANT_MODE");
38078
+ VelocityOverLifetimeModule._orbitalCurveModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_CURVE_MODE");
38079
+ VelocityOverLifetimeModule._orbitalRandomModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_IS_RANDOM_TWO");
38080
+ VelocityOverLifetimeModule._radialConstantModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_CONSTANT_MODE");
38081
+ VelocityOverLifetimeModule._radialCurveModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_CURVE_MODE");
38082
+ VelocityOverLifetimeModule._radialRandomModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_IS_RANDOM_TWO");
38083
+ VelocityOverLifetimeModule._orbitalMinConstantProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinConst");
38084
+ VelocityOverLifetimeModule._orbitalMaxConstantProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxConst");
38085
+ VelocityOverLifetimeModule._orbitalMinCurveXProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveX");
38086
+ VelocityOverLifetimeModule._orbitalMinCurveYProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveY");
38087
+ VelocityOverLifetimeModule._orbitalMinCurveZProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveZ");
38088
+ VelocityOverLifetimeModule._orbitalMaxCurveXProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveX");
38089
+ VelocityOverLifetimeModule._orbitalMaxCurveYProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveY");
38090
+ VelocityOverLifetimeModule._orbitalMaxCurveZProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveZ");
38091
+ VelocityOverLifetimeModule._radialMinConstantProperty = ShaderProperty.getByName("renderer_VOLRadialMinConst");
38092
+ VelocityOverLifetimeModule._radialMaxConstantProperty = ShaderProperty.getByName("renderer_VOLRadialMaxConst");
38093
+ VelocityOverLifetimeModule._radialMinCurveProperty = ShaderProperty.getByName("renderer_VOLRadialMinCurve");
38094
+ VelocityOverLifetimeModule._radialMaxCurveProperty = ShaderProperty.getByName("renderer_VOLRadialMaxCurve");
38095
+ VelocityOverLifetimeModule._offsetProperty = ShaderProperty.getByName("renderer_VOLOffset");
37780
38096
  __decorate([
37781
38097
  ignoreClone
37782
38098
  ], VelocityOverLifetimeModule.prototype, "_velocityRand", void 0);
@@ -37792,6 +38108,24 @@ __decorate([
37792
38108
  __decorate([
37793
38109
  ignoreClone
37794
38110
  ], VelocityOverLifetimeModule.prototype, "_randomModeMacro", void 0);
38111
+ __decorate([
38112
+ ignoreClone
38113
+ ], VelocityOverLifetimeModule.prototype, "_orbitalMinConstant", void 0);
38114
+ __decorate([
38115
+ ignoreClone
38116
+ ], VelocityOverLifetimeModule.prototype, "_orbitalConstant", void 0);
38117
+ __decorate([
38118
+ ignoreClone
38119
+ ], VelocityOverLifetimeModule.prototype, "_orbitalMacro", void 0);
38120
+ __decorate([
38121
+ ignoreClone
38122
+ ], VelocityOverLifetimeModule.prototype, "_orbitalRandomModeMacro", void 0);
38123
+ __decorate([
38124
+ ignoreClone
38125
+ ], VelocityOverLifetimeModule.prototype, "_radialMacro", void 0);
38126
+ __decorate([
38127
+ ignoreClone
38128
+ ], VelocityOverLifetimeModule.prototype, "_radialRandomModeMacro", void 0);
37795
38129
  __decorate([
37796
38130
  deepClone
37797
38131
  ], VelocityOverLifetimeModule.prototype, "_velocityX", void 0);
@@ -37801,6 +38135,24 @@ __decorate([
37801
38135
  __decorate([
37802
38136
  deepClone
37803
38137
  ], VelocityOverLifetimeModule.prototype, "_velocityZ", void 0);
38138
+ __decorate([
38139
+ deepClone
38140
+ ], VelocityOverLifetimeModule.prototype, "_orbitalX", void 0);
38141
+ __decorate([
38142
+ deepClone
38143
+ ], VelocityOverLifetimeModule.prototype, "_orbitalY", void 0);
38144
+ __decorate([
38145
+ deepClone
38146
+ ], VelocityOverLifetimeModule.prototype, "_orbitalZ", void 0);
38147
+ __decorate([
38148
+ deepClone
38149
+ ], VelocityOverLifetimeModule.prototype, "_radial", void 0);
38150
+ __decorate([
38151
+ deepClone
38152
+ ], VelocityOverLifetimeModule.prototype, "_offset", void 0);
38153
+ __decorate([
38154
+ ignoreClone
38155
+ ], VelocityOverLifetimeModule.prototype, "_onTransformFeedbackDirty", void 0);
37804
38156
 
37805
38157
  /**
37806
38158
  * Optional parent properties a sub-emitter inherits
@@ -38401,12 +38753,10 @@ __decorate([
38401
38753
  /**
38402
38754
  * @internal
38403
38755
  */ _proto._setTransformFeedback = function _setTransformFeedback() {
38404
- var needed = this._renderer.engine._hardwareRenderer.isWebGL2 && (this.limitVelocityOverLifetime.enabled || this.noise.enabled || this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Death));
38756
+ var _this_limitVelocityOverLifetime, _this_noise, _this_velocityOverLifetime, _this_subEmitters;
38757
+ var needed = !!(this._renderer.engine._hardwareRenderer.isWebGL2 && (((_this_limitVelocityOverLifetime = this.limitVelocityOverLifetime) == null ? void 0 : _this_limitVelocityOverLifetime.enabled) || ((_this_noise = this.noise) == null ? void 0 : _this_noise.enabled) || ((_this_velocityOverLifetime = this.velocityOverLifetime) == null ? void 0 : _this_velocityOverLifetime._needTransformFeedback()) || ((_this_subEmitters = this.subEmitters) == null ? void 0 : _this_subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Death))));
38405
38758
  if (needed === this._useTransformFeedback) return;
38406
38759
  this._useTransformFeedback = needed;
38407
- // Switching TF mode invalidates all active particle state: feedback buffers and instance
38408
- // buffer layout are incompatible between the two paths. Clear rather than show a one-frame
38409
- // jump; new particles will fill in naturally from the next emit cycle.
38410
38760
  this._clearActiveParticles();
38411
38761
  if (needed) {
38412
38762
  if (!this._feedbackSimulator) {
@@ -38484,7 +38834,12 @@ __decorate([
38484
38834
  this._calculateTransformedBounds(maxLifetime, generatorBounds, transformedBounds);
38485
38835
  renderer._setDirtyFlagFalse(ParticleUpdateFlags.TransformVolume);
38486
38836
  }
38487
- this._addGravityToBounds(maxLifetime, transformedBounds, bounds);
38837
+ if (this._useOrbitalBounds()) {
38838
+ bounds.min.copyFrom(transformedBounds.min);
38839
+ bounds.max.copyFrom(transformedBounds.max);
38840
+ } else {
38841
+ this._addGravityToBounds(maxLifetime, transformedBounds, bounds);
38842
+ }
38488
38843
  };
38489
38844
  /**
38490
38845
  * @internal
@@ -38510,7 +38865,9 @@ __decorate([
38510
38865
  }
38511
38866
  }
38512
38867
  var maxLifetime = this.main.startLifetime._getMax();
38513
- this._addGravityToBounds(maxLifetime, bounds, bounds);
38868
+ if (!this._useOrbitalBounds()) {
38869
+ this._addGravityToBounds(maxLifetime, bounds, bounds);
38870
+ }
38514
38871
  };
38515
38872
  /**
38516
38873
  * @internal
@@ -38659,7 +39016,7 @@ __decorate([
38659
39016
  }
38660
39017
  // Velocity random
38661
39018
  var velocityOverLifetime = this.velocityOverLifetime;
38662
- if (velocityOverLifetime.enabled && velocityOverLifetime.velocityX.mode === ParticleCurveMode.TwoConstants && velocityOverLifetime.velocityY.mode === ParticleCurveMode.TwoConstants && velocityOverLifetime.velocityZ.mode === ParticleCurveMode.TwoConstants) {
39019
+ if (velocityOverLifetime.enabled && velocityOverLifetime._isRandomMode()) {
38663
39020
  var rand = velocityOverLifetime._velocityRand;
38664
39021
  instanceVertices[offset + 24] = rand.random();
38665
39022
  instanceVertices[offset + 25] = rand.random();
@@ -39071,7 +39428,7 @@ __decorate([
39071
39428
  max.set(Math.max(max.x, boundsArray[offset + 3]), Math.max(max.y, boundsArray[offset + 4]), Math.max(max.z, boundsArray[offset + 5]));
39072
39429
  };
39073
39430
  _proto._calculateTransformedBounds = function _calculateTransformedBounds(maxLifetime, origin, out) {
39074
- var velMinMaxX = ParticleGenerator._tempVector20, velMinMaxY = ParticleGenerator._tempVector21, velMinMaxZ = ParticleGenerator._tempVector22, worldOffsetMin = ParticleGenerator._tempVector30, worldOffsetMax = ParticleGenerator._tempVector31, rotateMat = ParticleGenerator._tempMat;
39431
+ var velMinMaxX = ParticleGenerator._tempVector20, velMinMaxY = ParticleGenerator._tempVector21, velMinMaxZ = ParticleGenerator._tempVector22, worldOffsetMin = ParticleGenerator._tempVector30, worldOffsetMax = ParticleGenerator._tempVector31, noiseBoundsExtents = ParticleGenerator._tempVector32, rotateMat = ParticleGenerator._tempMat;
39075
39432
  worldOffsetMin.set(0, 0, 0);
39076
39433
  worldOffsetMax.set(0, 0, 0);
39077
39434
  var transform = this._renderer.entity.transform;
@@ -39114,27 +39471,89 @@ __decorate([
39114
39471
  worldOffsetMax.set(worldOffsetMax.x + forceMinMaxX.y, worldOffsetMax.y + forceMinMaxY.y, worldOffsetMax.z + forceMinMaxZ.y);
39115
39472
  }
39116
39473
  }
39117
- out.transform(rotateMat);
39118
- min.add(worldOffsetMin);
39119
- max.add(worldOffsetMax);
39120
- // Noise module impact: noise output is normalized to [-1, 1],
39121
- // max displacement = |strength_max|
39122
39474
  var noise = this.noise;
39123
- if (noise.enabled) {
39124
- var noiseMaxX, noiseMaxY, noiseMaxZ;
39125
- if (noise.separateAxes) {
39126
- noiseMaxX = Math.abs(noise.strengthX._getMax());
39127
- noiseMaxY = Math.abs(noise.strengthY._getMax());
39128
- noiseMaxZ = Math.abs(noise.strengthZ._getMax());
39129
- } else {
39130
- noiseMaxX = noiseMaxY = noiseMaxZ = Math.abs(noise.strengthX._getMax());
39475
+ this._getNoiseBoundsExtents(maxLifetime, noiseBoundsExtents);
39476
+ var needTransformFeedback = velocityOverLifetime._needTransformFeedback();
39477
+ var orbitalActive = needTransformFeedback && velocityOverLifetime._isOrbitalActive();
39478
+ if (needTransformFeedback) {
39479
+ var centerOffset = velocityOverLifetime.centerOffset;
39480
+ var radialReach = 0;
39481
+ if (velocityOverLifetime._isRadialActive()) {
39482
+ this._getExtremeValueFromZero(velocityOverLifetime.radial, velMinMaxX);
39483
+ radialReach = Math.max(Math.abs(velMinMaxX.x), Math.abs(velMinMaxX.y)) * maxLifetime;
39484
+ }
39485
+ if (orbitalActive) {
39486
+ var dx = Math.max(Math.abs(min.x - centerOffset.x), Math.abs(max.x - centerOffset.x));
39487
+ var dy = Math.max(Math.abs(min.y - centerOffset.y), Math.abs(max.y - centerOffset.y));
39488
+ var dz = Math.max(Math.abs(min.z - centerOffset.z), Math.abs(max.z - centerOffset.z));
39489
+ var worldReach = this._getRangeReach(worldOffsetMin, worldOffsetMax);
39490
+ var noiseReach = this._getVectorReach(noiseBoundsExtents);
39491
+ var gravityReach = this._getGravityBoundsReach(maxLifetime);
39492
+ var reach = Math.sqrt(dx * dx + dy * dy + dz * dz) + worldReach + noiseReach + gravityReach + radialReach;
39493
+ min.set(Math.min(min.x, centerOffset.x - reach), Math.min(min.y, centerOffset.y - reach), Math.min(min.z, centerOffset.z - reach));
39494
+ max.set(Math.max(max.x, centerOffset.x + reach), Math.max(max.y, centerOffset.y + reach), Math.max(max.z, centerOffset.z + reach));
39495
+ } else if (radialReach > 0) {
39496
+ min.set(min.x - radialReach, min.y - radialReach, min.z - radialReach);
39497
+ max.set(max.x + radialReach, max.y + radialReach, max.z + radialReach);
39498
+ }
39499
+ }
39500
+ out.transform(rotateMat);
39501
+ if (!orbitalActive) {
39502
+ min.add(worldOffsetMin);
39503
+ max.add(worldOffsetMax);
39504
+ if (noise.enabled) {
39505
+ min.set(min.x - noiseBoundsExtents.x, min.y - noiseBoundsExtents.y, min.z - noiseBoundsExtents.z);
39506
+ max.set(max.x + noiseBoundsExtents.x, max.y + noiseBoundsExtents.y, max.z + noiseBoundsExtents.z);
39131
39507
  }
39132
- min.set(min.x - noiseMaxX, min.y - noiseMaxY, min.z - noiseMaxZ);
39133
- max.set(max.x + noiseMaxX, max.y + noiseMaxY, max.z + noiseMaxZ);
39134
39508
  }
39135
39509
  min.add(worldPosition);
39136
39510
  max.add(worldPosition);
39137
39511
  };
39512
+ _proto._useOrbitalBounds = function _useOrbitalBounds() {
39513
+ var velocityOverLifetime = this.velocityOverLifetime;
39514
+ return velocityOverLifetime._needTransformFeedback() && velocityOverLifetime._isOrbitalActive();
39515
+ };
39516
+ _proto._getNoiseBoundsExtents = function _getNoiseBoundsExtents(maxLifetime, out) {
39517
+ var noise = this.noise;
39518
+ if (!noise.enabled) {
39519
+ out.set(0, 0, 0);
39520
+ return;
39521
+ }
39522
+ var noiseMaxX, noiseMaxY, noiseMaxZ;
39523
+ if (noise.separateAxes) {
39524
+ noiseMaxX = this._getCurveMagnitudeFromZero(noise.strengthX);
39525
+ noiseMaxY = this._getCurveMagnitudeFromZero(noise.strengthY);
39526
+ noiseMaxZ = this._getCurveMagnitudeFromZero(noise.strengthZ);
39527
+ } else {
39528
+ noiseMaxX = noiseMaxY = noiseMaxZ = this._getCurveMagnitudeFromZero(noise.strengthX);
39529
+ }
39530
+ out.set(noiseMaxX * maxLifetime, noiseMaxY * maxLifetime, noiseMaxZ * maxLifetime);
39531
+ };
39532
+ _proto._getGravityBoundsReach = function _getGravityBoundsReach(maxLifetime) {
39533
+ var modifierMinMax = ParticleGenerator._tempVector20;
39534
+ this._getExtremeValueFromZero(this.main.gravityModifier, modifierMinMax);
39535
+ var coefficient = 0.5 * maxLifetime * maxLifetime;
39536
+ var minGravityEffect = modifierMinMax.x * coefficient;
39537
+ var maxGravityEffect = modifierMinMax.y * coefficient;
39538
+ var _this__renderer_scene_physics_gravity = this._renderer.scene.physics.gravity, x = _this__renderer_scene_physics_gravity.x, y = _this__renderer_scene_physics_gravity.y, z = _this__renderer_scene_physics_gravity.z;
39539
+ var gravityBoundsExtents = ParticleGenerator._tempVector33;
39540
+ gravityBoundsExtents.set(Math.max(Math.abs(x * minGravityEffect), Math.abs(x * maxGravityEffect)), Math.max(Math.abs(y * minGravityEffect), Math.abs(y * maxGravityEffect)), Math.max(Math.abs(z * minGravityEffect), Math.abs(z * maxGravityEffect)));
39541
+ return this._getVectorReach(gravityBoundsExtents);
39542
+ };
39543
+ _proto._getRangeReach = function _getRangeReach(min, max) {
39544
+ var x = Math.max(Math.abs(min.x), Math.abs(max.x));
39545
+ var y = Math.max(Math.abs(min.y), Math.abs(max.y));
39546
+ var z = Math.max(Math.abs(min.z), Math.abs(max.z));
39547
+ return Math.sqrt(x * x + y * y + z * z);
39548
+ };
39549
+ _proto._getVectorReach = function _getVectorReach(value) {
39550
+ return Math.sqrt(value.x * value.x + value.y * value.y + value.z * value.z);
39551
+ };
39552
+ _proto._getCurveMagnitudeFromZero = function _getCurveMagnitudeFromZero(curve) {
39553
+ var minMax = ParticleGenerator._tempVector20;
39554
+ this._getExtremeValueFromZero(curve, minMax);
39555
+ return Math.max(Math.abs(minMax.x), Math.abs(minMax.y));
39556
+ };
39138
39557
  _proto._addGravityToBounds = function _addGravityToBounds(maxLifetime, origin, out) {
39139
39558
  var originMin = origin.min, originMax = origin.max;
39140
39559
  var modifierMinMax = ParticleGenerator._tempVector20;
@@ -39196,6 +39615,7 @@ ParticleGenerator._tempVector22 = new Vector2();
39196
39615
  ParticleGenerator._tempVector30 = new Vector3();
39197
39616
  ParticleGenerator._tempVector31 = new Vector3();
39198
39617
  ParticleGenerator._tempVector32 = new Vector3();
39618
+ ParticleGenerator._tempVector33 = new Vector3();
39199
39619
  ParticleGenerator._tempMat = new Matrix();
39200
39620
  ParticleGenerator._tempColor = new Color();
39201
39621
  ParticleGenerator._tempQuat0 = new Quaternion();
@@ -41033,7 +41453,14 @@ var cacheDir = new Vector3();
41033
41453
  * Suspend the audio context.
41034
41454
  * @returns A promise that resolves when the audio context is suspended
41035
41455
  */ AudioManager.suspend = function suspend() {
41036
- return AudioManager.getContext().suspend();
41456
+ // No context means nothing is playing: suspending is a no-op and must NOT flag a caller-suspend
41457
+ // (a ghost flag would later block foreground recovery), and don't create a cold context just to suspend
41458
+ var context = AudioManager._context;
41459
+ if (!context) {
41460
+ return Promise.resolve();
41461
+ }
41462
+ AudioManager._suspendedByCaller = true;
41463
+ return context.suspend();
41037
41464
  };
41038
41465
  /**
41039
41466
  * Resume the audio context.
@@ -41041,6 +41468,7 @@ var cacheDir = new Vector3();
41041
41468
  * @returns A promise that resolves when the audio context is resumed
41042
41469
  */ AudioManager.resume = function resume() {
41043
41470
  var _AudioManager;
41471
+ AudioManager._suspendedByCaller = false;
41044
41472
  var __resumePromise;
41045
41473
  return (__resumePromise = (_AudioManager = AudioManager)._resumePromise) != null ? __resumePromise : _AudioManager._resumePromise = AudioManager.getContext().resume().then(function() {
41046
41474
  AudioManager._needsUserGestureResume = false;
@@ -41055,7 +41483,9 @@ var cacheDir = new Vector3();
41055
41483
  if (!context) {
41056
41484
  AudioManager._context = context = new window.AudioContext();
41057
41485
  document.addEventListener("visibilitychange", AudioManager._onVisibilityChange);
41058
- // iOS Safari requires user gesture to resume AudioContext
41486
+ // iOS Safari bfcache restore fires pageshow (persisted) but NOT visibilitychange, so recover here too
41487
+ window.addEventListener("pageshow", AudioManager._onPageShow);
41488
+ // iOS Safari requires a user gesture to resume the AudioContext
41059
41489
  document.addEventListener("touchstart", AudioManager._resumeAfterInterruption, {
41060
41490
  passive: true
41061
41491
  });
@@ -41083,27 +41513,62 @@ var cacheDir = new Vector3();
41083
41513
  return AudioManager.getContext().state === "running";
41084
41514
  };
41085
41515
  AudioManager._onVisibilityChange = function _onVisibilityChange() {
41086
- if (!document.hidden && AudioManager._playingCount > 0 && !AudioManager.isAudioContextRunning()) {
41087
- // iOS WKWebView WebKit bug(Triggered in LingGuang App): AudioContext may be in a "zombie" state where
41088
- // state reports "suspended" but resume() alone won't restart audio rendering.
41089
- // Calling suspend() first forces a clean internal state reset before user gesture triggers resume.
41090
- // Related: https://bugs.webkit.org/show_bug.cgi?id=263627
41091
- AudioManager.suspend();
41092
- AudioManager._needsUserGestureResume = true;
41516
+ if (document.hidden) {
41517
+ var // Desktop/Android don't auto-suspend a running WebAudio context when backgrounded (only iOS does),
41518
+ // so suspend here to stop audio in the background; only if a context already exists (don't create one)
41519
+ _AudioManager__context;
41520
+ (_AudioManager__context = AudioManager._context) == null ? void 0 : _AudioManager__context.suspend().catch(function() {});
41521
+ } else {
41522
+ AudioManager._recoverPlaybackContext();
41523
+ }
41524
+ };
41525
+ AudioManager._recoverPlaybackContext = function _recoverPlaybackContext() {
41526
+ // Returning to foreground with a non-running context (and not a deliberate pause): iOS leaves it
41527
+ // "interrupted", which cannot be resumed directly; suspend() first transitions it to "suspended",
41528
+ // then resume() restarts the pipeline https://bugs.webkit.org/show_bug.cgi?id=263627
41529
+ // _recovering guards re-entry: a bfcache restore fires both visibilitychange and pageshow
41530
+ if (AudioManager._recovering || document.hidden || AudioManager._suspendedByCaller || AudioManager._playingCount <= 0 || AudioManager.isAudioContextRunning()) {
41531
+ return;
41532
+ }
41533
+ AudioManager._recovering = true;
41534
+ AudioManager._needsUserGestureResume = true; // fallback if the auto-resume below is rejected
41535
+ var context = AudioManager.getContext();
41536
+ context.suspend().catch(function() {});
41537
+ // 100ms empirical delay (resume too soon after suspend is unreliable on iOS); _recovering is cleared
41538
+ // on the timer rather than off a promise because iOS may never settle suspend/resume in interrupted
41539
+ setTimeout(function() {
41540
+ AudioManager._recovering = false;
41541
+ if (document.hidden || AudioManager._suspendedByCaller) {
41542
+ return;
41543
+ }
41544
+ // Go through AudioManager.resume() so _resumePromise coalesces any gesture-resume racing us during
41545
+ // the slow iOS interrupted->running transition; a bare context.resume() here wouldn't dedupe
41546
+ AudioManager.resume().catch(function() {});
41547
+ }, 100);
41548
+ };
41549
+ AudioManager._onPageShow = function _onPageShow(event) {
41550
+ // iOS Safari bfcache restore (persisted) needs recovery; a normal load has no suspended context
41551
+ if (event.persisted) {
41552
+ AudioManager._recoverPlaybackContext();
41093
41553
  }
41094
41554
  };
41095
41555
  AudioManager._resumeAfterInterruption = function _resumeAfterInterruption() {
41096
- if (AudioManager._needsUserGestureResume) {
41097
- AudioManager.resume().catch(function(e) {
41098
- console.warn("Failed to resume AudioContext:", e);
41099
- });
41556
+ // iOS Safari gesture fallback for when auto-resume is blocked.
41557
+ // _recovering: don't bypass the 100ms delay (would resume on a still-interrupted context)
41558
+ if (AudioManager._recovering || AudioManager._suspendedByCaller || !AudioManager._needsUserGestureResume) {
41559
+ return;
41100
41560
  }
41561
+ AudioManager.resume().catch(function(e) {
41562
+ console.warn("Failed to resume AudioContext:", e);
41563
+ });
41101
41564
  };
41102
41565
  return AudioManager;
41103
41566
  }();
41104
41567
  /** @internal */ AudioManager._playingCount = 0;
41105
41568
  AudioManager._resumePromise = null;
41106
41569
  AudioManager._needsUserGestureResume = false;
41570
+ AudioManager._suspendedByCaller = false;
41571
+ AudioManager._recovering = false;
41107
41572
 
41108
41573
  /**
41109
41574
  * Audio Source Component.
@@ -41113,8 +41578,6 @@ AudioManager._needsUserGestureResume = false;
41113
41578
  var _this;
41114
41579
  _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._pendingPlay = false, _this._sourceNode = null, _this._pausedTime = -1, _this._playTime = -1, _this._volume = 1, _this._lastVolume = 1, _this._playbackRate = 1, _this._loop = false;
41115
41580
  _this._onPlayEnd = _this._onPlayEnd.bind(_this);
41116
- _this._gainNode = AudioManager.getContext().createGain();
41117
- _this._gainNode.connect(AudioManager.getGainNode());
41118
41581
  return _this;
41119
41582
  }
41120
41583
  var _proto = AudioSource.prototype;
@@ -41126,6 +41589,10 @@ AudioManager._needsUserGestureResume = false;
41126
41589
  if (!((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) || this._isPlaying || this._pendingPlay) {
41127
41590
  return;
41128
41591
  }
41592
+ // Hidden page: don't start (would leak a sound) and don't pend (would replay out of sync) -> drop
41593
+ if (document.hidden) {
41594
+ return;
41595
+ }
41129
41596
  if (AudioManager.isAudioContextRunning()) {
41130
41597
  this._startPlayback();
41131
41598
  } else {
@@ -41138,8 +41605,8 @@ AudioManager._needsUserGestureResume = false;
41138
41605
  return;
41139
41606
  }
41140
41607
  _this._pendingPlay = false;
41141
- // Check if still valid to play after async resume
41142
- if (_this._destroyed || !_this.enabled || !_this._clip) {
41608
+ // Check if still valid to play after async resume (page may have been hidden meanwhile)
41609
+ if (_this._destroyed || !_this.enabled || !_this._clip || document.hidden) {
41143
41610
  return;
41144
41611
  }
41145
41612
  _this._startPlayback();
@@ -41156,10 +41623,11 @@ AudioManager._needsUserGestureResume = false;
41156
41623
  if (this._isPlaying) {
41157
41624
  this._clearSourceNode();
41158
41625
  this._isPlaying = false;
41159
- this._pausedTime = -1;
41160
- this._playTime = -1;
41161
41626
  AudioManager._playingCount--;
41162
41627
  }
41628
+ // stop() always resets to the start, including from a paused state (where _isPlaying is already false)
41629
+ this._pausedTime = -1;
41630
+ this._playTime = -1;
41163
41631
  };
41164
41632
  /**
41165
41633
  * Pauses playing the clip.
@@ -41177,7 +41645,7 @@ AudioManager._needsUserGestureResume = false;
41177
41645
  */ _proto._cloneTo = function _cloneTo(target) {
41178
41646
  var _target__clip;
41179
41647
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
41180
- target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);
41648
+ // _volume is field-cloned; its gain node is applied lazily on first play
41181
41649
  };
41182
41650
  /**
41183
41651
  * @internal
@@ -41199,6 +41667,15 @@ AudioManager._needsUserGestureResume = false;
41199
41667
  _proto._onPlayEnd = function _onPlayEnd() {
41200
41668
  this.stop();
41201
41669
  };
41670
+ _proto._ensureGainNode = function _ensureGainNode() {
41671
+ var gainNode = this._gainNode;
41672
+ if (!gainNode) {
41673
+ this._gainNode = gainNode = AudioManager.getContext().createGain();
41674
+ gainNode.connect(AudioManager.getGainNode());
41675
+ gainNode.gain.setValueAtTime(this._volume, AudioManager.getContext().currentTime);
41676
+ }
41677
+ return gainNode;
41678
+ };
41202
41679
  _proto._startPlayback = function _startPlayback() {
41203
41680
  var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
41204
41681
  this._initSourceNode(startTime);
@@ -41210,13 +41687,17 @@ AudioManager._needsUserGestureResume = false;
41210
41687
  _proto._initSourceNode = function _initSourceNode(startTime) {
41211
41688
  var context = AudioManager.getContext();
41212
41689
  var sourceNode = context.createBufferSource();
41213
- sourceNode.buffer = this._clip._getAudioSource();
41690
+ var buffer = this._clip._getAudioSource();
41691
+ sourceNode.buffer = buffer;
41214
41692
  sourceNode.playbackRate.value = this._playbackRate;
41215
41693
  sourceNode.loop = this._loop;
41216
41694
  sourceNode.onended = this._onPlayEnd;
41217
41695
  this._sourceNode = sourceNode;
41218
- sourceNode.connect(this._gainNode);
41219
- sourceNode.start(0, startTime);
41696
+ sourceNode.connect(this._ensureGainNode());
41697
+ // startTime is total elapsed time; for a looping clip wrap it into the buffer to keep the loop phase
41698
+ // (start()'s offset clamps past the end, it does not wrap)
41699
+ var offset = this._loop && buffer.duration > 0 ? startTime % buffer.duration : startTime;
41700
+ sourceNode.start(0, offset);
41220
41701
  };
41221
41702
  _proto._clearSourceNode = function _clearSourceNode() {
41222
41703
  this._sourceNode.stop();
@@ -41259,9 +41740,11 @@ AudioManager._needsUserGestureResume = false;
41259
41740
  return this._volume;
41260
41741
  },
41261
41742
  set: function set(value) {
41743
+ var // No node yet -> _ensureGainNode() applies _volume on first play
41744
+ _this__gainNode;
41262
41745
  value = Math.min(Math.max(0, value), 1.0);
41263
41746
  this._volume = value;
41264
- this._gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
41747
+ (_this__gainNode = this._gainNode) == null ? void 0 : _this__gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
41265
41748
  }
41266
41749
  },
41267
41750
  {
@@ -41373,6 +41856,7 @@ __decorate([
41373
41856
  Polyfill.registerPolyfill = function registerPolyfill() {
41374
41857
  Polyfill._registerMatchAll();
41375
41858
  Polyfill._registerAudioContext();
41859
+ Polyfill._registerOfflineAudioContext();
41376
41860
  Polyfill._registerTextMetrics();
41377
41861
  Polyfill._registerPromiseFinally();
41378
41862
  };
@@ -41437,20 +41921,32 @@ __decorate([
41437
41921
  if (!window.AudioContext && window.webkitAudioContext) {
41438
41922
  Logger.info("Polyfill window.AudioContext");
41439
41923
  window.AudioContext = window.webkitAudioContext;
41440
- var originalDecodeAudioData = AudioContext.prototype.decodeAudioData;
41441
- AudioContext.prototype.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
41442
- var _this = this;
41443
- return new Promise(function(resolve, reject) {
41444
- originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
41445
- successCallback == null ? void 0 : successCallback(buffer);
41446
- resolve(buffer);
41447
- }, function(error) {
41448
- errorCallback == null ? void 0 : errorCallback(error);
41449
- reject(error);
41450
- });
41924
+ Polyfill._promisifyDecodeAudioData(AudioContext.prototype);
41925
+ }
41926
+ };
41927
+ Polyfill._registerOfflineAudioContext = function _registerOfflineAudioContext() {
41928
+ // iOS 14.0 and earlier expose only webkitOfflineAudioContext, with callback-form decodeAudioData
41929
+ if (!window.OfflineAudioContext && window.webkitOfflineAudioContext) {
41930
+ Logger.info("Polyfill window.OfflineAudioContext");
41931
+ window.OfflineAudioContext = window.webkitOfflineAudioContext;
41932
+ Polyfill._promisifyDecodeAudioData(OfflineAudioContext.prototype);
41933
+ }
41934
+ };
41935
+ // Wrap the old callback-form decodeAudioData (on prefixed iOS contexts) into the modern Promise form
41936
+ Polyfill._promisifyDecodeAudioData = function _promisifyDecodeAudioData(proto) {
41937
+ var originalDecodeAudioData = proto.decodeAudioData;
41938
+ proto.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
41939
+ var _this = this;
41940
+ return new Promise(function(resolve, reject) {
41941
+ originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
41942
+ successCallback == null ? void 0 : successCallback(buffer);
41943
+ resolve(buffer);
41944
+ }, function(error) {
41945
+ errorCallback == null ? void 0 : errorCallback(error);
41946
+ reject(error);
41451
41947
  });
41452
- };
41453
- }
41948
+ });
41949
+ };
41454
41950
  };
41455
41951
  Polyfill._registerTextMetrics = function _registerTextMetrics() {
41456
41952
  // Based on the specific version of the engine implementation, when actualBoundingBoxLeft is not supported, width is used to represent the rendering width, and `textAlign` uses the default value `start` and direction is left to right.