Ejemplo n.º 1
0
        private void HandleRetargetAnimationsToolStripMenuItemClick(object sender, EventArgs e)
        {
            var originalScene = ModuleImportUtilities.SelectImportFile <ModelPack>("Select the original model file.")?.Model;

            if (originalScene == null)
            {
                return;
            }

            var newScene = ModuleImportUtilities.SelectImportFile <ModelPack>("Select the new model file.")?.Model;

            if (newScene == null)
            {
                return;
            }

            bool fixArms = MessageBox.Show("Fix arms? If unsure, select No.", "Question", MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes;

            string directoryPath;

            using (var dialog = new VistaFolderBrowserDialog())
            {
                dialog.Description =
                    "Select a directory containing GAP files, or subdirectories containing GAP files to retarget to the new model.\n" +
                    "Note that this will replace the original files.";

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                directoryPath = dialog.SelectedPath;
            }

            var failures = new ConcurrentBag <string>();

            using (var dialog = new ProgressDialog())
            {
                dialog.DoWork += (o, progress) =>
                {
                    var filePaths          = Directory.EnumerateFiles(directoryPath, "*.GAP", SearchOption.AllDirectories).ToList();
                    var processedFileCount = 0;

                    Parallel.ForEach(filePaths, (filePath, state) =>
                    {
                        lock ( dialog )
                        {
                            if (dialog.CancellationPending)
                            {
                                state.Stop();
                                return;
                            }

                            dialog.ReportProgress(( int )((( float )++processedFileCount / filePaths.Count) * 100),
                                                  $"Processing {Path.GetFileName( filePath )}", null);
                        }

                        try
                        {
                            var animationPack = Resource.Load <AnimationPack>(filePath);
                            animationPack.Retarget(originalScene, newScene, fixArms);
                            animationPack.Save(filePath);
                        }
                        catch (Exception)
                        {
                            failures.Add(filePath);
                        }
                    });
                };

                dialog.ShowDialog();
            }

            if (failures.Count > 0)
            {
                MessageBox.Show("An error occured while processing the following files:\n" + string.Join("\n", failures));
            }
        }
Ejemplo n.º 2
0
        private void copyP5SplitGAPToMultipleModelsInDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var aGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with a.");

            if (aGap == null)
            {
                return;
            }

            var bGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with b.");

            if (bGap == null)
            {
                return;
            }

            var cGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with c.");

            if (cGap == null)
            {
                return;
            }

            bool isGAP52 = MessageBox.Show("GAP ID 52? If unsure, select No.", "Question", MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes;

            string directoryPath;
            var    browserDialog = new VistaFolderBrowserDialog();
            {
                browserDialog.Description =
                    "Select a directory containing Model files, or subdirectories containing model files to make the new GAP files for.\n" +
                    "Note that this will replace the original files.";

                if (browserDialog.ShowDialog() != true)
                {
                    return;
                }

                directoryPath = browserDialog.SelectedPath;
            }

            var failures = new ConcurrentBag <string>();

            string GAP_ID = "_051_";

            if (isGAP52)
            {
                GAP_ID = "_052_";
            }

            var filePaths = Directory.EnumerateFiles(directoryPath, "*.GMD", SearchOption.AllDirectories).ToList();

            foreach (string filePath in filePaths)
            {
                var targetCharID  = Path.GetFileName(filePath).Split("_")[0].Remove(0, 1); // get character ID from model
                var targetGAPname = Path.GetFileName(filePath).Split("_")[1];              // get model ID from model
                var targetGAPDir  = Path.Join(Path.GetDirectoryName(filePath), "battle");  // directory of model
                try
                {
                    var targetModel = ModuleImportUtilities.ImportFile <ModelPack>(filePath)?.Model;

                    if (targetModel == null)
                    {
                        return;
                    }

                    aGap.FixTargetIds(targetModel);
                    aGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "a.GAP"));

                    bGap.FixTargetIds(targetModel);
                    bGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "b.GAP"));

                    cGap.FixTargetIds(targetModel);
                    cGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "c.GAP"));
                }
                catch (Exception)
                {
                    failures.Add(filePath);
                }
            }

            if (failures.Count > 0)
            {
                MessageBox.Show("An error occured while processing the following files:\n" + string.Join("\n", failures));
            }
            else
            {
                MessageBox.Show("All split GAPs successfully generated!");
            }
        }