public void Export(IFile outputFile, IModel model) { var outputPath = outputFile.FullName; var outputExtension = outputFile.Extension; var inputFile = outputFile.CloneWithExtension(".glb"); var inputPath = inputFile.FullName; var inputExtension = inputFile.Extension; var ctx = new AssimpContext(); string exportFormatId; { var supportedImportFormatExtensions = ctx.GetSupportedImportFormats(); Asserts.True(supportedImportFormatExtensions.Contains(inputExtension), $"'{inputExtension}' is not a supported import format!"); var supportedExportFormats = ctx.GetSupportedExportFormats(); var exportFormatIds = supportedExportFormats .Where(exportFormat => outputExtension == $".{exportFormat.FileExtension}") .Select(exportFormat => exportFormat.FormatId); Asserts.True(exportFormatIds.Any(), $"'{outputExtension}' is not a supported export format!"); exportFormatId = exportFormatIds.First(); } var sc = ctx.ImportFile(inputPath); var success = ctx.ExportFile(sc, outputPath, exportFormatId); Asserts.True(success, "Failed to export model."); }
public static string[] GetSupportedImportFormats() { Assimp.AssimpContext C = new AssimpContext(); string[] _Formats = C.GetSupportedImportFormats(); C.Dispose(); return(_Formats); }
public AssimpImporter() { var importer = new AssimpContext(); AvaliableFormats = importer.GetSupportedImportFormats(); importer.Dispose(); }
public void Create(Device1 device) { PrimitiveTopology = PrimitiveTopology.TriangleList; VertexStride = Marshal.SizeOf <VertexPosColNormTex>(); var verts = new List <VertexPosColNormTex>(); var importer = new AssimpContext(); var s = importer.GetSupportedImportFormats(); if (!importer.IsImportFormatSupported(Path.GetExtension(_FileName))) { throw new ArgumentException( "Model format " + Path.GetExtension(_FileName) + " is not supported! Cannot load {1}", "filename"); } var model = importer.ImportFile(_FileName, PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.CalculateTangentSpace | PostProcessSteps.Triangulate); foreach (var mesh in model.Meshes) { for (int i = 0; i < mesh.VertexCount; i++) { var pos = new Vector3(mesh.Vertices[i].X, mesh.Vertices[i].Y, mesh.Vertices[i].Z); var color = Color.AliceBlue; var norm = new Vector3(mesh.Normals[i].X, mesh.Normals[i].Y, mesh.Normals[i].Z); var tx = new Vector2(mesh.TextureCoordinateChannels[0][i].X, -mesh.TextureCoordinateChannels[0][i].Y); verts.Add(new VertexPosColNormTex(pos, color, norm, tx)); } var bufferDesc = new BufferDescription { Usage = ResourceUsage.Immutable, BindFlags = BindFlags.VertexBuffer, SizeInBytes = VertexStride * verts.Count, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; VertexBuffer = new Buffer(device, DataStream.Create(verts.ToArray(), false, false), bufferDesc); IndexCount = mesh.GetIndices().Length; //buffer creations bufferDesc = new BufferDescription { Usage = ResourceUsage.Immutable, BindFlags = BindFlags.IndexBuffer, SizeInBytes = sizeof(uint) * IndexCount, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; IndexBuffer = new Buffer(device, DataStream.Create(mesh.GetIndices(), false, false), bufferDesc); } }
/// <summary> /// Gets supported file extensions for filtering (removes the "." from the front). /// </summary> public void GetSupportedFileFilters() { AssimpContext context = new AssimpContext(); List <string> supported = new List <string>(); char[] period = ".".ToCharArray(); foreach (string format in context.GetSupportedImportFormats()) { supported.Add(format.TrimStart(period)); } supportedImportFormats.Equals(supported.ToString()); }
public void TestSupportedFormats() { AssimpContext importer = new AssimpContext(); ExportFormatDescription[] exportDescs = importer.GetSupportedExportFormats(); String[] importFormats = importer.GetSupportedImportFormats(); Assert.IsNotNull(exportDescs); Assert.IsNotNull(importFormats); Assert.IsTrue(exportDescs.Length >= 1); Assert.IsTrue(importFormats.Length >= 1); Assert.IsTrue(importer.IsExportFormatSupported(exportDescs[0].FileExtension)); Assert.IsTrue(importer.IsImportFormatSupported(importFormats[0])); }
/// <summary> /// loads a graphic file with the name. /// </summary> /// <param name="FileName">the pathname of the file.</param> /// <returns>the graphic file.</returns> public static Scene FromFile(string FileName) { AssimpContext C = new AssimpContext(); string[] _Formats = C.GetSupportedImportFormats(); Assimp.Scene SC = null; try { SC = C.ImportFile(FileName); System.IO.FileStream FS = new System.IO.FileStream(FileName, System.IO.FileMode.Open); } catch (Exception E) { System.Windows.Forms.MessageBox.Show(E.Message); return(null); } ConvertAssimp.BaseDir = System.IO.Path.GetDirectoryName(FileName); return(ConvertAssimp.ConvertFromAssimp(SC)); }
static Importer() { using (var temp = new AssimpContext()) { SupportedFormats = temp.GetSupportedImportFormats(); } var builder = new StringBuilder(); builder.Append($"All Supported |"); foreach (var s in SupportedFormats) { builder.Append($"*{ s };"); } builder.Append($"|"); foreach (var s in SupportedFormats) { builder.Append($"(*{ s })|*{ s }|"); } SupportedFormatsString = builder.ToString(0, builder.Length - 1); SupportedTextureFormatDict = new HashSet <string>(SupportedTextureFormats); }
public string[] GetSupportedImportFormats() { return(Importer.GetSupportedImportFormats()); }