// Function that handles the actual blending. Called each frame in update private void playTransition() { // Initialize Transition when it begins if (fInitTransition) { transitionClip.reset(); fInitTransition = false; fPlayMainAfterTransition = false; // In case a new transition starts while a transitionIn animation is still playing } // LERP Transition and currently playing emotion // Interpolation website: http://paulbourke.net/miscellaneous/interpolation/ currentTime += Time.deltaTime; float mu = currentTime / blendDuration; //float t; float upcomingBlendWeight = 0; float pStart = 0f; float pEnd = 1f; switch (interpolationMode) { case "Linear": upcomingBlendWeight = IFALerp.linear(pStart, pEnd, mu); break; case "Cubic": upcomingBlendWeight = IFALerp.cubic(pStart, pEnd, mu); break; case "Bezier": upcomingBlendWeight = IFALerp.bezier(pStart, pEnd, mu, pBezierP1, pBezierP2); break; default: break; } // Draw for display purposes if (drawGraphOnImage) { drawGraphOnImage.drawPoint(0, pStart, Color.red); drawGraphOnImage.drawPoint(1, pEnd, Color.green); drawGraphOnImage.drawPoint(mu, upcomingBlendWeight, Color.black); } // Set Blend Weights if (oldMainClips != null) { for (int i = 0; i < oldMainClips.Count; i++) { oldMainClips[i].setWeight((1f - upcomingBlendWeight) * oldMainClipsInitialWeight[i]); } } transitionClip.setWeight(upcomingBlendWeight); // Update Clips? foreach (IFAClip clip in allClips) { clip.update(); } // End Transition CleanUp, Prepare playing Main if (currentTime >= blendDuration) { fPlayMainAfterTransition = true; fInitTransition = true; currentTime = 0; //previousEmotionNumber = emotionNumber; transitionDone = true; } //normalize = true; }
// Function that handles the actual blending. Called each frame in update private void playTransition() { // Initialize Transition when it begins if (fInitTransition) { newMainClip.reset(); // TODO: Might need to comment this back in if auto-main-loop doesnt work fInitTransition = false; } // LERP Transition and currently playing emotion // Interpolation website: http://paulbourke.net/miscellaneous/interpolation/ currentTime += Time.deltaTime; float mu = currentTime / blendDuration; //float t; float upcomingBlendWeight = 0; float pStart = 0f; float pEnd = 1f; switch (interpolationMode) { case "Linear": upcomingBlendWeight = IFALerp.linear(pStart, pEnd, mu); break; case "Cubic": upcomingBlendWeight = IFALerp.cubic(pStart, pEnd, mu); break; case "Bezier": upcomingBlendWeight = IFALerp.bezier(pStart, pEnd, mu, pBezierP1, pBezierP2); break; default: break; } // Draw for display purposes if (drawGraphOnImage) { drawGraphOnImage.drawPoint(0, pStart, Color.red); drawGraphOnImage.drawPoint(1, pEnd, Color.green); drawGraphOnImage.drawPoint(mu, upcomingBlendWeight, Color.black); } // Set Blend Weights if (oldMainClips != null) { for (int i = 0; i < oldMainClips.Count; i++) { oldMainClips[i].setWeight((1f - upcomingBlendWeight) * oldMainClipsInitialWeight[i]); } } newMainClip.setWeight(upcomingBlendWeight); // TODO: Update Clips? foreach (IFAClip clip in allClips) { clip.update(); } // End Transition CleanUp, Prepare playing Main if (currentTime >= blendDuration) { blendingDone = true; } }
private void playTransition() { // Initialize Transition when it begins if (fInitTransition) { if (fWithTransitionIn) { blendToKey = transitionEmotion + "TransitionIn" + emotionNumber; mixerEmotionPlayable.GetInput(playablesDict[blendToKey]).SetTime(0f); mixerEmotionPlayable.GetInput(playablesDict[blendToKey]).SetDone(false); } else { blendToKey = transitionEmotion + emotionNumber; mixerEmotionPlayable.GetInput(playablesDict[blendToKey]).GetInput(mainMixerMainIndex).SetTime(0f); mixerEmotionPlayable.GetInput(playablesDict[blendToKey]).GetInput(mainMixerMainIndex).SetDone(false); } fInitTransition = false; fPlayMainAfterTransition = false; // In case a new transition starts while a transitionIn animation is still playing } // LERP Transition and currently playing emotion // Interpolation website: http://paulbourke.net/miscellaneous/interpolation/ currentTime += Time.deltaTime; float mu = currentTime / lerpBlendDuration; //float t; float upcomingBlendWeight = 0; float pStart = 0f; float pEnd = 1f; switch (interpolationMode) { case interpolationENUM.Linear: upcomingBlendWeight = myLerp(pStart, pEnd, mu, interpolationENUM.Linear); break; case interpolationENUM.Cubic: upcomingBlendWeight = myLerp(pStart, pEnd, mu, interpolationENUM.Cubic); break; case interpolationENUM.Bezier: upcomingBlendWeight = myLerp(pStart, pEnd, mu, interpolationENUM.Bezier, pBezierP1, pBezierP2); break; default: break; } // Draw for display purposes if (GOWithDrawGraphOnImage) { drawGraphOnImage.drawPoint(0, pStart, Color.red); drawGraphOnImage.drawPoint(1, pEnd, Color.green); drawGraphOnImage.drawPoint(mu, upcomingBlendWeight, Color.black); } // Set Blend Weights mixerEmotionPlayable.SetInputWeight(playablesDict[currentlyPlaying + previousEmotionNumber], 1f - upcomingBlendWeight); mixerEmotionPlayable.SetInputWeight(playablesDict[blendToKey], upcomingBlendWeight); // End Transition CleanUp, Prepare playing Main if (currentTime >= lerpBlendDuration) { Debug.Log("Transition from " + currentlyPlaying + previousEmotionNumber + " to " + blendToKey + " complete."); if (fWithTransitionIn) { fPlayMainAfterTransition = true; currentlyPlaying = transitionEmotion + "TransitionIn"; } else { currentlyPlaying = transitionEmotion; } fPlayTransition = false; fInitTransition = true; currentTime = 0; previousEmotionNumber = emotionNumber; } normalize = true; }