/// <summary> /// Bind all contained animations to the animation instance. /// </summary> /// <param name="inst"></param> public void Bind(AnimationInstance inst) { for (int i = 0; i < animData.Length; ++i) { animData[i].Bind(inst); } }
/// <summary> /// Attempt to make an animation instance, return null if /// there isn't one to be made (e.g. the model isn't animated). /// </summary> /// <param name="model"></param> /// <returns></returns> public static AnimationInstance TryMake(Model model) { AnimationInstance inst = new AnimationInstance(); inst.animDict = Animation.Dict.Extract(model); if (inst.animDict == null) { return(null); } inst.boneDict = Bone.Dict.Extract(model.Bones); if (inst.boneDict == null) { return(null); } inst.skinList = SkinDataList.Extract(model); if (inst.skinList == null) { return(null); } if (!inst.Bind()) { return(null); } return(inst); }
public AnimatorList(FBXModel model) { /// Note these are only setting up capacity, they're still empty. animList = new List <AnimationInstance>(model.NumLODs); restPalettes = new List <Matrix[]>(model.NumLODs); lastUpdates = new List <int>(model.NumLODs); for (int lod = 0; lod < model.NumLODs; ++lod) { AnimationInstance animator = model.MakeAnimator(lod); if (animator != null) { animList.Add(animator); lastUpdates.Add(0); Matrix[] animPalette = animList[lod].Palette; int boneCount = animPalette.Length; Matrix[] palette = new Matrix[boneCount]; for (int bone = 0; bone < boneCount; ++bone) { palette[bone] = animPalette[bone]; } restPalettes.Add(palette); } } }
/// <summary> /// Compute the localToParent values we know about, leaving the rest alone. /// localToParent has already been populated with default values. /// </summary> /// <param name="inst"></param> /// <param name="localToParent"></param> internal override void GetTransforms(AnimationInstance inst, Matrix[] localToParent) { int numBones = inst.NumBones; CheckLocalToParent(localToParent, numBones); for (int i = 0; i < animations.Count; ++i) { BaseController anim = animations[i]; float wgt = anim.Weight; if (wgt > 0) { ReZero(numBones); anim.GetTransforms(inst, _childLocalToParent); for (int j = 0; j < numBones; ++j) { if (_childLocalToParent[j].M44 != 0) { localToParent[j] += _childLocalToParent[j] * wgt; } else { localToParent[j] += _defaults[j] * wgt; } } } } }
/// <summary> /// Bind self to animation instance. This just means building the /// key index to bone index lookup table. /// </summary> /// <param name="inst"></param> private void Bind(AnimationInstance inst) { keyIdxToBoneIdx = new int[KeysList.Length]; for (int i = 0; i < keyIdxToBoneIdx.Length; ++i) { keyIdxToBoneIdx[i] = inst.BoneIndex(KeysList[i].BoneName); } }
public void ApplyController(BaseController activeController) { for (int lod = 0; lod < animList.Count; ++lod) { AnimationInstance animator = animList[lod]; animator.SetAnimation(activeController); SetRestPalette(lod); } }
/// <summary> /// Try to make a simple controller of animation from inst named "name". If that's /// not found, try "backup". Will return null if neither is found. /// </summary> /// <param name="inst"></param> /// <param name="name"></param> /// <param name="backup"></param> /// <returns></returns> public static SimpleController TryMake(AnimationInstance inst, string name, string backup) { Animation anim = inst.FindAnimation(name); if ((anim == null) && (backup != null)) { anim = inst.FindAnimation(backup); } return(anim != null ? new SimpleController(inst, anim) : null); }
public AnimationInstance this[int lod] { get { AnimationInstance ret = null; if (lod < Count) { ret = animList[lod]; } return(ret); } }
/// <summary> /// Compute the localToParent values we know about, leaving the rest alone. /// localToParent has already been populated with default values. /// </summary> /// <param name="inst"></param> /// <param name="localToParent"></param> internal override void GetTransforms(AnimationInstance inst, Matrix[] localToParent) { Animation animation = inst.FindAnimation(animName); Debug.Assert(Weight > 0); if (animation != null) { BoneKeys[] keyList = animation.KeysList; int keyIdx = keyList[0].IndexAtTime(CurrentTicks); for (int i = 0; i < keyList.Length; ++i) { int boneIdx = animation.KeyIndexToBoneIndex(i); localToParent[boneIdx] = keyList[i].AtIndex(keyIdx); } } }
/// <summary> /// Compute the localToParent values we know about, leaving the rest alone. /// localToParent has already been populated with default values. /// </summary> /// <param name="inst"></param> /// <param name="localToParent"></param> internal abstract void GetTransforms(AnimationInstance inst, Matrix[] localToParent);
/// <summary> /// Try to make a simple controller of the animation of given name /// in the container inst. May return null (e.g. if the named animation doesn't exist). /// </summary> /// <param name="inst"></param> /// <param name="name"></param> /// <returns></returns> public static SimpleController TryMake(AnimationInstance inst, string name) { return(TryMake(inst, name, null)); }
/// <summary> /// Internal constructor from an instance and an animation within that instance. /// </summary> /// <param name="inst"></param> /// <param name="anim"></param> internal SimpleController(AnimationInstance inst, Animation anim) { animName = anim.Name; duration = anim.Duration; }
private readonly string name; // currently debug only. #endregion Members #region Accessors #endregion Accessors #region Public /// <summary> /// Constructor. /// </summary> /// <param name="inst"></param> /// <param name="name"></param> public BlendController(AnimationInstance inst, string name) { this.name = name; this.Weight = 1.0f; }