Beispiel #1
0
        public static async Task <Configuration> Save(ActorViewModel?actor, SkeletonVisual3d?skeleton, Configuration?config = null)
        {
            if (config == null)
            {
                config = new Configuration();
            }

            if (actor == null || skeleton == null)
            {
                return(config);
            }

            SaveResult result = await FileService.Save <PoseFile>();

            if (string.IsNullOrEmpty(result.Path) || result.Info == null)
            {
                return(config);
            }

            PoseFile file = new PoseFile();

            file.WriteToFile(actor, skeleton, config);

            using FileStream stream = new FileStream(result.Path, FileMode.Create);
            result.Info.SerializeFile(file, stream);
            return(config);
        }
Beispiel #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);
        }
Beispiel #3
0
        public PoseFile Upgrade(Appearance.Races race)
        {
            PoseFile file = new PoseFile();

            file.Config.IncludeRotation = true;
            file.Config.IncludePosition = false;
            file.Config.IncludeScale    = true;
            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);

            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;
                }

                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;
                }

                Transform transform = StringToBone(rotString, scaleString);

                int index;
                if (SkeletonUtility.BodyBoneIndexLookup.TryGetValue(boneName, out index))
                {
                    if (file.Body == null)
                    {
                        file.Body = new List <PoseFile.Bone?>();
                    }

                    while (file.Body.Count <= index)
                    {
                        file.Body.Add(null);
                    }

                    file.Body[index] = new PoseFile.Bone(transform);
                }
                else if (SkeletonUtility.HeadBoneIndexLookup.TryGetValue(boneName, out index))
                {
                    if (file.Head == null)
                    {
                        file.Head = new List <PoseFile.Bone?>();
                    }

                    while (file.Head.Count <= index)
                    {
                        file.Head.Add(null);
                    }

                    file.Head[index] = new PoseFile.Bone(transform);
                }
                else if (SkeletonUtility.HairBoneIndexLookup.TryGetValue(boneName, out index))
                {
                    if (file.Hair == null)
                    {
                        file.Hair = new List <PoseFile.Bone?>();
                    }

                    while (file.Hair.Count <= index)
                    {
                        file.Hair.Add(null);
                    }

                    file.Hair[index] = new PoseFile.Bone(transform);
                }
                else if (SkeletonUtility.MetBoneIndexLookup.TryGetValue(boneName, out index))
                {
                    if (file.Met == null)
                    {
                        file.Met = new List <PoseFile.Bone?>();
                    }

                    while (file.Met.Count <= index)
                    {
                        file.Met.Add(null);
                    }

                    file.Met[index] = new PoseFile.Bone(transform);
                }
                else if (SkeletonUtility.TopBoneIndexLookup.TryGetValue(boneName, out index))
                {
                    if (file.Top == null)
                    {
                        file.Top = new List <PoseFile.Bone?>();
                    }

                    while (file.Top.Count <= index)
                    {
                        file.Top.Add(null);
                    }

                    file.Top[index] = new PoseFile.Bone(transform);
                }
                else
                {
                    throw new Exception("Failed to find index for bone: " + boneName);
                }
            }

            return(file);
        }