static Vector3 ComputeTranslationCurrentFrame(int boneIndex, AnimationClip.KeyFrame currentFrame, AnimationClip.KeyFrame nextFrame, float animationInterpolation) { var animationValueCurrentFrame = currentFrame.Position[boneIndex]; if (nextFrame != null) { var animationValueNextFrame = nextFrame.Position[boneIndex]; animationValueCurrentFrame = Vector3.Lerp(animationValueCurrentFrame, animationValueNextFrame, animationInterpolation); } return(animationValueCurrentFrame); }
static Quaternion ComputeRotationsCurrentFrame(int boneIndex, AnimationClip.KeyFrame currentFrame, AnimationClip.KeyFrame nextFrame, float animationInterpolation) { var animationValueCurrentFrame = currentFrame.Rotation[boneIndex]; if (nextFrame != null) { var animationValueNextFrame = nextFrame.Rotation[boneIndex]; animationValueCurrentFrame = Quaternion.Slerp(animationValueCurrentFrame, animationValueNextFrame, animationInterpolation); } animationValueCurrentFrame.Normalize(); return(animationValueCurrentFrame); }
static void ApplyAnimation(AnimationClip.KeyFrame currentFrame, AnimationClip.KeyFrame nextFrame, float animationInterpolation, AnimationFrame finalAnimationFrame, List <AnimationBoneMapping> rotMapping, List <AnimationBoneMapping> transMapping, AnimationBoneMappingType boneMappingMode) { if (currentFrame == null) { return; } for (int i = 0; i < finalAnimationFrame.BoneTransforms.Count(); i++) { if (transMapping[i].MappingType == boneMappingMode) { finalAnimationFrame.BoneTransforms[i].Translation = ComputeTranslationCurrentFrame(transMapping[i].Id, currentFrame, nextFrame, animationInterpolation); } if (rotMapping[i].MappingType == boneMappingMode) { finalAnimationFrame.BoneTransforms[i].Rotation = ComputeRotationsCurrentFrame(rotMapping[i].Id, currentFrame, nextFrame, animationInterpolation); } } }