public void WriteB3dmWithBatchTest() { // arrange var buildingGlb = File.ReadAllBytes(@"testfixtures/with_batch.glb"); var batchTableJson = File.ReadAllText(@"testfixtures/BatchTableJsonExpected.json"); var b3dmBytesExpected = File.OpenRead(@"testfixtures/with_batch.b3dm"); var b3dmExpected = B3dmReader.ReadB3dm(b3dmBytesExpected); var b3dm = new B3dm(buildingGlb); b3dm.FeatureTableJson = b3dmExpected.FeatureTableJson; b3dm.BatchTableJson = b3dmExpected.BatchTableJson; b3dm.FeatureTableBinary = b3dmExpected.FeatureTableBinary; b3dm.BatchTableBinary = b3dmExpected.BatchTableBinary; // act var result = "with_batch.b3dm"; var newB3dm = B3dmWriter.WriteB3dm(result, b3dm); var b3dmActual = B3dmReader.ReadB3dm(File.OpenRead(newB3dm)); // Assert Assert.IsTrue(b3dmActual.B3dmHeader.Magic == b3dmExpected.B3dmHeader.Magic); Assert.IsTrue(b3dmActual.B3dmHeader.Version == b3dmExpected.B3dmHeader.Version); Assert.IsTrue(b3dmActual.B3dmHeader.FeatureTableJsonByteLength == b3dmExpected.B3dmHeader.FeatureTableJsonByteLength); Assert.IsTrue(b3dmActual.B3dmHeader.BatchTableJsonByteLength == b3dmExpected.B3dmHeader.BatchTableJsonByteLength); Assert.IsTrue(b3dmActual.B3dmHeader.ByteLength == b3dmExpected.B3dmHeader.ByteLength); var fiResult = new FileInfo(result); var fiExpected = new FileInfo(@"testfixtures/with_batch.b3dm"); Assert.IsTrue(fiResult.Length == fiExpected.Length); Assert.IsTrue(FilesAreEqual(fiResult, fiExpected)); }
static void Pack(PackOptions o) { Console.WriteLine($"Action: Pack"); Console.WriteLine($"Input: {o.Input}"); var f = File.ReadAllBytes(o.Input); var batchFile = Path.GetFileNameWithoutExtension(o.Input) + ".batch"; var b3dm = new B3dm.Tile.B3dm(f); if (File.Exists(batchFile)) { Console.WriteLine($"Input batch file: {batchFile}"); var batchTableJson = File.ReadAllLines(batchFile); b3dm.FeatureTableJson = batchTableJson[0]; b3dm.BatchTableJson = batchTableJson[1]; } var b3dmfile = (o.Output == string.Empty ? Path.GetFileNameWithoutExtension(o.Input) + ".b3dm" : o.Output); if (File.Exists(b3dmfile) && !o.Force) { Console.WriteLine($"File {b3dmfile} already exists. Specify -f or --force to overwrite existing files."); } else { B3dmWriter.WriteB3dm(b3dmfile, b3dm); Console.WriteLine("B3dm created " + b3dmfile); } }
private static int WriteTiles(NpgsqlConnection conn, string geometryTable, string geometryColumn, string idcolumn, double[] translation, List <Tile> tiles, int epsg, string outputPath, int counter, int maxcount, string colorColumn = "", string attributesColumn = "", string lodColumn = "", string query = "") { foreach (var t in tiles) { counter++; var perc = Math.Round(((double)counter / maxcount) * 100, 2); Console.Write($"\rcreating tiles: {counter}/{maxcount} - {perc:F}%"); var geometries = BoundingBoxRepository.GetGeometrySubset(conn, geometryTable, geometryColumn, idcolumn, translation, t, epsg, colorColumn, attributesColumn, lodColumn, query); var triangleCollection = GetTriangles(geometries); var attributes = GetAttributes(geometries); var b3dm = B3dmCreator.GetB3dm(attributesColumn, attributes, triangleCollection); B3dmWriter.WriteB3dm($"{outputPath}/tiles/{counter}.b3dm", b3dm); if (t.Children != null) { counter = WriteTiles(conn, geometryTable, geometryColumn, idcolumn, translation, t.Children, epsg, outputPath, counter, maxcount, colorColumn, attributesColumn, lodColumn, query); } } return(counter); }
static void Main(string[] args) { Console.WriteLine("Sample conversion from glb to b3dm."); var inputfile = @"testfixtures/building.glb"; var buildingGlb = File.ReadAllBytes(inputfile); var b3dm = new B3dm.Tile.B3dm(buildingGlb); B3dmWriter.WriteB3dm($"building.b3dm", b3dm); Console.WriteLine($"File building.b3dm is written..."); Console.WriteLine($"Press any key to continue..."); Console.ReadKey(); }
private static void WriteTiles(NpgsqlConnection conn, string geometryTable, string geometryColumn, string idcolumn, double[] translation, Node node, string outputPath, string colorColumn = "", string attributesColumn = "") { if (node.Features.Count > 0) { counter++; var subset = (from f in node.Features select(f.Id)).ToArray(); var geometries = BoundingBoxRepository.GetGeometrySubset(conn, geometryTable, geometryColumn, idcolumn, translation, subset, colorColumn, attributesColumn); var triangleCollection = GetTriangles(geometries); var bytes = GlbCreator.GetGlb(triangleCollection); var b3dm = new B3dm.Tile.B3dm(bytes); var featureTable = new FeatureTable(); featureTable.BATCH_LENGTH = geometries.Count; b3dm.FeatureTableJson = JsonConvert.SerializeObject(featureTable); if (attributesColumn != string.Empty) { var batchtable = new BatchTable(); var allattributes = new List <object>(); foreach (var geom in geometries) { // only take the first now.... allattributes.Add(geom.Attributes[0]); } var item = new BatchTableItem(); item.Name = attributesColumn; item.Values = allattributes.ToArray(); batchtable.BatchTableItems.Add(item); var json = JsonConvert.SerializeObject(batchtable, new BatchTableJsonConverter(typeof(BatchTable))); b3dm.BatchTableJson = json; } B3dmWriter.WriteB3dm($"{outputPath}/tiles/{node.Id}.b3dm", b3dm); } // and write children too foreach (var subnode in node.Children) { var perc = Math.Round(((double)counter / Counter.Instance.Count) * 100, 2); Console.Write($"\rProgress: tile {counter} - {perc.ToString("F")}%"); WriteTiles(conn, geometryTable, geometryColumn, idcolumn, translation, subnode, outputPath, colorColumn, attributesColumn); } }
public void WriteB3dmTest() { // arrange var buildingGlb = File.ReadAllBytes(@"testfixtures/1.glb"); var b3dm = new B3dm(buildingGlb); var b3dmExpected = File.ReadAllBytes(@"testfixtures/1_expected.b3dm"); // act var result = @"1.b3dm"; B3dmWriter.WriteB3dm(result, b3dm); // Assert var fiResult = new FileInfo(result); var fiExpected = new FileInfo(@"testfixtures/1_expected.b3dm"); Assert.IsTrue(FilesAreEqual(fiResult, fiExpected)); Assert.IsTrue(fiResult.Length == b3dmExpected.Length); }
private static void WriteTiles(NpgsqlConnection conn, string geometryTable, string geometryColumn, double[] translation, Node node, string outputPath, string colorColumn = "") { if (node.Features.Count > 0) { counter++; var subset = (from f in node.Features select(f.Id)).ToArray(); var geometries = BoundingBoxRepository.GetGeometrySubset(conn, geometryTable, geometryColumn, translation, subset, colorColumn); var triangleCollection = Triangulator.GetTriangles(geometries); var bytes = GlbCreator.GetGlb(triangleCollection); var b3dm = new B3dm.Tile.B3dm(bytes); var featureTable = new FeatureTable(); featureTable.BATCH_LENGTH = geometries.Count; b3dm.FeatureTableJson = JsonConvert.SerializeObject(featureTable); var batchTable = new BatchTable(); var r = new Random(); var heights = new List <float>(); for (var i = 0; i < geometries.Count; i++) { heights.Add(r.Next(100)); } batchTable.Height = heights.ToArray(); b3dm.BatchTableJson = JsonConvert.SerializeObject(batchTable); B3dmWriter.WriteB3dm($"{outputPath}/tiles/{node.Id}.b3dm", b3dm); } // and write children too foreach (var subnode in node.Children) { var perc = Math.Round(((double)counter / Counter.Instance.Count) * 100, 2); Console.Write($"\rProgress: tile {counter} - {perc.ToString("F")}%"); WriteTiles(conn, geometryTable, geometryColumn, translation, subnode, outputPath, colorColumn); } }