private void UpdateBlendshapes(FaceDataFrame curFrame, FaceDataFrame nextFrame, float frameDif) { for (int i = 0; i < currentData.blendShapesNames.Length; i++) { int index = jsonToUnityBlendMap[i]; if (index == -1) { continue; } float blendshapeVal; if (!useInterpolation) { blendshapeVal = curFrame.blendshapes[i]; } else { var curVal = curFrame.blendshapes[i]; var nextVal = nextFrame.blendshapes[i]; blendshapeVal = Mathf.Lerp(curVal, nextVal, frameDif); } target.SetBlendShapeWeight(index, blendshapeVal); } }
private void UpdateBones(FaceDataFrame curFrame, FaceDataFrame nextFrame, float frameDif) { if (!animateBones || currentData.bonesNames == null) { return; } for (int i = 0; i < currentData.bonesNames.Length; i++) { int index = jsonToUnityBoneMap[i]; if (index == -1) { continue; } Quaternion boneRotation; if (!useInterpolation) { boneRotation = curFrame.bones[i].Transform.rotation; } else { var curBoneRotation = curFrame.bones[i].Transform.rotation; var nextBoneRotation = nextFrame.bones[i].Transform.rotation; boneRotation = Quaternion.Lerp(curBoneRotation, nextBoneRotation, frameDif); } var bone = bones[index]; bone.transform.localRotation = bone.ApplyBoneTransformation(boneRotation); } }
private IEnumerator BlendTo(float blendingTime, FaceDataFrame targetFrame) { var initFrame = GenerateCurrentFrame(); float curTime = 0f; while (curTime < blendingTime) { float frameDif = curTime / blendingTime; UpdateBlendshapes(initFrame, targetFrame, frameDif); UpdateBones(initFrame, targetFrame, frameDif); curTime += Time.deltaTime; yield return(null); } }