@galacean/engine-core 1.0.0-beta.11 → 1.0.0-beta.13

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
@@ -798,6 +798,14 @@ __decorate([
798
798
  TextureFormat[TextureFormat[/** 32-bit depth + 8-bit stencil format. */ "Depth32Stencil8"] = 31] = "Depth32Stencil8";
799
799
  })(exports.TextureFormat || (exports.TextureFormat = {}));
800
800
 
801
+ /**
802
+ * Texture usage.
803
+ */ exports.TextureUsage = void 0;
804
+ (function(TextureUsage) {
805
+ TextureUsage[TextureUsage[/** The content of the texture is intended to be specified once. */ "Static"] = 0] = "Static";
806
+ TextureUsage[TextureUsage[/** The content of the texture is intended to be updated frequently, with better performance. */ "Dynamic"] = 1] = "Dynamic";
807
+ })(exports.TextureUsage || (exports.TextureUsage = {}));
808
+
801
809
  /**
802
810
  * Wrapping mode of the texture.
803
811
  */ exports.TextureWrapMode = void 0;
@@ -938,6 +946,14 @@ var Logger = {
938
946
  return this._height;
939
947
  }
940
948
  },
949
+ {
950
+ key: "usage",
951
+ get: /**
952
+ * The usage of the texture.
953
+ */ function get() {
954
+ return this._usage;
955
+ }
956
+ },
941
957
  {
942
958
  key: "wrapModeU",
943
959
  get: /**
@@ -1181,14 +1197,16 @@ var Logger = {
1181
1197
  * Two-dimensional texture.
1182
1198
  */ var Texture2D = /*#__PURE__*/ function(Texture) {
1183
1199
  _inherits(Texture2D, Texture);
1184
- function Texture2D(engine, width, height, format, mipmap) {
1200
+ function Texture2D(engine, width, height, format, mipmap, usage) {
1185
1201
  if (format === void 0) format = exports.TextureFormat.R8G8B8A8;
1186
1202
  if (mipmap === void 0) mipmap = true;
1203
+ if (usage === void 0) usage = exports.TextureUsage.Static;
1187
1204
  var _this;
1188
1205
  _this = Texture.call(this, engine) || this;
1189
1206
  _this._mipmap = mipmap;
1190
1207
  _this._width = width;
1191
1208
  _this._height = height;
1209
+ _this._usage = usage;
1192
1210
  _this._format = format;
1193
1211
  _this._mipmapCount = _this._getMipmapCount();
1194
1212
  _this._isDepthTexture = format == exports.TextureFormat.Depth || format == exports.TextureFormat.DepthStencil || format == exports.TextureFormat.Depth16 || format == exports.TextureFormat.Depth24 || format == exports.TextureFormat.Depth32 || format == exports.TextureFormat.Depth24Stencil8 || format == exports.TextureFormat.Depth32Stencil8;
@@ -2288,29 +2306,7 @@ var /** @internal */ PromiseState;
2288
2306
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
2289
2307
  */ _proto.gc = function gc() {
2290
2308
  this._gc(false);
2291
- var engine = this.engine;
2292
- engine._renderElementPool.garbageCollection();
2293
- engine._meshRenderDataPool.garbageCollection();
2294
- engine._spriteRenderDataPool.garbageCollection();
2295
- engine._spriteMaskRenderDataPool.garbageCollection();
2296
- engine._textRenderDataPool.garbageCollection();
2297
- var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
2298
- _componentsManager._renderers.garbageCollection();
2299
- // @ts-ignore
2300
- _componentsManager._onStartScripts.garbageCollection();
2301
- // @ts-ignore
2302
- _componentsManager._onUpdateScripts.garbageCollection();
2303
- // @ts-ignore
2304
- _componentsManager._onLateUpdateScripts.garbageCollection();
2305
- // @ts-ignore
2306
- _componentsManager._onPhysicsUpdateScripts.garbageCollection();
2307
- // @ts-ignore
2308
- _componentsManager._onUpdateAnimations.garbageCollection();
2309
- // @ts-ignore
2310
- _componentsManager._onUpdateRenderers.garbageCollection();
2311
- _lightManager._spotLights.garbageCollection();
2312
- _lightManager._pointLights.garbageCollection();
2313
- _lightManager._directLights.garbageCollection();
2309
+ this.engine._pendingGC();
2314
2310
  };
2315
2311
  /**
2316
2312
  * Add content restorer.
@@ -3236,6 +3232,17 @@ exports.GLCapabilityType = void 0;
3236
3232
  componentContainer.length = 0;
3237
3233
  this._componentsContainerPool.push(componentContainer);
3238
3234
  };
3235
+ /**
3236
+ * @internal
3237
+ */ _proto._gc = function _gc() {
3238
+ this._renderers.garbageCollection();
3239
+ this._onStartScripts.garbageCollection();
3240
+ this._onUpdateScripts.garbageCollection();
3241
+ this._onLateUpdateScripts.garbageCollection();
3242
+ this._onPhysicsUpdateScripts.garbageCollection();
3243
+ this._onUpdateAnimations.garbageCollection();
3244
+ this._onUpdateRenderers.garbageCollection();
3245
+ };
3239
3246
  return ComponentsManager;
3240
3247
  }();
3241
3248
 
@@ -5867,6 +5874,11 @@ var Collision = function Collision() {
5867
5874
  elements[i]._onLateUpdate();
5868
5875
  }
5869
5876
  };
5877
+ /**
5878
+ * @internal
5879
+ */ _proto._gc = function _gc() {
5880
+ this._colliders.garbageCollection();
5881
+ };
5870
5882
  _proto._setGravity = function _setGravity() {
5871
5883
  this._nativePhysicsManager.setGravity(this._gravity);
5872
5884
  };
@@ -8444,6 +8456,13 @@ __decorate([
8444
8456
  shaderData.disableMacro("SCENE_SPOT_LIGHT_COUNT");
8445
8457
  }
8446
8458
  };
8459
+ /**
8460
+ * @internal
8461
+ */ _proto._gc = function _gc() {
8462
+ this._spotLights.garbageCollection();
8463
+ this._pointLights.garbageCollection();
8464
+ this._directLights.garbageCollection();
8465
+ };
8447
8466
  return LightManager;
8448
8467
  }();
8449
8468
 
@@ -16893,6 +16912,7 @@ ShaderPool.init();
16893
16912
  _this._frameInProcess = false;
16894
16913
  _this._waitingDestroy = false;
16895
16914
  _this._isDeviceLost = false;
16915
+ _this._waitingGC = false;
16896
16916
  _this._animate = function() {
16897
16917
  if (_this._vSyncCount) {
16898
16918
  _this._requestId = requestAnimationFrame(_this._animate);
@@ -16996,6 +17016,10 @@ ShaderPool.init();
16996
17016
  if (this._waitingDestroy) {
16997
17017
  this._destroy();
16998
17018
  }
17019
+ if (this._waitingGC) {
17020
+ this._gc();
17021
+ this._waitingGC = false;
17022
+ }
16999
17023
  this._frameInProcess = false;
17000
17024
  };
17001
17025
  /**
@@ -17154,6 +17178,15 @@ ShaderPool.init();
17154
17178
  };
17155
17179
  /**
17156
17180
  * @internal
17181
+ */ _proto._pendingGC = function _pendingGC() {
17182
+ if (this._frameInProcess) {
17183
+ this._waitingGC = true;
17184
+ } else {
17185
+ this._gc();
17186
+ }
17187
+ };
17188
+ /**
17189
+ * @internal
17157
17190
  */ _proto._initialize = function _initialize(configuration) {
17158
17191
  var _this = this;
17159
17192
  var physics = configuration.physics;
@@ -17216,6 +17249,16 @@ ShaderPool.init();
17216
17249
  console.error(error);
17217
17250
  });
17218
17251
  };
17252
+ _proto._gc = function _gc() {
17253
+ this._renderElementPool.garbageCollection();
17254
+ this._meshRenderDataPool.garbageCollection();
17255
+ this._spriteRenderDataPool.garbageCollection();
17256
+ this._spriteMaskRenderDataPool.garbageCollection();
17257
+ this._textRenderDataPool.garbageCollection();
17258
+ this._componentsManager._gc();
17259
+ this._lightManager._gc();
17260
+ this.physicsManager._gc();
17261
+ };
17219
17262
  _create_class(Engine, [
17220
17263
  {
17221
17264
  key: "settings",
@@ -22631,7 +22674,6 @@ var DirtyFlag;
22631
22674
  * @internal
22632
22675
  */ var AnimationCurveOwner = /*#__PURE__*/ function() {
22633
22676
  function AnimationCurveOwner(target, type, property, cureType) {
22634
- this.hasSavedDefaultValue = false;
22635
22677
  this.baseEvaluateData = {
22636
22678
  curKeyframeIndex: 0,
22637
22679
  value: null
@@ -22644,7 +22686,7 @@ var DirtyFlag;
22644
22686
  this.type = type;
22645
22687
  this.property = property;
22646
22688
  this.component = target.getComponent(type);
22647
- this._cureType = cureType;
22689
+ this.cureType = cureType;
22648
22690
  var assemblerType = AnimationCurveOwner.getAssemblerType(type, property);
22649
22691
  this._assembler = new assemblerType();
22650
22692
  this._assembler.initialize(this);
@@ -22653,89 +22695,80 @@ var DirtyFlag;
22653
22695
  }
22654
22696
  }
22655
22697
  var _proto = AnimationCurveOwner.prototype;
22656
- _proto.evaluateAndApplyValue = function evaluateAndApplyValue(curve, time, layerWeight, additive) {
22657
- if (curve.keys.length) {
22658
- if (additive) {
22659
- var value = curve._evaluateAdditive(time, this.baseEvaluateData);
22660
- var cureType = this._cureType;
22661
- if (cureType._isReferenceType) {
22662
- cureType._additiveValue(value, layerWeight, this.referenceTargetValue);
22663
- } else {
22664
- var assembler = this._assembler;
22665
- var originValue = assembler.getTargetValue();
22666
- var additiveValue = cureType._additiveValue(value, layerWeight, originValue);
22667
- assembler.setTargetValue(additiveValue);
22668
- }
22669
- } else {
22670
- var value1 = curve._evaluate(time, this.baseEvaluateData);
22671
- this._applyValue(value1, layerWeight);
22672
- }
22673
- }
22698
+ _proto.evaluateValue = function evaluateValue(curve, time, additive) {
22699
+ return additive ? curve._evaluateAdditive(time, this.baseEvaluateData) : curve._evaluate(time, this.baseEvaluateData);
22674
22700
  };
22675
- _proto.crossFadeAndApplyValue = function crossFadeAndApplyValue(srcCurve, destCurve, srcTime, destTime, crossWeight, layerWeight, additive) {
22676
- var srcValue = srcCurve && srcCurve.keys.length ? additive ? srcCurve._evaluateAdditive(srcTime, this.baseEvaluateData) : srcCurve._evaluate(srcTime, this.baseEvaluateData) : additive ? this._cureType._getZeroValue(this.baseEvaluateData.value) : this.defaultValue;
22677
- var destValue = destCurve && destCurve.keys.length ? additive ? destCurve._evaluateAdditive(destTime, this.crossEvaluateData) : destCurve._evaluate(destTime, this.crossEvaluateData) : additive ? this._cureType._getZeroValue(this.crossEvaluateData.value) : this.defaultValue;
22678
- this._applyCrossValue(srcValue, destValue, crossWeight, layerWeight, additive);
22701
+ _proto.evaluateCrossFadeValue = function evaluateCrossFadeValue(srcCurve, destCurve, srcTime, destTime, crossWeight, additive) {
22702
+ var srcValue = srcCurve && srcCurve.keys.length ? additive ? srcCurve._evaluateAdditive(srcTime, this.baseEvaluateData) : srcCurve._evaluate(srcTime, this.baseEvaluateData) : additive ? this.cureType._getZeroValue(this.baseEvaluateData.value) : this.defaultValue;
22703
+ var destValue = destCurve && destCurve.keys.length ? additive ? destCurve._evaluateAdditive(destTime, this.crossEvaluateData) : destCurve._evaluate(destTime, this.crossEvaluateData) : additive ? this.cureType._getZeroValue(this.crossEvaluateData.value) : this.defaultValue;
22704
+ return this._lerpValue(srcValue, destValue, crossWeight);
22679
22705
  };
22680
- _proto.crossFadeFromPoseAndApplyValue = function crossFadeFromPoseAndApplyValue(destCurve, destTime, crossWeight, layerWeight, additive) {
22681
- var srcValue = additive ? this._cureType._subtractValue(this.fixedPoseValue, this.defaultValue, this.baseEvaluateData.value) : this.fixedPoseValue;
22682
- var destValue = destCurve && destCurve.keys.length ? additive ? destCurve._evaluateAdditive(destTime, this.crossEvaluateData) : destCurve._evaluate(destTime, this.crossEvaluateData) : additive ? this._cureType._getZeroValue(this.crossEvaluateData.value) : this.defaultValue;
22683
- this._applyCrossValue(srcValue, destValue, crossWeight, layerWeight, additive);
22706
+ _proto.crossFadeFromPoseAndApplyValue = function crossFadeFromPoseAndApplyValue(destCurve, destTime, crossWeight, additive) {
22707
+ var srcValue = additive ? this.cureType._subtractValue(this.fixedPoseValue, this.defaultValue, this.baseEvaluateData.value) : this.fixedPoseValue;
22708
+ var destValue = destCurve && destCurve.keys.length ? additive ? destCurve._evaluateAdditive(destTime, this.crossEvaluateData) : destCurve._evaluate(destTime, this.crossEvaluateData) : additive ? this.cureType._getZeroValue(this.crossEvaluateData.value) : this.defaultValue;
22709
+ return this._lerpValue(srcValue, destValue, crossWeight);
22684
22710
  };
22685
22711
  _proto.revertDefaultValue = function revertDefaultValue() {
22686
22712
  this._assembler.setTargetValue(this.defaultValue);
22687
22713
  };
22714
+ _proto.getEvaluateValue = function getEvaluateValue(out) {
22715
+ if (this.cureType._isReferenceType) {
22716
+ this.cureType._copyValue(this.baseEvaluateData.value, out);
22717
+ return out;
22718
+ } else {
22719
+ return this.baseEvaluateData.value;
22720
+ }
22721
+ };
22688
22722
  _proto.saveDefaultValue = function saveDefaultValue() {
22689
- if (this._cureType._isReferenceType) {
22690
- this._cureType._copyValue(this.referenceTargetValue, this.defaultValue);
22723
+ if (this.cureType._isReferenceType) {
22724
+ this.cureType._copyValue(this.referenceTargetValue, this.defaultValue);
22691
22725
  } else {
22692
22726
  this.defaultValue = this._assembler.getTargetValue();
22693
22727
  }
22694
- this.hasSavedDefaultValue = true;
22695
22728
  };
22696
22729
  _proto.saveFixedPoseValue = function saveFixedPoseValue() {
22697
- if (this._cureType._isReferenceType) {
22698
- this._cureType._copyValue(this.referenceTargetValue, this.fixedPoseValue);
22730
+ if (this.cureType._isReferenceType) {
22731
+ this.cureType._copyValue(this.referenceTargetValue, this.fixedPoseValue);
22699
22732
  } else {
22700
22733
  this.fixedPoseValue = this._assembler.getTargetValue();
22701
22734
  }
22702
22735
  };
22703
- _proto._applyValue = function _applyValue(value, weight) {
22704
- if (weight === 1.0) {
22705
- if (this._cureType._isReferenceType) {
22706
- this._cureType._copyValue(value, this.referenceTargetValue);
22736
+ _proto.applyValue = function applyValue(value, weight, additive) {
22737
+ var cureType = this.cureType;
22738
+ if (additive) {
22739
+ if (cureType._isReferenceType) {
22740
+ cureType._additiveValue(value, weight, this.referenceTargetValue);
22707
22741
  } else {
22708
- this._assembler.setTargetValue(value);
22742
+ var assembler = this._assembler;
22743
+ var originValue = assembler.getTargetValue();
22744
+ var additiveValue = cureType._additiveValue(value, weight, originValue);
22745
+ assembler.setTargetValue(additiveValue);
22709
22746
  }
22710
22747
  } else {
22711
- if (this._cureType._isReferenceType) {
22712
- var targetValue = this.referenceTargetValue;
22713
- this._cureType._lerpValue(targetValue, value, weight, targetValue);
22748
+ if (weight === 1.0) {
22749
+ if (cureType._isReferenceType) {
22750
+ cureType._copyValue(value, this.referenceTargetValue);
22751
+ } else {
22752
+ this._assembler.setTargetValue(value);
22753
+ }
22714
22754
  } else {
22715
- var originValue = this._assembler.getTargetValue();
22716
- var lerpValue = this._cureType._lerpValue(originValue, value, weight);
22717
- this._assembler.setTargetValue(lerpValue);
22755
+ if (cureType._isReferenceType) {
22756
+ var targetValue = this.referenceTargetValue;
22757
+ cureType._lerpValue(targetValue, value, weight, targetValue);
22758
+ } else {
22759
+ var originValue1 = this._assembler.getTargetValue();
22760
+ var lerpValue = cureType._lerpValue(originValue1, value, weight);
22761
+ this._assembler.setTargetValue(lerpValue);
22762
+ }
22718
22763
  }
22719
22764
  }
22720
22765
  };
22721
- _proto._applyCrossValue = function _applyCrossValue(srcValue, destValue, crossWeight, layerWeight, additive) {
22722
- var out;
22723
- if (this._cureType._isReferenceType) {
22724
- out = this.baseEvaluateData.value;
22725
- this._cureType._lerpValue(srcValue, destValue, crossWeight, out);
22726
- } else {
22727
- out = this._cureType._lerpValue(srcValue, destValue, crossWeight);
22728
- }
22729
- if (additive) {
22730
- if (this._cureType._isReferenceType) {
22731
- this._cureType._additiveValue(out, layerWeight, this.referenceTargetValue);
22732
- } else {
22733
- var originValue = this._assembler.getTargetValue();
22734
- var lerpValue = this._cureType._additiveValue(out, layerWeight, originValue);
22735
- this._assembler.setTargetValue(lerpValue);
22736
- }
22766
+ _proto._lerpValue = function _lerpValue(srcValue, destValue, crossWeight) {
22767
+ if (this.cureType._isReferenceType) {
22768
+ return this.cureType._lerpValue(srcValue, destValue, crossWeight, this.baseEvaluateData.value);
22737
22769
  } else {
22738
- this._applyValue(out, layerWeight);
22770
+ this.baseEvaluateData.value = this.cureType._lerpValue(srcValue, destValue, crossWeight);
22771
+ return this.baseEvaluateData.value;
22739
22772
  }
22740
22773
  };
22741
22774
  AnimationCurveOwner.registerAssembler = function registerAssembler(componentType, property, assemblerType) {
@@ -22831,9 +22864,24 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
22831
22864
 
22832
22865
  /**
22833
22866
  * @internal
22834
- */ var AnimationCurveLayerOwner = function AnimationCurveLayerOwner() {
22835
- this.crossCurveMark = 0;
22836
- };
22867
+ */ var AnimationCurveLayerOwner = /*#__PURE__*/ function() {
22868
+ function AnimationCurveLayerOwner() {
22869
+ this.crossCurveMark = 0;
22870
+ }
22871
+ var _proto = AnimationCurveLayerOwner.prototype;
22872
+ _proto.initFinalValue = function initFinalValue() {
22873
+ var _this_curveOwner = this.curveOwner, cureType = _this_curveOwner.cureType, defaultValue = _this_curveOwner.defaultValue;
22874
+ if (cureType._isReferenceType) {
22875
+ cureType._copyValue(defaultValue, this.finalValue);
22876
+ } else {
22877
+ this.finalValue = defaultValue;
22878
+ }
22879
+ };
22880
+ _proto.saveFinalValue = function saveFinalValue() {
22881
+ this.finalValue = this.curveOwner.getEvaluateValue(this.finalValue);
22882
+ };
22883
+ return AnimationCurveLayerOwner;
22884
+ }();
22837
22885
 
22838
22886
  /**
22839
22887
  * Associate AnimationCurve and the Entity
@@ -22848,13 +22896,18 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
22848
22896
  var curveType = this.curve.constructor;
22849
22897
  var owner = new AnimationCurveOwner(entity, this.type, this.property, curveType);
22850
22898
  curveType._initializeOwner(owner);
22899
+ owner.saveDefaultValue();
22851
22900
  return owner;
22852
22901
  };
22853
22902
  /**
22854
22903
  * @internal
22855
22904
  */ _proto._createCurveLayerOwner = function _createCurveLayerOwner(owner) {
22905
+ var curveType = this.curve.constructor;
22856
22906
  var layerOwner = new AnimationCurveLayerOwner();
22857
22907
  layerOwner.curveOwner = owner;
22908
+ curveType._initializeLayerOwner(layerOwner);
22909
+ // If curve.keys.length is 0, updateFinishedState will assign 0 to the target, causing an error, so initialize by assigning defaultValue to finalValue.
22910
+ layerOwner.initFinalValue();
22858
22911
  return layerOwner;
22859
22912
  };
22860
22913
  /**
@@ -22942,7 +22995,8 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
22942
22995
  var targetEntity = entity.findByPath(curveData.relativePath);
22943
22996
  if (targetEntity) {
22944
22997
  var curveOwner = curveData._getTempCurveOwner(targetEntity);
22945
- curveOwner.evaluateAndApplyValue(curveData.curve, time, 1, false);
22998
+ var value = curveOwner.evaluateValue(curveData.curve, time, false);
22999
+ curveOwner.applyValue(value, 1, false);
22946
23000
  }
22947
23001
  }
22948
23002
  };
@@ -23086,6 +23140,7 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
23086
23140
  break;
23087
23141
  }
23088
23142
  }
23143
+ evaluateData.value = value;
23089
23144
  return value;
23090
23145
  };
23091
23146
  /**
@@ -23142,6 +23197,11 @@ exports.AnimationArrayCurve = (_AnimationArrayCurve = /*#__PURE__*/ function(Ani
23142
23197
  };
23143
23198
  /**
23144
23199
  * @internal
23200
+ */ AnimationArrayCurve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23201
+ owner.finalValue = [];
23202
+ };
23203
+ /**
23204
+ * @internal
23145
23205
  */ AnimationArrayCurve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23146
23206
  for(var i = 0, n = out.length; i < n; ++i){
23147
23207
  var src = srcValue[i];
@@ -23232,6 +23292,11 @@ exports.AnimationBoolCurve = (_AnimationBoolCurve = /*#__PURE__*/ function(Anima
23232
23292
  };
23233
23293
  /**
23234
23294
  * @internal
23295
+ */ AnimationBoolCurve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23296
+ owner.finalValue = false;
23297
+ };
23298
+ /**
23299
+ * @internal
23235
23300
  */ AnimationBoolCurve._lerpValue = function _lerpValue(srcValue, destValue) {
23236
23301
  return destValue;
23237
23302
  };
@@ -23289,6 +23354,11 @@ exports.AnimationColorCurve = (_AnimationColorCurve = /*#__PURE__*/ function(Ani
23289
23354
  };
23290
23355
  /**
23291
23356
  * @internal
23357
+ */ AnimationColorCurve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23358
+ owner.finalValue = new engineMath.Color();
23359
+ };
23360
+ /**
23361
+ * @internal
23292
23362
  */ AnimationColorCurve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23293
23363
  engineMath.Color.lerp(srcValue, destValue, weight, out);
23294
23364
  return out;
@@ -23395,6 +23465,12 @@ exports.AnimationFloatArrayCurve = (_AnimationFloatArrayCurve = /*#__PURE__*/ fu
23395
23465
  };
23396
23466
  /**
23397
23467
  * @internal
23468
+ */ AnimationFloatArrayCurve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23469
+ var size = owner.curveOwner.referenceTargetValue.length;
23470
+ owner.finalValue = new Float32Array(size);
23471
+ };
23472
+ /**
23473
+ * @internal
23398
23474
  */ AnimationFloatArrayCurve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23399
23475
  for(var i = 0, n = out.length; i < n; ++i){
23400
23476
  var src = srcValue[i];
@@ -23485,6 +23561,11 @@ exports.AnimationFloatCurve = (_AnimationFloatCurve = /*#__PURE__*/ function(Ani
23485
23561
  };
23486
23562
  /**
23487
23563
  * @internal
23564
+ */ AnimationFloatCurve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23565
+ owner.finalValue = 0;
23566
+ };
23567
+ /**
23568
+ * @internal
23488
23569
  */ AnimationFloatCurve._lerpValue = function _lerpValue(srcValue, destValue, crossWeight) {
23489
23570
  return srcValue + (destValue - srcValue) * crossWeight;
23490
23571
  };
@@ -23554,6 +23635,11 @@ exports.AnimationQuaternionCurve = (_AnimationQuaternionCurve = /*#__PURE__*/ fu
23554
23635
  };
23555
23636
  /**
23556
23637
  * @internal
23638
+ */ AnimationQuaternionCurve1._initializeLayerOwner = function _initializeLayerOwner(owner) {
23639
+ owner.finalValue = new engineMath.Quaternion();
23640
+ };
23641
+ /**
23642
+ * @internal
23557
23643
  */ AnimationQuaternionCurve1._lerpValue = function _lerpValue(src, dest, weight, out) {
23558
23644
  engineMath.Quaternion.slerp(src, dest, weight, out);
23559
23645
  return out;
@@ -23658,6 +23744,11 @@ exports.AnimationVector2Curve = (_AnimationVector2Curve = /*#__PURE__*/ function
23658
23744
  };
23659
23745
  /**
23660
23746
  * @internal
23747
+ */ AnimationVector2Curve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23748
+ owner.finalValue = new engineMath.Vector2();
23749
+ };
23750
+ /**
23751
+ * @internal
23661
23752
  */ AnimationVector2Curve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23662
23753
  engineMath.Vector2.lerp(srcValue, destValue, weight, out);
23663
23754
  return out;
@@ -23743,6 +23834,11 @@ exports.AnimationVector3Curve = (_AnimationVector3Curve = /*#__PURE__*/ function
23743
23834
  };
23744
23835
  /**
23745
23836
  * @internal
23837
+ */ AnimationVector3Curve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23838
+ owner.finalValue = new engineMath.Vector3();
23839
+ };
23840
+ /**
23841
+ * @internal
23746
23842
  */ AnimationVector3Curve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23747
23843
  engineMath.Vector3.lerp(srcValue, destValue, weight, out);
23748
23844
  return out;
@@ -23840,6 +23936,11 @@ exports.AnimationVector4Curve = (_AnimationVector4Curve = /*#__PURE__*/ function
23840
23936
  };
23841
23937
  /**
23842
23938
  * @internal
23939
+ */ AnimationVector4Curve._initializeLayerOwner = function _initializeLayerOwner(owner) {
23940
+ owner.finalValue = new engineMath.Vector4();
23941
+ };
23942
+ /**
23943
+ * @internal
23843
23944
  */ AnimationVector4Curve._lerpValue = function _lerpValue(srcValue, destValue, weight, out) {
23844
23945
  engineMath.Vector4.lerp(srcValue, destValue, weight, out);
23845
23946
  return out;
@@ -23949,6 +24050,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23949
24050
  LayerState[LayerState[/** Playing state. */ "Playing"] = 1] = "Playing";
23950
24051
  LayerState[LayerState[/** CrossFading state. */ "CrossFading"] = 2] = "CrossFading";
23951
24052
  LayerState[LayerState[/** FixedCrossFading state. */ "FixedCrossFading"] = 3] = "FixedCrossFading";
24053
+ LayerState[LayerState[/** Finished state. */ "Finished"] = 4] = "Finished";
23952
24054
  })(LayerState || (LayerState = {}));
23953
24055
 
23954
24056
  /**
@@ -24025,7 +24127,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24025
24127
  this.layerState = LayerState.Standby;
24026
24128
  this.crossCurveMark = 0;
24027
24129
  this.manuallyTransition = new AnimatorStateTransition();
24028
- this.crossOwnerLayerDataCollection = [];
24130
+ this.crossLayerOwnerCollection = [];
24029
24131
  }
24030
24132
  var _proto = AnimatorLayerData.prototype;
24031
24133
  _proto.switchPlayData = function switchPlayData() {
@@ -24055,6 +24157,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24055
24157
  /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0;
24056
24158
  _this._animatorLayersData = [];
24057
24159
  _this._curveOwnerPool = Object.create(null);
24160
+ _this._needRevertCurveOwners = [];
24058
24161
  _this._animationEventHandlerPool = new ClassPool(AnimationEventHandler);
24059
24162
  _this._tempAnimatorStateInfo = {
24060
24163
  layerIndex: -1,
@@ -24077,7 +24180,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24077
24180
  this._reset();
24078
24181
  }
24079
24182
  var stateInfo = this._getAnimatorStateInfo(stateName, layerIndex);
24080
- var state = stateInfo.state;
24183
+ var state = stateInfo.state, playLayerIndex = stateInfo.layerIndex;
24081
24184
  if (!state) {
24082
24185
  return;
24083
24186
  }
@@ -24086,8 +24189,8 @@ exports.AnimatorLayerBlendingMode = void 0;
24086
24189
  return;
24087
24190
  }
24088
24191
  var animatorLayerData = this._getAnimatorLayerData(stateInfo.layerIndex);
24089
- var animatorStateData = this._getAnimatorStateData(stateName, state, animatorLayerData);
24090
- this._preparePlay(animatorLayerData, state, animatorStateData);
24192
+ var animatorStateData = this._getAnimatorStateData(stateName, state, animatorLayerData, playLayerIndex);
24193
+ this._preparePlay(animatorLayerData, state);
24091
24194
  animatorLayerData.layerState = LayerState.Playing;
24092
24195
  animatorLayerData.srcPlayData.reset(state, animatorStateData, state._getDuration() * normalizedTimeOffset);
24093
24196
  };
@@ -24138,6 +24241,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24138
24241
  return;
24139
24242
  }
24140
24243
  deltaTime *= this.speed;
24244
+ this._revertCurveOwners();
24141
24245
  for(var i1 = 0, n1 = animatorController.layers.length; i1 < n1; i1++){
24142
24246
  var animatorLayerData = this._getAnimatorLayerData(i1);
24143
24247
  if (animatorLayerData.layerState === LayerState.Standby) {
@@ -24181,10 +24285,11 @@ exports.AnimatorLayerBlendingMode = void 0;
24181
24285
  var propertyOwners = animationCurveOwners[instanceId];
24182
24286
  for(var property in propertyOwners){
24183
24287
  var owner = propertyOwners[property];
24184
- owner.hasSavedDefaultValue && owner.revertDefaultValue();
24288
+ owner.revertDefaultValue();
24185
24289
  }
24186
24290
  }
24187
24291
  this._animatorLayersData.length = 0;
24292
+ this._needRevertCurveOwners.length = 0;
24188
24293
  this._curveOwnerPool = {};
24189
24294
  this._animationEventHandlerPool.resetPool();
24190
24295
  if (this._controllerUpdateFlag) {
@@ -24212,25 +24317,18 @@ exports.AnimatorLayerBlendingMode = void 0;
24212
24317
  stateInfo.state = state;
24213
24318
  return stateInfo;
24214
24319
  };
24215
- _proto._saveDefaultValues = function _saveDefaultValues(stateData) {
24216
- var curveLayerOwner = stateData.curveLayerOwner;
24217
- for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24218
- var _curveLayerOwner_i;
24219
- (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.saveDefaultValue();
24220
- }
24221
- };
24222
- _proto._getAnimatorStateData = function _getAnimatorStateData(stateName, animatorState, animatorLayerData) {
24320
+ _proto._getAnimatorStateData = function _getAnimatorStateData(stateName, animatorState, animatorLayerData, layerIndex) {
24223
24321
  var animatorStateDataMap = animatorLayerData.animatorStateDataMap;
24224
24322
  var animatorStateData = animatorStateDataMap[stateName];
24225
24323
  if (!animatorStateData) {
24226
24324
  animatorStateData = new AnimatorStateData();
24227
24325
  animatorStateDataMap[stateName] = animatorStateData;
24228
- this._saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData);
24326
+ this._saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData, layerIndex);
24229
24327
  this._saveAnimatorEventHandlers(animatorState, animatorStateData);
24230
24328
  }
24231
24329
  return animatorStateData;
24232
24330
  };
24233
- _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData) {
24331
+ _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData, layerIndex) {
24234
24332
  var _this = this, entity = _this.entity, curveOwnerPool = _this._curveOwnerPool;
24235
24333
  var curveLayerOwner = animatorStateData.curveLayerOwner;
24236
24334
  var layerCurveOwnerPool = animatorLayerData.curveOwnerPool;
@@ -24242,9 +24340,22 @@ exports.AnimatorLayerBlendingMode = void 0;
24242
24340
  var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
24243
24341
  var property = curve.property;
24244
24342
  var instanceId = targetEntity.instanceId;
24343
+ var needRevert = false;
24344
+ var baseAnimatorLayerData = this._animatorLayersData[0];
24345
+ var baseLayerCurveOwnerPool = baseAnimatorLayerData.curveOwnerPool;
24346
+ if (this.animatorController.layers[layerIndex].blendingMode === exports.AnimatorLayerBlendingMode.Additive && layerIndex > 0 && !(baseLayerCurveOwnerPool[instanceId] && baseLayerCurveOwnerPool[instanceId][property])) {
24347
+ needRevert = true;
24348
+ }
24245
24349
  // Get owner
24246
24350
  var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
24247
24351
  var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity));
24352
+ //@todo: There is performance waste here, which will be handled together with organizing AnimatorStateData later. The logic is changing from runtime to initialization.
24353
+ if (needRevert) {
24354
+ this._needRevertCurveOwners.push(owner);
24355
+ } else {
24356
+ var index = this._needRevertCurveOwners.indexOf(owner);
24357
+ index > -1 && this._needRevertCurveOwners.splice(index, 1);
24358
+ }
24248
24359
  // Get layer owner
24249
24360
  var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
24250
24361
  var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
@@ -24278,12 +24389,12 @@ exports.AnimatorLayerBlendingMode = void 0;
24278
24389
  };
24279
24390
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
24280
24391
  animatorLayerData.crossCurveMark++;
24281
- animatorLayerData.crossOwnerLayerDataCollection.length = 0;
24392
+ animatorLayerData.crossLayerOwnerCollection.length = 0;
24282
24393
  };
24283
24394
  _proto._addCrossOwner = function _addCrossOwner(animatorLayerData, layerOwner, curCurveIndex, nextCurveIndex) {
24284
24395
  layerOwner.crossSrcCurveIndex = curCurveIndex;
24285
24396
  layerOwner.crossDestCurveIndex = nextCurveIndex;
24286
- animatorLayerData.crossOwnerLayerDataCollection.push(layerOwner);
24397
+ animatorLayerData.crossLayerOwnerCollection.push(layerOwner);
24287
24398
  };
24288
24399
  _proto._prepareCrossFading = function _prepareCrossFading(animatorLayerData) {
24289
24400
  // Add src cross curve data.
@@ -24298,10 +24409,10 @@ exports.AnimatorLayerBlendingMode = void 0;
24298
24409
  this._prepareDestCrossData(animatorLayerData, true);
24299
24410
  };
24300
24411
  _proto._prepareFixedPoseCrossFading = function _prepareFixedPoseCrossFading(animatorLayerData) {
24301
- var crossOwnerLayerDataCollection = animatorLayerData.crossOwnerLayerDataCollection;
24412
+ var crossLayerOwnerCollection = animatorLayerData.crossLayerOwnerCollection;
24302
24413
  // Save current cross curve data owner fixed pose.
24303
- for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24304
- var layerOwner = crossOwnerLayerDataCollection[i];
24414
+ for(var i = crossLayerOwnerCollection.length - 1; i >= 0; i--){
24415
+ var layerOwner = crossLayerOwnerCollection[i];
24305
24416
  if (!layerOwner) continue;
24306
24417
  layerOwner.curveOwner.saveFixedPoseValue();
24307
24418
  // Reset destCurveIndex When fixed pose crossFading again.
@@ -24329,7 +24440,6 @@ exports.AnimatorLayerBlendingMode = void 0;
24329
24440
  layerOwner.crossDestCurveIndex = i;
24330
24441
  } else {
24331
24442
  var owner = layerOwner.curveOwner;
24332
- owner.saveDefaultValue();
24333
24443
  saveFixed && owner.saveFixedPoseValue();
24334
24444
  layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
24335
24445
  this._addCrossOwner(animatorLayerData, layerOwner, -1, i);
@@ -24347,7 +24457,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24347
24457
  var srcPlayData = layerData.srcPlayData, destPlayData = layerData.destPlayData, crossFadeTransitionInfo = layerData.crossFadeTransition;
24348
24458
  var additive = blendingMode === exports.AnimatorLayerBlendingMode.Additive;
24349
24459
  firstLayer && (weight = 1.0);
24350
- //TODO: 任意情况都应该检查,后面要优化
24460
+ //@todo: All situations should be checked, optimizations will follow later.
24351
24461
  layerData.layerState !== LayerState.FixedCrossFading && this._checkTransition(srcPlayData, crossFadeTransitionInfo, layerIndex);
24352
24462
  switch(layerData.layerState){
24353
24463
  case LayerState.Playing:
@@ -24359,6 +24469,9 @@ exports.AnimatorLayerBlendingMode = void 0;
24359
24469
  case LayerState.CrossFading:
24360
24470
  this._updateCrossFade(srcPlayData, destPlayData, layerData, layerIndex, weight, deltaTime, additive, aniUpdate);
24361
24471
  break;
24472
+ case LayerState.Finished:
24473
+ this._updateFinishedState(srcPlayData, weight, additive, aniUpdate);
24474
+ break;
24362
24475
  }
24363
24476
  };
24364
24477
  _proto._updatePlayingState = function _updatePlayingState(playData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
@@ -24366,19 +24479,26 @@ exports.AnimatorLayerBlendingMode = void 0;
24366
24479
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
24367
24480
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
24368
24481
  playData.update(this.speed < 0);
24369
- if (!aniUpdate) {
24370
- return;
24371
- }
24372
24482
  var clipTime = playData.clipTime, playState = playData.playState;
24373
- eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
24374
- for(var i = curveBindings.length - 1; i >= 0; i--){
24375
- var _curveLayerOwner_i;
24376
- (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
24483
+ var finished = playState === AnimatorStatePlayState.Finished;
24484
+ if (aniUpdate || finished) {
24485
+ for(var i = curveBindings.length - 1; i >= 0; i--){
24486
+ var layerOwner = curveLayerOwner[i];
24487
+ var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
24488
+ if (!owner) continue;
24489
+ var curve = curveBindings[i].curve;
24490
+ if (curve.keys.length) {
24491
+ var value = owner.evaluateValue(curve, clipTime, additive);
24492
+ aniUpdate && owner.applyValue(value, weight, additive);
24493
+ finished && layerOwner.saveFinalValue();
24494
+ }
24495
+ }
24377
24496
  }
24378
24497
  playData.frameTime += state.speed * delta;
24379
24498
  if (playState === AnimatorStatePlayState.Finished) {
24380
- layerData.layerState = LayerState.Standby;
24499
+ layerData.layerState = LayerState.Finished;
24381
24500
  }
24501
+ eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
24382
24502
  if (lastPlayState === AnimatorStatePlayState.UnStarted) {
24383
24503
  this._callAnimatorScriptOnEnter(state, layerIndex);
24384
24504
  }
@@ -24389,7 +24509,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24389
24509
  }
24390
24510
  };
24391
24511
  _proto._updateCrossFade = function _updateCrossFade(srcPlayData, destPlayData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
24392
- var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
24512
+ var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
24393
24513
  var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
24394
24514
  var srcState = srcPlayData.state, srcStateData = srcPlayData.stateData, lastSrcPlayState = srcPlayData.playState;
24395
24515
  var srcEventHandlers = srcStateData.eventHandlers;
@@ -24398,18 +24518,27 @@ exports.AnimatorLayerBlendingMode = void 0;
24398
24518
  var _destState_clip = destState.clip, destCurves = _destState_clip._curveBindings;
24399
24519
  var lastSrcClipTime = srcPlayData.clipTime;
24400
24520
  var lastDestClipTime = destPlayData.clipTime;
24401
- var crossWeight = Math.abs(destPlayData.frameTime) / (destState._getDuration() * layerData.crossFadeTransition.duration);
24402
- crossWeight >= 1.0 && (crossWeight = 1.0);
24521
+ var duration = destState._getDuration() * layerData.crossFadeTransition.duration;
24522
+ var crossWeight = Math.abs(destPlayData.frameTime) / duration;
24523
+ (crossWeight >= 1.0 || duration === 0) && (crossWeight = 1.0);
24403
24524
  srcPlayData.update(this.speed < 0);
24404
24525
  destPlayData.update(this.speed < 0);
24405
- var srcPlayState = srcPlayData.playState;
24406
- var destPlayState = destPlayData.playState;
24407
- this._updateCrossFadeData(layerData, crossWeight, delta, false);
24408
- if (!aniUpdate) {
24409
- return;
24526
+ var srcClipTime = srcPlayData.clipTime, srcPlayState = srcPlayData.playState;
24527
+ var destClipTime = destPlayData.clipTime, destPlayState = destPlayData.playState;
24528
+ var finished = destPlayData.playState === AnimatorStatePlayState.Finished;
24529
+ if (aniUpdate || finished) {
24530
+ for(var i = crossLayerOwnerCollection.length - 1; i >= 0; i--){
24531
+ var layerOwner = crossLayerOwnerCollection[i];
24532
+ var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
24533
+ if (!owner) continue;
24534
+ var srcCurveIndex = layerOwner.crossSrcCurveIndex;
24535
+ var destCurveIndex = layerOwner.crossDestCurveIndex;
24536
+ var value = owner.evaluateCrossFadeValue(srcCurveIndex >= 0 ? srcCurves[srcCurveIndex].curve : null, destCurveIndex >= 0 ? destCurves[destCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, additive);
24537
+ aniUpdate && owner.applyValue(value, weight, additive);
24538
+ finished && layerOwner.saveFinalValue();
24539
+ }
24410
24540
  }
24411
- var srcClipTime = srcPlayData.clipTime;
24412
- var destClipTime = destPlayData.clipTime;
24541
+ this._updateCrossFadeData(layerData, crossWeight, delta, false);
24413
24542
  srcEventHandlers.length && this._fireAnimationEvents(srcPlayData, srcEventHandlers, lastSrcClipTime, srcClipTime);
24414
24543
  destEventHandlers.length && this._fireAnimationEvents(destPlayData, destEventHandlers, lastDestClipTime, destClipTime);
24415
24544
  if (lastSrcPlayState === AnimatorStatePlayState.UnStarted) {
@@ -24428,30 +24557,34 @@ exports.AnimatorLayerBlendingMode = void 0;
24428
24557
  } else {
24429
24558
  this._callAnimatorScriptOnUpdate(destState, layerIndex);
24430
24559
  }
24431
- for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24432
- var layerOwner = crossOwnerLayerDataCollection[i];
24433
- if (!layerOwner) continue;
24434
- var srcCurveIndex = layerOwner.crossSrcCurveIndex;
24435
- var destCurveIndex = layerOwner.crossDestCurveIndex;
24436
- layerOwner.curveOwner.crossFadeAndApplyValue(srcCurveIndex >= 0 ? srcCurves[srcCurveIndex].curve : null, destCurveIndex >= 0 ? destCurves[destCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
24437
- }
24438
24560
  };
24439
- _proto._updateCrossFadeFromPose = function _updateCrossFadeFromPose(destPlayData, layerData, layerIndex, layerWeight, delta, additive, aniUpdate) {
24440
- var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
24561
+ _proto._updateCrossFadeFromPose = function _updateCrossFadeFromPose(destPlayData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
24562
+ var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
24441
24563
  var state = destPlayData.state, stateData = destPlayData.stateData, lastPlayState = destPlayData.playState;
24442
24564
  var eventHandlers = stateData.eventHandlers;
24443
24565
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
24444
24566
  var lastDestClipTime = destPlayData.clipTime;
24445
- var crossWeight = Math.abs(destPlayData.frameTime) / (state._getDuration() * layerData.crossFadeTransition.duration);
24446
- crossWeight >= 1.0 && (crossWeight = 1.0);
24567
+ var duration = state._getDuration() * layerData.crossFadeTransition.duration;
24568
+ var crossWeight = Math.abs(destPlayData.frameTime) / duration;
24569
+ (crossWeight >= 1.0 || duration === 0) && (crossWeight = 1.0);
24447
24570
  destPlayData.update(this.speed < 0);
24448
24571
  var playState = destPlayData.playState;
24449
24572
  this._updateCrossFadeData(layerData, crossWeight, delta, true);
24450
- if (!aniUpdate) {
24451
- return;
24452
- }
24453
24573
  var destClipTime = destPlayData.clipTime;
24454
- //TODO: srcState 少了最新一段时间的判断
24574
+ var finished = playState === AnimatorStatePlayState.Finished;
24575
+ // When the animator is culled (aniUpdate=false), if the play state has finished, the final value needs to be calculated and saved to be applied directly.
24576
+ if (aniUpdate || finished) {
24577
+ for(var i = crossLayerOwnerCollection.length - 1; i >= 0; i--){
24578
+ var layerOwner = crossLayerOwnerCollection[i];
24579
+ var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
24580
+ if (!owner) continue;
24581
+ var curveIndex = layerOwner.crossDestCurveIndex;
24582
+ var value = layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, additive);
24583
+ aniUpdate && owner.applyValue(value, weight, additive);
24584
+ finished && layerOwner.saveFinalValue();
24585
+ }
24586
+ }
24587
+ //@todo: srcState is missing the judgment of the most recent period."
24455
24588
  eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime);
24456
24589
  if (lastPlayState === AnimatorStatePlayState.UnStarted) {
24457
24590
  this._callAnimatorScriptOnEnter(state, layerIndex);
@@ -24461,11 +24594,18 @@ exports.AnimatorLayerBlendingMode = void 0;
24461
24594
  } else {
24462
24595
  this._callAnimatorScriptOnUpdate(state, layerIndex);
24463
24596
  }
24464
- for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24465
- var layerOwner = crossOwnerLayerDataCollection[i];
24466
- if (!layerOwner) continue;
24467
- var curveIndex = layerOwner.crossDestCurveIndex;
24468
- layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
24597
+ };
24598
+ _proto._updateFinishedState = function _updateFinishedState(playData, weight, additive, aniUpdate) {
24599
+ if (!aniUpdate) {
24600
+ return;
24601
+ }
24602
+ var curveLayerOwner = playData.stateData.curveLayerOwner;
24603
+ var _playData_state_clip = playData.state.clip, curveBindings = _playData_state_clip._curveBindings;
24604
+ for(var i = curveBindings.length - 1; i >= 0; i--){
24605
+ var layerOwner = curveLayerOwner[i];
24606
+ var owner = layerOwner == null ? void 0 : layerOwner.curveOwner;
24607
+ if (!owner) continue;
24608
+ owner.applyValue(layerOwner.finalValue, weight, additive);
24469
24609
  }
24470
24610
  };
24471
24611
  _proto._updateCrossFadeData = function _updateCrossFadeData(layerData, crossWeight, delta, fixed) {
@@ -24473,7 +24613,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24473
24613
  destPlayData.frameTime += destPlayData.state.speed * delta;
24474
24614
  if (crossWeight === 1.0) {
24475
24615
  if (destPlayData.playState === AnimatorStatePlayState.Finished) {
24476
- layerData.layerState = LayerState.Standby;
24616
+ layerData.layerState = LayerState.Finished;
24477
24617
  } else {
24478
24618
  layerData.layerState = LayerState.Playing;
24479
24619
  }
@@ -24483,7 +24623,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24483
24623
  fixed || (layerData.srcPlayData.frameTime += layerData.srcPlayData.state.speed * delta);
24484
24624
  }
24485
24625
  };
24486
- _proto._preparePlay = function _preparePlay(layerData, playState, playStateData) {
24626
+ _proto._preparePlay = function _preparePlay(layerData, playState) {
24487
24627
  if (layerData.layerState === LayerState.Playing) {
24488
24628
  var srcPlayData = layerData.srcPlayData;
24489
24629
  if (srcPlayData.state !== playState) {
@@ -24491,18 +24631,16 @@ exports.AnimatorLayerBlendingMode = void 0;
24491
24631
  for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24492
24632
  var _curveLayerOwner_i;
24493
24633
  var owner = (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner;
24494
- (owner == null ? void 0 : owner.hasSavedDefaultValue) && owner.revertDefaultValue();
24634
+ owner.revertDefaultValue();
24495
24635
  }
24496
- this._saveDefaultValues(playStateData);
24497
24636
  }
24498
24637
  } else {
24499
- // layerState is CrossFading, FixedCrossFading, Standby
24500
- var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
24501
- for(var i1 = crossOwnerLayerDataCollection.length - 1; i1 >= 0; i1--){
24502
- var owner1 = crossOwnerLayerDataCollection[i1].curveOwner;
24503
- owner1.hasSavedDefaultValue && owner1.revertDefaultValue();
24638
+ // layerState is CrossFading, FixedCrossFading, Standby, Finished
24639
+ var crossLayerOwnerCollection = layerData.crossLayerOwnerCollection;
24640
+ for(var i1 = crossLayerOwnerCollection.length - 1; i1 >= 0; i1--){
24641
+ var owner1 = crossLayerOwnerCollection[i1].curveOwner;
24642
+ owner1.revertDefaultValue();
24504
24643
  }
24505
- this._saveDefaultValues(playStateData);
24506
24644
  }
24507
24645
  };
24508
24646
  _proto._checkTransition = function _checkTransition(stateData, crossFadeTransition, layerIndex) {
@@ -24519,7 +24657,7 @@ exports.AnimatorLayerBlendingMode = void 0;
24519
24657
  _proto._crossFadeByTransition = function _crossFadeByTransition(transition, layerIndex) {
24520
24658
  var name = transition.destinationState.name;
24521
24659
  var stateInfo = this._getAnimatorStateInfo(name, layerIndex);
24522
- var crossState = stateInfo.state;
24660
+ var crossState = stateInfo.state, playLayerIndex = stateInfo.layerIndex;
24523
24661
  if (!crossState) {
24524
24662
  return;
24525
24663
  }
@@ -24527,21 +24665,21 @@ exports.AnimatorLayerBlendingMode = void 0;
24527
24665
  console.warn("The state named " + name + " has no AnimationClip data.");
24528
24666
  return;
24529
24667
  }
24530
- var animatorLayerData = this._getAnimatorLayerData(stateInfo.layerIndex);
24668
+ var animatorLayerData = this._getAnimatorLayerData(playLayerIndex);
24531
24669
  var layerState = animatorLayerData.layerState;
24532
24670
  var destPlayData = animatorLayerData.destPlayData;
24533
- var animatorStateData = this._getAnimatorStateData(name, crossState, animatorLayerData);
24671
+ var animatorStateData = this._getAnimatorStateData(name, crossState, animatorLayerData, playLayerIndex);
24534
24672
  var duration = crossState._getDuration();
24535
24673
  var offset = duration * transition.offset;
24536
24674
  destPlayData.reset(crossState, animatorStateData, offset);
24537
24675
  switch(layerState){
24538
- // Maybe not play, maybe end.
24539
24676
  case LayerState.Standby:
24540
24677
  animatorLayerData.layerState = LayerState.FixedCrossFading;
24541
24678
  this._clearCrossData(animatorLayerData);
24542
24679
  this._prepareStandbyCrossFading(animatorLayerData);
24543
24680
  break;
24544
24681
  case LayerState.Playing:
24682
+ case LayerState.Finished:
24545
24683
  animatorLayerData.layerState = LayerState.CrossFading;
24546
24684
  this._clearCrossData(animatorLayerData);
24547
24685
  this._prepareCrossFading(animatorLayerData);
@@ -24638,6 +24776,12 @@ exports.AnimatorLayerBlendingMode = void 0;
24638
24776
  }
24639
24777
  }
24640
24778
  };
24779
+ _proto._revertCurveOwners = function _revertCurveOwners() {
24780
+ var curveOwners = this._needRevertCurveOwners;
24781
+ for(var i = 0, n = curveOwners.length; i < n; ++i){
24782
+ curveOwners[i].revertDefaultValue();
24783
+ }
24784
+ };
24641
24785
  _create_class(Animator, [
24642
24786
  {
24643
24787
  key: "animatorController",
@@ -24670,6 +24814,9 @@ __decorate([
24670
24814
  __decorate([
24671
24815
  ignoreClone
24672
24816
  ], Animator.prototype, "_curveOwnerPool", void 0);
24817
+ __decorate([
24818
+ ignoreClone
24819
+ ], Animator.prototype, "_needRevertCurveOwners", void 0);
24673
24820
  __decorate([
24674
24821
  ignoreClone
24675
24822
  ], Animator.prototype, "_animationEventHandlerPool", void 0);