public ExpressionAnimation(GenerateDAZMorphsControlUI morphControl, ExpressionAnimation stopping, ExpressionAnimation starting)
        {
            this.morphControl = morphControl;

            ExpressionKeyframe stoppingFrame = stopping.keyframes[0];
            ExpressionKeyframe startingFrame = starting.keyframes[0];

            List <string> stoppingMorphs = stoppingFrame.morphValues.Keys.ToList();
            List <string> startingMorphs = startingFrame.morphValues.Keys.ToList();
            List <string> notInStarting  = stoppingMorphs.Where((stoppingName) =>
            {
                return(startingMorphs.Contains(stoppingName) == false);
            }).ToList();

            ExpressionKeyframe startFrame = new ExpressionKeyframe()
            {
                time = 0
            };
            ExpressionKeyframe endFrame = new ExpressionKeyframe()
            {
                time = 1
            };

            notInStarting.ForEach((morphName) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(morphName);
                startFrame.morphValues[morphName] = morph.appliedValue;
                endFrame.morphValues[morphName]   = morph.startValue;
            });

            keyframes.Add(startFrame);
            keyframes.Add(endFrame);
            duration = TRANSITION_ANIMATION_DURATION;
        }
        public bool UpdateFadeOut()
        {
            if (keyframes.Count <= 0)
            {
                return(true);
            }

            isFading = true;
            ExpressionKeyframe step = keyframes[0];

            step.morphValues.Keys.ToList().ForEach((morphName) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(morphName);

                float currentValue = morph.morphValue;
                float morphValue   = morph.startValue;
                float lerpedValue  = currentValue + (morphValue - currentValue) * Time.deltaTime * ANIMATION_LERP_RATE;
                morph.SetValue(lerpedValue);
            });

            if ((Time.time - fadeStartTime) > FADE_OUT_TIME)
            {
                isFading = false;
                return(true);
            }

            return(false);
        }
        public ExpressionAnimation(GenerateDAZMorphsControlUI morphControl, string jsonString)
        {
            this.morphControl = morphControl;

            JSONClass obj = JSON.Parse(jsonString).AsObject;

            audio    = obj["audio"].Value;
            duration = obj["duration"].AsFloat;
            JSONArray keyframesData = obj["keyframes"].AsArray;

            for (int i = 0; i < keyframesData.Count; i++)
            {
                ExpressionKeyframe keyframe = new ExpressionKeyframe();

                JSONClass keyframeData = keyframesData[i].AsObject;

                keyframeData.Keys.ToList().ForEach((keyName) =>
                {
                    float value = keyframeData[keyName].AsFloat;
                    if (keyName == "time")
                    {
                        keyframe.time = value;
                    }
                    else
                    {
                        keyframe.morphValues[keyName] = value;
                    }
                });

                keyframes.Add(keyframe);
            }

            nac = URLAudioClipManager.singleton.GetClip(audio);
        }
 int GetPrevStep(float t)
 {
     for (int i = 0; i < keyframes.Count; i++)
     {
         ExpressionKeyframe step = keyframes[i];
         if (step.time >= t)
         {
             return(Math.Max(i - 1, 0));
         }
     }
     return(keyframes.Count - 1);
 }
예제 #5
0
        public ExpressionKeyframe ToKeyFrame()
        {
            ExpressionKeyframe keyframe = new ExpressionKeyframe()
            {
                time = t
            };

            morphKeyframe.Keys.ToList().ForEach((morph) =>
            {
                //Debug.Log(morph.displayName + " " + morphKeyframe[morph]);
                keyframe.morphValues[morph.displayName] = morphKeyframe[morph];
            });
            return(keyframe);
        }
        float GetValueBetweenSteps(float t, string morphName, ExpressionKeyframe prevStep, ExpressionKeyframe nextStep)
        {
            float prevValue = prevStep.morphValues[morphName];
            float nextValue = nextStep.morphValues[morphName];
            float prevT     = prevStep.time;
            float nextT     = nextStep.time;

            float tToPrev = t - prevT;
            float deltaT  = nextT - prevT;

            if (deltaT <= 0)
            {
                return(prevValue);
            }

            float morphAlpha = tToPrev / deltaT;
            float morphValue = prevValue + (nextValue - prevValue) * morphAlpha;

            return(morphValue);
        }
        public void Stop()
        {
            if (keyframes.Count <= 0)
            {
                return;
            }

            isPlaying = false;
            ExpressionKeyframe step = keyframes[0];

            step.morphValues.Keys.ToList().ForEach((morphName) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(morphName);
                if (morph != null)
                {
                    //morph.SetValue(morph.startValue);
                    morph.SetDefaultValue();
                }
            });
        }
        void SetMorphAtT(float t)
        {
            if (keyframes.Count <= 0)
            {
                return;
            }

            int current = GetPrevStep(t);
            ExpressionKeyframe prevStep = keyframes[current];
            ExpressionKeyframe nextStep = keyframes[Math.Min(current + 1, keyframes.Count - 1)];

            prevStep.morphValues.Keys.ToList().ForEach((morphName) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(morphName);

                float currentValue = morph.appliedValue;
                float morphValue   = GetValueBetweenSteps(t, morphName, prevStep, nextStep);
                float lerpedValue  = currentValue + (morphValue - currentValue) * Time.deltaTime * ANIMATION_LERP_RATE;
                morph.SetValue(lerpedValue);
            });
        }