// --------------------------------------------------------------------

        private void AutodetectWithRules()         // TODO - Move this to an autodetection thing
        {
            FaceSyncData syncData = target as FaceSyncData;

            if (syncData.ReferenceText == null || syncData.ReferenceText.Length == 0)
            {
                return;
            }

            Dictionary <string, FaceSyncBlendSet> rules = FaceSyncSettings.GetSettings().GetHashedRules();
            float  totalDuration = syncData.GetDuration();
            string lowerCaseText = syncData.ReferenceText.ToLower();

            for (int i = 0; i < syncData.ReferenceText.Length; ++i)
            {
                foreach (var rule in rules)
                {
                    if (lowerCaseText.Substring(i).StartsWith(rule.Key.ToLower()))
                    {
                        FaceSyncKeyframe kf = new FaceSyncKeyframe(((float)i / syncData.ReferenceText.Length) * totalDuration);
                        kf.BlendSet = rule.Value;
                        syncData.Keyframes.Add(kf);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // --------------------------------------------------------------------

        public void ApplyBlendData(FaceSyncData data, float time)
        {
            for (int i = 0; i < data.Keyframes.Count; ++i)
            {
                FaceSyncKeyframe keyframe         = data.Keyframes[i];
                float            keyframeDuration = keyframe.BlendSet.Duration;
                if (time > keyframe.Time && time < (keyframe.Time + keyframeDuration))
                {
                    float keyframeProgress = (time - keyframe.Time) / keyframeDuration;
                    ApplyBlendSet(keyframe.BlendSet, keyframeProgress);
                }
            }
        }
Exemplo n.º 3
0
        // --------------------------------------------------------------------

        public float GetDuration()
        {
            float duration = Sound ? Sound.length : 0f;

            for (int i = 0; i < Keyframes.Count; ++i)
            {
                FaceSyncKeyframe keyframe = Keyframes[i];
                if (keyframe.BlendSet)
                {
                    duration = Mathf.Max(keyframe.Time + keyframe.BlendSet.Duration, duration);
                }
            }
            return(duration);
        }
        // --------------------------------------------------------------------

        public void ShowKeyframeDataUI(FaceSyncKeyframe keyframe, float maxTime)
        {
            EditorGUI.BeginChangeCheck();
            keyframe.BlendSet = EditorGUILayout.ObjectField(keyframe.BlendSet, typeof(FaceSyncBlendSet), false, null) as FaceSyncBlendSet;
            keyframe.Time     = EditorGUILayout.Slider("Time", keyframe.Time, 0, maxTime);

            if (GUILayout.Button("Delete"))
            {
                (target as FaceSyncData).Keyframes.Remove(keyframe);
                mSelectedKeyframe = -1;
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }
        }
        // --------------------------------------------------------------------

        private void ShowKeyframesUI()
        {
            FaceSyncData syncData = target as FaceSyncData;

            EditorGUI.BeginChangeCheck();

            syncData.ReferenceText = EditorGUILayout.TextArea(syncData.ReferenceText);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Detect Keyframes"))
            {
                AutodetectWithRules();
            }

            if (GUILayout.Button("Clear Keyframes"))
            {
                syncData.Keyframes.Clear();
                mSelectedKeyframe = -1;
            }
            EditorGUILayout.EndHorizontal();

            float totalDuration = syncData.GetDuration();

            for (int i = 0; i < syncData.Keyframes.Count; ++i)
            {
                FaceSyncKeyframe keyframe = syncData.Keyframes[i];
                float            x        = (mWidth - (sBorder * 2)) * (keyframe.Time / totalDuration);
                string           label    = keyframe.BlendSet ? keyframe.BlendSet.Label : "!";
                GUI.contentColor    = keyframe.BlendSet ? Color.white : Color.red;
                GUI.backgroundColor = i == mSelectedKeyframe ? Color.cyan : (keyframe.BlendSet ? keyframe.BlendSet.Color : Color.white);
                if (GUI.Button(new Rect(sBorder + x - 10, sInitY - 20, 20, 18), label))
                {
                    mSelectedKeyframe = i;
                }
                GUI.Box(new Rect(sBorder + x, sInitY, 1, 5), "");
            }
            GUI.contentColor    = Color.white;
            GUI.backgroundColor = Color.white;
        }