From 0fb0b065d7ad77dc4219a25506d30012a87e7fee Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 19 Mar 2021 16:10:42 +0100 Subject: [PATCH] [unity] Fixed SkeletonMecanim BlendTree animations being incorrectly applied on WebGL. Was numeric problem of `weight == 0` and actual weight being e.g. `1.1E-15`. Closes #1862. --- .../spine-unity/Components/SkeletonMecanim.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs index 14b30c7cc..3355aa610 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -142,6 +142,9 @@ namespace Spine.Unity { [System.Serializable] public class MecanimTranslator { + + const float WeightEpsilon = 0.0001f; + #region Inspector public bool autoReset = true; public bool useCustomMixMode = true; @@ -220,7 +223,7 @@ namespace Spine.Unity { private bool ApplyAnimation (Skeleton skeleton, AnimatorClipInfo info, AnimatorStateInfo stateInfo, int layerIndex, float layerWeight, MixBlend layerBlendMode, bool useClipWeight1 = false) { float weight = info.weight * layerWeight; - if (weight == 0) + if (weight < WeightEpsilon) return false; var clip = GetAnimation(info.clip); @@ -244,7 +247,7 @@ namespace Spine.Unity { float clipWeight = interpolateWeightTo1 ? (info.weight + 1.0f) * 0.5f : info.weight; float weight = clipWeight * layerWeight; - if (weight == 0) + if (weight < WeightEpsilon) return false; var clip = GetAnimation(info.clip); @@ -320,7 +323,7 @@ namespace Spine.Unity { for (int c = 0; c < clipInfoCount; c++) { var info = clipInfo[c]; - float weight = info.weight * layerWeight; if (weight == 0) continue; + float weight = info.weight * layerWeight; if (weight < WeightEpsilon) continue; var clip = GetAnimation(info.clip); if (clip != null) previousAnimations.Add(clip); @@ -329,7 +332,7 @@ namespace Spine.Unity { if (hasNext) { for (int c = 0; c < nextClipInfoCount; c++) { var info = nextClipInfo[c]; - float weight = info.weight * layerWeight; if (weight == 0) continue; + float weight = info.weight * layerWeight; if (weight < WeightEpsilon) continue; var clip = GetAnimation(info.clip); if (clip != null) previousAnimations.Add(clip); @@ -341,7 +344,7 @@ namespace Spine.Unity { { var info = interruptingClipInfo[c]; float clipWeight = shallInterpolateWeightTo1 ? (info.weight + 1.0f) * 0.5f : info.weight; - float weight = clipWeight * layerWeight; if (weight == 0) continue; + float weight = clipWeight * layerWeight; if (weight < WeightEpsilon) continue; var clip = GetAnimation(info.clip); if (clip != null) previousAnimations.Add(clip);