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 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 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 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 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 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); }
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"); }
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 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"); }
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])); }
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); }
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]); } } }
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")); }
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); }