Пример #1
0
        private void MeshWriter_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            if (worker == null)
            {
                return;
            }

            MeshConvertRequest request = e.Argument as MeshConvertRequest;

            if (request == null)
            {
                return;
            }

            int       meshCount         = request.MeshQueue.Count;
            const int stageCount        = 4;
            int       progressIncrement = 100 / meshCount / stageCount;
            int       progress          = 0;

            for (int i = 0; i < meshCount; i++)
            {
                FluxMesh mesh = request.MeshQueue.Dequeue();

                string     filePath = $"{request.SaveDirectory}\\{mesh.Name}";
                FileStream stream   = File.Create($"{filePath}.flux");

                worker.ReportProgress(progress, $"'{mesh.Name}' Writing mesh data...");
                WriteMesh(mesh, stream);
                progress += progressIncrement;
                stream.Close();
                if (mesh.CookConvexMesh)
                {
                    stream = File.Create($"{filePath}_convex.collision");
                    worker.ReportProgress(progress, $"'{mesh.Name}' Cooking convex mesh...");
                    WriteConvexMeshData(mesh, stream);
                    progress += progressIncrement;
                    stream.Close();
                }
                if (mesh.CookTriangleMesh)
                {
                    stream = File.Create($"{filePath}_triangle.collision");
                    worker.ReportProgress(progress, $"'{mesh.Name}' Cooking triangle mesh...");
                    WriteTriangleMeshData(mesh, stream);
                    stream.Close();
                }

                progress += progressIncrement;
                DebugLog.Log($"Exported {mesh.Name}", "Mesh Formatter");
            }
        }
Пример #2
0
        public void ExportMeshesAsync(MeshConvertRequest request)
        {
            int count = request.MeshQueue.Count;

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += MeshWriter_DoWork;
            worker.WorkerReportsProgress = true;

            ExportingDialogViewModel viewModel       = new ExportingDialogViewModel();
            ExportingDialog          exportingDialog = new ExportingDialog();

            exportingDialog.DataContext   = viewModel;
            exportingDialog.ShowInTaskbar = false;
            exportingDialog.Show();

            worker.ProgressChanged    += viewModel.OnWorkerOnProgressChanged;
            worker.RunWorkerCompleted += (sender, args) =>
            {
                exportingDialog.Close();
                DebugLog.Log($"Exported {count} meshes", "Mesh Formatter");
            };
            worker.RunWorkerAsync(request);
        }