private void ConvertToMaterialPreset()
        {
            using (var dialog = new ModelConverterOptionsDialog(false))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                ModelPackConverterOptions options = new ModelPackConverterOptions()
                {
                    MaterialPreset = dialog.MaterialPreset,
                    Version        = dialog.Version
                };
                Replace(MaterialDictionary.ConvertToMaterialPreset(Data, options));
            }
        }
Ejemplo n.º 2
0
        public static ModelPack ConvertAssimpModel(string path)
        {
            using (var dialog = new ModelConverterOptionsDialog(false))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }

                ModelPackConverterOptions options = new ModelPackConverterOptions()
                {
                    MaterialPreset       = dialog.MaterialPreset,
                    Version              = dialog.Version,
                    ConvertSkinToZUp     = dialog.ConvertSkinToZUp,
                    GenerateVertexColors = dialog.GenerateVertexColors
                };

                return(ModelPackConverter.ConvertFromAssimpScene(path, options));
            }
        }
Ejemplo n.º 3
0
        private void HandleConvertMaterialsToolStripMenuItemClick(object sender, EventArgs e)
        {
            string directoryPath;

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

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

                directoryPath = dialog.SelectedPath;
            }

            var failures = new ConcurrentBag <string>();

            ModelPackConverterOptions option;

            using (var dialog = new ModelConverterOptionsDialog(false))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                ModelPackConverterOptions options = new ModelPackConverterOptions()
                {
                    MaterialPreset = dialog.MaterialPreset,
                    Version        = dialog.Version
                };

                option = options;
            }

            using (var dialog = new ProgressDialog())
            {
                dialog.DoWork += (o, progress) =>
                {
                    var filePaths          = Directory.EnumerateFiles(directoryPath, "*.GMD", 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 model              = Resource.Load <ModelPack>(filePath);
                            var materials          = model.Materials;
                            var materialsConverted = MaterialDictionary.ConvertToMaterialPreset(materials, option);
                            model.Materials        = materialsConverted;
                            model.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));
            }
        }