public void FirstBatchTableTest() { // arrange var batchTable = new BatchTable(); var batchTableItem1 = new BatchTableItem(); batchTableItem1.Name = "first item"; batchTableItem1.Values = new string[3] { "0", "1", "2" }; var batchTableItem2 = new BatchTableItem(); batchTableItem2.Name = "second item"; batchTableItem2.Values = new string[3] { "100", "101", "102" }; batchTable.BatchTableItems.Add(batchTableItem1); batchTable.BatchTableItems.Add(batchTableItem2); // act var json = JsonConvert.SerializeObject(batchTable, new BatchTableJsonConverter(typeof(BatchTable))); // assert Assert.IsTrue(json == "{\"first item\":[\"0\",\"1\",\"2\"],\"second item\":[\"100\",\"101\",\"102\"]}"); }
public IEnumerator LoadStream(string relativeFilePath) { yield return(this.loader.LoadStream(relativeFilePath)); if (this.loader.LoadedStream.Length == 0) { LoadedStream = new MemoryStream(0); } else { // We need to read the header info off of the .b3dm file // Using statment will ensure this.loader.LoadedStream is disposed using (BinaryReader br = new BinaryReader(this.loader.LoadedStream)) { // Remove query parameters if there are any string filename = relativeFilePath.Split('?')[0]; // If this isn't a b3dm file (i.e. gltf or glb) this should just copy the underlying stream if (Path.GetExtension(filename).ToLower() == ".b3dm") { UInt32 magic = br.ReadUInt32(); if (magic != 0x6D643362) { Debug.LogError("Unsupported magic number in b3dm file: " + magic + " " + relativeFilePath); } UInt32 version = br.ReadUInt32(); if (version != 1) { Debug.LogError("Unsupported version number in b3dm file: " + version + " " + relativeFilePath); } // The length of the entire tile, including the header, in bytes. UInt32 byteLength = br.ReadUInt32(); if (byteLength == 0) { Debug.LogError("Unexpected zero length in b3dm file: " + relativeFilePath); } // The length of the Feature Table JSON section in bytes. UInt32 featureTableLength = br.ReadUInt32(); if (featureTableLength == 0) { Debug.LogError("Unexpected zero length feature table in b3dm file: " + relativeFilePath); } // The length of the Feature Table binary section in bytes. UInt32 featureBinaryLength = br.ReadUInt32(); if (featureBinaryLength != 0) { Debug.LogError("Unexpected non-zero length feature binary in b3dm file: " + relativeFilePath); } // The length of the Batch Table JSON section in bytes. Zero indicates there is no Batch Table. UInt32 batchTableLength = br.ReadUInt32(); // The length of the Batch Table binary section in bytes. // If batchTableJSONByteLength is zero, this will also be zero. UInt32 batchBinaryLength = br.ReadUInt32(); if (batchTableLength == 0 && batchBinaryLength != 0) { Debug.LogError("Unexpected non-zero length batch binary in b3dm file: " + relativeFilePath); } string featureTableJson = new String(br.ReadChars((int)featureTableLength)); FeatureTable ft = JsonConvert.DeserializeObject <FeatureTable>(featureTableJson); if (batchTableLength == 0) { if (ft.BATCH_LENGTH != 0) { Debug.LogError("Unexpected non-zero length feature table BATCH_LENGTH in b3dm file: " + relativeFilePath); } } else { string batchTableJson = new string(br.ReadChars((int)batchTableLength)); BatchTable bt = JsonConvert.DeserializeObject <BatchTable>(batchTableJson); } // after this will be the binary glTF } LoadedStream = new MemoryStream((int)(loader.LoadedStream.Length - loader.LoadedStream.Position)); CopyStream(loader.LoadedStream, LoadedStream); } } }