//Allow user of this method to optionally pass in a stance for a more detailed lookup. public FacialAnimationData GetFacialAnimation(string type, string actionID, InteractionAnimationType interactionType, Stance stance) { try { if (this.databases.ContainsKey(type)) { actionID = actionID.ToLower(); List <FacialAnimationData> list = this.databases[type]; FacialAnimationData item = null; //Track how many recursive runs we have done, so we dont run into stack overflows. this.searchDepth += 1; for (int i = 0; i < list.Count; i++) { FacialAnimationData currentItem = list[i]; if (string.Compare(currentItem.ID, actionID, true) == 0 && currentItem.Stance == (int)stance && currentItem.InteractionType == interactionType) { item = currentItem; break; } } //We did not find a excakt match for the facial animation we where looking for, try to find an approximate hit. if (item == null && this.searchDepth <= MaxSearchDepth) { //If first iteration fails we use lookup based on stance. if (searchDepth == 1) { if ((stance & Stance.UseStanding) != 0) { item = GetFacialAnimation(type, actionID, interactionType, Stance.StandingNormal); } if ((stance & Stance.UseSitting) != 0) { item = GetFacialAnimation(type, actionID, interactionType, Stance.SittingNormal); } } //Else we default to standing stance. else { item = GetFacialAnimation(type, actionID, interactionType, Stance.StandingNormal); } } //Reset for the next caller. this.searchDepth = 0; return(item); } } catch (Exception e) { //CrashHelp.Report("AnimationMetaDatabase", e.Message, e); } return(null); }
public FacialAnimationClip ConstructFacialAnimationClip(string type, string actionID, string stance, InteractionAnimationType interactionType = InteractionAnimationType.Null) { FacialAnimationData data = FacialAnimationDatabase.Instance.GetFacialAnimation(type, actionID, interactionType, AnimationUtilities.StanceStringToEnum(stance)); if (data != null) { FacialAnimationClip clip = FillAnimationClip(data); return(clip); } return(null); }
//Fill clip with animation channels from animation data from the database. FacialAnimationClip FillAnimationClip(FacialAnimationData data) { //Create animation clip to fill. FacialAnimationClip clip = new FacialAnimationClip(data.ID, this.baseChannels, FRAMERATE); for (int i = 0; i < data.RotationChannels.Count; i++) { RotationFacialAnimationChannel channelData = data.RotationChannels[i]; RotationChannel rotationChannel = new RotationChannel(channelData.ChannelName, channelData.Keys, channelData.CanLoop, channelData.CanMirror, false, false, FRAMERATE); clip.AddAnimationChannel(rotationChannel); } for (int i = 0; i < data.MorphChannels.Count; i++) { MorphFacialAnimationChannel channelData = data.MorphChannels[i]; MorphChannel morphChannel = new MorphChannel(channelData.ChannelName, channelData.Keys, channelData.CanLoop, channelData.CanMirror, false, false, FRAMERATE); clip.AddAnimationChannel(morphChannel); } return(clip); }