Ejemplo n.º 1
0
        private static PoseFile.Bone StringToBone(string?rot = null, string?scale = null, string?position = null)
        {
            PoseFile.Bone bone = new PoseFile.Bone();

            if (!string.IsNullOrEmpty(rot) && rot != "null")
            {
                byte[] data = StringToByteArray(rot);

                Quaternion value = default;
                value.X       = BitConverter.ToSingle(data, 0);
                value.Y       = BitConverter.ToSingle(data, 4);
                value.Z       = BitConverter.ToSingle(data, 8);
                value.W       = BitConverter.ToSingle(data, 12);
                bone.Rotation = value;
            }

            if (!string.IsNullOrEmpty(scale) && scale != "null")
            {
                byte[] data = StringToByteArray(scale);

                Vector value = default;
                value.X    = BitConverter.ToSingle(data, 0);
                value.Y    = BitConverter.ToSingle(data, 4);
                value.Z    = BitConverter.ToSingle(data, 8);
                bone.Scale = value;
            }

            return(bone);
        }
Ejemplo n.º 2
0
        public PoseFile Upgrade(Appearance.Races race)
        {
            PoseFile file       = new PoseFile();
            Type     legacyType = this.GetType();

            if (this.Race == null)
            {
                throw new Exception("Legacy pose file has no race specified");
            }

            Appearance.Races fileRace = (Appearance.Races) byte.Parse(this.Race);
            file.Bones = new Dictionary <string, PoseFile.Bone?>();

            PropertyInfo[] props = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
            foreach (PropertyInfo propertyInfo in props)
            {
                string boneName = propertyInfo.Name;

                if (boneName == "Race")
                {
                    continue;
                }

                if (boneName.EndsWith("Size"))
                {
                    continue;
                }

                if (boneName == "Type")
                {
                    continue;
                }

                PropertyInfo?rotProp   = legacyType.GetProperty(boneName);
                PropertyInfo?scaleProp = legacyType.GetProperty(boneName + "Size");

                if (boneName.StartsWith(@"Hroth") && fileRace != Appearance.Races.Hrothgar)
                {
                    continue;
                }

                if (boneName.StartsWith("Viera") && fileRace != Appearance.Races.Viera)
                {
                    continue;
                }

                boneName = boneName.Replace(@"Hroth", string.Empty);
                boneName = boneName.Replace(@"Viera", string.Empty);

                string?rotString   = null;
                string?scaleString = null;

                if (rotProp != null)
                {
                    rotString = (string?)rotProp.GetValue(this);
                }

                if (scaleProp != null)
                {
                    scaleString = (string?)scaleProp.GetValue(this);
                }

                if (rotString == null && scaleString == null)
                {
                    continue;
                }

                PoseFile.Bone bone = StringToBone(rotString, scaleString);

                if (file.Bones.ContainsKey(boneName))
                {
                    file.Bones.Remove(boneName);
                }

                file.Bones.Add(boneName, bone);
            }

            return(file);
        }