Пример #1
0
        public bool AddBone(string parent, ESK_Bone boneToAdd)
        {
            if (parent == String.Empty)
            {
                ESKBones.Add(boneToAdd.Clone());
                return(true);
            }

            for (int i = 0; i < ESKBones.Count; i++)
            {
                if (ESKBones[i].Name == parent)
                {
                    ESKBones[i].ESK_Bones.Add(boneToAdd.Clone());
                    return(true);
                }

                if (ESKBones[i].ESK_Bones != null)
                {
                    bool result = AddBoneRecursive(parent, boneToAdd, ESKBones[i].ESK_Bones);

                    if (result == true)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public ESK_Bone GetBoneWithName(string name)
        {
            if (Name == name)
            {
                return(this);
            }
            if (ESK_Bones == null)
            {
                return(null);
            }

            foreach (var child in ESK_Bones)
            {
                if (child.Name == name)
                {
                    return(child);
                }

                ESK_Bone _children = child.GetBoneWithName(name);

                if (_children != null)
                {
                    return(_children);
                }
            }

            return(null);
        }
Пример #3
0
        public ESK_Bone GetBoneWithIndex(int index)
        {
            if (Index == index)
            {
                return(this);
            }
            if (ESK_Bones == null)
            {
                return(null);
            }

            foreach (var child in ESK_Bones)
            {
                if (child.Index == index)
                {
                    return(child);
                }

                ESK_Bone _children = child.GetBoneWithIndex(index);

                if (_children != null)
                {
                    return(_children);
                }
            }

            return(null);
        }
Пример #4
0
        private void ParseSkeleton(int offset)
        {
            //Init
            int unk1Offset = BitConverter.ToInt32(rawBytes, offset + 20) + offset;
            int unk2Offset = BitConverter.ToInt32(rawBytes, offset + 24) + offset;

            //Skeleton init
            eskFile.Skeleton = new ESK_Skeleton()
            {
                I_02     = BitConverter.ToInt16(rawBytes, offset + 2),
                I_28     = BitConverter_Ex.ToInt32Array(rawBytes, offset + 28, 2),
                Unk1     = ESK_Unk1.Read(rawBytes, unk1Offset),
                UseUnk2  = (unk2Offset != 0) ? true : false,
                ESKBones = new ObservableCollection <ESK_Bone>()
            };

            //Setting the offsets for the initial loop to use
            int[] offsets               = GetBoneOffset(0, offset);
            int   boneIndexOffset       = offsets[0];
            int   nameOffset            = offsets[1];
            int   skinningMatrixOffset  = offsets[2];
            int   transformMatrixOffset = offsets[3];

            while (true)
            {
                int      idx    = eskFile.Skeleton.ESKBones.Count;
                ESK_Bone parent = ESK_Bone.Read(bytes, rawBytes, offsets, _index, null);
                eskFile.Skeleton.ESKBones.Add(parent);
                _index += 1;
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 2) != -1)
                {
                    eskFile.Skeleton.ESKBones[idx].ESK_Bones = ParseChildrenBones(BitConverter.ToInt16(rawBytes, boneIndexOffset + 2), offset, parent);
                }
                //Loop management
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 4) != -1)
                {
                    //There is a sibling
                    offsets               = GetBoneOffset(BitConverter.ToInt16(rawBytes, boneIndexOffset + 4), offset);
                    boneIndexOffset       = offsets[0];
                    nameOffset            = offsets[1];
                    skinningMatrixOffset  = offsets[2];
                    transformMatrixOffset = offsets[3];
                }
                else
                {
                    //There is no sibling. End loop.
                    break;
                }
            }
        }
Пример #5
0
        private ObservableCollection <ESK_Bone> ParseChildrenBones(int indexOfFirstSibling, int offset, ESK_Bone parent)
        {
            ObservableCollection <ESK_Bone> newBones = new ObservableCollection <ESK_Bone>();

            int[] offsets               = GetBoneOffset(indexOfFirstSibling, offset);
            int   boneIndexOffset       = offsets[0];
            int   nameOffset            = offsets[1];
            int   skinningMatrixOffset  = offsets[2];
            int   transformMatrixOffset = offsets[3];

            while (true)
            {
                int      idx  = newBones.Count;
                ESK_Bone bone = ESK_Bone.Read(bytes, rawBytes, offsets, _index, parent);
                newBones.Add(bone);
                _index += 1;
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 2) != -1)
                {
                    newBones[idx].ESK_Bones = ParseChildrenBones(BitConverter.ToInt16(rawBytes, boneIndexOffset + 2), offset, bone);
                }
                //Loop management
                if (BitConverter.ToInt16(rawBytes, boneIndexOffset + 4) != -1)
                {
                    //There is a sibling
                    offsets               = GetBoneOffset(BitConverter.ToInt16(rawBytes, boneIndexOffset + 4), offset);
                    boneIndexOffset       = offsets[0];
                    nameOffset            = offsets[1];
                    skinningMatrixOffset  = offsets[2];
                    transformMatrixOffset = offsets[3];
                }
                else
                {
                    //There is no sibling. End loop.
                    break;
                }
            }

            return(newBones);
        }
Пример #6
0
        private bool AddBoneRecursive(string parent, ESK_Bone boneToAdd, ObservableCollection <ESK_Bone> eskBones)
        {
            for (int i = 0; i < eskBones.Count; i++)
            {
                if (eskBones[i].Name == parent)
                {
                    eskBones[i].ESK_Bones.Add(boneToAdd.Clone());
                    return(true);
                }

                if (eskBones[i].ESK_Bones != null)
                {
                    bool result = AddBoneRecursive(parent, boneToAdd, eskBones[i].ESK_Bones);

                    if (result == true)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #7
0
        public static ESK_Bone Read(List <byte> listBytes, byte[] bytes, int[] offsets, int idx, ESK_Bone parent = null)
        {
            int boneIndexOffset       = offsets[0];
            int nameOffset            = offsets[1];
            int skinningMatrixOffset  = offsets[2];
            int transformMatrixOffset = offsets[3];

            return(new ESK_Bone()
            {
                Index4 = BitConverter.ToInt16(bytes, boneIndexOffset + 6),
                Index = (short)idx,
                Name = Utils.GetString(listBytes, nameOffset),
                RelativeTransform = ESK_RelativeTransform.Read(bytes, skinningMatrixOffset),
                AbsoluteTransform = ESK_AbsoluteTransform.Read(bytes, transformMatrixOffset),
                Parent = parent
            });
        }