//sets the first frame for the take and file (e.g. "Take 001", "dude") public void SetAnimation(string takeName, string fileNameNoSuffix) { AnimationDictionaryKey key = new AnimationDictionaryKey(takeName, fileNameNoSuffix); //have we requested a different animation and is it in the dictionary? //first time or different animation request if (this.oldKey == null || (!this.oldKey.Equals(key) && this.modelDictionary.ContainsKey(key))) { //set the model based on the animation being played this.Model = modelDictionary[key]; //retrieve the animation player animationPlayer = animationPlayerDictionary[key]; //retrieve the skinning data skinningData = skinningDataDictionary[key]; //set the skinning data in the animation player and set the player to start at the first frame for the take animationPlayer.StartClip(skinningData.AnimationClips[key.takeName]); } //store current key for comparison in next update to prevent re-setting the same animation in successive calls to SetAnimation() this.oldKey = key; }
public void AddAnimation(string takeName, string fileNameNoSuffix, Model model) { AnimationDictionaryKey key = new AnimationDictionaryKey(takeName, fileNameNoSuffix); //if not already added if (!this.modelDictionary.ContainsKey(key)) { this.modelDictionary.Add(key, model); //read the skinning data (i.e. the set of transforms applied to each model bone for each frame of the animation) skinningData = model.Tag as SkinningData; if (skinningData == null) { throw new InvalidOperationException("The model [" + fileNameNoSuffix + "] does not contain a SkinningData tag."); } //make an animation player for the model this.animationPlayerDictionary.Add(key, new AnimationPlayer(skinningData)); //store the skinning data for the model this.skinningDataDictionary.Add(key, skinningData); } }
//Why do we override equals and gethashcode? Clue: this.modelDictionary.ContainsKey() public override bool Equals(object obj) { AnimationDictionaryKey other = obj as AnimationDictionaryKey; return(this.takeName.Equals(other.takeName) && this.fileNameNoSuffix.Equals(other.fileNameNoSuffix)); }