Exemplo n.º 1
0
    // Token: 0x0600867A RID: 34426 RVA: 0x0034A374 File Offset: 0x00348774
    public void CalculateBlendShape()
    {
        if (FBSTarget.Length == 0)
        {
            return;
        }
        var b   = correctOpenMax >= 0f ? correctOpenMax : OpenMax;
        var num = Mathf.Lerp(OpenMin, b, openRate);

        if (0f <= FixedRate)
        {
            num = FixedRate;
        }
        var num2 = 0f;

        if (blendTimeCtrl != null)
        {
            num2 = blendTimeCtrl.Calculate();
        }
        foreach (var fbstargetInfo in FBSTarget)
        {
            var skinnedMeshRenderer = fbstargetInfo.GetSkinnedMeshRenderer();
            var dictionary          = DictionaryPool <int, float> .Get();

            for (var j = 0; j < fbstargetInfo.PtnSet.Length; j++)
            {
                dictionary[fbstargetInfo.PtnSet[j].Close] = 0f;
                dictionary[fbstargetInfo.PtnSet[j].Open]  = 0f;
            }

            var num3 = (int)Mathf.Clamp(num * 100f, 0f, 100f);
            if (num2 != 1f)
            {
                foreach (var num4 in dictBackFace.Keys)
                {
                    dictionary[fbstargetInfo.PtnSet[num4].Close] = dictionary[fbstargetInfo.PtnSet[num4].Close] + dictBackFace[num4] * (100 - num3) * (1f - num2);
                    dictionary[fbstargetInfo.PtnSet[num4].Open]  = dictionary[fbstargetInfo.PtnSet[num4].Open] + dictBackFace[num4] * num3 * (1f - num2);
                }
            }

            foreach (var num5 in dictNowFace.Keys)
            {
                dictionary[fbstargetInfo.PtnSet[num5].Close] = dictionary[fbstargetInfo.PtnSet[num5].Close] + dictNowFace[num5] * (100 - num3) * num2;
                dictionary[fbstargetInfo.PtnSet[num5].Open]  = dictionary[fbstargetInfo.PtnSet[num5].Open] + dictNowFace[num5] * num3 * num2;
            }

            foreach (var keyValuePair in dictionary)
            {
                if (keyValuePair.Key != -1)
                {
                    skinnedMeshRenderer.SetBlendShapeWeight(keyValuePair.Key, keyValuePair.Value);
                }
            }
            DictionaryPool <int, float> .Release(dictionary);
        }
    }
Exemplo n.º 2
0
 public void CalculateBlendShape()
 {
     if (FBSTarget.Length != 0)
     {
         float b   = (!(correctOpenMax < 0f)) ? correctOpenMax : OpenMax;
         float num = Mathf.Lerp(OpenMin, b, openRate);
         if (0f <= FixedRate)
         {
             num = FixedRate;
         }
         float num2 = 0f;
         if (blendTimeCtrl != null)
         {
             num2 = blendTimeCtrl.Calculate();
         }
         FBSTargetInfo[] fBSTarget = FBSTarget;
         foreach (FBSTargetInfo fBSTargetInfo in fBSTarget)
         {
             SkinnedMeshRenderer     skinnedMeshRenderer = fBSTargetInfo.GetSkinnedMeshRenderer();
             Dictionary <int, float> dictionary          = new Dictionary <int, float>();
             for (int j = 0; j < fBSTargetInfo.PtnSet.Length; j++)
             {
                 dictionary[fBSTargetInfo.PtnSet[j].Close] = 0f;
                 dictionary[fBSTargetInfo.PtnSet[j].Open]  = 0f;
             }
             int num3 = (int)Mathf.Clamp(num * 100f, 0f, 100f);
             if (num2 != 1f)
             {
                 foreach (int key in dictBackFace.Keys)
                 {
                     dictionary[fBSTargetInfo.PtnSet[key].Close] = dictionary[fBSTargetInfo.PtnSet[key].Close] + dictBackFace[key] * (float)(100 - num3) * (1f - num2);
                     dictionary[fBSTargetInfo.PtnSet[key].Open]  = dictionary[fBSTargetInfo.PtnSet[key].Open] + dictBackFace[key] * (float)num3 * (1f - num2);
                 }
             }
             foreach (int key2 in dictNowFace.Keys)
             {
                 dictionary[fBSTargetInfo.PtnSet[key2].Close] = dictionary[fBSTargetInfo.PtnSet[key2].Close] + dictNowFace[key2] * (float)(100 - num3) * num2;
                 dictionary[fBSTargetInfo.PtnSet[key2].Open]  = dictionary[fBSTargetInfo.PtnSet[key2].Open] + dictNowFace[key2] * (float)num3 * num2;
             }
             foreach (KeyValuePair <int, float> item in dictionary)
             {
                 if (item.Key == -1)
                 {
                     Debug.LogError(skinnedMeshRenderer.sharedMesh.name + ": 多分、名前が間違ったデ\u30fcタがある");
                 }
                 else
                 {
                     skinnedMeshRenderer.SetBlendShapeWeight(item.Key, item.Value);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
            public static bool CalculateBlendShape(FBSBase __instance, float ___correctOpenMax, float ___openRate,
                TimeProgressCtrl ___blendTimeCtrl, Dictionary<int, float> ___dictBackFace,
                Dictionary<int, float> ___dictNowFace)
            {
                if (__instance.FBSTarget.Length == 0) return false;

                var openMax = ___correctOpenMax >= 0f ? ___correctOpenMax : __instance.OpenMax;
                var lerpOpenRate = Mathf.Lerp(__instance.OpenMin, openMax, ___openRate);
                if (0f <= __instance.FixedRate) lerpOpenRate = __instance.FixedRate;

                var rate = 0f;
                if (___blendTimeCtrl != null) rate = ___blendTimeCtrl.Calculate();

                retry:
                try
                {
                    for (var index = 0; index < __instance.FBSTarget.Length; index++)
                    {
                        for (var i = 0; i < _blendIdCache.Count; i++)
                        {
                            _blendIdCache[i] = false;
                            _blendValueCache[i] = 0f;
                        }

                        var targetInfo = __instance.FBSTarget[index];
                        var skinnedMeshRenderer = targetInfo.GetSkinnedMeshRenderer();

                        var percent = (int)Mathf.Clamp(lerpOpenRate * 100f, 0f, 100f);

                        for (var j = 0; j < targetInfo.PtnSet.Length; j++)
                        {
                            var ptnSet = targetInfo.PtnSet[j];
                            var resultClose = 0f;
                            var resultOpen = 0f;

                            if (rate != 1f)
                            {
                                if (___dictBackFace.TryGetValue(j, out var valueBack))
                                {
                                    resultClose += valueBack * (100 - percent) * (1f - rate);
                                    resultOpen += valueBack * percent * (1f - rate);
                                }
                            }

                            if (___dictNowFace.TryGetValue(j, out var valueNow))
                            {
                                resultClose += valueNow * (100 - percent) * rate;
                                resultOpen += valueNow * percent * rate;
                            }

                            if (ptnSet.Close >= 0)
                            {
                                _blendIdCache[ptnSet.Close] = true;
                                _blendValueCache[ptnSet.Close] += resultClose;
                            }
                            if (ptnSet.Open >= 0)
                            {
                                _blendIdCache[ptnSet.Open] = true;
                                _blendValueCache[ptnSet.Open] += resultOpen;
                            }
                        }

                        for (var i = 0; i < _blendIdCache.Count; i++)
                        {
                            if (_blendIdCache[i])
                            {
                                skinnedMeshRenderer.SetBlendShapeWeight(i, _blendValueCache[i]);
                            }
                        }
                    }

                    return false;
                }
                catch (ArgumentOutOfRangeException)
                {
                    UnityEngine.Debug.Log("Increasing blend ID cache size");
                    _blendIdCache.AddRange(Enumerable.Repeat(false, 50));
                    _blendValueCache.AddRange(Enumerable.Repeat(0f, 50));
                    goto retry;
                }
            }