I am trying a complete my method, which crops Maya-Animations (from Maya-Models) to specific ones using the SkinnedModelProcessor.
My only problem is, that after one animation-loop completes, the model stays in its last position for about 2-3 seconds until he catches up to the run-cycle again.
My goal is to get rid of that freeze time. I want to loop it seamlessly.
Here is what I wrote:
public AnimationClip getCurrentAnimation(string clipName, string cropName, float blendTime, int beginFrame, int endFrame, int totalFrames)
{
//The new list which only has the specific keyframes
List<Keyframe> region = new List<Keyframe>();
//The original clip "Take 001" from Maya, which has every
//animation in one timeline
AnimationClip clip = _skinningData.AnimationClips[clipName];
//The new duration of the cropped clip
int duration = 0;
//Since XNA makes 7502 frames out of 21, I have to
//calc the region-keyframes to proper numbers
if (endFrame == 0)
endFrame = clip.Keyframes.Count;
else
endFrame = ((endFrame * clip.Keyframes.Count) / totalFrames);
beginFrame = ((beginFrame * clip.Keyframes.Count) / totalFrames);
//Start to sort out
for (int i = beginFrame; i < endFrame; i += 1)
{
Keyframe k = clip.Keyframes[i];
//Add duration of 16 (60fps) to overall-length
//of animation, if this keyframe does some "real"
//transformation, instead of being a static keyframe of XNA
if (k.Time.Milliseconds > duration)
duration += 16;
k.Time = TimeSpan.FromMilliseconds(duration);
region.Add(k);
}
AnimationClip cropped = new AnimationClip(cropName, TimeSpan.FromMilliseconds(duration), region);
return cropped;
}