Пример #1
0
        private async void Export(FileFormat3D format)
        {
            var path = WpfHelper.ShowSaveFileDialog("." + format, format.ToString());
            if (string.IsNullOrEmpty(path))
                return;

            var controler = await __Main.MakeProgressDialog("Generating " + format);
            controler.SetCancelable(true);

            var cts = new CancellationTokenSource();
            var token = cts.Token;

            var cancelTask = new Task(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    if (controler.IsCanceled)
                    {
                        cts.Cancel();
                        controler.CloseAsync();
                        break;
                    }

                    Thread.Sleep(100);
                }
            }, token);

            var generationTask = new Task(() =>
            {
                var main = MainWindow.Instance;

                var pg = new PlanetGenerator();
                var model = pg.Generate3D(main.Settings, null).Result;

                if (model == null)
                    return;

                using (var sw = new StreamWriter(path))
                {
                    switch (format)
                    {
                        case FileFormat3D.Ply:
                            model.ToPly(sw);
                            break;
                        case FileFormat3D.Dae:
                            model.ToDae(sw);
                            break;
                        case FileFormat3D.Obj:
                            model.ToObj(sw);
                            break;
                    }
                }
            });

            cancelTask.Start();

            generationTask.Start();

            await generationTask;

            cts.Cancel();
            await controler.CloseAsync();
        }
Пример #2
0
        public MainWindow()
        {
            Settings = new PlanetContainer();

            __Instance = this;

            InitializeComponent();

            DataContext = this;

            __PlanetGenerator = new PlanetGenerator();
        }