Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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"));
        }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
0
            /// <summary>
            /// Exports to BLOB.
            /// </summary>
            /// <param name="root">The root.</param>
            /// <param name="formatId">The format identifier.</param>
            /// <param name="blob">The BLOB.</param>
            /// <returns></returns>
            public ErrorCode ExportToBlob(HxScene.SceneNode root, string formatId, out ExportDataBlob blob)
            {
                Clear();
                AssimpContext exporter  = null;
                var           useExtern = false;

                if (Configuration.ExternalContext != null)
                {
                    exporter  = Configuration.ExternalContext;
                    useExtern = true;
                }
                else
                {
                    exporter = new AssimpContext();
                }
                var scene          = CreateScene(root);
                var postProcessing = configuration.PostProcessing;

                if (configuration.FlipWindingOrder)
                {
                    postProcessing |= PostProcessSteps.FlipWindingOrder;
                }
                blob = null;
                try
                {
                    blob = exporter.ExportToBlob(scene, formatId, postProcessing);
                    return(ErrorCode.Succeed);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex.Message);
                    AssimpExceptionOccurred?.Invoke(this, ex);
                }
                finally
                {
                    if (!useExtern)
                    {
                        exporter.Dispose();
                    }
                }

                return(ErrorCode.Failed);
            }
Exemplo n.º 7
0
        /// <summary>
        /// Exports the given scene to a chosen file format. Returns the exported data as a binary blob which you can embed into another data structure or file.
        /// </summary>
        /// <param name="scene">Scene to export, it is the responsibility of the caller to free this when finished.</param>
        /// <param name="formatId">Format id describing which format to export to.</param>
        /// <param name="preProcessing">Pre processing flags to operate on the scene during the export.</param>
        /// <returns>Exported binary blob, or null if there was an error.</returns>
        public static ExportDataBlob ExportSceneToBlob(IntPtr scene, String formatId, PostProcessSteps preProcessing)
        {
            if(String.IsNullOrEmpty(formatId) || scene == IntPtr.Zero)
                return null;

            IntPtr blobPtr = aiExportSceneToBlob(scene, formatId, (uint) preProcessing);

            if(blobPtr == IntPtr.Zero)
                return null;

            AiExportDataBlob blob = MemoryHelper.MarshalStructure<AiExportDataBlob>(blobPtr);
            ExportDataBlob dataBlob = new ExportDataBlob(ref blob);
            aiReleaseExportBlob(blobPtr);

            return dataBlob;
        }