/// <summary> /// Construct an AnimationPlayer to play the clip /// </summary> /// <param name="model"></param> /// <param name="clip"></param> public AnimationPlayer(AnimatedModel model, AnimationClips.Clip clip) { this.model = model; this.clip = clip; Initialize(); }
private void ProcessAnimationRecursive(NodeContent input, AnimationClips animationClips) { foreach(KeyValuePair<string, AnimationContent> animation in input.Animations) { // do we have this animation before? AnimationClips.Clip clip; if (!animationClips.Clips.TryGetValue(animation.Key, out clip)) { //never before seen clip System.Diagnostics.Trace.WriteLine("New clip: " + animation.Key); clip = new AnimationClips.Clip(); clip.Name = animation.Key; clip.Duration = animation.Value.Duration.TotalSeconds; clip.Keyframes = new List<AnimationClips.Keyframe>[bones.Count]; for (int b = 0; b < bones.Count; b++) clip.Keyframes[b] = new List<AnimationClips.Keyframe>(); animationClips.Clips[animation.Key] = clip; } //for each canell, determine the bone and then process all of the keyframes for that bone foreach (KeyValuePair<string, AnimationChannel> channel in animation.Value.Channels) { // what is the bone index? int boneIndex; if (!bones.TryGetValue(channel.Key, out boneIndex)) continue; //ignore if not a named bone foreach (AnimationKeyframe keyframe in channel.Value) { Matrix transform = keyframe.Transform; //keyframe transformation AnimationClips.Keyframe newKeyFrame = new AnimationClips.Keyframe(); newKeyFrame.Time = keyframe.Time.TotalSeconds; transform.Right = Vector3.Normalize(transform.Right); transform.Up = Vector3.Normalize(transform.Up); transform.Backward = Vector3.Normalize(transform.Backward); newKeyFrame.Rotation = Quaternion.CreateFromRotationMatrix(transform); newKeyFrame.Translastion = transform.Translation; clip.Keyframes[boneIndex].Add(newKeyFrame); } } } //System.Diagnostics.Trace.WriteLine(input.Name); foreach (NodeContent child in input.Children) { ProcessAnimationRecursive(child, animationClips); } }
protected override AnimationClips Read(ContentReader input, AnimationClips existingInstance) { AnimationClips clips = new AnimationClips(); // Determine how many clips there are. int clipCnt = input.ReadInt32(); for (int c = 0; c < clipCnt; c++) { // Create a clip and load it up AnimationClips.Clip clip = new AnimationClips.Clip(); clip.Name = input.ReadString(); clip.Duration = input.ReadDouble(); // Determine how many bones there are. int boneCnt = input.ReadInt32(); clip.Keyframes = new List <AnimationClips.Keyframe> [boneCnt]; for (int i = 0; i < boneCnt; i++) { // Determine how many keyframes there are. int cnt = input.ReadInt32(); List <AnimationClips.Keyframe> boneKeyframes = new List <AnimationClips.Keyframe>(cnt); clip.Keyframes[i] = boneKeyframes; for (int j = 0; j < cnt; j++) { AnimationClips.Keyframe keyframe = new AnimationClips.Keyframe(); keyframe.Time = input.ReadDouble(); keyframe.Rotation = input.ReadQuaternion(); keyframe.Translastion = input.ReadVector3(); boneKeyframes.Add(keyframe); } } clips.Clips[clip.Name] = clip; } return(clips); }
public AnimationPlayer(AnimationClips.Clip clip) { this.clip = clip; }
/// <summary> /// Play an animation clip on this model. /// </summary> /// <param name="name"></param> public AnimationPlayer PlayClip(string name) { player = null; AnimationClips clips = model.Tag as AnimationClips; /* if (clips != null && clips.Clips.Count > 0) { clip = clips.Clips[name]; player = new AnimationPlayer(clip); player.Looping = false; player.Initialize(); Update(0); } * */ if (assetClips.Count > 0) { clip = assetClips[name].TheClip; player = new AnimationPlayer(clip); player.Looping = false; player.Initialize(); Update(0); } return player; }
public AnimationPlayer(AnimationClips.Clip clips) { clip = clips; }
/// <summary> /// Recursive function that processes the entire scene graph, collecting up /// all of the animation data. /// </summary> /// <param name="input">The input scene graph node</param> /// <param name="animationClips">The animation clips object we put animation in</param> private void ProcessAnimationsRecursive(NodeContent input, AnimationClips animationClips) { foreach (KeyValuePair<string, AnimationContent> animation in input.Animations) { // Do we have this animation before? AnimationClips.Clip clip; if (!animationClips.Clips.TryGetValue(animation.Key, out clip)) { // Never before seen clip // System.Diagnostics.Trace.WriteLine("New clip: " + animation.Key); clip = new AnimationClips.Clip(); clip.Name = animation.Key; clip.Duration = animation.Value.Duration.TotalSeconds; clip.Keyframes = new List<AnimationClips.Keyframe>[bones.Count]; for (int b = 0; b < bones.Count; b++) clip.Keyframes[b] = new List<AnimationClips.Keyframe>(); animationClips.Clips[animation.Key] = clip; } else if (animation.Value.Duration.TotalSeconds > clip.Duration) { clip.Duration = animation.Value.Duration.TotalSeconds; } // // For each channel, determine the bone and then process all of the // keyframes for that bone. // foreach (KeyValuePair<string, AnimationChannel> channel in animation.Value.Channels) { // What is the bone index? int boneIndex; // Get rid of unnamed bones if (!bones.TryGetValue(channel.Key, out boneIndex)) { continue; // Ignore if not a named bone } // Get rid of useless animations if (!skinned && IsUselessAnimation(boneIndex)) { // System.Diagnostics.Debug.WriteLine("Removed " + boneIndex.ToString()); continue; // Ignore if useless } foreach (AnimationKeyframe keyframe in channel.Value) { Matrix transform = keyframe.Transform; // Keyframe transformation AnimationClips.Keyframe newKeyframe = new AnimationClips.Keyframe(); newKeyframe.Time = keyframe.Time.TotalSeconds; transform.Right = Vector3.Normalize(transform.Right); transform.Up = Vector3.Normalize(transform.Up); transform.Backward = Vector3.Normalize(transform.Backward); newKeyframe.Rotation = Quaternion.CreateFromRotationMatrix(transform); newKeyframe.Translation = transform.Translation; clip.Keyframes[boneIndex].Add(newKeyframe); } // Linear keyframe reduction (remove from clip.Keyframes) System.Diagnostics.Debug.WriteLine(clip.Keyframes[boneIndex].Count); LinkedList<AnimationClips.Keyframe> keyframes = new LinkedList<AnimationClips.Keyframe>(); foreach (AnimationClips.Keyframe keyframe in clip.Keyframes[boneIndex]) { keyframes.AddLast(keyframe); } LinearKeyframeReduction(keyframes); clip.Keyframes[boneIndex] = keyframes.ToList<AnimationClips.Keyframe>(); System.Diagnostics.Debug.WriteLine(clip.Keyframes[boneIndex].Count); } } // System.Diagnostics.Trace.WriteLine(input.Name); foreach (NodeContent child in input.Children) { ProcessAnimationsRecursive(child, animationClips); } }
/// <summary> /// Play an animation clip on this model. /// </summary> /// <param name="name"></param> public AnimationClips.Clip PlayClip(string name) { AnimationClips clips = model.Tag as AnimationClips; if (clips != null) { clip = clips.Clips[name]; player = new AnimationPlayer(clip); player.Initialize(); } return clip; }