Beispiel #1
0
        private async void OnOpenClicked(object sender, RoutedEventArgs e)
        {
            SkeletonViewModel vm = this.DataContext as SkeletonViewModel;

            try
            {
                IFileService fileService = Services.Get <IFileService>();
                FileBase     file        = await fileService.OpenAny(PoseFile.FileType, LegacyPoseFile.FileType);

                if (file == null)
                {
                    return;
                }

                if (file is LegacyPoseFile legacyFile)
                {
                    file = legacyFile.Upgrade(vm.Race);
                }

                IViewService    viewService = Services.Get <IViewService>();
                PoseFile.Groups groups      = await viewService.ShowDialog <BoneGroupsSelectorDialog, PoseFile.Groups>("Load Pose...");

                if (groups == PoseFile.Groups.None)
                {
                    return;
                }

                if (file is PoseFile poseFile)
                {
                    await poseFile.Write(vm, groups);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, "Pose", Log.Severity.Error);
            }
        }
Beispiel #2
0
        public async Task Write(SkeletonViewModel skeleton, Configuration config)
        {
            PoseService poseService = Services.Get <PoseService>();

            poseService.IsEnabled = true;

            // don't freeze positions if we aren't writing any
            poseService.FreezePositions = this.Config.IncludePosition;

            foreach (Bone bone in skeleton.Bones)
            {
                if (!bone.IsEnabled)
                {
                    continue;
                }

                Groups group = Enum.Parse <Groups>(bone.Definition.Group);
                if (!config.Groups.HasFlag(group))
                {
                    continue;
                }

                if (this.Bones.ContainsKey(bone.BoneName))
                {
                    try
                    {
                        this.Bones[bone.BoneName].Rotation.Normalize();

                        Transform trans    = bone.LiveTransform;
                        Transform newTrans = this.Bones[bone.BoneName];

                        if (config.IncludeScale && this.Config.IncludeScale && newTrans.Scale != Vector.Zero)
                        {
                            trans.Scale = newTrans.Scale;
                        }

                        if (config.IncludePosition && this.Config.IncludePosition && newTrans.Position != Vector.Zero)
                        {
                            trans.Position = newTrans.Position;
                        }

                        if (config.IncludeRotation && this.Config.IncludeRotation)
                        {
                            trans.Rotation = newTrans.Rotation;
                        }

                        bone.LiveTransform = trans;
                        bone.ReadTransform();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to apply pose transform to bone: " + bone.BoneName, ex);
                    }
                }
            }

            await Task.Delay(100);

            poseService.FreezePositions = true;

            skeleton.RefreshBones();
        }