Exemple #1
0
            public static void FrameCleanup(CameraControl __instance)
            {
                LipsyncConfig instance = LipsyncConfig.Instance;

                if (instance.cleaned)
                {
                    return;
                }

                var inactiveFrames = instance.inactiveFrames;

                foreach (var hash in instance.frameStore.Keys)
                {
                    if (!instance.activeFrames.Contains(hash))
                    {
                        inactiveFrames.Add(hash);
                    }
                }
                foreach (var inactiveFrame in inactiveFrames)
                {
                    instance.frameStore.Remove(inactiveFrame);
                    instance.baseFaceStore.Remove(inactiveFrame);
                    instance.lastFaceStore.Remove(inactiveFrame);
                }

                // Cleanup
                instance.activeFrames.Clear();
                instance.cleaned = true;
                instance.inactiveFrames.Clear();
            }
Exemple #2
0
            public static bool NewCalcBlendShape(FBSBase __instance)
            {
                var enabled = LipsyncConfig.Instance.enabled;

                if (!enabled)
                {
                    return(true);
                }

                var nowFace = AccessTools.Field(typeof(FBSCtrlMouth), "dictNowFace").GetValue(__instance) as Dictionary <int, float>;

                if (nowFace is null)
                {
                    return(true);
                }

                LipsyncConfig cfg = LipsyncConfig.Instance;

                if (cfg.frameStore.TryGetValue(__instance.GetHashCode(), out var targetFrame))
                {
                    var openness = (float)AccessTools.Field(typeof(FBSCtrlMouth), "openRate").GetValue(__instance);

                    if (!cfg.baseFaceStore.TryGetValue(__instance.GetHashCode(), out var baseFace))
                    {
                        baseFace = new Dictionary <int, float>();
                        cfg.baseFaceStore[__instance.GetHashCode()] = baseFace;
                    }

                    if (!cfg.lastFaceStore.TryGetValue(__instance.GetHashCode(), out var lastFace))
                    {
                        lastFace = new Dictionary <int, float>();
                        cfg.lastFaceStore[__instance.GetHashCode()] = lastFace;
                    }

                    MapFrame(targetFrame, ref baseFace, ref lastFace, ref nowFace, ref openness);
                    AccessTools.Field(typeof(FBSCtrlMouth), "openRate").SetValue(__instance, openness);
                    AccessTools.Field(typeof(FBSCtrlMouth), "dictNowFace").SetValue(__instance, nowFace);
                    return(true);
                }
                else
                {
                    return(true);
                }
            }