private BufferViewId AddBinaryDataToStreamHelper(GLBObject glbObject, Stream blobToAdd) { int previousCount = 0; if (glbObject.Root.BufferViews != null) { previousCount = glbObject.Root.BufferViews.Count; } uint previousGLBLength = glbObject.Header.FileLength; uint previousChunkLength = glbObject.BinaryChunkInfo.Length; uint bufferSize = GLBBuilder.CalculateAlignment((uint)blobToAdd.Length, 4); BufferViewId bufferViewId = GLBBuilder.AddBinaryData(glbObject, blobToAdd); uint headerModifier = previousChunkLength == 0 ? GLTFParser.CHUNK_HEADER_SIZE : 0; Assert.AreEqual(previousCount + 1, glbObject.Root.BufferViews.Count); Assert.AreEqual(previousCount, bufferViewId.Id); Assert.AreEqual(previousGLBLength + bufferSize + headerModifier, glbObject.Header.FileLength); Assert.AreEqual(previousChunkLength + bufferSize, glbObject.BinaryChunkInfo.Length); Assert.AreEqual(previousChunkLength + bufferSize, glbObject.Root.Buffers[0].ByteLength); Assert.AreEqual(glbObject.Header.FileLength, glbObject.Stream.Length); return(bufferViewId); }
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(); }