public static string[] GetSupportedImportFormats() { Assimp.AssimpContext C = new AssimpContext(); string[] _Formats = C.GetSupportedImportFormats(); C.Dispose(); return(_Formats); }
public ModelUtil(string file) { AssimpContext importer = new AssimpContext(); fileInfo = new FileInfo(file); if (fileInfo.Exists && importer.IsImportFormatSupported(fileInfo.Extension)) { scene = importer.ImportFile(file, PostProcessSteps.GenerateNormals | PostProcessSteps.CalculateTangentSpace | PostProcessSteps.Triangulate); } else { Console.WriteLine("Extension <{0}> isn't supported!", fileInfo.Extension); } name = fileInfo.Name.Substring(0, fileInfo.Name.LastIndexOf('.')); string outDir = fileInfo.DirectoryName + @"\" + name; if (!Directory.Exists(outDir)) { outDirInfo = Directory.CreateDirectory(outDir); } else { outDirInfo = new DirectoryInfo(outDir); } }
public void TestConvertFromStream() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.obj"); String outputPath2 = Path.Combine(TestHelper.RootPath, "TestFiles\\duck-fromBlob.obj"); FileStream fs = File.OpenRead(path); new ConsoleLogStream().Attach(); AssimpContext importer = new AssimpContext(); importer.ConvertFromStreamToFile(fs, ".dae", outputPath, "obj"); fs.Position = 0; ExportDataBlob blob = importer.ConvertFromStreamToBlob(fs, ".dae", "collada"); fs.Close(); //Take ExportDataBlob's data, write it to a memory stream and export that back to an obj and write it MemoryStream memStream = new MemoryStream(); memStream.Write(blob.Data, 0, blob.Data.Length); memStream.Position = 0; importer.ConvertFromStreamToFile(memStream, ".dae", outputPath2, "obj"); memStream.Close(); LogStream.DetachAllLogstreams(); }
public static void ExportFile(HSD_JOBJ rootJOBJ, Dictionary <int, string> boneLabels = null) { StringBuilder sup = new StringBuilder(); AssimpContext importer = new AssimpContext(); var length = importer.GetSupportedExportFormats().Length; var index = 0; foreach (var v in importer.GetSupportedExportFormats()) { sup.Append($"{v.Description} (*.{v.FileExtension})|*.{v.FileExtension};"); index++; if (index != length) { sup.Append("|"); } } var f = Tools.FileIO.SaveFile(sup.ToString()); if (f != null) { var settings = new ModelExportSettings(); using (PropertyDialog d = new PropertyDialog("Model Import Options", settings)) { if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ExportFile(f, rootJOBJ, settings, boneLabels); } } } }
public unsafe IMesh[] Import(string fileName) { var newMeshes = new List <IMesh>(); var context = new AssimpContext(); var scene = context.ImportFile(fileName); foreach (var mesh in scene.Meshes) { var newMesh = _packet.CreateScoped <IMesh>(); var indices = new List <uint>(); var vertex = new List <PositionNormalUVTIDVertex>(); foreach (var face in mesh.Faces) { indices.AddRange((IEnumerable <uint>)face.Indices); } for (var i = 0; i < mesh.VertexCount; i++) { var vertice = mesh.Vertices[i]; var normal = mesh.Normals[i]; vertex.Add(new PositionNormalUVTIDVertex(*(Vector3 *)&vertice, *(Vector3 *)&normal, new Vector2(0), 0)); } newMesh.VertexArray = vertex; newMesh.IndexArray = indices; newMesh.ModelMatrix = Matrix.Identity; // TODO: copy material stuff. // newMesh.Material = newMeshes.Add(newMesh); } return(newMeshes.ToArray()); }
/// <summary> /// Loads an Assimp Scene from Stream /// </summary> /// <param name="s">Stream</param> /// <param name="hint">File extension(obj, fbx, ...)</param> /// <returns></returns> internal static Scene LoadInternalAssimpScene(Stream s, string hint = "") { AssimpContext context = new AssimpContext(); context.SetConfig(new NormalSmoothingAngleConfig(66)); return(context.ImportFileFromStream(s, hint)); }
public Model LoadFromFile(string path) { AssimpContext Importer = new AssimpContext(); Importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); String fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path); modelDirPath = Path.GetDirectoryName(fileName); //Scene scene = Importer.ImportFileFromStream(stream); Assimp.Scene scene = Importer.ImportFile( fileName, PostProcessSteps.FindDegenerates | PostProcessSteps.FindInvalidData | PostProcessSteps.FlipUVs | // Required for Direct3D PostProcessSteps.FlipWindingOrder | // Required for Direct3D PostProcessSteps.JoinIdenticalVertices | PostProcessSteps.ImproveCacheLocality | PostProcessSteps.OptimizeMeshes | PostProcessSteps.Triangulate ); _meshes = new List <Mesh>(); ProcessNode(scene.RootNode, scene); return(new Model(path, ref _meshes)); }
static void GainSphere() { AssimpContext c = new AssimpContext(); Scene s = c.ImportFile(@"C:\Users\jaken\Desktop\sphere.obj"); string text = ""; foreach (Vector3D v in s.Meshes[0].Vertices) { //text += v.X.ToString() + "f, " + v.Y.ToString() + "f, " + v.Z.ToString() + "f,\n"; } for (int i = 0; i < s.Meshes[0].GetIndices().Count(); i += 10) { text += s.Meshes[0].GetIndices()[i + 0].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 1].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 2].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 3].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 4].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 5].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 6].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 7].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 8].ToString() + ", "; text += s.Meshes[0].GetIndices()[i + 9].ToString() + ",\n"; } File.WriteAllText(@"C:\Users\jaken\Desktop\sphere.txt", text); }
public void TestToStream() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); AssimpContext importer = new AssimpContext(); ExportDataBlob blob = importer.ConvertFromFileToBlob(path, "obj"); Assert.IsNotNull(blob); MemoryStream stream = new MemoryStream(); blob.ToStream(stream); Assert.IsTrue(stream.Length != 0); stream.Position = 0; ExportDataBlob blob2 = ExportDataBlob.FromStream(stream); Assert.IsNotNull(blob2); Assert.IsTrue(blob.Data.Length == blob.Data.Length); if(blob.NextBlob != null) { Assert.IsTrue(blob2.NextBlob != null); Assert.IsTrue(blob2.NextBlob.Name.Equals(blob.NextBlob.Name)); Assert.IsTrue(blob2.NextBlob.Data.Length == blob.NextBlob.Data.Length); } }
public void TestToStream() { String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae"); AssimpContext importer = new AssimpContext(); ExportDataBlob blob = importer.ConvertFromFileToBlob(path, "obj"); Assert.IsNotNull(blob); MemoryStream stream = new MemoryStream(); blob.ToStream(stream); Assert.IsTrue(stream.Length != 0); stream.Position = 0; ExportDataBlob blob2 = ExportDataBlob.FromStream(stream); Assert.IsNotNull(blob2); Assert.IsTrue(blob.Data.Length == blob.Data.Length); if (blob.NextBlob != null) { Assert.IsTrue(blob2.NextBlob != null); Assert.IsTrue(blob2.NextBlob.Name.Equals(blob.NextBlob.Name)); Assert.IsTrue(blob2.NextBlob.Data.Length == blob.NextBlob.Data.Length); } }
public static ModelMesh[] LoadFromFile(GameMode gameMode, string filePath) { if (".pmesh".Equals(Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase)) { return(new[] { LoadPMesh(gameMode, filePath) }); } else { var modelDirectory = Path.GetDirectoryName(filePath); var context = new AssimpContext(); const PostProcessSteps flags = PostProcessSteps.GenerateNormals | PostProcessSteps.GenerateUVCoords | PostProcessSteps.FlipWindingOrder | PostProcessSteps.FlipUVs; var scene = context.ImportFile(filePath, flags); var meshs = new List <ModelMesh>(); foreach (var assimpMesh in scene.Meshes) { var modelMesh = new ModelMesh(gameMode, scene, assimpMesh, modelDirectory); meshs.Add(modelMesh); } return(meshs.ToArray()); } }
public bool ExportCollada(FileInfo file) { using (var exporter = new AssimpContext()) { return(exporter.ExportFile(Scene, file.FullName, "collada", PostProcessSteps.ValidateDataStructure)); //collada or obj } }
protected bool CreateMesh(string sFullPath) { // Console.WriteLine("Create MEsh:" + sFullPath); AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(35.0f)); try { Scene _modelScene = importer.ImportFile(sFullPath, PostProcessSteps.Triangulate); processNode(_modelScene.RootNode, _modelScene, this); //ComputeBoundingBox(); ComputeBoundingBox(_modelScene); BoundingBox.P1 = m_sceneMin; BoundingBox.P2 = m_sceneMax; } catch (Exception e) { Globals.Log(this, e.Message); Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } return(false); } return(true); }
private void LoadModel(Asset asset) { // TODO: Remove assimp var context = new AssimpContext(); var logStream = new LogStream((msg, userData) => { Logging.Log($"{msg}"); }); logStream.Attach(); var extension = Path.GetExtension(asset.MountPath).Substring(1); using var memoryStream = new MemoryStream(asset.Data); memoryStream.Seek(0, SeekOrigin.Begin); var scene = context.ImportFile("Content/" + asset.MountPath, PostProcessSteps.Triangulate | PostProcessSteps.PreTransformVertices | PostProcessSteps.RemoveRedundantMaterials | PostProcessSteps.CalculateTangentSpace | PostProcessSteps.OptimizeMeshes | PostProcessSteps.OptimizeGraph | PostProcessSteps.ValidateDataStructure | PostProcessSteps.GenerateNormals | PostProcessSteps.FlipUVs); directory = Path.GetDirectoryName(asset.MountPath); ProcessNode(scene.RootNode, scene); }
public bool ExportObject(FileInfo file) { using (var exporter = new AssimpContext()) { return(exporter.ExportFile(Scene, file.FullName, "obj", PostProcessSteps.ValidateDataStructure)); } }
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."); }
} // Disable parameterless constructor public static Model LoadModel(string path) { if (path == null) { throw new ArgumentNullException("path", "Path must not be null"); } var mdl = new Model(); Scene scene; var lmp = LumpManager.GetLumpFullPath(path); using (Stream stream = lmp.AsStream) { using (AssimpContext context = new AssimpContext()) { LumpIOSystem ioSys = new LumpIOSystem(); context.SetIOSystem(ioSys); scene = context.ImportFileFromStream(stream, PostProcessSteps.Triangulate | PostProcessSteps.FlipUVs); if (scene == null || scene.SceneFlags.HasFlag(SceneFlags.Incomplete) || scene.RootNode == null) { throw new Core.FatalError(String.Format("Error loading model \"{0}\"", path)); } } } mdl.directory = Path.GetDirectoryName(path); mdl.meshes = new List <MeshData> (scene.MeshCount); mdl.ProcessNode(scene.RootNode, scene); return(mdl); }
public bool LoadMesh(string fileName) { Vao = GL.GenVertexArray(); GL.BindVertexArray(Vao); GL.GenBuffers((int)VB_TYPES.NUM_VBs, Buffers); bool ret = false; Importer = new AssimpContext(); Scene = Importer.ImportFile(fileName, ASSIMP_LOAD_FLAGS);; if (Scene != null) { GlobalInverseTransform = Scene.RootNode.Transform.ToOtk(); GlobalInverseTransform.Invert(); ret = InitFromScene(Scene, fileName); } else { Console.WriteLine($"Error parsing {fileName}: {Scene}!"); } GL.BindVertexArray(0); return(ret); }
/// <summary> /// Loads a model with assimp /// </summary> /// <param name="stream">the input stream for assimp</param> /// <returns></returns> internal static List <Mesh> LoadModel(Stream stream) { AssimpContext context = new AssimpContext(); context.SetConfig(new NormalSmoothingAngleConfig(66)); return(LoadAssimpScene(context.ImportFileFromStream(stream), "")); }
public static Assimp.Scene Import(string filePath) { AssimpContext importer = new AssimpContext(); //importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); return(importer.ImportFile(filePath, PostProcessPreset.TargetRealTimeMaximumQuality)); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine(EXENAME + " <filename>"); return; } string fname = Environment.CurrentDirectory + "/" + args[0]; if (!File.Exists(fname)) { Console.WriteLine("Invalid filename."); Console.WriteLine(EXENAME + " <filename>"); return; } AssimpContext ac = new AssimpContext(); PT = args.Length > 1 && args[1].ToLower().Contains("pretrans"); TEXTURE = args.Length > 1 && args[1].ToLower().Contains("texture"); Console.WriteLine("Pre-transform = " + PT); Console.WriteLine("Texture = " + TEXTURE); Scene fdata = ac.ImportFile(fname, PostProcessSteps.Triangulate | PostProcessSteps.FlipWindingOrder); if (File.Exists(fname + ".vmd")) { File.Delete(fname + ".vmd"); } FileStream fs = File.OpenWrite(fname + ".vmd"); File.WriteAllText(fname + ".skin", ExportModelData(fdata, fs)); fs.Flush(); fs.Close(); }
public Model LoadModel(string filePath) { string path = Path.Combine(rootFolder, filePath); if (_loadedModels.TryGetValue(path, out var mesh)) { return(mesh); } var model = new Model(filePath.ToLower()); var context = new AssimpContext(); var scene = context.ImportFile(path, PostProcessSteps.Triangulate); if (scene.SceneFlags == SceneFlags.Incomplete) { throw new Exception("Assimp import error"); } foreach (var aiMesh in scene.Meshes) { model.Meshes.Add(LoadMesh(aiMesh, scene)); } //SetupModel(model); _loadedModels.Add(path, model); return(model); }
public void LoadFile(string FileName) { try { AssimpContext Importer = new AssimpContext(); STConsole.WriteLine($"Loading File {FileName}", Color.FromArgb(0, 255, 0)); var Flags = PostProcessSteps.Triangulate; Flags |= PostProcessSteps.JoinIdenticalVertices; Flags |= PostProcessSteps.FlipUVs; Flags |= PostProcessSteps.LimitBoneWeights; Flags |= PostProcessSteps.CalculateTangentSpace; Flags |= PostProcessSteps.GenerateNormals; scene = Importer.ImportFile(FileName, Flags); LoadScene(); } catch (Exception e) { if (e.ToString().Contains("Error loading unmanaged library from path")) { MessageBox.Show($"Failed to load assimp! Make sure you have Assimp32.dll next to the program!"); } Console.WriteLine(e); } }
public void TestImportFromFile() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\sphere.obj"); AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(55.0f)); importer.Scale = .5f; importer.XAxisRotation = 25.0f; importer.YAxisRotation = 50.0f; LogStream.IsVerboseLoggingEnabled = true; Assert.IsTrue(importer.ContainsConfig(NormalSmoothingAngleConfig.NormalSmoothingAngleConfigName)); importer.RemoveConfigs(); Assert.IsFalse(importer.ContainsConfig(NormalSmoothingAngleConfig.NormalSmoothingAngleConfigName)); importer.SetConfig(new NormalSmoothingAngleConfig(65.0f)); importer.SetConfig(new NormalSmoothingAngleConfig(22.5f)); importer.RemoveConfig(NormalSmoothingAngleConfig.NormalSmoothingAngleConfigName); Assert.IsFalse(importer.ContainsConfig(NormalSmoothingAngleConfig.NormalSmoothingAngleConfigName)); importer.SetConfig(new NormalSmoothingAngleConfig(65.0f)); Scene scene = importer.ImportFile(path, PostProcessPreset.TargetRealTimeMaximumQuality); Assert.IsNotNull(scene); Assert.IsTrue((scene.SceneFlags & SceneFlags.Incomplete) != SceneFlags.Incomplete); }
private AssimpContext GetImporter() { AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); return(importer); }
private void OnLoadAssets_Click(object sender, RoutedEventArgs e) { OpenFileDialog filePicker = new OpenFileDialog { Filter = "Any Assets|*.*" }; if (filePicker.ShowDialog() == true) { string assetPath = filePicker.FileName; // Check for duplicates if (_assetPaths.LastIndexOf(assetPath) > -1) { MessageBox.Show("This file has already been loaded!"); return; } _assetPaths.Add(assetPath); LoadedAssetsListbox.Items.Add(assetPath); AssimpContext importer = new AssimpContext(); Scene scene = importer.ImportFile(assetPath, PostProcessSteps.None); } }
public static MeshData[] LoadModelFromFile(string filename) { var importer = new AssimpContext(); if (!importer.IsImportFormatSupported(System.IO.Path.GetExtension(filename))) { throw new ArgumentException($"Model format {System.IO.Path.GetExtension(filename)} is not supported. Cannot load {filename}.", nameof(filename)); } var postProcessFlags = PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.CalculateTangentSpace; var model = importer.ImportFile(filename, postProcessFlags); List <MeshData> meshDatas = new List <MeshData>(model.MeshCount); MeshData meshData = new MeshData(); foreach (var mesh in model.Meshes) { List <MyVertex> myVertices = new List <MyVertex>(mesh.VertexCount); for (int i = 0; i < mesh.VertexCount; i++) { var pos = mesh.HasVertices ? mesh.Vertices[i].ToVector3() : new Vector3(); var norm = mesh.HasNormals ? mesh.Normals[i] : new Vector3D(); var texC = mesh.HasTextureCoords(0) ? mesh.TextureCoordinateChannels[0][i] : new Vector3D(1, 1, 0); var v = new MyVertex(pos, norm.ToVector3(), texC.ToVector2()); myVertices.Add(v); } var indices = mesh.GetIndices().ToList(); meshData.Vertices = myVertices.ToArray(); meshData.Indices = indices.ToArray(); meshDatas.Add(meshData); } return(meshDatas.ToArray()); }
public void Load(string sPath) { Filename = sPath; string sFullPath = Path.Combine(Globals.ResourcePath, sPath); //string sFullPath = sPath; if (!File.Exists(sFullPath)) { Console.WriteLine("File:" + sFullPath + " not found"); return; } AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); try { _modelScene = importer.ImportFile(sFullPath); processNode(_modelScene.RootNode, _modelScene, this); ComputeBoundingBox(); } catch (Exception e) { Globals.Log(this, e.Message); Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } }
public Task <MeshData <VertexPositionNormal> > Import(Stream assetData) { var importer = new AssimpContext(); importer.SetConfig(new SortByPrimitiveTypeConfig(PrimitiveType.Polygon | PrimitiveType.Line)); _scene = importer.ImportFileFromStream(assetData, PostProcessSteps); ComputeBoundingBox(); var vertices = new List <IVertexBufferDescription>(); var indices = new List <ushort>(); foreach (var mesh in _scene.Meshes) { vertices.AddRange(mesh.Vertices.Select((vertex, i) => new VertexPositionNormal(FromVector(vertex), FromVector(mesh.Normals[i])) as IVertexBufferDescription)); indices.AddRange(mesh.GetUnsignedIndices().Cast <ushort>()); } var meshData = new MeshData <VertexPositionNormal>( _scene.RootNode.Name, new VertexBuffer <VertexPositionNormal>(vertices.ToArray(), indices.ToArray())); return(Task.FromResult(meshData)); }
public AssimpImporter() { var importer = new AssimpContext(); AvaliableFormats = importer.GetSupportedImportFormats(); importer.Dispose(); }
public static bool SaveToGltf(this Scene model, string path, string fileName) { try { using (var importer = new AssimpContext()) { string outputFilePath = $"{path}/{fileName}.gltf"; if (importer.ExportFile(model, outputFilePath, "gltf2")) { // Replace the buffer path to a relative one. string gltf = File.ReadAllText(outputFilePath); gltf = gltf.Replace(path + '/', ""); File.WriteAllText(outputFilePath, gltf); return(true); } else { return(false); } } } catch (Exception e) { //Logger.LogException("Error in saving gltf: ", e); return(false); } }
public void TestConvertFromFile() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\Bob.md5mesh"); String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles\\Bob.dae"); AssimpContext importer = new AssimpContext(); importer.ConvertFromFileToFile(path, outputPath, "collada"); ExportDataBlob blob = importer.ConvertFromFileToBlob(path, "collada"); }
public void TestObjLoad() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\sphere.obj"); AssimpContext importer = new AssimpContext(); Scene scene = importer.ImportFile(path); Assert.IsNotNull(scene); Assert.IsNotNull(scene.RootNode); Assert.IsTrue(scene.RootNode.Name.Equals("sphere.obj")); }
public SimpleOpenGLSample() : base() { Title = "Quack! - AssimpNet Simple OpenGL Sample"; String fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "duck.dae"); AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); m_model = importer.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality); ComputeBoundingBox(); }
public void TestMultiSearchDirectoryLoad() { String fileName = "fenris.lws"; String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles\\fenris\\scenes"), Path.Combine(TestHelper.RootPath, "TestFiles\\fenris\\objects") }; FileIOSystem ioSystem = new FileIOSystem(searchPaths); AssimpContext importer = new AssimpContext(); importer.SetIOSystem(ioSystem); //None, using the "target high quality flags caused a crash with this model. Scene scene = importer.ImportFile(fileName, PostProcessSteps.None); Assert.IsNotNull(scene); }
public void TestMultiSearchDirectoryConvert() { String fileName = Path.Combine(TestHelper.RootPath, "TestFiles\\fenris\\scenes\\fenris.lws"); String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles\\fenris\\objects") }; FileIOSystem ioSystem = new FileIOSystem(searchPaths); AssimpContext importer = new AssimpContext(); importer.SetIOSystem(ioSystem); //Output path has to be specified fully, since we may be creating the file String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles\\fenris\\fenris2.obj"); importer.ConvertFromFileToFile(fileName, PostProcessSteps.None, outputPath, "obj", PostProcessSteps.None); }
public void TestIOSystemError() { String fileName = "duckduck.dae"; //GOOSE! String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles") }; FileIOSystem ioSystem = new FileIOSystem(searchPaths); AssimpContext importer = new AssimpContext(); importer.SetIOSystem(ioSystem); Assert.Throws<AssimpException>(delegate() { importer.ImportFile(fileName, PostProcessSteps.None); }); }
public void TestImportExportImportFile() { String colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); String plyPath = Path.Combine(TestHelper.RootPath, "TestFiles\\duck2.dae"); AssimpContext context = new AssimpContext(); Scene ducky = context.ImportFile(colladaPath); context.ExportFile(ducky, plyPath, "collada"); Scene ducky2 = context.ImportFile(plyPath); Assert.IsNotNull(ducky2); }
public void TestLoadFreeLibrary() { if(AssimpLibrary.Instance.IsLibraryLoaded) AssimpLibrary.Instance.FreeLibrary(); AssimpLibrary.Instance.LoadLibrary(); String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); AssimpContext importer = new AssimpContext(); importer.ImportFile(path); importer.Dispose(); AssimpLibrary.Instance.FreeLibrary(); }
public void TestImportFromStream() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); FileStream fs = File.OpenRead(path); AssimpContext importer = new AssimpContext(); LogStream.IsVerboseLoggingEnabled = true; LogStream logstream = new LogStream(delegate(String msg, String userData) { Console.WriteLine(msg); }); logstream.Attach(); Scene scene = importer.ImportFileFromStream(fs, ".dae"); fs.Close(); Assert.IsNotNull(scene); Assert.IsTrue((scene.SceneFlags & SceneFlags.Incomplete) != SceneFlags.Incomplete); }
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])); }
private void ConvertSceneC() { Console.WriteLine("Thread C: Starting convert."); AssimpContext importer = new AssimpContext(); String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles\\duck2.obj"); new ConsoleLogStream("Thread C:").Attach(); importer.SetConfig(new NormalSmoothingAngleConfig(55.0f)); importer.SetConfig(new FavorSpeedConfig(true)); Console.WriteLine("Thread C: Converting"); ExportDataBlob blob = importer.ConvertFromFileToBlob(path, "obj"); Console.WriteLine("Thread C: Done converting"); }
private void LoadSceneA() { Console.WriteLine("Thread A: Starting import."); AssimpContext importer = new AssimpContext(); String path = Path.Combine(TestHelper.RootPath, "TestFiles\\Bob.md5mesh"); new ConsoleLogStream("Thread A:").Attach(); Console.WriteLine("Thread A: Importing"); Scene scene = importer.ImportFile(path); Console.WriteLine("Thread A: Done importing"); }
private void LoadSceneB() { Console.WriteLine("Thread B: Starting import."); AssimpContext importer = new AssimpContext(); String path = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); new ConsoleLogStream("Thread B:").Attach(); importer.SetConfig(new NormalSmoothingAngleConfig(55.0f)); Console.WriteLine("Thread B: Importing"); Scene scene = importer.ImportFile(path); Console.WriteLine("Thread B: Done importing"); }
public void TestExportToBlob() { String colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles\\duck.dae"); AssimpContext context = new AssimpContext(); Scene ducky = context.ImportFile(colladaPath); ExportDataBlob blob = context.ExportToBlob(ducky, "obj"); Assert.IsTrue(blob.HasData); Assert.IsTrue(blob.NextBlob != null); Assert.IsTrue(blob.NextBlob.Name.Equals("mtl")); }
static void ExportFile(string fileName, string destFolder) { String targetMeshFile = Path.GetFileNameWithoutExtension(fileName) + ".mesh"; String targetAnimFile = Path.GetFileNameWithoutExtension(fileName) + ".anim"; Console.WriteLine("Exporting " + targetMeshFile + "..."); AssimpContext importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); importer.SetConfig(new VertexBoneWeightLimitConfig(4)); Scene scene = importer.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessSteps.FlipUVs); System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; FileStream fs = new FileStream(Path.Combine(destFolder, targetMeshFile), FileMode.Create); BinaryWriter dest = new BinaryWriter(fs); MeshBlock meshBlock = new MeshBlock(dest, "MX3D"); List<MeshNode> nodes = new List<MeshNode>(); addNodes(nodes, scene.RootNode, scene.Meshes[0]); for (int j = 0; j < 1; j++) { MeshBlock groupBlock = new MeshBlock(dest, "XGRP"); exportGroup(dest, scene.Meshes[j], scene, nodes); groupBlock.EndBlock(dest); } MeshBlock skeletonDataBlock; skeletonDataBlock = new MeshBlock(dest, "XSKL"); UInt32 boneCount = (UInt32)nodes.Count; dest.Write(boneCount); for (int j = 0; j < nodes.Count; j++) { exportBone(dest, nodes[j], scene, j); } skeletonDataBlock.EndBlock(dest); meshBlock.EndBlock(dest); dest.Close(); fs.Close(); for (int i = 0; i < scene.AnimationCount; i++) { Animation animation = scene.Animations[i]; String name = animation.Name; if (name.Length <= 0) { name = Path.GetFileNameWithoutExtension(targetAnimFile); int p = name.LastIndexOf("@"); if (p >= 0) { name = name.Substring(p + 1); } } Console.WriteLine("Exporting " + name + " animation..."); fs = new FileStream(Path.Combine(destFolder, targetAnimFile), FileMode.Create); dest = new BinaryWriter(fs); byte[] tagData = Encoding.ASCII.GetBytes("ANIM"); dest.Write(tagData); float FPS = (float)animation.TicksPerSecond; dest.Write(FPS); byte loop = 1; dest.Write(loop); float loopPoint = 0.0f; dest.Write(loopPoint); float animSpeed = 1.0f; dest.Write(animSpeed); String nextAnim = ""; exportString(dest, nextAnim); UInt32 channelCount = (UInt32)animation.NodeAnimationChannelCount; dest.Write(channelCount); for (int j = 0; j < channelCount; j++) { NodeAnimationChannel channel = animation.NodeAnimationChannels[j]; exportString(dest, channel.NodeName); UInt32 posCount = (UInt32)channel.PositionKeyCount; dest.Write(posCount); for (int k = 0; k < posCount; k++) { float t = (float)channel.PositionKeys[k].Time; float x = channel.PositionKeys[k].Value.X; float y = channel.PositionKeys[k].Value.Y; float z = channel.PositionKeys[k].Value.Z; float w = 1.0f; dest.Write(t); dest.Write(x); dest.Write(y); dest.Write(z); dest.Write(w); } UInt32 rotCount = (UInt32)channel.RotationKeyCount; dest.Write(rotCount); for (int k = 0; k < rotCount; k++) { float t = (float)channel.RotationKeys[k].Time; float x = channel.RotationKeys[k].Value.X; float y = channel.RotationKeys[k].Value.Y; float z = channel.RotationKeys[k].Value.Z; float w = channel.RotationKeys[k].Value.W; dest.Write(t); dest.Write(x); dest.Write(y); dest.Write(z); dest.Write(w); } UInt32 scaleCount = (UInt32)channel.ScalingKeyCount; dest.Write(scaleCount); for (int k = 0; k < scaleCount; k++) { float t = (float)channel.ScalingKeys[k].Time; float x = channel.ScalingKeys[k].Value.X; float y = channel.ScalingKeys[k].Value.Y; float z = channel.ScalingKeys[k].Value.Z; float w = 1.0f; dest.Write(t); dest.Write(x); dest.Write(y); dest.Write(z); dest.Write(w); } } dest.Close(); fs.Close(); } }
public void TestExportToFile() { String path = Path.Combine(TestHelper.RootPath, "TestFiles\\ExportedTriangle.obj"); //Create a very simple scene a single node with a mesh that has a single face, a triangle and a default material Scene scene = new Scene(); scene.RootNode = new Node("Root"); Mesh triangle = new Mesh("", PrimitiveType.Triangle); triangle.Vertices.Add(new Vector3D(1, 0, 0)); triangle.Vertices.Add(new Vector3D(5, 5, 0)); triangle.Vertices.Add(new Vector3D(10, 0, 0)); triangle.Faces.Add(new Face(new int[] { 0, 1, 2 })); triangle.MaterialIndex = 0; scene.Meshes.Add(triangle); scene.RootNode.MeshIndices.Add(0); Material mat = new Material(); mat.Name = "MyMaterial"; scene.Materials.Add(mat); //Export the scene then read it in and compare! AssimpContext context = new AssimpContext(); Assert.IsTrue(context.ExportFile(scene, path, "obj")); Scene importedScene = context.ImportFile(path); Assert.IsTrue(importedScene.MeshCount == scene.MeshCount); Assert.IsTrue(importedScene.MaterialCount == 2); //Always has the default material, should also have our material //Compare the meshes Mesh importedTriangle = importedScene.Meshes[0]; Assert.IsTrue(importedTriangle.VertexCount == triangle.VertexCount); for(int i = 0; i < importedTriangle.VertexCount; i++) { Assert.IsTrue(importedTriangle.Vertices[i].Equals(triangle.Vertices[i])); } Assert.IsTrue(importedTriangle.FaceCount == triangle.FaceCount); for(int i = 0; i < importedTriangle.FaceCount; i++) { Face importedFace = importedTriangle.Faces[i]; Face face = triangle.Faces[i]; for(int j = 0; j < importedFace.IndexCount; j++) { Assert.IsTrue(importedFace.Indices[j] == face.Indices[j]); } } }