コード例 #1
0
        public void GLBSaveWithoutBinary()
        {
            string outPath =
                TestAssetPaths.GetOutPath(TestAssetPaths.GLB_BOX_OUT_PATH_TEMPLATE, 15, TestAssetPaths.GLB_EXTENSION);
            FileStream glbOutStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            // first create from empty stream
            GLBObject glbObject        = GLBBuilder.ConstructFromStream(glbOutStream);
            uint      initialGLBLength = glbObject.BinaryChunkInfo.Length;

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.Write(TestAssetPaths.MIN_GLTF_STR);
            writer.Flush();
            stream.Position = 0;

            GLTFRoot newRoot;

            GLTFParser.ParseJson(stream, out newRoot);
            GLBBuilder.SetRoot(glbObject, newRoot);
            GLBBuilder.UpdateStream(glbObject);
            Assert.AreEqual(glbObject.Header.FileLength, glbObject.JsonChunkInfo.StartPosition + glbObject.JsonChunkInfo.Length + GLTFParser.CHUNK_HEADER_SIZE);
            glbOutStream.Close();
            glbOutStream = new FileStream(outPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            List <ChunkInfo> chunks = GLTFParser.FindChunks(glbOutStream);

            Assert.AreEqual(1, chunks.Count);

            glbOutStream.Position = 0;
            GLBObject testObject = GLBBuilder.ConstructFromStream(glbOutStream);

            Assert.AreEqual(glbObject.JsonChunkInfo.Length, testObject.JsonChunkInfo.Length);
            Assert.AreEqual(glbObject.BinaryChunkInfo.Length, testObject.BinaryChunkInfo.Length);
        }
コード例 #2
0
        public void UpdateStream()
        {
            Assert.IsTrue(File.Exists(TestAssetPaths.GLB_BOOMBOX_PATH));
            FileStream glbStream = File.OpenRead(TestAssetPaths.GLB_BOOMBOX_PATH);
            string     outPath   =
                TestAssetPaths.GetOutPath(TestAssetPaths.GLB_BOX_OUT_PATH_TEMPLATE, 0, TestAssetPaths.GLB_EXTENSION);
            FileStream glbOutStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
            GLBObject  glbObject    = GLBBuilder.ConstructFromStream(glbStream, glbOutStream);

            for (int i = 0; i < 10; ++i)
            {
                glbObject.Root.Nodes.Add(new Node
                {
                    Mesh = new MeshId
                    {
                        Id   = 0,
                        Root = glbObject.Root
                    }
                });
            }

            GLBBuilder.UpdateStream(glbObject);
            glbOutStream.Position = 0;

            GLTFRoot glbOutRoot;

            GLTFParser.ParseJson(glbOutStream, out glbOutRoot);
            FileStream glbFileStream = glbObject.Stream as FileStream;

            Assert.AreEqual(glbFileStream, glbFileStream);
            glbOutStream.Position = 0;
            List <ChunkInfo> chunkInfo = GLTFParser.FindChunks(glbOutStream);

            Assert.AreEqual(2, chunkInfo.Count);
            CompareBinaryData(glbObject, glbStream);
        }