private void CollectFiles() { var selectedFolder = SelectedFolder; if (string.IsNullOrEmpty(selectedFolder) || !System.IO.Directory.Exists(selectedFolder)) { selectedFolder = Environment.CurrentDirectory; } var wpf3dFileNames = System.IO.Directory.GetFiles(selectedFolder, "*.wpf3d", SearchOption.TopDirectoryOnly); if (wpf3dFileNames == null || wpf3dFileNames.Length == 0) { FilesListBox.ItemsSource = null; return; } // Here we read only wpf3d file header that contains description, number of objects and thumbnail. // Note: Calling ReadFileHeader can be also done in a background thread. var wpf3dFiles = new List <Ab3d.Utilities.Wpf3DFile>(wpf3dFileNames.Length); foreach (var wpf3dFileName in wpf3dFileNames) { try { var wpf3DFile = new Ab3d.Utilities.Wpf3DFile(); wpf3DFile.ReadFileHeader(wpf3dFileName); wpf3dFiles.Add(wpf3DFile); } catch { // pass //MessageBox.Show(string.Format("Cannot read file\r\n{0}\r\n\r\nError: {1}", wpf3dFileName, ex.Message)); } } FilesListBox.ItemsSource = wpf3dFiles; }
private void SaveButton_Click(object sender, RoutedEventArgs e) { try { //Ab3d.Utilities.Wpf3DFile.IsLogging = true; Ab3d.Utilities.Wpf3DFile wpf3DFile = new Ab3d.Utilities.Wpf3DFile(); wpf3DFile.Description = DescriptionTextBox.Text; wpf3DFile.Comment = CommentTextBox.Text; wpf3DFile.SourceFileName = this.SourceFileName; wpf3DFile.SaveNormals = SaveNormalsCheckBox.IsChecked ?? false; wpf3DFile.SaveTextureCoordinates = SaveTextureCoordinatesCheckBox.IsChecked ?? false; if (SaveThumbnailCheckBox.IsChecked ?? false) { wpf3DFile.Thumbnail = Thumbnail; } Ab3d.Utilities.Wpf3DFile.DataPrecisionType dataPrecession; switch (PrecisionComboBox.SelectedIndex) { case 0: dataPrecession = Ab3d.Utilities.Wpf3DFile.DataPrecisionType.Double; break; default: dataPrecession = Ab3d.Utilities.Wpf3DFile.DataPrecisionType.Float; break; } wpf3DFile.WriteFile(FileNameTextBox.Text, RootModel, NamedObjects, Camera, dataPrecession); if (CheckSavedFile && wpf3DFile.SaveNormals && wpf3DFile.SaveTextureCoordinates) { var model = wpf3DFile.ReadFile(FileNameTextBox.Text); if (model == null) { throw new Exception("model == null"); } string s1 = Ab3d.Utilities.Dumper.GetModelInfoString(RootModel); string s2 = Ab3d.Utilities.Dumper.GetModelInfoString(model); if (s1 != s2) { MessageBox.Show("3D model not correctly saved - loaded models are different as the original models!"); } //else // MessageBox.Show("3D models successfully saved to\r\n" + FileNameTextBox.Text); } } catch (Exception ex) { MessageBox.Show("Error writing wpf3d file\r\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnSaveButtonClicked(); }