コード例 #1
0
        /// <summary>
        /// Processes a list of images
        /// </summary>
        private void ProcessImages(string[] files)
        {
            var progressWindow = new ProgressWindow()
            {
                Owner = this,
                Title = "CoDImageUtil | Working"
            };

            Dispatcher.BeginInvoke(new Action(() => progressWindow.ShowDialog()));
            progressWindow.SetProgressCount(files.Length);
            progressWindow.SetProgressMessage("Processing Images...");

            var mode      = Mode.SelectedItem.ToString();
            var format    = Helpers.GetDXGIFormat(DDSFormat.SelectedItem.ToString());
            var extension = OutputFormat.SelectedItem.ToString().ToLower();

            new Thread(() =>
            {
                Parallel.ForEach(files, new ParallelOptions {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                }, (file, loop) =>
                {
                    try
                    {
                        ProcessImage(file, extension, format, mode);
                    }
                    catch
                    {
                    }

                    if (progressWindow.IncrementProgress())
                    {
                        loop.Break();
                    }
                });

                progressWindow.SetProgressMessage("Complete");
                progressWindow.ProgressComplete();
            }).Start();
        }
コード例 #2
0
        private void ProcessMaterials(string[] files)
        {
            var progressWindow = new ProgressWindow()
            {
                Owner = this,
                Title = "CoDImageUtil | Working"
            };

            var mode      = Mode.SelectedItem.ToString();
            var format    = Helpers.GetDXGIFormat(DDSFormat.SelectedItem.ToString());
            var extension = OutputFormat.SelectedItem.ToString().ToLower();

            Dispatcher.BeginInvoke(new Action(() => progressWindow.ShowDialog()));
            progressWindow.SetProgressCount(files.Length);
            progressWindow.SetProgressMessage("Processing Images...");

            new Thread(() =>
            {
                foreach (var file in files)
                {
                    bool quit = false;

                    try
                    {
                        progressWindow.SetProgressMessage(string.Format("Processing {0}...", Path.GetFileName(file)));

                        var images = new Dictionary <string, string>();

                        foreach (var line in File.ReadLines(file))
                        {
                            if (line == "semantic,image_name")
                            {
                                continue;
                            }

                            var lineSplit = line.Split(',');

                            var imageType = lineSplit[0];
                            var imagePath = Path.Combine(Path.GetDirectoryName(file), "_images", lineSplit[1] + extension);

                            switch (imageType)
                            {
                            case "unk_semantic_0x0":
                                images[imagePath] = "Split Specular Color (CoD IW/MW 2019)";
                                break;

                            case "unk_semantic_0x9":
                                images[imagePath] = "Split Normal/Gloss/Occlusion (CoD IW/MW 2019)";
                                break;

                            case "unk_semantic_0x7B":
                            case "unk_semantic_0x7C":
                                images[imagePath] = "Direct Convert";
                                break;
                            }
                        }

                        progressWindow.SetProgressCount(images.Count);

                        Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file)));

                        foreach (var image in images)
                        {
                            var outputPath = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file), Path.GetFileNameWithoutExtension(image.Key).Split('&')[0]);

                            try
                            {
                                ProcessImage(image.Key, extension, format, image.Value, outputPath);
                            }
                            catch
                            {
                            }

                            if (progressWindow.IncrementProgress())
                            {
                                quit = true;
                                break;
                            }
                        }

                        if (quit)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }

                progressWindow.SetProgressMessage("Complete");
                progressWindow.ProgressComplete();
            }).Start();
        }