@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/main.js CHANGED
@@ -3852,7 +3852,7 @@ exports.TiledSpriteAssembler = __decorate([
3852
3852
  sprite.name === name && outSprites.push(sprite);
3853
3853
  }
3854
3854
  } else {
3855
- console.warn("The name of the sprite you want to find is not exit in SpriteAtlas.");
3855
+ console.warn("There is no sprite named " + name + " in the atlas.");
3856
3856
  }
3857
3857
  return outSprites;
3858
3858
  };
@@ -6063,6 +6063,9 @@ __decorate([
6063
6063
  __decorate([
6064
6064
  ignoreClone
6065
6065
  ], Transform.prototype, "_isParentDirty", void 0);
6066
+ __decorate([
6067
+ ignoreClone
6068
+ ], Transform.prototype, "_parentTransformCache", void 0);
6066
6069
  __decorate([
6067
6070
  ignoreClone
6068
6071
  ], Transform.prototype, "_dirtyFlag", void 0);
@@ -17075,9 +17078,10 @@ var ComponentCloner = /*#__PURE__*/ function() {
17075
17078
  };
17076
17079
  /**
17077
17080
  * Get the components which match the type of the entity and it's children.
17081
+ * @remarks The components are returned in depth-first pre-order: the entity itself first, then each child's subtree in sibling order.
17078
17082
  * @param type - The component type
17079
17083
  * @param results - The components collection
17080
- * @returns The components collection which match the type
17084
+ * @returns The components collection which match the type
17081
17085
  */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
17082
17086
  results.length = 0;
17083
17087
  this._getComponentsInChildren(type, results);
@@ -17382,14 +17386,16 @@ var ComponentCloner = /*#__PURE__*/ function() {
17382
17386
  }
17383
17387
  };
17384
17388
  _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
17385
- for(var i = this._components.length - 1; i >= 0; i--){
17386
- var component = this._components[i];
17389
+ var components = this._components;
17390
+ for(var i = 0, n = components.length; i < n; i++){
17391
+ var component = components[i];
17387
17392
  if (_instanceof(component, type)) {
17388
17393
  results.push(component);
17389
17394
  }
17390
17395
  }
17391
- for(var i1 = this._children.length - 1; i1 >= 0; i1--){
17392
- this._children[i1]._getComponentsInChildren(type, results);
17396
+ var children = this._children;
17397
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
17398
+ children[i1]._getComponentsInChildren(type, results);
17393
17399
  }
17394
17400
  };
17395
17401
  _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
@@ -18613,7 +18619,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
18613
18619
  this._graphicResourcePool = Object.create(null);
18614
18620
  this._contentRestorerPool = Object.create(null);
18615
18621
  this._subAssetPromiseCallbacks = {};
18616
- this.//-----------------Editor temp solution-----------------
18622
+ this.// Virtual resource mapping
18617
18623
  /** @internal */ _objectPool = Object.create(null);
18618
18624
  this./** @internal */ _virtualPathResourceMap = Object.create(null);
18619
18625
  }
@@ -18727,21 +18733,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
18727
18733
  };
18728
18734
  /**
18729
18735
  * @internal
18730
- */ _proto._onSubAssetFail = function _onSubAssetFail(assetBaseURL, assetSubPath, value) {
18731
- var _this__subAssetPromiseCallbacks_assetBaseURL;
18732
- var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
18733
- if (subPromiseCallback) {
18734
- subPromiseCallback.reject(value);
18735
- } else {
18736
- var // Pending
18737
- _this__subAssetPromiseCallbacks, _assetBaseURL;
18738
- ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
18739
- rejectedValue: value
18740
- };
18741
- }
18742
- };
18743
- /**
18744
- * @internal
18745
18736
  */ _proto._addAsset = function _addAsset(path, asset) {
18746
18737
  this._assetPool[asset.instanceId] = path;
18747
18738
  this._assetUrlPool[path] = asset;
@@ -18821,37 +18812,39 @@ var MultiExecutor = /*#__PURE__*/ function() {
18821
18812
  this._contentRestorerPool = null;
18822
18813
  this._loadingPromises = null;
18823
18814
  };
18824
- _proto._assignDefaultOptions = function _assignDefaultOptions(assetInfo) {
18825
- var _assetInfo_type;
18826
- assetInfo.type = (_assetInfo_type = assetInfo.type) != null ? _assetInfo_type : ResourceManager._getTypeByUrl(assetInfo.url);
18815
+ _proto._resolveLoadItemOptions = function _resolveLoadItemOptions(assetInfo, virtualResourceEntry) {
18816
+ var _assetInfo;
18817
+ var _virtualResourceEntry_type, _ref;
18818
+ assetInfo.type = (_ref = (_virtualResourceEntry_type = virtualResourceEntry == null ? void 0 : virtualResourceEntry.type) != null ? _virtualResourceEntry_type : assetInfo.type) != null ? _ref : ResourceManager._getTypeByUrl(assetInfo.url);
18827
18819
  if (assetInfo.type === undefined) {
18828
18820
  throw "asset type should be specified: " + assetInfo.url;
18829
18821
  }
18822
+ var _params;
18823
+ (_params = (_assetInfo = assetInfo).params) != null ? _params : _assetInfo.params = virtualResourceEntry == null ? void 0 : virtualResourceEntry.params;
18830
18824
  var _assetInfo_retryCount;
18831
18825
  assetInfo.retryCount = (_assetInfo_retryCount = assetInfo.retryCount) != null ? _assetInfo_retryCount : this.retryCount;
18832
18826
  var _assetInfo_timeout;
18833
18827
  assetInfo.timeout = (_assetInfo_timeout = assetInfo.timeout) != null ? _assetInfo_timeout : this.timeout;
18834
18828
  var _assetInfo_retryInterval;
18835
18829
  assetInfo.retryInterval = (_assetInfo_retryInterval = assetInfo.retryInterval) != null ? _assetInfo_retryInterval : this.retryInterval;
18836
- var _assetInfo_url;
18837
- assetInfo.url = (_assetInfo_url = assetInfo.url) != null ? _assetInfo_url : assetInfo.urls.join(",");
18838
- return assetInfo;
18839
18830
  };
18840
18831
  _proto._loadSingleItem = function _loadSingleItem(itemOrURL) {
18841
18832
  var _this = this;
18842
- var item = this._assignDefaultOptions(typeof itemOrURL === "string" ? {
18833
+ var item = typeof itemOrURL === "string" ? {
18843
18834
  url: itemOrURL
18844
- } : itemOrURL);
18845
- var url = item.url;
18846
- // Not absolute and base url is set
18847
- if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
18835
+ } : itemOrURL;
18836
+ var _item_url;
18837
+ item.url = (_item_url = item.url) != null ? _item_url : item.urls.join(",");
18848
18838
  // Parse url
18849
- var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18839
+ var _this__parseURL = this._parseURL(item.url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18850
18840
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
18851
18841
  // Get remote asset base url
18852
- var remoteConfig = this._virtualPathResourceMap[assetBaseURL];
18853
- var _remoteConfig_path;
18854
- var remoteAssetBaseURL = (_remoteConfig_path = remoteConfig == null ? void 0 : remoteConfig.path) != null ? _remoteConfig_path : assetBaseURL;
18842
+ var virtualResourceEntry = this._virtualPathResourceMap[assetBaseURL];
18843
+ this._resolveLoadItemOptions(item, virtualResourceEntry);
18844
+ // Not absolute and base url is set
18845
+ item.url = !Utils.isAbsoluteUrl(assetBaseURL) && this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, assetBaseURL) : assetBaseURL;
18846
+ var _virtualResourceEntry_path;
18847
+ var remoteAssetBaseURL = (_virtualResourceEntry_path = virtualResourceEntry == null ? void 0 : virtualResourceEntry.path) != null ? _virtualResourceEntry_path : item.url;
18855
18848
  // Check cache
18856
18849
  var cacheObject = this._assetUrlPool[remoteAssetBaseURL];
18857
18850
  if (cacheObject) {
@@ -18885,25 +18878,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
18885
18878
  if (!loader) {
18886
18879
  throw "loader not found: " + item.type;
18887
18880
  }
18888
- var subpackageName = remoteConfig == null ? void 0 : remoteConfig.subpackageName;
18881
+ var subpackageName = virtualResourceEntry == null ? void 0 : virtualResourceEntry.subpackageName;
18889
18882
  // Check sub asset
18890
18883
  if (queryPath) {
18891
18884
  // Check whether load main asset
18892
- var mainPromise = loadingPromises[remoteAssetBaseURL] || this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName);
18893
- mainPromise.catch(function(e) {
18894
- _this._onSubAssetFail(remoteAssetBaseURL, queryPath, e);
18895
- });
18896
- return this._createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, queryPath);
18885
+ var mainPromise = loadingPromises[remoteAssetBaseURL] || this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName);
18886
+ return this._createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, queryPath, mainPromise);
18897
18887
  }
18898
- return this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName);
18888
+ return this._loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName);
18899
18889
  };
18900
18890
  // For adapter mini-game platform
18901
- _proto._loadSubpackageAndMainAsset = function _loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL, subpackageName) {
18902
- return this._loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL);
18891
+ _proto._loadSubpackageAndMainAsset = function _loadSubpackageAndMainAsset(loader, item, remoteAssetBaseURL, subpackageName) {
18892
+ return this._loadMainAsset(loader, item, remoteAssetBaseURL);
18903
18893
  };
18904
- _proto._loadMainAsset = function _loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL) {
18894
+ _proto._loadMainAsset = function _loadMainAsset(loader, item, remoteAssetBaseURL) {
18905
18895
  var _this = this;
18906
- item.url = assetBaseURL;
18907
18896
  var loadingPromises = this._loadingPromises;
18908
18897
  var promise = loader.load(item, this);
18909
18898
  loadingPromises[remoteAssetBaseURL] = promise;
@@ -18919,30 +18908,33 @@ var MultiExecutor = /*#__PURE__*/ function() {
18919
18908
  });
18920
18909
  return promise;
18921
18910
  };
18922
- _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, assetSubPath) {
18911
+ _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, assetSubPath, mainPromise) {
18923
18912
  var _this = this;
18924
18913
  var _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
18925
18914
  var loadingPromises = this._loadingPromises;
18926
18915
  var subPromiseCallback = (_this__subAssetPromiseCallbacks_remoteAssetBaseURL = this._subAssetPromiseCallbacks[remoteAssetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_remoteAssetBaseURL[assetSubPath];
18927
18916
  var resolvedValue = subPromiseCallback == null ? void 0 : subPromiseCallback.resolvedValue;
18928
- var rejectedValue = subPromiseCallback == null ? void 0 : subPromiseCallback.rejectedValue;
18929
- // Already resolved or rejected
18930
- if (resolvedValue || rejectedValue) {
18931
- return new AssetPromise(function(resolve, reject) {
18932
- if (resolvedValue) {
18933
- resolve(resolvedValue);
18934
- } else if (rejectedValue) {
18935
- reject(rejectedValue);
18936
- }
18937
- });
18917
+ // Already resolved
18918
+ if (resolvedValue) {
18919
+ return AssetPromise.resolve(resolvedValue);
18938
18920
  }
18939
18921
  // Pending
18940
- var promise = new AssetPromise(function(resolve, reject) {
18922
+ var promise = new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
18941
18923
  var _this__subAssetPromiseCallbacks, _remoteAssetBaseURL;
18942
18924
  ((_this__subAssetPromiseCallbacks = _this._subAssetPromiseCallbacks)[_remoteAssetBaseURL = remoteAssetBaseURL] || (_this__subAssetPromiseCallbacks[_remoteAssetBaseURL] = {}))[assetSubPath] = {
18943
18925
  resolve: resolve,
18944
18926
  reject: reject
18945
18927
  };
18928
+ // A loader may finish the main asset before its eager sub-asset notification reaches this callback.
18929
+ // Always resolve from the completed main asset as the authoritative fallback so callback cleanup cannot
18930
+ // strand a sub-asset request.
18931
+ mainPromise.onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(resource) {
18932
+ try {
18933
+ resolve(_this._getResolveResource(resource, _this._parseQueryPath(assetSubPath)));
18934
+ } catch (error) {
18935
+ reject(error);
18936
+ }
18937
+ }, reject);
18946
18938
  });
18947
18939
  loadingPromises[remoteAssetURL] = promise;
18948
18940
  promise.then(function() {
@@ -18966,7 +18958,10 @@ var MultiExecutor = /*#__PURE__*/ function() {
18966
18958
  if (paths) {
18967
18959
  for(var i = 0, n = paths.length; i < n; i++){
18968
18960
  var path = paths[i];
18969
- subResource = subResource[path];
18961
+ subResource = subResource == null ? void 0 : subResource[path];
18962
+ if (subResource === undefined) {
18963
+ throw new Error("Sub-asset path does not exist: " + paths.join("."));
18964
+ }
18970
18965
  }
18971
18966
  }
18972
18967
  return subResource;
@@ -19012,6 +19007,16 @@ var MultiExecutor = /*#__PURE__*/ function() {
19012
19007
  delete this._subAssetPromiseCallbacks[assetBaseURL];
19013
19008
  };
19014
19009
  /**
19010
+ * Register virtual asset paths and their load descriptors.
19011
+ * @remarks References inside runtime scenes and Prefabs can keep stable virtual paths while the backing URLs
19012
+ * are generated dynamically, such as object URLs created from a resource package.
19013
+ */ _proto.registerVirtualResources = function registerVirtualResources(resources) {
19014
+ var _this = this;
19015
+ resources.forEach(function(resource) {
19016
+ _this._virtualPathResourceMap[resource.virtualPath] = resource;
19017
+ });
19018
+ };
19019
+ /**
19015
19020
  * @internal
19016
19021
  * @beta Just for internal editor, not recommended for developers.
19017
19022
  */ _proto.getResourceByRef = function getResourceByRef(ref) {
@@ -19030,10 +19035,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19030
19035
  return AssetPromise.resolve(null);
19031
19036
  }
19032
19037
  var loadUrl = key ? url + "?q=" + key : url;
19038
+ // type and params omitted: resolved from the virtualPath map, the single source of truth
19033
19039
  var promise = this.load({
19034
- url: loadUrl,
19035
- type: mapped.type,
19036
- params: mapped.params
19040
+ url: loadUrl
19037
19041
  });
19038
19042
  return isClone ? promise.then(function(item) {
19039
19043
  return item.clone();
@@ -19041,18 +19045,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
19041
19045
  };
19042
19046
  /**
19043
19047
  * @internal
19044
- * @beta Just for internal editor, not recommended for developers.
19045
- */ _proto.initVirtualResources = function initVirtualResources(config) {
19046
- var _this = this;
19047
- config.forEach(function(element) {
19048
- _this._virtualPathResourceMap[element.virtualPath] = element;
19049
- if (element.dependentAssetMap) {
19050
- _this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
19051
- }
19052
- });
19053
- };
19054
- /**
19055
- * @internal
19056
19048
  */ ResourceManager._addLoader = function _addLoader(type, loader, extNames) {
19057
19049
  this._loaders[type] = loader;
19058
19050
  for(var i = 0, len = extNames.length; i < len; i++){
@@ -20440,6 +20432,13 @@ __decorate([
20440
20432
  this._phasedActiveInScene && this._nativeCollider.addForce(force);
20441
20433
  };
20442
20434
  /**
20435
+ * Apply a force to the DynamicCollider at a given position in world space.
20436
+ * @param force - The force to apply, in world space
20437
+ * @param position - The position where the force is applied, in world space
20438
+ */ _proto.applyForceAtPosition = function applyForceAtPosition(force, position) {
20439
+ this._phasedActiveInScene && this._nativeCollider.addForceAtPosition(force, position);
20440
+ };
20441
+ /**
20443
20442
  * Apply a torque to the DynamicCollider.
20444
20443
  * @param torque - The force make the collider rotate
20445
20444
  */ _proto.applyTorque = function applyTorque(torque) {
@@ -26792,6 +26791,7 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
26792
26791
  depthOnlyPass.release();
26793
26792
  camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
26794
26793
  }
26794
+ var pool = engine._renderTargetPool;
26795
26795
  // Check if need to create internal color texture or grab texture
26796
26796
  if (independentCanvasEnabled) {
26797
26797
  var depthFormat;
@@ -26807,26 +26807,12 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
26807
26807
  depthFormat = null;
26808
26808
  }
26809
26809
  var viewport = camera.pixelViewport;
26810
- var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, !camera.enableHDR, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26810
+ this._internalColorTarget = pool.allocateRenderTarget(viewport.width, viewport.height, camera._getInternalColorTextureFormat(), depthFormat, false, false, !camera.enableHDR, msaaSamples, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26811
26811
  if (this._shouldCopyBackgroundColor) {
26812
26812
  var _camera_renderTarget;
26813
26813
  var colorTexture = (_camera_renderTarget = camera.renderTarget) == null ? void 0 : _camera_renderTarget.getColorTexture(0);
26814
26814
  var _colorTexture_format, _colorTexture_isSRGBColorSpace;
26815
- 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);
26816
- this._copyBackgroundTexture = copyBackgroundTexture;
26817
- }
26818
- this._internalColorTarget = internalColorTarget;
26819
- } else {
26820
- var internalColorTarget1 = this._internalColorTarget;
26821
- var copyBackgroundTexture1 = this._copyBackgroundTexture;
26822
- var pool = engine._renderTargetPool;
26823
- if (internalColorTarget1) {
26824
- pool.freeRenderTarget(internalColorTarget1);
26825
- this._internalColorTarget = null;
26826
- }
26827
- if (copyBackgroundTexture1) {
26828
- pool.freeTexture(copyBackgroundTexture1);
26829
- this._copyBackgroundTexture = null;
26815
+ 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);
26830
26816
  }
26831
26817
  }
26832
26818
  // Scalable ambient obscurance pass
@@ -26839,6 +26825,15 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
26839
26825
  this._saoPass.release();
26840
26826
  }
26841
26827
  this._drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel);
26828
+ // Return the per-frame leases so the next camera with matching shape can reuse them
26829
+ if (this._internalColorTarget) {
26830
+ pool.freeRenderTarget(this._internalColorTarget);
26831
+ this._internalColorTarget = null;
26832
+ }
26833
+ if (this._copyBackgroundTexture) {
26834
+ pool.freeTexture(this._copyBackgroundTexture);
26835
+ this._copyBackgroundTexture = null;
26836
+ }
26842
26837
  };
26843
26838
  _proto._drawRenderPass = function _drawRenderPass(context, camera, finalClearFlags, cubeFace, mipLevel) {
26844
26839
  var cullingResults = this._cullingResults;
@@ -27172,7 +27167,9 @@ var OverlayCamera = function OverlayCamera() {
27172
27167
  _inherits(Engine, EventDispatcher);
27173
27168
  function Engine(canvas, hardwareRenderer, configuration) {
27174
27169
  var _this;
27175
- _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() {
27170
+ _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() {
27171
+ return _this._renderTargetPool.gc();
27172
+ }, _this._animate = function() {
27176
27173
  if (_this._vSyncCount) {
27177
27174
  var _this_xrManager;
27178
27175
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -27193,6 +27190,7 @@ var OverlayCamera = function OverlayCamera() {
27193
27190
  _this._textDefaultFont.isGCIgnored = true;
27194
27191
  _this._batcherManager = new BatcherManager(_this);
27195
27192
  _this._renderTargetPool = new RenderTargetPool(_this);
27193
+ canvas._sizeUpdateFlagManager.addListener(_this._onCanvasResize);
27196
27194
  _this.inputManager = new InputManager(_this, configuration.input);
27197
27195
  var xrDevice = configuration.xrDevice;
27198
27196
  if (xrDevice) {
@@ -27250,6 +27248,7 @@ var OverlayCamera = function OverlayCamera() {
27250
27248
  * Update the engine loop manually. If you call engine.run(), you generally don't need to call this function.
27251
27249
  */ _proto.update = function update() {
27252
27250
  var _this_xrManager;
27251
+ this._canvas._pumpPendingResolution();
27253
27252
  var time = this._time;
27254
27253
  time._update();
27255
27254
  var deltaTime = time.deltaTime;
@@ -27396,6 +27395,8 @@ var OverlayCamera = function OverlayCamera() {
27396
27395
  var _this_xrManager;
27397
27396
  this._destroyed = true;
27398
27397
  this._waitingDestroy = false;
27398
+ this._canvas._sizeUpdateFlagManager.removeListener(this._onCanvasResize);
27399
+ this._canvas._destroy();
27399
27400
  this._sceneManager._destroyAllScene();
27400
27401
  this._resourceManager._destroy();
27401
27402
  this.inputManager._destroy();
@@ -27692,40 +27693,57 @@ var OverlayCamera = function OverlayCamera() {
27692
27693
  /** @internal */ Engine._physicalObjectsMap = {};
27693
27694
 
27694
27695
  /**
27695
- * Canvas.
27696
+ * The canvas the engine renders to; owns the render-buffer resolution.
27696
27697
  */ var Canvas = /*#__PURE__*/ function() {
27697
27698
  function Canvas() {
27698
- /* @internal */ this._sizeUpdateFlagManager = new UpdateFlagManager();
27699
+ /**
27700
+ * @internal
27701
+ */ this._sizeUpdateFlagManager = new UpdateFlagManager();
27702
+ this._width = 0;
27703
+ this._height = 0;
27699
27704
  }
27705
+ var _proto = Canvas.prototype;
27706
+ /**
27707
+ * Lock the render buffer to an explicit resolution and stop following the display size.
27708
+ * @param width - Render buffer width in pixels
27709
+ * @param height - Render buffer height in pixels
27710
+ *
27711
+ * @throws
27712
+ * Throw an error if width or height is not a positive finite number.
27713
+ */ _proto.setResolution = function setResolution(width, height) {
27714
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
27715
+ throw new Error("Canvas.setResolution: invalid size " + width + "x" + height);
27716
+ }
27717
+ this._exitAutoResolution();
27718
+ this._setResolution(Math.round(width), Math.round(height));
27719
+ };
27720
+ _proto._setResolution = function _setResolution(width, height) {
27721
+ if (this._width !== width || this._height !== height) {
27722
+ this._width = width;
27723
+ this._height = height;
27724
+ this._onResolutionChanged(width, height);
27725
+ this._sizeUpdateFlagManager.dispatch();
27726
+ }
27727
+ };
27728
+ /**
27729
+ * @internal
27730
+ */ _proto._pumpPendingResolution = function _pumpPendingResolution() {};
27731
+ _proto._exitAutoResolution = function _exitAutoResolution() {};
27700
27732
  _create_class(Canvas, [
27701
27733
  {
27702
27734
  key: "width",
27703
27735
  get: /**
27704
- * The width of the canvas.
27736
+ * The width component of the canvas resolution, in pixels.
27705
27737
  */ function get() {
27706
27738
  return this._width;
27707
- },
27708
- set: function set(value) {
27709
- if (this._width !== value) {
27710
- this._width = value;
27711
- this._onWidthChanged(value);
27712
- this._sizeUpdateFlagManager.dispatch();
27713
- }
27714
27739
  }
27715
27740
  },
27716
27741
  {
27717
27742
  key: "height",
27718
27743
  get: /**
27719
- *The height of the canvas.
27744
+ * The height component of the canvas resolution, in pixels.
27720
27745
  */ function get() {
27721
27746
  return this._height;
27722
- },
27723
- set: function set(value) {
27724
- if (this._height !== value) {
27725
- this._height = value;
27726
- this._onHeightChange(value);
27727
- this._sizeUpdateFlagManager.dispatch();
27728
- }
27729
27747
  }
27730
27748
  }
27731
27749
  ]);
@@ -27736,11 +27754,11 @@ var OverlayCamera = function OverlayCamera() {
27736
27754
  * The manager of the components.
27737
27755
  */ var ComponentsManager = /*#__PURE__*/ function() {
27738
27756
  function ComponentsManager() {
27739
- /* @internal */ this._cameraNeedSorting = false;
27757
+ /** @internal */ this._cameraNeedSorting = false;
27740
27758
  /** @internal */ this._activeCameras = new DisorderedArray();
27741
27759
  /** @internal */ this._renderers = new DisorderedArray();
27742
27760
  /** @internal */ this._overlayCanvases = new DisorderedArray();
27743
- /* @internal */ this._overlayCanvasesSortingDirty = false;
27761
+ /** @internal */ this._overlayCanvasesSortingDirty = false;
27744
27762
  /** @internal */ this._canvases = new DisorderedArray();
27745
27763
  // Script
27746
27764
  this._onStartScripts = new DisorderedArray();
@@ -28959,7 +28977,7 @@ AmbientOcclusion._enableMacro = ShaderMacro.getByName("SCENE_ENABLE_AMBIENT_OCCL
28959
28977
  * @remarks
28960
28978
  * Darkens areas where objects are close together to simulate natural light blocking,
28961
28979
  * such as corners, crevices, and contact points between surfaces.
28962
- */ _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 engineMath.Color(0.21404114048223255, 0.21404114048223255, 0.21404114048223255, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new engineMath.Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
28980
+ */ _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 engineMath.Color(0.21404114048223255, 0.21404114048223255, 0.21404114048223255, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new engineMath.Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
28963
28981
  _this.name = name || "";
28964
28982
  var shaderData = _this.shaderData;
28965
28983
  shaderData._addReferCount(1);
@@ -29730,7 +29748,7 @@ var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
29730
29748
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29731
29749
  signalArgs[_key] = arguments[_key];
29732
29750
  }
29733
- return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
29751
+ return (_target = target)[methodName].apply(_target, [].concat(signalArgs, args));
29734
29752
  } : function() {
29735
29753
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29736
29754
  signalArgs[_key] = arguments[_key];
@@ -30164,7 +30182,7 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30164
30182
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
30165
30183
  function AnimationClipCurveBinding() {
30166
30184
  /** The index of the component that is animated. */ this.typeIndex = 0;
30167
- this._tempCurveOwner = {};
30185
+ this._tempCurveOwner = new WeakMap();
30168
30186
  }
30169
30187
  var _proto = AnimationClipCurveBinding.prototype;
30170
30188
  /**
@@ -30190,11 +30208,12 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30190
30208
  /**
30191
30209
  * @internal
30192
30210
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity, component) {
30193
- var instanceId = entity.instanceId;
30194
- if (!this._tempCurveOwner[instanceId]) {
30195
- this._tempCurveOwner[instanceId] = this._createCurveOwner(entity, component);
30211
+ var owner = this._tempCurveOwner.get(entity);
30212
+ if (!owner) {
30213
+ owner = this._createCurveOwner(entity, component);
30214
+ this._tempCurveOwner.set(entity, owner);
30196
30215
  }
30197
- return this._tempCurveOwner[instanceId];
30216
+ return owner;
30198
30217
  };
30199
30218
  return AnimationClipCurveBinding;
30200
30219
  }();
@@ -30276,11 +30295,10 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
30276
30295
  this._length = 0;
30277
30296
  };
30278
30297
  /**
30279
- * @internal
30280
30298
  * Samples an animation at a given time.
30281
30299
  * @param entity - The animated entity
30282
30300
  * @param time - The time to sample an animation
30283
- */ _proto._sampleAnimation = function _sampleAnimation(entity, time) {
30301
+ */ _proto.sampleAnimation = function sampleAnimation(entity, time) {
30284
30302
  var _this = this, curveBindings = _this._curveBindings;
30285
30303
  var components = AnimationCurveOwner._components;
30286
30304
  for(var i = curveBindings.length - 1; i >= 0; i--){
@@ -31455,12 +31473,6 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31455
31473
  return LayerState;
31456
31474
  }({});
31457
31475
 
31458
- /**
31459
- * @internal
31460
- */ var AnimationEventHandler = function AnimationEventHandler() {
31461
- this.handlers = [];
31462
- };
31463
-
31464
31476
  /**
31465
31477
  * Animation wrap mode.
31466
31478
  */ var WrapMode = /*#__PURE__*/ function(WrapMode) {
@@ -31469,6 +31481,12 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31469
31481
  return WrapMode;
31470
31482
  }({});
31471
31483
 
31484
+ /**
31485
+ * @internal
31486
+ */ var AnimationEventHandler = function AnimationEventHandler() {
31487
+ this.handlers = [];
31488
+ };
31489
+
31472
31490
  /**
31473
31491
  * @internal
31474
31492
  */ var AnimatorStatePlayData = /*#__PURE__*/ function() {
@@ -31509,19 +31527,21 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31509
31527
  this.playedTime += deltaTime;
31510
31528
  var instance = this.instance;
31511
31529
  var state = instance._state;
31530
+ var clipLength = state.clip.length;
31531
+ var clipStartTime = state.clipStartTime;
31512
31532
  var time = this.playedTime + this.offsetFrameTime;
31513
- var duration = state._getDuration();
31533
+ var duration = (state.clipEndTime - clipStartTime) * clipLength;
31514
31534
  this.playState = AnimatorStatePlayState.Playing;
31515
31535
  if (instance.wrapMode === WrapMode.Loop) {
31516
31536
  time = duration ? time % duration : 0;
31517
- } else {
31518
- if (Math.abs(time) >= duration) {
31519
- time = time < 0 ? -duration : duration;
31520
- this.playState = AnimatorStatePlayState.Finished;
31521
- }
31537
+ } else if (time >= duration || time <= -duration) {
31538
+ time = time < 0 ? -duration : duration;
31539
+ this.playState = AnimatorStatePlayState.Finished;
31540
+ }
31541
+ if (time < 0) {
31542
+ time += duration;
31522
31543
  }
31523
- time < 0 && (time += duration);
31524
- this.clipTime = time + state.clipStartTime * state.clip.length;
31544
+ this.clipTime = time + clipStartTime * clipLength;
31525
31545
  if (this._changedOrientation) {
31526
31546
  !this.isForward && this._correctTime();
31527
31547
  this._changedOrientation = false;
@@ -31534,6 +31554,26 @@ var AnimatorLayerBlendingMode = /*#__PURE__*/ function(AnimatorLayerBlendingMode
31534
31554
  this.clipTime = state.clipEndTime * state.clip.length;
31535
31555
  }
31536
31556
  };
31557
+ _create_class(AnimatorStatePlayData, [
31558
+ {
31559
+ key: "state",
31560
+ get: function get() {
31561
+ return this.instance._state;
31562
+ }
31563
+ },
31564
+ {
31565
+ key: "speed",
31566
+ get: function get() {
31567
+ return this.instance.speed;
31568
+ }
31569
+ },
31570
+ {
31571
+ key: "wrapMode",
31572
+ get: function get() {
31573
+ return this.instance.wrapMode;
31574
+ }
31575
+ }
31576
+ ]);
31537
31577
  return AnimatorStatePlayData;
31538
31578
  }();
31539
31579
 
@@ -31712,8 +31752,8 @@ function _type_of(obj) {
31712
31752
  * @internal
31713
31753
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
31714
31754
  function AnimatorLayerData() {
31715
- this.curveOwnerPool = Object.create(null);
31716
- this.animatorStateDataMap = new WeakMap();
31755
+ this.curveOwnerPool = new WeakMap();
31756
+ this.animatorStateDataMap = new Map();
31717
31757
  this.instanceMap = new WeakMap();
31718
31758
  this.srcPlayData = null;
31719
31759
  this.destPlayData = null;
@@ -31732,15 +31772,6 @@ function _type_of(obj) {
31732
31772
  }
31733
31773
  return instance;
31734
31774
  };
31735
- _proto.completeCrossFade = function completeCrossFade() {
31736
- this.srcPlayData = this.destPlayData;
31737
- this.destPlayData = null;
31738
- this.crossFadeTransition = null;
31739
- };
31740
- _proto.clearCrossFadeSlot = function clearCrossFadeSlot() {
31741
- this.destPlayData = null;
31742
- this.crossFadeTransition = null;
31743
- };
31744
31775
  _proto.resetCurrentCheckIndex = function resetCurrentCheckIndex() {
31745
31776
  this.layer.stateMachine._entryTransitionCollection.needResetCurrentCheckIndex = true;
31746
31777
  this.layer.stateMachine._anyStateTransitionCollection.needResetCurrentCheckIndex = true;
@@ -31764,7 +31795,7 @@ function _type_of(obj) {
31764
31795
  _inherits(Animator, Component);
31765
31796
  function Animator(entity) {
31766
31797
  var _this;
31767
- _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 = {
31798
+ _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 = {
31768
31799
  layerIndex: -1,
31769
31800
  state: null
31770
31801
  }, _this._controlledRenderers = new Array();
@@ -31947,16 +31978,21 @@ function _type_of(obj) {
31947
31978
  /**
31948
31979
  * @internal
31949
31980
  */ _proto._reset = function _reset() {
31950
- var _this = this, animationCurveOwners = _this._curveOwnerPool;
31951
- for(var instanceId in animationCurveOwners){
31952
- var propertyOwners = animationCurveOwners[instanceId];
31953
- for(var property in propertyOwners){
31954
- var owner = propertyOwners[property];
31955
- owner.revertDefaultValue();
31981
+ var layersData = this._animatorLayersData;
31982
+ for(var i = 0, n = layersData.length; i < n; i++){
31983
+ var layerData = layersData[i];
31984
+ if (!layerData) continue;
31985
+ for(var _iterator = _create_for_of_iterator_helper_loose(layerData.animatorStateDataMap.values()), _step; !(_step = _iterator()).done;){
31986
+ var stateData = _step.value;
31987
+ var layerOwners = stateData.curveLayerOwner;
31988
+ for(var k = 0, l = layerOwners.length; k < l; k++){
31989
+ var _layerOwners_k_curveOwner, _layerOwners_k;
31990
+ (_layerOwners_k = layerOwners[k]) == null ? void 0 : (_layerOwners_k_curveOwner = _layerOwners_k.curveOwner) == null ? void 0 : _layerOwners_k_curveOwner.revertDefaultValue();
31991
+ }
31956
31992
  }
31957
31993
  }
31958
31994
  this._animatorLayersData.length = 0;
31959
- this._curveOwnerPool = Object.create(null);
31995
+ this._curveOwnerPool = new WeakMap();
31960
31996
  this._parametersValueMap = Object.create(null);
31961
31997
  if (this._controllerUpdateFlag) {
31962
31998
  this._controllerUpdateFlag.flag = false;
@@ -31979,6 +32015,7 @@ function _type_of(obj) {
31979
32015
  };
31980
32016
  _proto._onDestroy = function _onDestroy() {
31981
32017
  Component.prototype._onDestroy.call(this);
32018
+ this._reset();
31982
32019
  var controller = this._animatorController;
31983
32020
  if (controller) {
31984
32021
  var _this__controllerUpdateFlag;
@@ -31992,7 +32029,8 @@ function _type_of(obj) {
31992
32029
  if (!state) {
31993
32030
  return;
31994
32031
  }
31995
- var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
32032
+ var animatorLayerData = this._getAnimatorLayerData(playLayerIndex);
32033
+ var manuallyTransition = animatorLayerData.manuallyTransition;
31996
32034
  manuallyTransition.duration = duration;
31997
32035
  manuallyTransition.offset = normalizedTimeOffset;
31998
32036
  manuallyTransition.isFixedDuration = isFixedDuration;
@@ -32047,20 +32085,30 @@ function _type_of(obj) {
32047
32085
  var relativePath = curve.relativePath;
32048
32086
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
32049
32087
  if (targetEntity) {
32050
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
32088
+ var _layerPropertyOwners, _property;
32051
32089
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
32052
32090
  components.length = 0;
32053
32091
  if (!component) {
32054
32092
  continue;
32055
32093
  }
32056
32094
  var property = curve.property;
32057
- var instanceId = component.instanceId;
32058
- // Get owner
32059
- var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
32060
- var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
32061
- // Get layer owner
32062
- var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
32063
- var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
32095
+ // Key owner lookup by Component identity instead of instanceId.
32096
+ var propertyOwners = curveOwnerPool.get(component);
32097
+ if (!propertyOwners) {
32098
+ propertyOwners = Object.create(null);
32099
+ curveOwnerPool.set(component, propertyOwners);
32100
+ }
32101
+ var owner = propertyOwners[property];
32102
+ if (!owner) {
32103
+ owner = curve._createCurveOwner(targetEntity, component);
32104
+ propertyOwners[property] = owner;
32105
+ }
32106
+ var layerPropertyOwners = layerCurveOwnerPool.get(component);
32107
+ if (!layerPropertyOwners) {
32108
+ layerPropertyOwners = Object.create(null);
32109
+ layerCurveOwnerPool.set(component, layerPropertyOwners);
32110
+ }
32111
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property = property] || (_layerPropertyOwners[_property] = curve._createCurveLayerOwner(owner));
32064
32112
  if (mask && mask.pathMasks.length) {
32065
32113
  var _mask_getPathMask;
32066
32114
  var _mask_getPathMask_active;
@@ -32074,8 +32122,6 @@ function _type_of(obj) {
32074
32122
  }
32075
32123
  };
32076
32124
  _proto._ensureEventHandlers = function _ensureEventHandlers(state, animatorStateData) {
32077
- // state._updateFlagManager dispatches on both clip-swap and clip-events-mutation,
32078
- // so its version covers every input that affects eventHandlers binding
32079
32125
  var stateVersion = state._updateFlagManager.version;
32080
32126
  var scriptsVersion = this._entity._scriptsVersion;
32081
32127
  if (animatorStateData.eventsBuiltVersion === stateVersion && animatorStateData.eventsBuiltScriptsVersion === scriptsVersion) {
@@ -32199,8 +32245,8 @@ function _type_of(obj) {
32199
32245
  };
32200
32246
  _proto._updatePlayingState = function _updatePlayingState(layerData, weight, additive, deltaTime, aniUpdate) {
32201
32247
  var srcPlayData = layerData.srcPlayData;
32202
- var state = srcPlayData.instance._state;
32203
- var playSpeed = srcPlayData.instance.speed * this.speed;
32248
+ var state = srcPlayData.state;
32249
+ var playSpeed = srcPlayData.speed * this.speed;
32204
32250
  var playDeltaTime = playSpeed * deltaTime;
32205
32251
  srcPlayData.updateOrientation(playDeltaTime);
32206
32252
  var lastClipTime = srcPlayData.clipTime, lastPlayState = srcPlayData.playState;
@@ -32244,14 +32290,13 @@ function _type_of(obj) {
32244
32290
  this._evaluatePlayingState(srcPlayData, weight, additive, aniUpdate);
32245
32291
  this._fireAnimationEventsAndCallScripts(layerData.layerIndex, srcPlayData, state, lastClipTime, lastPlayState, playCostTime);
32246
32292
  if (transition) {
32247
- // Remove speed factor, use actual cost time. Per-instance speed=0 means the source
32248
- // state is paused, so it consumes no time — pass deltaTime through to the destination.
32293
+ // Remove speed factor, use actual cost time
32249
32294
  var remainDeltaTime = playSpeed === 0 ? deltaTime : deltaTime - playCostTime / playSpeed;
32250
32295
  remainDeltaTime > 0 && this._updateState(layerData, remainDeltaTime, aniUpdate);
32251
32296
  }
32252
32297
  };
32253
32298
  _proto._evaluatePlayingState = function _evaluatePlayingState(playData, weight, additive, aniUpdate) {
32254
- var curveBindings = playData.instance.clip._curveBindings;
32299
+ var curveBindings = playData.state.clip._curveBindings;
32255
32300
  var finished = playData.playState === AnimatorStatePlayState.Finished;
32256
32301
  if (aniUpdate || finished) {
32257
32302
  var curveLayerOwner = playData.stateData.curveLayerOwner;
@@ -32274,14 +32319,14 @@ function _type_of(obj) {
32274
32319
  _proto._updateCrossFadeState = function _updateCrossFadeState(layerData, weight, additive, deltaTime, aniUpdate) {
32275
32320
  var srcPlayData = layerData.srcPlayData, destPlayData = layerData.destPlayData, layerIndex = layerData.layerIndex;
32276
32321
  var speed = this.speed;
32277
- var srcState = srcPlayData.instance._state;
32278
- var destState = destPlayData.instance._state;
32322
+ var srcState = srcPlayData.state;
32323
+ var destState = destPlayData.state;
32279
32324
  var transitionDuration = layerData.crossFadeTransition._getFixedDuration();
32280
32325
  if (this._tryCrossFadeInterrupt(layerData, transitionDuration, destState, deltaTime, aniUpdate)) {
32281
32326
  return;
32282
32327
  }
32283
- var srcPlaySpeed = srcPlayData.instance.speed * speed;
32284
- var dstPlaySpeed = destPlayData.instance.speed * speed;
32328
+ var srcPlaySpeed = srcPlayData.speed * speed;
32329
+ var dstPlaySpeed = destPlayData.speed * speed;
32285
32330
  var dstPlayDeltaTime = dstPlaySpeed * deltaTime;
32286
32331
  srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
32287
32332
  destPlayData.updateOrientation(dstPlayDeltaTime);
@@ -32324,8 +32369,8 @@ function _type_of(obj) {
32324
32369
  };
32325
32370
  _proto._evaluateCrossFadeState = function _evaluateCrossFadeState(layerData, srcPlayData, destPlayData, weight, crossWeight, additive, aniUpdate) {
32326
32371
  var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
32327
- var _srcPlayData_instance_clip = srcPlayData.instance.clip, srcCurves = _srcPlayData_instance_clip._curveBindings;
32328
- var destState = destPlayData.instance._state;
32372
+ var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
32373
+ var destState = destPlayData.state;
32329
32374
  var _destState_clip = destState.clip, destCurves = _destState_clip._curveBindings;
32330
32375
  var finished = destPlayData.playState === AnimatorStatePlayState.Finished;
32331
32376
  if (aniUpdate || finished) {
@@ -32344,12 +32389,12 @@ function _type_of(obj) {
32344
32389
  };
32345
32390
  _proto._updateCrossFadeFromPoseState = function _updateCrossFadeFromPoseState(layerData, weight, additive, deltaTime, aniUpdate) {
32346
32391
  var destPlayData = layerData.destPlayData;
32347
- var state = destPlayData.instance._state;
32392
+ var state = destPlayData.state;
32348
32393
  var transitionDuration = layerData.crossFadeTransition._getFixedDuration();
32349
32394
  if (this._tryCrossFadeInterrupt(layerData, transitionDuration, state, deltaTime, aniUpdate)) {
32350
32395
  return;
32351
32396
  }
32352
- var playSpeed = destPlayData.instance.speed * this.speed;
32397
+ var playSpeed = destPlayData.speed * this.speed;
32353
32398
  var playDeltaTime = playSpeed * deltaTime;
32354
32399
  destPlayData.updateOrientation(playDeltaTime);
32355
32400
  var lastDestClipTime = destPlayData.clipTime, lastPlayState = destPlayData.playState;
@@ -32386,7 +32431,7 @@ function _type_of(obj) {
32386
32431
  };
32387
32432
  _proto._evaluateCrossFadeFromPoseState = function _evaluateCrossFadeFromPoseState(layerData, destPlayData, weight, crossWeight, additive, aniUpdate) {
32388
32433
  var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
32389
- var state = destPlayData.instance._state;
32434
+ var state = destPlayData.state;
32390
32435
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
32391
32436
  var destClipTime = destPlayData.clipTime, playState = destPlayData.playState;
32392
32437
  var finished = playState === AnimatorStatePlayState.Finished;
@@ -32398,7 +32443,7 @@ function _type_of(obj) {
32398
32443
  if (!owner) continue;
32399
32444
  var curveIndex = layerOwner.crossDestCurveIndex;
32400
32445
  this._checkRevertOwner(owner, additive);
32401
- var value = layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, additive);
32446
+ var value = owner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, additive);
32402
32447
  aniUpdate && owner.applyValue(value, weight, additive);
32403
32448
  finished && layerOwner.saveFinalValue();
32404
32449
  }
@@ -32406,8 +32451,8 @@ function _type_of(obj) {
32406
32451
  };
32407
32452
  _proto._updateFinishedState = function _updateFinishedState(layerData, weight, additive, deltaTime, aniUpdate) {
32408
32453
  var playData = layerData.srcPlayData;
32409
- var state = playData.instance._state;
32410
- var actualSpeed = playData.instance.speed * this.speed;
32454
+ var state = playData.state;
32455
+ var actualSpeed = playData.speed * this.speed;
32411
32456
  var actualDeltaTime = actualSpeed * deltaTime;
32412
32457
  playData.updateOrientation(actualDeltaTime);
32413
32458
  var clipTime = playData.clipTime, isForward = playData.isForward;
@@ -32425,7 +32470,7 @@ function _type_of(obj) {
32425
32470
  return;
32426
32471
  }
32427
32472
  var curveLayerOwner = playData.stateData.curveLayerOwner;
32428
- var _playData_instance_clip = playData.instance.clip, curveBindings = _playData_instance_clip._curveBindings;
32473
+ var _playData_state_clip = playData.state.clip, curveBindings = _playData_state_clip._curveBindings;
32429
32474
  for(var i = curveBindings.length - 1; i >= 0; i--){
32430
32475
  var layerOwner = curveLayerOwner[i];
32431
32476
  var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
@@ -32441,12 +32486,14 @@ function _type_of(obj) {
32441
32486
  } else {
32442
32487
  layerData.layerState = LayerState.Playing;
32443
32488
  }
32444
- layerData.completeCrossFade();
32489
+ layerData.srcPlayData = destPlayData;
32490
+ layerData.destPlayData = null;
32491
+ layerData.crossFadeTransition = null;
32445
32492
  };
32446
32493
  _proto._preparePlayOwner = function _preparePlayOwner(layerData, playState) {
32447
32494
  if (layerData.layerState === LayerState.Playing) {
32448
32495
  var srcPlayData = layerData.srcPlayData;
32449
- if (srcPlayData.instance._state !== playState) {
32496
+ if (srcPlayData.state !== playState) {
32450
32497
  var curveLayerOwner = srcPlayData.stateData.curveLayerOwner;
32451
32498
  for(var i = curveLayerOwner.length - 1; i >= 0; i--){
32452
32499
  var _curveLayerOwner_i;
@@ -32461,17 +32508,17 @@ function _type_of(obj) {
32461
32508
  }
32462
32509
  };
32463
32510
  _proto._applyStateTransitions = function _applyStateTransitions(layerData, isForward, playData, transitionCollection, lastClipTime, clipTime, deltaTime, aniUpdate) {
32464
- var state = playData.instance._state;
32465
- var clipDuration = state.clip.length;
32511
+ var state = playData.state;
32466
32512
  var targetTransition = null;
32467
- var startTime = state.clipStartTime * clipDuration;
32468
- var endTime = state.clipEndTime * clipDuration;
32469
32513
  if (transitionCollection.noExitTimeCount) {
32470
32514
  targetTransition = this._checkNoExitTimeTransitions(layerData, transitionCollection, aniUpdate);
32471
32515
  if (targetTransition) {
32472
32516
  return targetTransition;
32473
32517
  }
32474
32518
  }
32519
+ var clipDuration = state.clip.length;
32520
+ var startTime = state.clipStartTime * clipDuration;
32521
+ var endTime = state.clipEndTime * clipDuration;
32475
32522
  if (isForward) {
32476
32523
  if (lastClipTime + deltaTime >= endTime) {
32477
32524
  targetTransition = this._checkSubTransition(layerData, state, transitionCollection, lastClipTime, endTime, aniUpdate);
@@ -32578,9 +32625,8 @@ function _type_of(obj) {
32578
32625
  var playData = animatorLayerData.getOrCreateInstance(state)._playData;
32579
32626
  playData.reset(animatorStateData, state._getClipActualEndTime() * normalizedTimeOffset);
32580
32627
  animatorLayerData.srcPlayData = playData;
32581
- // Drop any dangling cross-fade slot from a previously-interrupted crossFade
32582
- // so a later crossFade(B) isn't wrongly no-op'd by the active-dest guard.
32583
- animatorLayerData.clearCrossFadeSlot();
32628
+ animatorLayerData.destPlayData = null;
32629
+ animatorLayerData.crossFadeTransition = null;
32584
32630
  animatorLayerData.resetCurrentCheckIndex();
32585
32631
  return true;
32586
32632
  };
@@ -32664,9 +32710,7 @@ function _type_of(obj) {
32664
32710
  return false;
32665
32711
  }
32666
32712
  var animatorLayerData = this._getAnimatorLayerData(layerIndex);
32667
- // Self/active-dest cross-fade is a no-op: each state has one persistent
32668
- // instance per layer, so a second concurrent fade has nowhere to live.
32669
- 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) {
32713
+ if (((_animatorLayerData_srcPlayData = animatorLayerData.srcPlayData) == null ? void 0 : _animatorLayerData_srcPlayData.state) === crossState || ((_animatorLayerData_destPlayData = animatorLayerData.destPlayData) == null ? void 0 : _animatorLayerData_destPlayData.state) === crossState) {
32670
32714
  return false;
32671
32715
  }
32672
32716
  var animatorStateData = this._getAnimatorStateData(crossState, animatorLayerData, layerIndex);
@@ -32698,23 +32742,27 @@ function _type_of(obj) {
32698
32742
  return true;
32699
32743
  };
32700
32744
  _proto._fireAnimationEvents = function _fireAnimationEvents(playData, eventHandlers, lastClipTime, deltaTime) {
32701
- var isForward = playData.isForward, clipTime = playData.clipTime;
32702
- var state = playData.instance._state;
32745
+ var state = playData.state, isForward = playData.isForward, clipTime = playData.clipTime, wrapMode = playData.wrapMode;
32703
32746
  var startTime = state._getClipActualStartTime();
32704
32747
  var endTime = state._getClipActualEndTime();
32748
+ var canWrap = wrapMode === WrapMode.Loop;
32705
32749
  if (isForward) {
32706
32750
  if (lastClipTime + deltaTime >= endTime) {
32707
32751
  this._fireSubAnimationEvents(playData, eventHandlers, lastClipTime, endTime);
32708
- playData.currentEventIndex = 0;
32709
- this._fireSubAnimationEvents(playData, eventHandlers, startTime, clipTime);
32752
+ if (canWrap) {
32753
+ playData.currentEventIndex = 0;
32754
+ this._fireSubAnimationEvents(playData, eventHandlers, startTime, clipTime);
32755
+ }
32710
32756
  } else {
32711
32757
  this._fireSubAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
32712
32758
  }
32713
32759
  } else {
32714
32760
  if (lastClipTime + deltaTime <= startTime) {
32715
32761
  this._fireBackwardSubAnimationEvents(playData, eventHandlers, lastClipTime, startTime);
32716
- playData.currentEventIndex = eventHandlers.length - 1;
32717
- this._fireBackwardSubAnimationEvents(playData, eventHandlers, endTime, clipTime);
32762
+ if (canWrap) {
32763
+ playData.currentEventIndex = eventHandlers.length - 1;
32764
+ this._fireBackwardSubAnimationEvents(playData, eventHandlers, endTime, clipTime);
32765
+ }
32718
32766
  } else {
32719
32767
  this._fireBackwardSubAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
32720
32768
  }
@@ -32730,8 +32778,10 @@ function _type_of(obj) {
32730
32778
  }
32731
32779
  var handlers = eventHandler.handlers;
32732
32780
  if (time >= lastClipTime) {
32733
- for(var j = handlers.length - 1; j >= 0; j--){
32734
- handlers[j](parameter);
32781
+ if (this.fireEvents) {
32782
+ for(var j = handlers.length - 1; j >= 0; j--){
32783
+ handlers[j](parameter);
32784
+ }
32735
32785
  }
32736
32786
  playState.currentEventIndex = Math.min(eventIndex + 1, n - 1);
32737
32787
  }
@@ -32747,8 +32797,10 @@ function _type_of(obj) {
32747
32797
  }
32748
32798
  if (time <= lastClipTime) {
32749
32799
  var handlers = eventHandler.handlers;
32750
- for(var j = handlers.length - 1; j >= 0; j--){
32751
- handlers[j](parameter);
32800
+ if (this.fireEvents) {
32801
+ for(var j = handlers.length - 1; j >= 0; j--){
32802
+ handlers[j](parameter);
32803
+ }
32752
32804
  }
32753
32805
  playState.currentEventIndex = Math.max(eventIndex - 1, 0);
32754
32806
  }
@@ -32779,9 +32831,6 @@ function _type_of(obj) {
32779
32831
  owner.updateMark = this._updateMark;
32780
32832
  };
32781
32833
  _proto._fireAnimationEventsAndCallScripts = function _fireAnimationEventsAndCallScripts(layerIndex, playData, state, lastClipTime, lastPlayState, deltaTime) {
32782
- // Re-check whether the clip events/scripts changed since the last build —
32783
- // play()/crossFade() entry points already ensure on enter, but addEvent()
32784
- // or addComponent(Script) after play() must also flow through.
32785
32834
  this._ensureEventHandlers(state, playData.stateData);
32786
32835
  var eventHandlers = playData.stateData.eventHandlers;
32787
32836
  eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, deltaTime);
@@ -32849,6 +32898,9 @@ Animator._tempScripts = [];
32849
32898
  __decorate([
32850
32899
  assignmentClone
32851
32900
  ], Animator.prototype, "speed", void 0);
32901
+ __decorate([
32902
+ assignmentClone
32903
+ ], Animator.prototype, "fireEvents", void 0);
32852
32904
  __decorate([
32853
32905
  assignmentClone
32854
32906
  ], Animator.prototype, "_animatorController", void 0);
@@ -32920,7 +32972,10 @@ function _assert_this_initialized(self) {
32920
32972
  /** @internal */ _this._parametersMap = {},
32921
32973
  /** @internal */ _this._layers = [],
32922
32974
  /** @internal */ _this._layersMap = {},
32923
- _this._updateFlagManager = new UpdateFlagManager()
32975
+ _this._updateFlagManager = new UpdateFlagManager(),
32976
+ _this._onStatesInvalidate = function() {
32977
+ return _this._updateFlagManager.dispatch();
32978
+ }
32924
32979
  ][0];
32925
32980
  return _assert_this_initialized(_this);
32926
32981
  }
@@ -32975,6 +33030,7 @@ function _assert_this_initialized(self) {
32975
33030
  */ _proto.addLayer = function addLayer(layer) {
32976
33031
  this._layers.push(layer);
32977
33032
  this._layersMap[layer.name] = layer;
33033
+ layer._setStatesInvalidateCallback(this._onStatesInvalidate);
32978
33034
  layer._setEngine(this._engine);
32979
33035
  this._updateFlagManager.dispatch();
32980
33036
  };
@@ -32984,13 +33040,18 @@ function _assert_this_initialized(self) {
32984
33040
  */ _proto.removeLayer = function removeLayer(layerIndex) {
32985
33041
  var theLayer = this.layers[layerIndex];
32986
33042
  this._layers.splice(layerIndex, 1);
33043
+ theLayer._setStatesInvalidateCallback(null);
32987
33044
  delete this._layersMap[theLayer.name];
32988
33045
  this._updateFlagManager.dispatch();
32989
33046
  };
32990
33047
  /**
32991
33048
  * Clear layers.
32992
33049
  */ _proto.clearLayers = function clearLayers() {
32993
- this._layers.length = 0;
33050
+ var _this = this, layers = _this._layers;
33051
+ for(var i = 0, n = layers.length; i < n; i++){
33052
+ layers[i]._setStatesInvalidateCallback(null);
33053
+ }
33054
+ layers.length = 0;
32994
33055
  for(var name in this._layersMap){
32995
33056
  delete this._layersMap[name];
32996
33057
  }
@@ -33006,7 +33067,9 @@ function _assert_this_initialized(self) {
33006
33067
  */ _proto._setEngine = function _setEngine(engine) {
33007
33068
  var _this = this, layers = _this._layers;
33008
33069
  for(var i = 0, n = layers.length; i < n; i++){
33009
- layers[i]._setEngine(engine);
33070
+ var layer = layers[i];
33071
+ layer._setStatesInvalidateCallback(this._onStatesInvalidate);
33072
+ layer._setEngine(engine);
33010
33073
  }
33011
33074
  };
33012
33075
  _proto._addParameter = function _addParameter(name, defaultValue, isTrigger) {
@@ -33393,6 +33456,7 @@ function _assert_this_initialized(self) {
33393
33456
  */ var AnimatorStateMachine = /*#__PURE__*/ function() {
33394
33457
  function AnimatorStateMachine() {
33395
33458
  /** The list of states. */ this.states = [];
33459
+ this._onStatesInvalidate = null;
33396
33460
  /**
33397
33461
  * The state will be played automatically.
33398
33462
  * @remarks When the Animator's AnimatorController changed or the Animator's onEnable be triggered. Cleared to `null` if the state is removed via `removeState`.
@@ -33429,6 +33493,7 @@ function _assert_this_initialized(self) {
33429
33493
  if (this.defaultState === state) {
33430
33494
  this.defaultState = null;
33431
33495
  }
33496
+ this._onStatesInvalidate == null ? void 0 : this._onStatesInvalidate.call(this);
33432
33497
  }
33433
33498
  };
33434
33499
  /**
@@ -33488,6 +33553,11 @@ function _assert_this_initialized(self) {
33488
33553
  states[i]._setEngine(engine);
33489
33554
  }
33490
33555
  };
33556
+ /**
33557
+ * @internal
33558
+ */ _proto._setStatesInvalidateCallback = function _setStatesInvalidateCallback(onStatesInvalidate) {
33559
+ this._onStatesInvalidate = onStatesInvalidate;
33560
+ };
33491
33561
  _create_class(AnimatorStateMachine, [
33492
33562
  {
33493
33563
  key: "entryTransitions",
@@ -33516,14 +33586,43 @@ function _assert_this_initialized(self) {
33516
33586
  this.name = name;
33517
33587
  this./** The blending weight that the layers has. It is not taken into account for the first layer. */ weight = 1.0;
33518
33588
  this./** The blending mode used by the layer. It is not taken into account for the first layer. */ blendingMode = AnimatorLayerBlendingMode.Override;
33519
- this.stateMachine = new AnimatorStateMachine();
33589
+ this._onStatesInvalidate = null;
33590
+ this._stateMachine = new AnimatorStateMachine();
33520
33591
  }
33521
33592
  var _proto = AnimatorControllerLayer.prototype;
33522
33593
  /**
33523
33594
  * @internal
33524
33595
  */ _proto._setEngine = function _setEngine(engine) {
33525
- this.stateMachine._setEngine(engine);
33596
+ this._engine = engine;
33597
+ this._stateMachine._setEngine(engine);
33526
33598
  };
33599
+ /**
33600
+ * @internal
33601
+ */ _proto._setStatesInvalidateCallback = function _setStatesInvalidateCallback(onStatesInvalidate) {
33602
+ this._onStatesInvalidate = onStatesInvalidate;
33603
+ this._stateMachine._setStatesInvalidateCallback(onStatesInvalidate);
33604
+ };
33605
+ _create_class(AnimatorControllerLayer, [
33606
+ {
33607
+ key: "stateMachine",
33608
+ get: /**
33609
+ * The state machine for the layer.
33610
+ */ function get() {
33611
+ return this._stateMachine;
33612
+ },
33613
+ set: function set(value) {
33614
+ var lastStateMachine = this._stateMachine;
33615
+ if (lastStateMachine === value) {
33616
+ return;
33617
+ }
33618
+ lastStateMachine._setStatesInvalidateCallback(null);
33619
+ this._stateMachine = value;
33620
+ value._setStatesInvalidateCallback(this._onStatesInvalidate);
33621
+ this._engine && value._setEngine(this._engine);
33622
+ this._onStatesInvalidate == null ? void 0 : this._onStatesInvalidate.call(this);
33623
+ }
33624
+ }
33625
+ ]);
33527
33626
  return AnimatorControllerLayer;
33528
33627
  }();
33529
33628
 
@@ -35125,6 +35224,7 @@ __decorate([
35125
35224
  /**
35126
35225
  * @internal
35127
35226
  */ _proto._getMax = function _getMax() {
35227
+ var minMaxRange = ParticleCompositeCurve._minMaxRange;
35128
35228
  switch(this.mode){
35129
35229
  case ParticleCurveMode.Constant:
35130
35230
  return this.constantMax;
@@ -35132,17 +35232,18 @@ __decorate([
35132
35232
  return Math.max(this.constantMin, this.constantMax);
35133
35233
  case ParticleCurveMode.Curve:
35134
35234
  var _this_curveMax;
35135
- return this._getMaxKeyValue((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys);
35235
+ this._getKeyMinMax((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys, minMaxRange);
35236
+ return minMaxRange.y;
35136
35237
  case ParticleCurveMode.TwoCurves:
35137
35238
  var _this_curveMin, _this_curveMax1;
35138
- var min = this._getMaxKeyValue((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys);
35139
- var max = this._getMaxKeyValue((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys);
35140
- return min > max ? min : max;
35239
+ this._getKeyMinMax((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys, minMaxRange);
35240
+ var maxCurveMin = minMaxRange.y;
35241
+ this._getKeyMinMax((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys, minMaxRange);
35242
+ return maxCurveMin > minMaxRange.y ? maxCurveMin : minMaxRange.y;
35141
35243
  }
35142
35244
  };
35143
35245
  /**
35144
35246
  * @internal
35145
-
35146
35247
  */ _proto._getMinMax = function _getMinMax(out) {
35147
35248
  switch(this.mode){
35148
35249
  case ParticleCurveMode.Constant:
@@ -35152,23 +35253,40 @@ __decorate([
35152
35253
  out.set(Math.min(this.constantMin, this.constantMax), Math.max(this.constantMin, this.constantMax));
35153
35254
  break;
35154
35255
  case ParticleCurveMode.Curve:
35155
- var _this_curveMax, _this_curveMax1;
35156
- 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));
35256
+ var _this_curveMax;
35257
+ this._getKeyMinMax((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax.keys, out);
35157
35258
  break;
35158
35259
  case ParticleCurveMode.TwoCurves:
35159
- var _this_curveMax2, _this_curveMin, _this_curveMax3, _this_curveMin1;
35160
- var minCurveMax = this._getMinKeyValue((_this_curveMax2 = this.curveMax) == null ? void 0 : _this_curveMax2.keys);
35161
- var minCurveMin = this._getMinKeyValue((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys);
35162
- var maxCurveMax = this._getMaxKeyValue((_this_curveMax3 = this.curveMax) == null ? void 0 : _this_curveMax3.keys);
35163
- var maxCurveMin = this._getMaxKeyValue((_this_curveMin1 = this.curveMin) == null ? void 0 : _this_curveMin1.keys);
35164
- var min = minCurveMax < minCurveMin ? minCurveMax : minCurveMin;
35165
- var max = maxCurveMax > maxCurveMin ? maxCurveMax : maxCurveMin;
35166
- out.set(min, max);
35260
+ var _this_curveMin, _this_curveMax1;
35261
+ this._getKeyMinMax((_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin.keys, out);
35262
+ var minCurveMin = out.x;
35263
+ var maxCurveMin = out.y;
35264
+ this._getKeyMinMax((_this_curveMax1 = this.curveMax) == null ? void 0 : _this_curveMax1.keys, out);
35265
+ var minCurveMax = out.x;
35266
+ var maxCurveMax = out.y;
35267
+ out.set(minCurveMax < minCurveMin ? minCurveMax : minCurveMin, maxCurveMax > maxCurveMin ? maxCurveMax : maxCurveMin);
35167
35268
  break;
35168
35269
  }
35169
35270
  };
35170
35271
  /**
35171
35272
  * @internal
35273
+ */ _proto._isZero = function _isZero() {
35274
+ var minMax = ParticleCompositeCurve._minMaxRange;
35275
+ this._getMinMax(minMax);
35276
+ return minMax.x === 0 && minMax.y === 0;
35277
+ };
35278
+ /**
35279
+ * @internal
35280
+ */ _proto._isCurveMode = function _isCurveMode() {
35281
+ return this._mode === ParticleCurveMode.Curve || this._mode === ParticleCurveMode.TwoCurves;
35282
+ };
35283
+ /**
35284
+ * @internal
35285
+ */ _proto._isRandomMode = function _isRandomMode() {
35286
+ return this._mode === ParticleCurveMode.TwoConstants || this._mode === ParticleCurveMode.TwoCurves;
35287
+ };
35288
+ /**
35289
+ * @internal
35172
35290
  */ _proto._registerOnValueChanged = function _registerOnValueChanged(listener) {
35173
35291
  this._updateManager.addListener(listener);
35174
35292
  };
@@ -35177,31 +35295,20 @@ __decorate([
35177
35295
  */ _proto._unRegisterOnValueChanged = function _unRegisterOnValueChanged(listener) {
35178
35296
  this._updateManager.removeListener(listener);
35179
35297
  };
35180
- _proto._getMaxKeyValue = function _getMaxKeyValue(keys) {
35181
- var max = undefined;
35182
- var _keys_length;
35183
- var count = (_keys_length = keys == null ? void 0 : keys.length) != null ? _keys_length : 0;
35184
- if (count > 0) {
35185
- max = keys[0].value;
35186
- for(var i = 1; i < count; i++){
35187
- var value = keys[i].value;
35188
- max = Math.max(max, value);
35189
- }
35190
- }
35191
- return max;
35192
- };
35193
- _proto._getMinKeyValue = function _getMinKeyValue(keys) {
35298
+ _proto._getKeyMinMax = function _getKeyMinMax(keys, out) {
35194
35299
  var min = undefined;
35300
+ var max = undefined;
35195
35301
  var _keys_length;
35196
35302
  var count = (_keys_length = keys == null ? void 0 : keys.length) != null ? _keys_length : 0;
35197
35303
  if (count > 0) {
35198
- min = keys[0].value;
35304
+ min = max = keys[0].value;
35199
35305
  for(var i = 1; i < count; i++){
35200
35306
  var value = keys[i].value;
35201
35307
  min = Math.min(min, value);
35308
+ max = Math.max(max, value);
35202
35309
  }
35203
35310
  }
35204
- return min;
35311
+ out.set(min != null ? min : 0, max != null ? max : 0);
35205
35312
  };
35206
35313
  _proto._onCurveChange = function _onCurveChange(lastValue, value) {
35207
35314
  var dispatch = this._updateDispatch;
@@ -35307,6 +35414,7 @@ __decorate([
35307
35414
  ]);
35308
35415
  return ParticleCompositeCurve;
35309
35416
  }();
35417
+ ParticleCompositeCurve._minMaxRange = new engineMath.Vector2();
35310
35418
  __decorate([
35311
35419
  ignoreClone
35312
35420
  ], ParticleCompositeCurve.prototype, "_updateManager", void 0);
@@ -37644,10 +37752,20 @@ __decorate([
37644
37752
  _inherits(VelocityOverLifetimeModule, ParticleGeneratorModule);
37645
37753
  function VelocityOverLifetimeModule(generator) {
37646
37754
  var _this;
37647
- _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._velocityRand = new engineMath.Rand(0, ParticleRandomSubSeeds.VelocityOverLifetime), _this._velocityMinConstant = new engineMath.Vector3(), _this._velocityMaxConstant = new engineMath.Vector3(), _this._space = ParticleSimulationSpace.Local;
37755
+ _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._velocityRand = new engineMath.Rand(0, ParticleRandomSubSeeds.VelocityOverLifetime), _this._velocityMinConstant = new engineMath.Vector3(), _this._velocityMaxConstant = new engineMath.Vector3(), _this._orbitalMinConstant = new engineMath.Vector3(), _this._orbitalConstant = new engineMath.Vector3(), _this._offset = new engineMath.Vector3(), _this._space = ParticleSimulationSpace.Local, _this._onTransformFeedbackDirty = function() {
37756
+ return _this._generator._setTransformFeedback();
37757
+ };
37648
37758
  _this.velocityX = new ParticleCompositeCurve(0);
37649
37759
  _this.velocityY = new ParticleCompositeCurve(0);
37650
37760
  _this.velocityZ = new ParticleCompositeCurve(0);
37761
+ _this.orbitalX = new ParticleCompositeCurve(0);
37762
+ _this.orbitalY = new ParticleCompositeCurve(0);
37763
+ _this.orbitalZ = new ParticleCompositeCurve(0);
37764
+ _this.radial = new ParticleCompositeCurve(0);
37765
+ // @ts-ignore
37766
+ _this._offset._onValueChanged = function() {
37767
+ return _this._generator._renderer._onGeneratorParamsChanged();
37768
+ };
37651
37769
  return _this;
37652
37770
  }
37653
37771
  var _proto = VelocityOverLifetimeModule.prototype;
@@ -37656,6 +37774,10 @@ __decorate([
37656
37774
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
37657
37775
  var velocityMacro = null;
37658
37776
  var isRandomModeMacro = null;
37777
+ var orbitalMacro = null;
37778
+ var orbitalRandomModeMacro = null;
37779
+ var radialMacro = null;
37780
+ var radialRandomModeMacro = null;
37659
37781
  if (this.enabled) {
37660
37782
  var velocityX = this.velocityX;
37661
37783
  var velocityY = this.velocityY;
@@ -37685,15 +37807,111 @@ __decorate([
37685
37807
  }
37686
37808
  }
37687
37809
  shaderData.setInt(VelocityOverLifetimeModule._spaceProperty, this.space);
37810
+ var needTransformFeedback = this._needTransformFeedback();
37811
+ var orbitalActive = needTransformFeedback && this._isOrbitalActive();
37812
+ var radialActive = needTransformFeedback && this._isRadialActive();
37813
+ if (orbitalActive) {
37814
+ var orbitalX = this._orbitalX;
37815
+ var orbitalY = this._orbitalY;
37816
+ var orbitalZ = this._orbitalZ;
37817
+ var isOrbitalRandomCurveMode = orbitalX.mode === ParticleCurveMode.TwoCurves && orbitalY.mode === ParticleCurveMode.TwoCurves && orbitalZ.mode === ParticleCurveMode.TwoCurves;
37818
+ if (isOrbitalRandomCurveMode || orbitalX.mode === ParticleCurveMode.Curve && orbitalY.mode === ParticleCurveMode.Curve && orbitalZ.mode === ParticleCurveMode.Curve) {
37819
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveXProperty, orbitalX.curveMax._getTypeArray());
37820
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveYProperty, orbitalY.curveMax._getTypeArray());
37821
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMaxCurveZProperty, orbitalZ.curveMax._getTypeArray());
37822
+ orbitalMacro = VelocityOverLifetimeModule._orbitalCurveModeMacro;
37823
+ if (isOrbitalRandomCurveMode) {
37824
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveXProperty, orbitalX.curveMin._getTypeArray());
37825
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveYProperty, orbitalY.curveMin._getTypeArray());
37826
+ shaderData.setFloatArray(VelocityOverLifetimeModule._orbitalMinCurveZProperty, orbitalZ.curveMin._getTypeArray());
37827
+ orbitalRandomModeMacro = VelocityOverLifetimeModule._orbitalRandomModeMacro;
37828
+ }
37829
+ } else {
37830
+ this._orbitalConstant.set(orbitalX.constantMax, orbitalY.constantMax, orbitalZ.constantMax);
37831
+ shaderData.setVector3(VelocityOverLifetimeModule._orbitalMaxConstantProperty, this._orbitalConstant);
37832
+ orbitalMacro = VelocityOverLifetimeModule._orbitalConstantModeMacro;
37833
+ if (orbitalX.mode === ParticleCurveMode.TwoConstants && orbitalY.mode === ParticleCurveMode.TwoConstants && orbitalZ.mode === ParticleCurveMode.TwoConstants) {
37834
+ this._orbitalMinConstant.set(orbitalX.constantMin, orbitalY.constantMin, orbitalZ.constantMin);
37835
+ shaderData.setVector3(VelocityOverLifetimeModule._orbitalMinConstantProperty, this._orbitalMinConstant);
37836
+ orbitalRandomModeMacro = VelocityOverLifetimeModule._orbitalRandomModeMacro;
37837
+ }
37838
+ }
37839
+ }
37840
+ if (radialActive) {
37841
+ var radial = this._radial;
37842
+ var isRadialRandomMode = radial._isRandomMode();
37843
+ if (radial._isCurveMode()) {
37844
+ shaderData.setFloatArray(VelocityOverLifetimeModule._radialMaxCurveProperty, radial.curveMax._getTypeArray());
37845
+ radialMacro = VelocityOverLifetimeModule._radialCurveModeMacro;
37846
+ if (isRadialRandomMode) {
37847
+ shaderData.setFloatArray(VelocityOverLifetimeModule._radialMinCurveProperty, radial.curveMin._getTypeArray());
37848
+ radialRandomModeMacro = VelocityOverLifetimeModule._radialRandomModeMacro;
37849
+ }
37850
+ } else {
37851
+ shaderData.setFloat(VelocityOverLifetimeModule._radialMaxConstantProperty, radial.constantMax);
37852
+ radialMacro = VelocityOverLifetimeModule._radialConstantModeMacro;
37853
+ if (isRadialRandomMode) {
37854
+ shaderData.setFloat(VelocityOverLifetimeModule._radialMinConstantProperty, radial.constantMin);
37855
+ radialRandomModeMacro = VelocityOverLifetimeModule._radialRandomModeMacro;
37856
+ }
37857
+ }
37858
+ }
37859
+ if (orbitalActive || radialActive) {
37860
+ shaderData.setVector3(VelocityOverLifetimeModule._offsetProperty, this._offset);
37861
+ }
37688
37862
  }
37689
37863
  this._velocityMacro = this._enableMacro(shaderData, this._velocityMacro, velocityMacro);
37690
37864
  this._randomModeMacro = this._enableMacro(shaderData, this._randomModeMacro, isRandomModeMacro);
37865
+ this._orbitalMacro = this._enableMacro(shaderData, this._orbitalMacro, orbitalMacro);
37866
+ this._orbitalRandomModeMacro = this._enableMacro(shaderData, this._orbitalRandomModeMacro, orbitalRandomModeMacro);
37867
+ this._radialMacro = this._enableMacro(shaderData, this._radialMacro, radialMacro);
37868
+ this._radialRandomModeMacro = this._enableMacro(shaderData, this._radialRandomModeMacro, radialRandomModeMacro);
37691
37869
  };
37692
37870
  /**
37693
37871
  * @internal
37694
37872
  */ _proto._resetRandomSeed = function _resetRandomSeed(seed) {
37695
37873
  this._velocityRand.reset(seed, ParticleRandomSubSeeds.VelocityOverLifetime);
37696
37874
  };
37875
+ /**
37876
+ * @internal
37877
+ */ _proto._needTransformFeedback = function _needTransformFeedback() {
37878
+ if (!this._enabled || !this._generator._renderer.engine._hardwareRenderer.isWebGL2) {
37879
+ return false;
37880
+ }
37881
+ return this._isOrbitalActive() || this._isRadialActive();
37882
+ };
37883
+ /**
37884
+ * @internal
37885
+ */ _proto._isOrbitalActive = function _isOrbitalActive() {
37886
+ return !(this._orbitalX._isZero() && this._orbitalY._isZero() && this._orbitalZ._isZero());
37887
+ };
37888
+ /**
37889
+ * @internal
37890
+ */ _proto._isRadialActive = function _isRadialActive() {
37891
+ return !this._radial._isZero();
37892
+ };
37893
+ /**
37894
+ * @internal
37895
+ */ _proto._isRandomMode = function _isRandomMode() {
37896
+ var velocityX = this.velocityX;
37897
+ var velocityY = this.velocityY;
37898
+ var velocityZ = this.velocityZ;
37899
+ 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;
37900
+ if (!this._needTransformFeedback()) {
37901
+ return isLinearRandomMode;
37902
+ }
37903
+ var orbitalX = this._orbitalX;
37904
+ var orbitalY = this._orbitalY;
37905
+ var orbitalZ = this._orbitalZ;
37906
+ 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;
37907
+ return isLinearRandomMode || isOrbitalRandomMode || this._radial._isRandomMode();
37908
+ };
37909
+ _proto._onOrbitalRadialChange = function _onOrbitalRadialChange(lastValue, value) {
37910
+ this._onCompositeCurveChange(lastValue, value);
37911
+ lastValue == null ? void 0 : lastValue._unRegisterOnValueChanged(this._onTransformFeedbackDirty);
37912
+ value == null ? void 0 : value._registerOnValueChanged(this._onTransformFeedbackDirty);
37913
+ this._generator._setTransformFeedback();
37914
+ };
37697
37915
  _create_class(VelocityOverLifetimeModule, [
37698
37916
  {
37699
37917
  key: "velocityX",
@@ -37740,6 +37958,84 @@ __decorate([
37740
37958
  }
37741
37959
  }
37742
37960
  },
37961
+ {
37962
+ key: "orbitalX",
37963
+ get: /**
37964
+ * Orbital velocity (radians/second) around the x axis of the system.
37965
+ * @remarks Requires WebGL2.
37966
+ */ function get() {
37967
+ return this._orbitalX;
37968
+ },
37969
+ set: function set(value) {
37970
+ var lastValue = this._orbitalX;
37971
+ if (value !== lastValue) {
37972
+ this._orbitalX = value;
37973
+ this._onOrbitalRadialChange(lastValue, value);
37974
+ }
37975
+ }
37976
+ },
37977
+ {
37978
+ key: "orbitalY",
37979
+ get: /**
37980
+ * Orbital velocity (radians/second) around the y axis of the system.
37981
+ * @remarks Requires WebGL2.
37982
+ */ function get() {
37983
+ return this._orbitalY;
37984
+ },
37985
+ set: function set(value) {
37986
+ var lastValue = this._orbitalY;
37987
+ if (value !== lastValue) {
37988
+ this._orbitalY = value;
37989
+ this._onOrbitalRadialChange(lastValue, value);
37990
+ }
37991
+ }
37992
+ },
37993
+ {
37994
+ key: "orbitalZ",
37995
+ get: /**
37996
+ * Orbital velocity (radians/second) around the z axis of the system.
37997
+ * @remarks Requires WebGL2.
37998
+ */ function get() {
37999
+ return this._orbitalZ;
38000
+ },
38001
+ set: function set(value) {
38002
+ var lastValue = this._orbitalZ;
38003
+ if (value !== lastValue) {
38004
+ this._orbitalZ = value;
38005
+ this._onOrbitalRadialChange(lastValue, value);
38006
+ }
38007
+ }
38008
+ },
38009
+ {
38010
+ key: "radial",
38011
+ get: /**
38012
+ * Radial velocity moving particles away from (or towards) the center.
38013
+ * @remarks Requires WebGL2.
38014
+ */ function get() {
38015
+ return this._radial;
38016
+ },
38017
+ set: function set(value) {
38018
+ var lastValue = this._radial;
38019
+ if (value !== lastValue) {
38020
+ this._radial = value;
38021
+ this._onOrbitalRadialChange(lastValue, value);
38022
+ }
38023
+ }
38024
+ },
38025
+ {
38026
+ key: "centerOffset",
38027
+ get: /**
38028
+ * The center offset of orbital/radial motion from the particle system origin.
38029
+ */ function get() {
38030
+ return this._offset;
38031
+ },
38032
+ set: function set(value) {
38033
+ var offset = this._offset;
38034
+ if (value !== offset) {
38035
+ offset.copyFrom(value);
38036
+ }
38037
+ }
38038
+ },
37743
38039
  {
37744
38040
  key: "space",
37745
38041
  get: /**
@@ -37762,6 +38058,7 @@ __decorate([
37762
38058
  set: function set(value) {
37763
38059
  if (value !== this._enabled) {
37764
38060
  this._enabled = value;
38061
+ this._generator._setTransformFeedback();
37765
38062
  this._generator._renderer._onGeneratorParamsChanged();
37766
38063
  }
37767
38064
  }
@@ -37781,6 +38078,25 @@ VelocityOverLifetimeModule._maxGradientXProperty = ShaderProperty.getByName("ren
37781
38078
  VelocityOverLifetimeModule._maxGradientYProperty = ShaderProperty.getByName("renderer_VOLMaxGradientY");
37782
38079
  VelocityOverLifetimeModule._maxGradientZProperty = ShaderProperty.getByName("renderer_VOLMaxGradientZ");
37783
38080
  VelocityOverLifetimeModule._spaceProperty = ShaderProperty.getByName("renderer_VOLSpace");
38081
+ VelocityOverLifetimeModule._orbitalConstantModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_CONSTANT_MODE");
38082
+ VelocityOverLifetimeModule._orbitalCurveModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_CURVE_MODE");
38083
+ VelocityOverLifetimeModule._orbitalRandomModeMacro = ShaderMacro.getByName("RENDERER_VOL_ORBITAL_IS_RANDOM_TWO");
38084
+ VelocityOverLifetimeModule._radialConstantModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_CONSTANT_MODE");
38085
+ VelocityOverLifetimeModule._radialCurveModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_CURVE_MODE");
38086
+ VelocityOverLifetimeModule._radialRandomModeMacro = ShaderMacro.getByName("RENDERER_VOL_RADIAL_IS_RANDOM_TWO");
38087
+ VelocityOverLifetimeModule._orbitalMinConstantProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinConst");
38088
+ VelocityOverLifetimeModule._orbitalMaxConstantProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxConst");
38089
+ VelocityOverLifetimeModule._orbitalMinCurveXProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveX");
38090
+ VelocityOverLifetimeModule._orbitalMinCurveYProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveY");
38091
+ VelocityOverLifetimeModule._orbitalMinCurveZProperty = ShaderProperty.getByName("renderer_VOLOrbitalMinCurveZ");
38092
+ VelocityOverLifetimeModule._orbitalMaxCurveXProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveX");
38093
+ VelocityOverLifetimeModule._orbitalMaxCurveYProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveY");
38094
+ VelocityOverLifetimeModule._orbitalMaxCurveZProperty = ShaderProperty.getByName("renderer_VOLOrbitalMaxCurveZ");
38095
+ VelocityOverLifetimeModule._radialMinConstantProperty = ShaderProperty.getByName("renderer_VOLRadialMinConst");
38096
+ VelocityOverLifetimeModule._radialMaxConstantProperty = ShaderProperty.getByName("renderer_VOLRadialMaxConst");
38097
+ VelocityOverLifetimeModule._radialMinCurveProperty = ShaderProperty.getByName("renderer_VOLRadialMinCurve");
38098
+ VelocityOverLifetimeModule._radialMaxCurveProperty = ShaderProperty.getByName("renderer_VOLRadialMaxCurve");
38099
+ VelocityOverLifetimeModule._offsetProperty = ShaderProperty.getByName("renderer_VOLOffset");
37784
38100
  __decorate([
37785
38101
  ignoreClone
37786
38102
  ], VelocityOverLifetimeModule.prototype, "_velocityRand", void 0);
@@ -37796,6 +38112,24 @@ __decorate([
37796
38112
  __decorate([
37797
38113
  ignoreClone
37798
38114
  ], VelocityOverLifetimeModule.prototype, "_randomModeMacro", void 0);
38115
+ __decorate([
38116
+ ignoreClone
38117
+ ], VelocityOverLifetimeModule.prototype, "_orbitalMinConstant", void 0);
38118
+ __decorate([
38119
+ ignoreClone
38120
+ ], VelocityOverLifetimeModule.prototype, "_orbitalConstant", void 0);
38121
+ __decorate([
38122
+ ignoreClone
38123
+ ], VelocityOverLifetimeModule.prototype, "_orbitalMacro", void 0);
38124
+ __decorate([
38125
+ ignoreClone
38126
+ ], VelocityOverLifetimeModule.prototype, "_orbitalRandomModeMacro", void 0);
38127
+ __decorate([
38128
+ ignoreClone
38129
+ ], VelocityOverLifetimeModule.prototype, "_radialMacro", void 0);
38130
+ __decorate([
38131
+ ignoreClone
38132
+ ], VelocityOverLifetimeModule.prototype, "_radialRandomModeMacro", void 0);
37799
38133
  __decorate([
37800
38134
  deepClone
37801
38135
  ], VelocityOverLifetimeModule.prototype, "_velocityX", void 0);
@@ -37805,6 +38139,24 @@ __decorate([
37805
38139
  __decorate([
37806
38140
  deepClone
37807
38141
  ], VelocityOverLifetimeModule.prototype, "_velocityZ", void 0);
38142
+ __decorate([
38143
+ deepClone
38144
+ ], VelocityOverLifetimeModule.prototype, "_orbitalX", void 0);
38145
+ __decorate([
38146
+ deepClone
38147
+ ], VelocityOverLifetimeModule.prototype, "_orbitalY", void 0);
38148
+ __decorate([
38149
+ deepClone
38150
+ ], VelocityOverLifetimeModule.prototype, "_orbitalZ", void 0);
38151
+ __decorate([
38152
+ deepClone
38153
+ ], VelocityOverLifetimeModule.prototype, "_radial", void 0);
38154
+ __decorate([
38155
+ deepClone
38156
+ ], VelocityOverLifetimeModule.prototype, "_offset", void 0);
38157
+ __decorate([
38158
+ ignoreClone
38159
+ ], VelocityOverLifetimeModule.prototype, "_onTransformFeedbackDirty", void 0);
37808
38160
 
37809
38161
  /**
37810
38162
  * Optional parent properties a sub-emitter inherits
@@ -38405,12 +38757,10 @@ __decorate([
38405
38757
  /**
38406
38758
  * @internal
38407
38759
  */ _proto._setTransformFeedback = function _setTransformFeedback() {
38408
- var needed = this._renderer.engine._hardwareRenderer.isWebGL2 && (this.limitVelocityOverLifetime.enabled || this.noise.enabled || this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Death));
38760
+ var _this_limitVelocityOverLifetime, _this_noise, _this_velocityOverLifetime, _this_subEmitters;
38761
+ 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))));
38409
38762
  if (needed === this._useTransformFeedback) return;
38410
38763
  this._useTransformFeedback = needed;
38411
- // Switching TF mode invalidates all active particle state: feedback buffers and instance
38412
- // buffer layout are incompatible between the two paths. Clear rather than show a one-frame
38413
- // jump; new particles will fill in naturally from the next emit cycle.
38414
38764
  this._clearActiveParticles();
38415
38765
  if (needed) {
38416
38766
  if (!this._feedbackSimulator) {
@@ -38488,7 +38838,12 @@ __decorate([
38488
38838
  this._calculateTransformedBounds(maxLifetime, generatorBounds, transformedBounds);
38489
38839
  renderer._setDirtyFlagFalse(ParticleUpdateFlags.TransformVolume);
38490
38840
  }
38491
- this._addGravityToBounds(maxLifetime, transformedBounds, bounds);
38841
+ if (this._useOrbitalBounds()) {
38842
+ bounds.min.copyFrom(transformedBounds.min);
38843
+ bounds.max.copyFrom(transformedBounds.max);
38844
+ } else {
38845
+ this._addGravityToBounds(maxLifetime, transformedBounds, bounds);
38846
+ }
38492
38847
  };
38493
38848
  /**
38494
38849
  * @internal
@@ -38514,7 +38869,9 @@ __decorate([
38514
38869
  }
38515
38870
  }
38516
38871
  var maxLifetime = this.main.startLifetime._getMax();
38517
- this._addGravityToBounds(maxLifetime, bounds, bounds);
38872
+ if (!this._useOrbitalBounds()) {
38873
+ this._addGravityToBounds(maxLifetime, bounds, bounds);
38874
+ }
38518
38875
  };
38519
38876
  /**
38520
38877
  * @internal
@@ -38663,7 +39020,7 @@ __decorate([
38663
39020
  }
38664
39021
  // Velocity random
38665
39022
  var velocityOverLifetime = this.velocityOverLifetime;
38666
- if (velocityOverLifetime.enabled && velocityOverLifetime.velocityX.mode === ParticleCurveMode.TwoConstants && velocityOverLifetime.velocityY.mode === ParticleCurveMode.TwoConstants && velocityOverLifetime.velocityZ.mode === ParticleCurveMode.TwoConstants) {
39023
+ if (velocityOverLifetime.enabled && velocityOverLifetime._isRandomMode()) {
38667
39024
  var rand = velocityOverLifetime._velocityRand;
38668
39025
  instanceVertices[offset + 24] = rand.random();
38669
39026
  instanceVertices[offset + 25] = rand.random();
@@ -39075,7 +39432,7 @@ __decorate([
39075
39432
  max.set(Math.max(max.x, boundsArray[offset + 3]), Math.max(max.y, boundsArray[offset + 4]), Math.max(max.z, boundsArray[offset + 5]));
39076
39433
  };
39077
39434
  _proto._calculateTransformedBounds = function _calculateTransformedBounds(maxLifetime, origin, out) {
39078
- var velMinMaxX = ParticleGenerator._tempVector20, velMinMaxY = ParticleGenerator._tempVector21, velMinMaxZ = ParticleGenerator._tempVector22, worldOffsetMin = ParticleGenerator._tempVector30, worldOffsetMax = ParticleGenerator._tempVector31, rotateMat = ParticleGenerator._tempMat;
39435
+ var velMinMaxX = ParticleGenerator._tempVector20, velMinMaxY = ParticleGenerator._tempVector21, velMinMaxZ = ParticleGenerator._tempVector22, worldOffsetMin = ParticleGenerator._tempVector30, worldOffsetMax = ParticleGenerator._tempVector31, noiseBoundsExtents = ParticleGenerator._tempVector32, rotateMat = ParticleGenerator._tempMat;
39079
39436
  worldOffsetMin.set(0, 0, 0);
39080
39437
  worldOffsetMax.set(0, 0, 0);
39081
39438
  var transform = this._renderer.entity.transform;
@@ -39118,27 +39475,89 @@ __decorate([
39118
39475
  worldOffsetMax.set(worldOffsetMax.x + forceMinMaxX.y, worldOffsetMax.y + forceMinMaxY.y, worldOffsetMax.z + forceMinMaxZ.y);
39119
39476
  }
39120
39477
  }
39121
- out.transform(rotateMat);
39122
- min.add(worldOffsetMin);
39123
- max.add(worldOffsetMax);
39124
- // Noise module impact: noise output is normalized to [-1, 1],
39125
- // max displacement = |strength_max|
39126
39478
  var noise = this.noise;
39127
- if (noise.enabled) {
39128
- var noiseMaxX, noiseMaxY, noiseMaxZ;
39129
- if (noise.separateAxes) {
39130
- noiseMaxX = Math.abs(noise.strengthX._getMax());
39131
- noiseMaxY = Math.abs(noise.strengthY._getMax());
39132
- noiseMaxZ = Math.abs(noise.strengthZ._getMax());
39133
- } else {
39134
- noiseMaxX = noiseMaxY = noiseMaxZ = Math.abs(noise.strengthX._getMax());
39479
+ this._getNoiseBoundsExtents(maxLifetime, noiseBoundsExtents);
39480
+ var needTransformFeedback = velocityOverLifetime._needTransformFeedback();
39481
+ var orbitalActive = needTransformFeedback && velocityOverLifetime._isOrbitalActive();
39482
+ if (needTransformFeedback) {
39483
+ var centerOffset = velocityOverLifetime.centerOffset;
39484
+ var radialReach = 0;
39485
+ if (velocityOverLifetime._isRadialActive()) {
39486
+ this._getExtremeValueFromZero(velocityOverLifetime.radial, velMinMaxX);
39487
+ radialReach = Math.max(Math.abs(velMinMaxX.x), Math.abs(velMinMaxX.y)) * maxLifetime;
39488
+ }
39489
+ if (orbitalActive) {
39490
+ var dx = Math.max(Math.abs(min.x - centerOffset.x), Math.abs(max.x - centerOffset.x));
39491
+ var dy = Math.max(Math.abs(min.y - centerOffset.y), Math.abs(max.y - centerOffset.y));
39492
+ var dz = Math.max(Math.abs(min.z - centerOffset.z), Math.abs(max.z - centerOffset.z));
39493
+ var worldReach = this._getRangeReach(worldOffsetMin, worldOffsetMax);
39494
+ var noiseReach = this._getVectorReach(noiseBoundsExtents);
39495
+ var gravityReach = this._getGravityBoundsReach(maxLifetime);
39496
+ var reach = Math.sqrt(dx * dx + dy * dy + dz * dz) + worldReach + noiseReach + gravityReach + radialReach;
39497
+ min.set(Math.min(min.x, centerOffset.x - reach), Math.min(min.y, centerOffset.y - reach), Math.min(min.z, centerOffset.z - reach));
39498
+ max.set(Math.max(max.x, centerOffset.x + reach), Math.max(max.y, centerOffset.y + reach), Math.max(max.z, centerOffset.z + reach));
39499
+ } else if (radialReach > 0) {
39500
+ min.set(min.x - radialReach, min.y - radialReach, min.z - radialReach);
39501
+ max.set(max.x + radialReach, max.y + radialReach, max.z + radialReach);
39502
+ }
39503
+ }
39504
+ out.transform(rotateMat);
39505
+ if (!orbitalActive) {
39506
+ min.add(worldOffsetMin);
39507
+ max.add(worldOffsetMax);
39508
+ if (noise.enabled) {
39509
+ min.set(min.x - noiseBoundsExtents.x, min.y - noiseBoundsExtents.y, min.z - noiseBoundsExtents.z);
39510
+ max.set(max.x + noiseBoundsExtents.x, max.y + noiseBoundsExtents.y, max.z + noiseBoundsExtents.z);
39135
39511
  }
39136
- min.set(min.x - noiseMaxX, min.y - noiseMaxY, min.z - noiseMaxZ);
39137
- max.set(max.x + noiseMaxX, max.y + noiseMaxY, max.z + noiseMaxZ);
39138
39512
  }
39139
39513
  min.add(worldPosition);
39140
39514
  max.add(worldPosition);
39141
39515
  };
39516
+ _proto._useOrbitalBounds = function _useOrbitalBounds() {
39517
+ var velocityOverLifetime = this.velocityOverLifetime;
39518
+ return velocityOverLifetime._needTransformFeedback() && velocityOverLifetime._isOrbitalActive();
39519
+ };
39520
+ _proto._getNoiseBoundsExtents = function _getNoiseBoundsExtents(maxLifetime, out) {
39521
+ var noise = this.noise;
39522
+ if (!noise.enabled) {
39523
+ out.set(0, 0, 0);
39524
+ return;
39525
+ }
39526
+ var noiseMaxX, noiseMaxY, noiseMaxZ;
39527
+ if (noise.separateAxes) {
39528
+ noiseMaxX = this._getCurveMagnitudeFromZero(noise.strengthX);
39529
+ noiseMaxY = this._getCurveMagnitudeFromZero(noise.strengthY);
39530
+ noiseMaxZ = this._getCurveMagnitudeFromZero(noise.strengthZ);
39531
+ } else {
39532
+ noiseMaxX = noiseMaxY = noiseMaxZ = this._getCurveMagnitudeFromZero(noise.strengthX);
39533
+ }
39534
+ out.set(noiseMaxX * maxLifetime, noiseMaxY * maxLifetime, noiseMaxZ * maxLifetime);
39535
+ };
39536
+ _proto._getGravityBoundsReach = function _getGravityBoundsReach(maxLifetime) {
39537
+ var modifierMinMax = ParticleGenerator._tempVector20;
39538
+ this._getExtremeValueFromZero(this.main.gravityModifier, modifierMinMax);
39539
+ var coefficient = 0.5 * maxLifetime * maxLifetime;
39540
+ var minGravityEffect = modifierMinMax.x * coefficient;
39541
+ var maxGravityEffect = modifierMinMax.y * coefficient;
39542
+ 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;
39543
+ var gravityBoundsExtents = ParticleGenerator._tempVector33;
39544
+ 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)));
39545
+ return this._getVectorReach(gravityBoundsExtents);
39546
+ };
39547
+ _proto._getRangeReach = function _getRangeReach(min, max) {
39548
+ var x = Math.max(Math.abs(min.x), Math.abs(max.x));
39549
+ var y = Math.max(Math.abs(min.y), Math.abs(max.y));
39550
+ var z = Math.max(Math.abs(min.z), Math.abs(max.z));
39551
+ return Math.sqrt(x * x + y * y + z * z);
39552
+ };
39553
+ _proto._getVectorReach = function _getVectorReach(value) {
39554
+ return Math.sqrt(value.x * value.x + value.y * value.y + value.z * value.z);
39555
+ };
39556
+ _proto._getCurveMagnitudeFromZero = function _getCurveMagnitudeFromZero(curve) {
39557
+ var minMax = ParticleGenerator._tempVector20;
39558
+ this._getExtremeValueFromZero(curve, minMax);
39559
+ return Math.max(Math.abs(minMax.x), Math.abs(minMax.y));
39560
+ };
39142
39561
  _proto._addGravityToBounds = function _addGravityToBounds(maxLifetime, origin, out) {
39143
39562
  var originMin = origin.min, originMax = origin.max;
39144
39563
  var modifierMinMax = ParticleGenerator._tempVector20;
@@ -39200,6 +39619,7 @@ ParticleGenerator._tempVector22 = new engineMath.Vector2();
39200
39619
  ParticleGenerator._tempVector30 = new engineMath.Vector3();
39201
39620
  ParticleGenerator._tempVector31 = new engineMath.Vector3();
39202
39621
  ParticleGenerator._tempVector32 = new engineMath.Vector3();
39622
+ ParticleGenerator._tempVector33 = new engineMath.Vector3();
39203
39623
  ParticleGenerator._tempMat = new engineMath.Matrix();
39204
39624
  ParticleGenerator._tempColor = new engineMath.Color();
39205
39625
  ParticleGenerator._tempQuat0 = new engineMath.Quaternion();
@@ -41037,7 +41457,14 @@ var cacheDir = new engineMath.Vector3();
41037
41457
  * Suspend the audio context.
41038
41458
  * @returns A promise that resolves when the audio context is suspended
41039
41459
  */ AudioManager.suspend = function suspend() {
41040
- return AudioManager.getContext().suspend();
41460
+ // No context means nothing is playing: suspending is a no-op and must NOT flag a caller-suspend
41461
+ // (a ghost flag would later block foreground recovery), and don't create a cold context just to suspend
41462
+ var context = AudioManager._context;
41463
+ if (!context) {
41464
+ return Promise.resolve();
41465
+ }
41466
+ AudioManager._suspendedByCaller = true;
41467
+ return context.suspend();
41041
41468
  };
41042
41469
  /**
41043
41470
  * Resume the audio context.
@@ -41045,6 +41472,7 @@ var cacheDir = new engineMath.Vector3();
41045
41472
  * @returns A promise that resolves when the audio context is resumed
41046
41473
  */ AudioManager.resume = function resume() {
41047
41474
  var _AudioManager;
41475
+ AudioManager._suspendedByCaller = false;
41048
41476
  var __resumePromise;
41049
41477
  return (__resumePromise = (_AudioManager = AudioManager)._resumePromise) != null ? __resumePromise : _AudioManager._resumePromise = AudioManager.getContext().resume().then(function() {
41050
41478
  AudioManager._needsUserGestureResume = false;
@@ -41059,7 +41487,9 @@ var cacheDir = new engineMath.Vector3();
41059
41487
  if (!context) {
41060
41488
  AudioManager._context = context = new window.AudioContext();
41061
41489
  document.addEventListener("visibilitychange", AudioManager._onVisibilityChange);
41062
- // iOS Safari requires user gesture to resume AudioContext
41490
+ // iOS Safari bfcache restore fires pageshow (persisted) but NOT visibilitychange, so recover here too
41491
+ window.addEventListener("pageshow", AudioManager._onPageShow);
41492
+ // iOS Safari requires a user gesture to resume the AudioContext
41063
41493
  document.addEventListener("touchstart", AudioManager._resumeAfterInterruption, {
41064
41494
  passive: true
41065
41495
  });
@@ -41087,27 +41517,62 @@ var cacheDir = new engineMath.Vector3();
41087
41517
  return AudioManager.getContext().state === "running";
41088
41518
  };
41089
41519
  AudioManager._onVisibilityChange = function _onVisibilityChange() {
41090
- if (!document.hidden && AudioManager._playingCount > 0 && !AudioManager.isAudioContextRunning()) {
41091
- // iOS WKWebView WebKit bug(Triggered in LingGuang App): AudioContext may be in a "zombie" state where
41092
- // state reports "suspended" but resume() alone won't restart audio rendering.
41093
- // Calling suspend() first forces a clean internal state reset before user gesture triggers resume.
41094
- // Related: https://bugs.webkit.org/show_bug.cgi?id=263627
41095
- AudioManager.suspend();
41096
- AudioManager._needsUserGestureResume = true;
41520
+ if (document.hidden) {
41521
+ var // Desktop/Android don't auto-suspend a running WebAudio context when backgrounded (only iOS does),
41522
+ // so suspend here to stop audio in the background; only if a context already exists (don't create one)
41523
+ _AudioManager__context;
41524
+ (_AudioManager__context = AudioManager._context) == null ? void 0 : _AudioManager__context.suspend().catch(function() {});
41525
+ } else {
41526
+ AudioManager._recoverPlaybackContext();
41527
+ }
41528
+ };
41529
+ AudioManager._recoverPlaybackContext = function _recoverPlaybackContext() {
41530
+ // Returning to foreground with a non-running context (and not a deliberate pause): iOS leaves it
41531
+ // "interrupted", which cannot be resumed directly; suspend() first transitions it to "suspended",
41532
+ // then resume() restarts the pipeline https://bugs.webkit.org/show_bug.cgi?id=263627
41533
+ // _recovering guards re-entry: a bfcache restore fires both visibilitychange and pageshow
41534
+ if (AudioManager._recovering || document.hidden || AudioManager._suspendedByCaller || AudioManager._playingCount <= 0 || AudioManager.isAudioContextRunning()) {
41535
+ return;
41536
+ }
41537
+ AudioManager._recovering = true;
41538
+ AudioManager._needsUserGestureResume = true; // fallback if the auto-resume below is rejected
41539
+ var context = AudioManager.getContext();
41540
+ context.suspend().catch(function() {});
41541
+ // 100ms empirical delay (resume too soon after suspend is unreliable on iOS); _recovering is cleared
41542
+ // on the timer rather than off a promise because iOS may never settle suspend/resume in interrupted
41543
+ setTimeout(function() {
41544
+ AudioManager._recovering = false;
41545
+ if (document.hidden || AudioManager._suspendedByCaller) {
41546
+ return;
41547
+ }
41548
+ // Go through AudioManager.resume() so _resumePromise coalesces any gesture-resume racing us during
41549
+ // the slow iOS interrupted->running transition; a bare context.resume() here wouldn't dedupe
41550
+ AudioManager.resume().catch(function() {});
41551
+ }, 100);
41552
+ };
41553
+ AudioManager._onPageShow = function _onPageShow(event) {
41554
+ // iOS Safari bfcache restore (persisted) needs recovery; a normal load has no suspended context
41555
+ if (event.persisted) {
41556
+ AudioManager._recoverPlaybackContext();
41097
41557
  }
41098
41558
  };
41099
41559
  AudioManager._resumeAfterInterruption = function _resumeAfterInterruption() {
41100
- if (AudioManager._needsUserGestureResume) {
41101
- AudioManager.resume().catch(function(e) {
41102
- console.warn("Failed to resume AudioContext:", e);
41103
- });
41560
+ // iOS Safari gesture fallback for when auto-resume is blocked.
41561
+ // _recovering: don't bypass the 100ms delay (would resume on a still-interrupted context)
41562
+ if (AudioManager._recovering || AudioManager._suspendedByCaller || !AudioManager._needsUserGestureResume) {
41563
+ return;
41104
41564
  }
41565
+ AudioManager.resume().catch(function(e) {
41566
+ console.warn("Failed to resume AudioContext:", e);
41567
+ });
41105
41568
  };
41106
41569
  return AudioManager;
41107
41570
  }();
41108
41571
  /** @internal */ AudioManager._playingCount = 0;
41109
41572
  AudioManager._resumePromise = null;
41110
41573
  AudioManager._needsUserGestureResume = false;
41574
+ AudioManager._suspendedByCaller = false;
41575
+ AudioManager._recovering = false;
41111
41576
 
41112
41577
  /**
41113
41578
  * Audio Source Component.
@@ -41117,8 +41582,6 @@ AudioManager._needsUserGestureResume = false;
41117
41582
  var _this;
41118
41583
  _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;
41119
41584
  _this._onPlayEnd = _this._onPlayEnd.bind(_this);
41120
- _this._gainNode = AudioManager.getContext().createGain();
41121
- _this._gainNode.connect(AudioManager.getGainNode());
41122
41585
  return _this;
41123
41586
  }
41124
41587
  var _proto = AudioSource.prototype;
@@ -41130,6 +41593,10 @@ AudioManager._needsUserGestureResume = false;
41130
41593
  if (!((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) || this._isPlaying || this._pendingPlay) {
41131
41594
  return;
41132
41595
  }
41596
+ // Hidden page: don't start (would leak a sound) and don't pend (would replay out of sync) -> drop
41597
+ if (document.hidden) {
41598
+ return;
41599
+ }
41133
41600
  if (AudioManager.isAudioContextRunning()) {
41134
41601
  this._startPlayback();
41135
41602
  } else {
@@ -41142,8 +41609,8 @@ AudioManager._needsUserGestureResume = false;
41142
41609
  return;
41143
41610
  }
41144
41611
  _this._pendingPlay = false;
41145
- // Check if still valid to play after async resume
41146
- if (_this._destroyed || !_this.enabled || !_this._clip) {
41612
+ // Check if still valid to play after async resume (page may have been hidden meanwhile)
41613
+ if (_this._destroyed || !_this.enabled || !_this._clip || document.hidden) {
41147
41614
  return;
41148
41615
  }
41149
41616
  _this._startPlayback();
@@ -41160,10 +41627,11 @@ AudioManager._needsUserGestureResume = false;
41160
41627
  if (this._isPlaying) {
41161
41628
  this._clearSourceNode();
41162
41629
  this._isPlaying = false;
41163
- this._pausedTime = -1;
41164
- this._playTime = -1;
41165
41630
  AudioManager._playingCount--;
41166
41631
  }
41632
+ // stop() always resets to the start, including from a paused state (where _isPlaying is already false)
41633
+ this._pausedTime = -1;
41634
+ this._playTime = -1;
41167
41635
  };
41168
41636
  /**
41169
41637
  * Pauses playing the clip.
@@ -41181,7 +41649,7 @@ AudioManager._needsUserGestureResume = false;
41181
41649
  */ _proto._cloneTo = function _cloneTo(target) {
41182
41650
  var _target__clip;
41183
41651
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
41184
- target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);
41652
+ // _volume is field-cloned; its gain node is applied lazily on first play
41185
41653
  };
41186
41654
  /**
41187
41655
  * @internal
@@ -41203,6 +41671,15 @@ AudioManager._needsUserGestureResume = false;
41203
41671
  _proto._onPlayEnd = function _onPlayEnd() {
41204
41672
  this.stop();
41205
41673
  };
41674
+ _proto._ensureGainNode = function _ensureGainNode() {
41675
+ var gainNode = this._gainNode;
41676
+ if (!gainNode) {
41677
+ this._gainNode = gainNode = AudioManager.getContext().createGain();
41678
+ gainNode.connect(AudioManager.getGainNode());
41679
+ gainNode.gain.setValueAtTime(this._volume, AudioManager.getContext().currentTime);
41680
+ }
41681
+ return gainNode;
41682
+ };
41206
41683
  _proto._startPlayback = function _startPlayback() {
41207
41684
  var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
41208
41685
  this._initSourceNode(startTime);
@@ -41214,13 +41691,17 @@ AudioManager._needsUserGestureResume = false;
41214
41691
  _proto._initSourceNode = function _initSourceNode(startTime) {
41215
41692
  var context = AudioManager.getContext();
41216
41693
  var sourceNode = context.createBufferSource();
41217
- sourceNode.buffer = this._clip._getAudioSource();
41694
+ var buffer = this._clip._getAudioSource();
41695
+ sourceNode.buffer = buffer;
41218
41696
  sourceNode.playbackRate.value = this._playbackRate;
41219
41697
  sourceNode.loop = this._loop;
41220
41698
  sourceNode.onended = this._onPlayEnd;
41221
41699
  this._sourceNode = sourceNode;
41222
- sourceNode.connect(this._gainNode);
41223
- sourceNode.start(0, startTime);
41700
+ sourceNode.connect(this._ensureGainNode());
41701
+ // startTime is total elapsed time; for a looping clip wrap it into the buffer to keep the loop phase
41702
+ // (start()'s offset clamps past the end, it does not wrap)
41703
+ var offset = this._loop && buffer.duration > 0 ? startTime % buffer.duration : startTime;
41704
+ sourceNode.start(0, offset);
41224
41705
  };
41225
41706
  _proto._clearSourceNode = function _clearSourceNode() {
41226
41707
  this._sourceNode.stop();
@@ -41263,9 +41744,11 @@ AudioManager._needsUserGestureResume = false;
41263
41744
  return this._volume;
41264
41745
  },
41265
41746
  set: function set(value) {
41747
+ var // No node yet -> _ensureGainNode() applies _volume on first play
41748
+ _this__gainNode;
41266
41749
  value = Math.min(Math.max(0, value), 1.0);
41267
41750
  this._volume = value;
41268
- this._gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
41751
+ (_this__gainNode = this._gainNode) == null ? void 0 : _this__gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
41269
41752
  }
41270
41753
  },
41271
41754
  {
@@ -41377,6 +41860,7 @@ __decorate([
41377
41860
  Polyfill.registerPolyfill = function registerPolyfill() {
41378
41861
  Polyfill._registerMatchAll();
41379
41862
  Polyfill._registerAudioContext();
41863
+ Polyfill._registerOfflineAudioContext();
41380
41864
  Polyfill._registerTextMetrics();
41381
41865
  Polyfill._registerPromiseFinally();
41382
41866
  };
@@ -41441,20 +41925,32 @@ __decorate([
41441
41925
  if (!window.AudioContext && window.webkitAudioContext) {
41442
41926
  Logger.info("Polyfill window.AudioContext");
41443
41927
  window.AudioContext = window.webkitAudioContext;
41444
- var originalDecodeAudioData = AudioContext.prototype.decodeAudioData;
41445
- AudioContext.prototype.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
41446
- var _this = this;
41447
- return new Promise(function(resolve, reject) {
41448
- originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
41449
- successCallback == null ? void 0 : successCallback(buffer);
41450
- resolve(buffer);
41451
- }, function(error) {
41452
- errorCallback == null ? void 0 : errorCallback(error);
41453
- reject(error);
41454
- });
41928
+ Polyfill._promisifyDecodeAudioData(AudioContext.prototype);
41929
+ }
41930
+ };
41931
+ Polyfill._registerOfflineAudioContext = function _registerOfflineAudioContext() {
41932
+ // iOS 14.0 and earlier expose only webkitOfflineAudioContext, with callback-form decodeAudioData
41933
+ if (!window.OfflineAudioContext && window.webkitOfflineAudioContext) {
41934
+ Logger.info("Polyfill window.OfflineAudioContext");
41935
+ window.OfflineAudioContext = window.webkitOfflineAudioContext;
41936
+ Polyfill._promisifyDecodeAudioData(OfflineAudioContext.prototype);
41937
+ }
41938
+ };
41939
+ // Wrap the old callback-form decodeAudioData (on prefixed iOS contexts) into the modern Promise form
41940
+ Polyfill._promisifyDecodeAudioData = function _promisifyDecodeAudioData(proto) {
41941
+ var originalDecodeAudioData = proto.decodeAudioData;
41942
+ proto.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
41943
+ var _this = this;
41944
+ return new Promise(function(resolve, reject) {
41945
+ originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
41946
+ successCallback == null ? void 0 : successCallback(buffer);
41947
+ resolve(buffer);
41948
+ }, function(error) {
41949
+ errorCallback == null ? void 0 : errorCallback(error);
41950
+ reject(error);
41455
41951
  });
41456
- };
41457
- }
41952
+ });
41953
+ };
41458
41954
  };
41459
41955
  Polyfill._registerTextMetrics = function _registerTextMetrics() {
41460
41956
  // 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.