/// <summary> /// Find a bone's index in the skeleton's list. /// </summary> /// <param name="bone">The bone to find.</param> /// <returns>The index of the bone.</returns> public int FindBone(Bone bone) { //Return the index of the bone. return (_Bones.FindIndex(b => (b.Equals(bone)))); }
/// <summary> /// Add a bone to the skeleton. /// </summary> /// <param name="bone">The bone to add.</param> public void AddBone(Bone bone) { //Add a bone to the skeleton. _Bones.Add(bone); //Make sure the bone is aware of this skeleton. _Bones[_Bones.Count - 1].Skeleton = this; //Set the index of this bone if it has not been already set. if (_Bones[_Bones.Count - 1].Index == -1) { _Bones[_Bones.Count - 1].Index = (_Bones.Count - 1); } }
/// <summary> /// Add a bone to a keyframe, thus enabling that bone to be animated. /// </summary> /// <param name="animationIndex">The index of the particular animation.</param> /// <param name="keyframeIndex">The index of the particular keyframe.</param> /// <param name="bone">A copy of the bone to animate, only modified to portray the final composition of that bone. This is what the bone will animate into.</param> public void AddBoneToBe(int animationIndex, int keyframeIndex, Bone bone) { //Add a bone to be the keyframe a keyframe of an animation. _Animations[animationIndex].Keyframes[keyframeIndex].AddBone(bone); }
/// <summary> /// Get the blend factor for a specified bone at the current phase of the animation. /// This includes both the bone's unique blending factor in the upcoming keyframe and the overall strength of the animation. /// </summary> /// <param name="bone">The bone in question.</param> /// <returns>The blend factor of this bone.</returns> public float GetBlendFactor(Bone bone) { //If the bone has found home in any keyframe, return the next keyframe's blend factor for it. if (_Keyframes.Exists(kf => (kf.ExistsBone(bone.Index)))) { return (GetNextKeyframe(bone).GetBlendFactor(bone) * _Strength); } //If not, return zero. return 0; }
/// <summary> /// Find the previous keyframe that modified a certain bone. /// </summary> /// <param name="bone">The bone that the previous keyframe modified.</param> public Keyframe GetPreviousKeyframe(Bone bone) { //Return the keyframe. return GetPreviousKeyframe(bone.Index, _CurrentFrameIndex); }
/// <summary> /// Deep clone this bone. /// </summary> public Bone DeepClone() { //Create a blank bone. Bone bone = new Bone(); //Add all the data to it. bone.Skeleton = _Skeleton; bone.Name = _Name; bone.Index = _Index; bone.ParentIndex = _ParentIndex; bone.RootBone = _RootBone; bone.AbsolutePosition = _AbsolutePosition; bone.AbsoluteRotation = _AbsoluteRotation; bone.RelativeDirection = _RelativeDirection; bone.Scale = _Scale; bone.Length = _Length; //Return the deep cloned bone. return bone; }
/// <summary> /// Add a bone to the keyframe, thus enabling an animation to occur with that bone. /// </summary> /// <param name="bone">A copy of a bone modified to act as an animation goal for the source bone.</param> public void AddBone(Bone bone) { //If the bone has been added before, swap that bone with this one. if (ExistsBone(bone.Index)) { SwapBone(bone); } //Otherwise just add a bone to be into the list and create a default blend factor. else { _BonesToBe.Add(bone); _BlendFactors.Add(1f); } }
/// <summary> /// Swap a bone with another bone. /// </summary> /// <param name="bone">The bone to swap.</param> public void SwapBone(Bone bone) { //Swap the bones. if (ExistsBone(bone.Index)) { _BonesToBe[GetBonePosition(bone.Index)] = bone; } }
/// <summary> /// Remove a bone from the keyframe. /// </summary> /// <param name="bone">The bone to remove from the keyframe.</param> public void RemoveBone(Bone bone) { //Try and remove a bone to be from the list. try { _BonesToBe.Remove(bone); } catch { } }
/// <summary> /// Get the blend factor for a certain bone. /// </summary> /// <param name="bone">The bone.</param> /// <returns>The blend factor.</returns> public float GetBlendFactor(Bone bone) { //If the bone exists in the keyframe, return its blend factor. if (ExistsBone(bone.Index)) { return _BlendFactors[GetBonePosition(bone.Index)]; } //If no bone was found, return zero. return 0; }