Beispiel #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);
        }
Beispiel #2
0
        public void CreateAndSaveFromEmptyStream()
        {
            string outPath =
                TestAssetPaths.GetOutPath(TestAssetPaths.GLB_BOX_OUT_PATH_TEMPLATE, 10, TestAssetPaths.GLB_EXTENSION);

            FileStream glbStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
            GLBObject  glbObject = GLBBuilder.ConstructFromStream(glbStream);

            Assert.IsNull(glbObject.Root);

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

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

            GLTFRoot gltfRoot;

            GLTFParser.ParseJson(stream, out gltfRoot);
            GLBBuilder.SetRoot(glbObject, gltfRoot);

            GLBBuilder.UpdateStream(glbObject);

            glbStream.Close();
            glbStream = new FileStream(outPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

            glbObject = GLBBuilder.ConstructFromStream(glbStream);
            Assert.IsNotNull(glbObject.Root);
            glbStream.Close();
        }
Beispiel #3
0
        public void CreateEmptyStreamAndAppendGLB()
        {
            string outPath =
                TestAssetPaths.GetOutPath(TestAssetPaths.GLB_BOX_OUT_PATH_TEMPLATE, 11, TestAssetPaths.GLB_EXTENSION);

            FileStream glbStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
            GLBObject  glbObject = GLBBuilder.ConstructFromStream(glbStream);

            Assert.IsNull(glbObject.Root);

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

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

            GLTFRoot gltfRoot;

            GLTFParser.ParseJson(stream, out gltfRoot);
            GLBBuilder.SetRoot(glbObject, gltfRoot);
            GLBBuilder.UpdateStream(glbObject);

            FileStream glbAppendStream = File.OpenRead(TestAssetPaths.GLB_BOOMBOX_PATH);
            GLBObject  glbAppendObject = GLBBuilder.ConstructFromStream(glbAppendStream);

            GLBBuilder.AddBinaryData(glbObject, glbAppendStream, false, glbAppendObject.BinaryChunkInfo.StartPosition + GLTFParser.CHUNK_HEADER_SIZE);

            glbStream.Close();
            glbStream = new FileStream(outPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

            glbObject = GLBBuilder.ConstructFromStream(glbStream);
            Assert.IsNotNull(glbObject.Root);
            Assert.AreEqual(glbAppendObject.BinaryChunkInfo.Length, glbObject.BinaryChunkInfo.Length);
            glbStream.Close();
        }