private void LoadWpf3DFile(string fileName) { string fileExtension = System.IO.Path.GetExtension(fileName); Model3D readModel3D = null; object readCamera = null; if (!fileExtension.Equals(".wpf3d", StringComparison.OrdinalIgnoreCase)) { MessageBox.Show("This sample can import only wpf3d files"); return; } InfoTextBlock.Visibility = Visibility.Collapsed; // Use Wpf3DFile importer to read wpf3d file format var wpf3DFile = new Ab3d.Utilities.Wpf3DFile(); // We could read only header (description and thumbnail without any model data - see importer sample): //wpf3DFile.ReadFileHeader(fileName); try { Mouse.OverrideCursor = Cursors.Wait; readModel3D = wpf3DFile.ReadFile(fileName); readCamera = wpf3DFile.Camera; } catch (Exception ex) { MessageBox.Show("Error reading file with Wpf3DFile:\r\n" + ex.Message); } finally { Mouse.OverrideCursor = null; } // Show the model if (readModel3D != null) { ShowModel(readModel3D, readCamera); _fileName = fileName; } }
public StandardTransformSample() { InitializeComponent(); // Read a teapot from wpf3d file string fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\wpf3d\teapot-hires.wpf3d"); var wpf3DFile = new Ab3d.Utilities.Wpf3DFile(); var teapotModel3D = wpf3DFile.ReadFile(fileName); Ab3d.Utilities.ModelUtils.ChangeMaterial(teapotModel3D, new DiffuseMaterial(Brushes.Gold), newBackMaterial: null); // Create a single StandardTransform3D that will be able to translate, rotate and scale the read teapot. _standardTransform3D = new StandardTransform3D(); // We could also create a new StandardTransform3D with some initial transformations: //_standardTransform3D = new StandardTransform3D() //{ // RotateY = 30, // TranslateX = 100, // ScaleX = 1.3 //}; // To assign the _standardTransform3D to teapotModel3D we use the static SetStandardTransform3D method StandardTransform3D.SetStandardTransform3D(teapotModel3D, _standardTransform3D, updateTransform3D: true); // In some other location in the application we can read the StandardTransform3D from the teapotModel3D by: //var standardTransform3D = StandardTransform3D.GetStandardTransform3D(teapotModel3D); // Assign the _standardTransform3D to the editor control: TransformEditor.StandardTransform3D = _standardTransform3D; var contentVisual3D = teapotModel3D.CreateContentVisual3D(); MainViewport.Children.Add(contentVisual3D); _rnd = new Random(); }
private void LoadModel(string fileName) { // Create an instance of AssimpWpfImporter var assimpWpfImporter = new Ab3d.Assimp.AssimpWpfImporter(); string fileExtension = System.IO.Path.GetExtension(fileName); Model3D readModel3D = null; object readCamera = null; if (fileExtension.Equals(".wpf3d", StringComparison.OrdinalIgnoreCase)) { // Use Wpf3DFile importer to read wpf3d file format var wpf3DFile = new Ab3d.Utilities.Wpf3DFile(); // We could read only header (description and thumbnail without any model data): //wpf3DFile.ReadFileHeader(fileName); try { Mouse.OverrideCursor = Cursors.Wait; readModel3D = wpf3DFile.ReadFile(fileName); readCamera = wpf3DFile.Camera; } catch (Exception ex) { MessageBox.Show("Error reading file with Wpf3DFile:\r\n" + ex.Message); } finally { Mouse.OverrideCursor = null; } } else if (assimpWpfImporter.IsImportFormatSupported(fileExtension)) { // Use assimp importer to read many other file formats try { Mouse.OverrideCursor = Cursors.Wait; assimpWpfImporter.DefaultMaterial = new DiffuseMaterial(Brushes.Silver); assimpWpfImporter.AssimpPostProcessSteps = PostProcessSteps.Triangulate; assimpWpfImporter.ReadPolygonIndices = true; // Read model from file readModel3D = assimpWpfImporter.ReadModel3D(fileName, texturesPath: null); // we can also define a textures path if the textures are located in some other directory (this is parameter can be skipped, but is defined here so you will know that you can use it) } catch (Exception ex) { MessageBox.Show("Error reading file with Assimp importer:\r\n" + ex.Message); } finally { // Dispose unmanaged resources assimpWpfImporter.Dispose(); Mouse.OverrideCursor = null; } } else { MessageBox.Show("Not supported file extension: " + fileExtension); } // Show the model if (readModel3D != null) { ShowModel(readModel3D, readCamera); _fileName = fileName; } }