Beispiel #1
0
        public GenericBone[] GetChildren(GenericBone b)
        {
            var index = Bones.IndexOf(b);

            if (index == -1)
            {
                return(null);
            }
            return(Bones.Where(e => e.ParentIndex == index).ToArray());
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="BoneIndex"></param>
        /// <returns></returns>
        public Matrix4 GetWorldTransform(int BoneIndex)
        {
            if (BoneIndex > Bones.Count || BoneIndex < 0)
            {
                return(Matrix4.Identity);
            }

            GenericBone b = Bones[BoneIndex];

            return(GetWorldTransform(b));
        }
Beispiel #3
0
        private void GetBreathFirst(GenericBone bone, List <GenericBone> bones)
        {
            bones.Add(bone);

            var index = Bones.IndexOf(bone);

            foreach (var v in Bones.FindAll(e => e.ParentIndex == index))
            {
                GetBreathFirst(v, bones);
            }
        }
Beispiel #4
0
        private void BoneWorldToRelativeTransform(GenericBone b)
        {
            if (b.ParentIndex != -1)
            {
                Matrix4 parentT = GetWorldTransform(b.ParentIndex).Inverted();
                b.Transform = parentT * b.Transform;
            }

            foreach (var child in GetChildren(b))
            {
                BoneWorldToRelativeTransform(child);
            }
        }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Bone"></param>
 /// <param name="animated"></param>
 /// <returns></returns>
 public Matrix4 GetWorldTransform(GenericBone Bone, bool animated = false)
 {
     if (Bone == null)
     {
         return(Matrix4.Identity);
     }
     if (Bone.ParentIndex == -1)
     {
         return(Bone.GetTransform(animated));
     }
     else
     {
         return(Bone.GetTransform(animated) * GetWorldTransform(Bones[Bone.ParentIndex], animated));
     }
 }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="skeleton"></param>
        public void UpdateSkeleton(float frame, GenericSkeleton skeleton)
        {
            foreach (var v in TransformNodes)
            {
                GenericBone bone = null;
                switch (v.HashType)
                {
                case AnimNodeHashType.Name:
                    bone = skeleton.Bones.Find(e => e.Name == v.Name);
                    break;

                case AnimNodeHashType.CRC32C:
                    bone = skeleton.Bones.Find(e => e.NameHash == v.Hash);
                    break;
                }
                if (bone != null)
                {
                    bone.AnimatedTransform = v.GetTransformAt(frame, bone);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Frame"></param>
        /// <param name="bone"></param>
        /// <returns></returns>
        public Matrix4 GetTransformAt(float Frame, GenericBone bone)
        {
            if (bone == null)
            {
                return(Matrix4.Identity);
            }

            GenericBone temp = new GenericBone();

            temp.Transform = bone.Transform;

            // temp for less matrix calculations
            Vector3 newPos = temp.Position;
            Vector3 newRot = temp.Rotation;
            Vector3 newSca = temp.Scale;

            foreach (var track in Tracks)
            {
                switch (track.Type)
                {
                case AnimationTrackFormat.TranslateX:
                    newPos.X = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.TranslateY:
                    newPos.Y = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.TranslateZ:
                    newPos.Z = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.RotateX:
                    newRot.X = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.RotateY:
                    newRot.Y = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.RotateZ:
                    newRot.Z = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.ScaleX:
                    newSca.X = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.ScaleY:
                    newSca.Y = track.Keys.GetValue(Frame);
                    break;

                case AnimationTrackFormat.ScaleZ:
                    newSca.Z = track.Keys.GetValue(Frame);
                    break;
                }
            }

            temp.Scale    = newSca;
            temp.Position = newPos;
            temp.Rotation = newRot;

            return(temp.Transform);
        }
Beispiel #8
0
 public int IndexOf(GenericBone Bone)
 {
     return(Bones.IndexOf(Bone));
 }