private static void ProcessAnimation(AnimationClip clip, MouthModel mouthModel, Transform animationRoot, Transform jawRoot) { var bindings = AnimationUtility.GetCurveBindings(clip); var uBinding = bindings.FirstOrDefault(binding => binding.propertyName == "material._MainTex_mouth_ST.z"); var vBinding = bindings.FirstOrDefault(binding => binding.propertyName == "material._MainTex_mouth_ST.w"); if (uBinding.path == null || vBinding.path == null) { Debug.LogWarning("Couldn't find animation binding for clip " + clip.name); return; } var uCurve = AnimationUtility.GetEditorCurve(clip, uBinding); var vCurve = AnimationUtility.GetEditorCurve(clip, vBinding); var snapshotsAtPath = new Dictionary<string, AnimationSnapshotData>(); for (int i = 0; i < uCurve.keys.Length; i++) { // We can assume that that the curves for the U and V value have the same keyframes Vector2 uvValue = new Vector2(uCurve.keys[i].value, vCurve.keys[i].value); mouthModel.CurrentPoseIndex = RtdxTextureToMouthType.ContainsKey(uvValue) ? RtdxTextureToMouthType[uvValue] : 0; TraverseRig(jawRoot, snapshotsAtPath, GetRelativePath(jawRoot, animationRoot), uCurve.keys[i].time); } foreach (var snapshot in snapshotsAtPath) { snapshot.Value.ApplyToClip(clip); clip.EnsureQuaternionContinuity(); } AnimationHelpers.SetAnimationTangentsToConstant(clip); }
public static void CreateSkeletalMouthAnimationsFromTextureAnimations(List<AnimationClip> textureAnimations, MouthModel mouthModel, Transform animationRoot) { var jawRoot = animationRoot.FindDeepChild("RootJaw"); if (jawRoot == null) { Debug.LogError("Couldn't create mouth animation since RootJaw bone is missing."); return; } foreach (var textureAnimation in textureAnimations) { ProcessAnimation(textureAnimation, mouthModel, animationRoot, jawRoot); } }