Exemplo n.º 1
0
        private static ConversionConfig PrepareConversionConfig([NotNull] MainWorkerInputParams ip)
        {
            var cc = new ConversionConfig();

            cc.MotionFormat                        = ip.MotionSource;
            cc.ScaleToPmxSize                      = ip.ScalePmx;
            cc.ApplyPmxCharacterHeight             = ip.ConsiderIdolHeight;
            cc.TranslateBoneNamesToMmd             = ip.TranslateBoneNames;
            cc.AppendIKBones                       = ip.AppendLegIkBones;
            cc.FixMmdCenterBones                   = ip.FixCenterBones;
            cc.FixTdaBindingPose                   = ip.ConvertBindingPose;
            cc.AppendEyeBones                      = ip.AppendEyeBones;
            cc.HideUnityGeneratedBones             = ip.HideUnityGeneratedBones;
            cc.SkeletonFormat                      = ip.MotionSource == MotionFormat.Mltd ? SkeletonFormat.Mltd : SkeletonFormat.Mmd;
            cc.TranslateFacialExpressionNamesToMmd = ip.TranslateFacialExpressionNames;
            cc.ImportPhysics                       = ip.ImportPhysics;
            cc.AddHairHighlights                   = ip.AddHairHighlights;
            cc.AddEyesHighlights                   = ip.AddEyesHighlights;

            cc.Transform60FpsTo30Fps = ip.TransformTo30Fps;
            cc.ScaleToVmdSize        = ip.ScaleVmd;

            {
                var mappingsJson = File.ReadAllText(ip.FacialExpressionMappingFilePath, Encoding.UTF8);
                var mappingsObj  = JsonConvert.DeserializeObject <FacialConfig>(mappingsJson);

                var dict = new Dictionary <int, IReadOnlyDictionary <string, float> >();

                foreach (var expr in mappingsObj.Expressions)
                {
                    var d2 = new Dictionary <string, float>();

                    foreach (var kv in expr.Data)
                    {
                        d2[kv.Key] = kv.Value;
                    }

                    dict[expr.Key] = d2;
                }

                cc.FacialExpressionMappings = dict;
            }

            return(cc);
        }
Exemplo n.º 2
0
 public MainWorker([NotNull] FMain form, [NotNull] MainWorkerInputParams inputParams)
 {
     _form        = form;
     _inputParams = inputParams;
 }
Exemplo n.º 3
0
        private void BtnGo_Click(object sender, EventArgs e)
        {
            void Alert(string text)
            {
                MessageBox.Show(text, ApplicationHelper.GetApplicationTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            bool Confirm(string text)
            {
                var r = MessageBox.Show(text, ApplicationHelper.GetApplicationTitle(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                return(r == DialogResult.Yes);
            }

            bool CheckInputParams()
            {
                bool CheckOutputDir(string filePath)
                {
                    var outputDirExists = !string.IsNullOrEmpty(filePath);

                    if (outputDirExists)
                    {
                        var file = new FileInfo(filePath);
                        var dir  = file.Directory;
                        outputDirExists = dir != null && dir.Exists;
                    }

                    if (!outputDirExists)
                    {
                        Alert($"Output folder of \"{filePath}\" does not exist.");
                    }

                    return(outputDirExists);
                }

                if (chkGenerateModel.Checked || chkGenerateCharAnim.Checked)
                {
                    if (!File.Exists(txtInputHead.Text))
                    {
                        Alert($"Head model \"{txtInputHead.Text}\" does not exist.");
                        return(false);
                    }

                    if (!File.Exists(txtInputBody.Text))
                    {
                        Alert($"Body model \"{txtInputBody.Text}\" does not exist.");
                        return(false);
                    }
                }

                if (chkGenerateModel.Checked)
                {
                    if (!CheckOutputDir(txtOutputModel.Text))
                    {
                        return(false);
                    }
                }

                if (chkOptApplyCharHeight.Checked)
                {
                    if (!uint.TryParse(txtOptCharHeight.Text, out var height) || (height <= 100 || 200 <= height))
                    {
                        Alert("Please enter a valid idol height.");
                    }
                }

                if (chkGenerateCharAnim.Checked)
                {
                    if (!File.Exists(txtInputDance.Text))
                    {
                        Alert($"Dance data \"{txtInputDance.Text}\" does not exist.");
                        return(false);
                    }

                    if (!CheckOutputDir(txtOutputCharAnim.Text))
                    {
                        return(false);
                    }
                }

                if (chkGenerateCharAnim.Checked || chkGenerateLipSync.Checked || chkGenerateFacialExpression.Checked || chkGenerateCameraMotion.Checked)
                {
                    if (!File.Exists(txtInputScenario.Text))
                    {
                        Alert($"Scenario data \"{txtInputScenario.Text}\" does not exist.");
                        return(false);
                    }
                }

                if (chkGenerateLipSync.Checked)
                {
                    if (!CheckOutputDir(txtOutputLipSync.Text))
                    {
                        return(false);
                    }
                }

                if (chkGenerateFacialExpression.Checked)
                {
                    if (!File.Exists(txtOptFEMappings.Text))
                    {
                        Alert($"Facial expression mapping file \"{txtOptFEMappings.Text}\" does not exist.");
                        return(false);
                    }

                    if (!CheckOutputDir(txtOutputFacialExpression.Text))
                    {
                        return(false);
                    }
                }

                if (chkGenerateCameraMotion.Checked)
                {
                    if (!File.Exists(txtInputCamera.Text))
                    {
                        Alert($"Camera data \"{txtInputCamera.Text}\" does not exist.");
                        return(false);
                    }

                    if (!CheckOutputDir(txtOutputCameraMotion.Text))
                    {
                        return(false);
                    }
                }

                if (radOptCamFormatVmd.Checked)
                {
                    if (!uint.TryParse(txtOptFixedFov.Text, out var u) || u == 0)
                    {
                        Alert($"FOV value \"{txtOptFixedFov.Text}\" should be a valid positive integer.");
                        return(false);
                    }
                }

                if (chkGenerateModel.Checked || chkGenerateCharAnim.Checked)
                {
                    if (!Regex.IsMatch(txtInputHead.Text, @"ch_[a-z]{2}\d{3}_(?:\d{3}[a-z]{3}|[a-z])(?:_v2)?\.unity3d$", RegexOptions.CultureInvariant))
                    {
                        Alert($"File \"{txtInputHead.Text}\" does not look like a character head file from the game.");
                        return(false);
                    }

                    if (!Regex.IsMatch(txtInputBody.Text, @"cb_[a-z]{2}\d{3}_(?:\d{3}[a-z]{3}|[a-z])\.unity3d$", RegexOptions.CultureInvariant))
                    {
                        Alert($"File \"{txtInputBody.Text}\" does not look like a character body file from the game.");
                        return(false);
                    }
                }

                if (chkGenerateCharAnim.Checked)
                {
                    if (!Regex.IsMatch(txtInputDance.Text, @"dan_[a-z0-9]{5}[a-z0-9+]_0[12345](?:\.imo)?\.unity3d$", RegexOptions.CultureInvariant))
                    {
                        Alert($"File \"{txtInputDance.Text}\" does not look like a dance data file from the game.");
                        return(false);
                    }
                }

                if (chkGenerateCharAnim.Checked || chkGenerateLipSync.Checked || chkGenerateFacialExpression.Checked || chkGenerateCameraMotion.Checked)
                {
                    if (!Regex.IsMatch(txtInputScenario.Text, @"scrobj_[a-z0-9]{5}[a-z0-9+]\.unity3d$", RegexOptions.CultureInvariant))
                    {
                        Alert($"File \"{txtInputScenario.Text}\" does not look like a scenario data file from the game.");
                        return(false);
                    }
                }

                if (chkGenerateCameraMotion.Checked)
                {
                    if (!Regex.IsMatch(txtInputCamera.Text, @"cam_[a-z0-9]{5}[a-z0-9+](?:\.imo)?\.unity3d$", RegexOptions.CultureInvariant))
                    {
                        Alert($"File \"{txtInputCamera.Text}\" does not look like a camera data file from the game.");
                        return(false);
                    }

                    if (radOptCamFormatVmd.Checked)
                    {
                        if (!txtOutputCameraMotion.Text.EndsWith(".vmd", StringComparison.OrdinalIgnoreCase))
                        {
                            if (!Confirm("The output camera file name does not ends with \".vmd\". Are you sure to continue?"))
                            {
                                return(false);
                            }
                        }
                    }
                    else if (radOptCamFormatMvd.Checked)
                    {
                        if (!txtOutputCameraMotion.Text.EndsWith(".mvd", StringComparison.OrdinalIgnoreCase))
                        {
                            if (!Confirm("The output camera file name does not ends with \".mvd\". Are you sure to continue?"))
                            {
                                return(false);
                            }
                        }
                    }
                }

                if (cboOptAppealType.SelectedIndex > 0)
                {
                    if (!string.IsNullOrWhiteSpace(txtOptExternalDanceAppealFile.Text))
                    {
                        if (!Regex.IsMatch(txtOptExternalDanceAppealFile.Text, @"dan_[a-z0-9]{5}[a-z0-9+]_ap\.imo\.unity3d$", RegexOptions.CultureInvariant))
                        {
                            Alert($"File \"{txtOptExternalDanceAppealFile.Text}\" does not look like an external appeal data file from the game.");
                            return(false);
                        }
                    }
                }

                return(true);
            }

            MainWorkerInputParams PrepareInputParams()
            {
                var ip = new MainWorkerInputParams();

                ip.GenerateModel             = chkGenerateModel.Checked;
                ip.GenerateCharacterMotion   = chkGenerateCharAnim.Checked;
                ip.GenerateLipSync           = chkGenerateLipSync.Checked;
                ip.GenerateFacialExpressions = chkGenerateFacialExpression.Checked;
                ip.GenerateCameraMotion      = chkGenerateCameraMotion.Checked;

                ip.InputHead     = txtInputHead.Text;
                ip.InputBody     = txtInputBody.Text;
                ip.InputDance    = txtInputDance.Text;
                ip.InputScenario = txtInputScenario.Text;
                ip.InputCamera   = txtInputCamera.Text;

                ip.OutputModel = txtOutputModel.Text;
                ip.OutputCharacterAnimation = txtOutputCharAnim.Text;
                ip.OutputLipSync            = txtOutputLipSync.Text;
                ip.OutputFacialExpressions  = txtOutputFacialExpression.Text;
                ip.OutputCamera             = txtOutputCameraMotion.Text;

                ip.MotionSource       = radOptMotionSourceMltd.Checked ? MotionFormat.Mltd : MotionFormat.Mmd;
                ip.ScalePmx           = chkOptScalePmx.Checked;
                ip.ConsiderIdolHeight = chkOptApplyCharHeight.Checked;
                var idolHeightInCm = Convert.ToUInt32(txtOptCharHeight.Text) / 100.0f;

                ip.IdolHeight                     = ip.ConsiderIdolHeight ? idolHeightInCm : 0;
                ip.TranslateBoneNames             = chkOptTranslateBoneNames.Checked;
                ip.AppendLegIkBones               = chkOptAppendLegIKBones.Checked;
                ip.FixCenterBones                 = chkOptFixCenterBones.Checked;
                ip.ConvertBindingPose             = chkOptConvertToTdaPose.Checked;
                ip.AppendEyeBones                 = chkOptAppendEyeBones.Checked;
                ip.HideUnityGeneratedBones        = chkOptHideUnityGenBones.Checked;
                ip.TranslateFacialExpressionNames = chkOptTranslateFacialExpressionNames.Checked;
                ip.ImportPhysics                  = chkOptImportPhysics.Checked;
                ip.ApplyGameStyledToon            = chkGameToon.Checked;
                ip.SkinToonNumber                 = cboGameToonSkinNumber.SelectedIndex + 1;
                ip.ClothesToonNumber              = cboGameToonClothesNumber.SelectedIndex + 1;
                ip.AddHairHighlights              = chkOptAddHighlightHair.Checked;
                ip.AddEyesHighlights              = chkOptAddHighlightEyes.Checked;

                ip.TransformTo30Fps        = radOptAnimFrameRate30.Checked;
                ip.ScaleVmd                = chkOptScaleVmd.Checked;
                ip.UseMvdForCamera         = radOptCamFormatMvd.Checked;
                ip.FixedFov                = ip.UseMvdForCamera ? 0 : Convert.ToUInt32(txtOptFixedFov.Text);
                ip.MotionNumber            = cboOptMotionNumber.SelectedIndex + 1;
                ip.FormationNumber         = cboOptFormationNumber.SelectedIndex + 1;
                ip.AppealType              = (AppealType)cboOptAppealType.SelectedIndex;
                ip.ExternalDanceAppealFile = txtOptExternalDanceAppealFile.Text;
                ip.IgnoreSingControl       = chkOptAlwaysSinging.Checked;

                ip.FacialExpressionMappingFilePath = txtOptFEMappings.Text;
                ip.PreferredFacialExpressionSource = radFESourceLandscape.Checked ? MainWorkerInputParams.FallbackFacialExpressionSource.Landscape : MainWorkerInputParams.FallbackFacialExpressionSource.Portrait;

                return(ip);
            }

            txtLog.Clear();

            MainWorkerInputParams p;

            try {
                if (!CheckInputParams())
                {
                    return;
                }

                p = PrepareInputParams();
            } catch (Exception ex) {
                Alert(ex.Message);
                return;
            }

            var worker = new MainWorker(this, p);

            worker.Start();

            EnableMainControls(false);
        }