From dc9fb87e216ac68c228c46b1c71fd017d30bc8ac Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Tue, 15 Oct 2024 10:30:09 +0200 Subject: [PATCH] add tileset version option, release 2.18 --- README.md | 4 ++++ src/b3dm.tileset/CesiumTiler.cs | 10 +++++----- src/b3dm.tileset/TilesetClasses.cs | 4 +++- src/b3dm.tileset/TreeSerializer.cs | 13 ++++++++----- src/b3dm.tileset/b3dm.tileset.csproj | 2 +- src/pg2b3dm/Options.cs | 4 ++++ src/pg2b3dm/Program.cs | 8 ++++++-- src/pg2b3dm/pg2b3dm.csproj | 8 ++++---- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 962a8995..083e6526 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,8 @@ If --username and/or --dbname are not specified the current username is used as --shaderscolumn (Default: '') shaders column (Cesium) + --tilesetVersion (Default: '') Tileset version (Cesium) + --use_implicit_tiling (Default: true) use 1.1 implicit tiling (Cesium) --add_outlines (Default: false) Add outlines (Cesium) @@ -564,6 +566,8 @@ Press F5 to start debugging. ## History +2024-10-15: release 2.18.0 add option tilesetVersion + 2024-09-04: release 2.17.0: - Add support for DateTime in 1.1 Metadata (EXT_Structural_Metadata) diff --git a/src/b3dm.tileset/CesiumTiler.cs b/src/b3dm.tileset/CesiumTiler.cs index d0d614cb..08e8cced 100644 --- a/src/b3dm.tileset/CesiumTiler.cs +++ b/src/b3dm.tileset/CesiumTiler.cs @@ -10,7 +10,7 @@ namespace B3dm.Tileset; public static class CesiumTiler { - public static void CreateImplicitTileset(Version version, bool createGltf, string outputDirectory, double[] translation, double geometricError, double[] rootBoundingVolumeRegion, string subtreesDirectory, List tiles) + public static void CreateImplicitTileset(Version version, bool createGltf, string outputDirectory, double[] translation, double geometricError, double[] rootBoundingVolumeRegion, string subtreesDirectory, List tiles, string tilesetVersion="") { if (!Directory.Exists(subtreesDirectory)) { Directory.CreateDirectory(subtreesDirectory); @@ -28,7 +28,7 @@ public static void CreateImplicitTileset(Version version, bool createGltf, strin var availableLevels = tiles.Max(t => t.Z) + 1; Console.WriteLine("Available Levels: " + availableLevels); Console.WriteLine("Subtree Levels: " + subtreeLevels); - var tilesetjson = TreeSerializer.ToImplicitTileset(translation, rootBoundingVolumeRegion, geometricError, availableLevels, subtreeLevels, version, createGltf); + var tilesetjson = TreeSerializer.ToImplicitTileset(translation, rootBoundingVolumeRegion, geometricError, availableLevels, subtreeLevels, version, createGltf, tilesetVersion); var file = $"{outputDirectory}{Path.AltDirectorySeparatorChar}tileset.json"; var json = JsonConvert.SerializeObject(tilesetjson, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); Console.WriteLine("SubdivisionScheme: QUADTREE"); @@ -36,12 +36,12 @@ public static void CreateImplicitTileset(Version version, bool createGltf, strin File.WriteAllText(file, json); } - public static void CreateExplicitTilesetsJson(Version version, string outputDirectory, double[] translation, double geometricError, double geometricErrorFactor, string refinement, bool use10, double[] rootBoundingVolumeRegion, Tile tile, List tiles) + public static void CreateExplicitTilesetsJson(Version version, string outputDirectory, double[] translation, double geometricError, double geometricErrorFactor, string refinement, bool use10, double[] rootBoundingVolumeRegion, Tile tile, List tiles, string tilesetVersion="") { var splitLevel = (int)Math.Ceiling((tiles.Max((Tile s) => s.Z) + 1.0) / 2.0); var rootTiles = TileSelector.Select(tiles, tile, 0, splitLevel); - var rootTileset = TreeSerializer.ToTileset(rootTiles, translation, rootBoundingVolumeRegion, geometricError, geometricErrorFactor, version, refinement, use10); + var rootTileset = TreeSerializer.ToTileset(rootTiles, translation, rootBoundingVolumeRegion, geometricError, geometricErrorFactor, version, refinement, use10, tilesetVersion); var maxlevel = tiles.Max((Tile s) => s.Z); @@ -61,7 +61,7 @@ public static void CreateExplicitTilesetsJson(Version version, string outputDire var zminmax = children.Select(t => new double[] { (double)t.ZMin, (double)t.ZMax }).SelectMany(t => t).ToArray(); var childrenBoundingVolumeRegion = GetBoundingBox(children).ToRadians().ToRegion(zminmax[0], zminmax[1]); /// translation is the same as identity matrix in case of child tileset - var tileset = TreeSerializer.ToTileset(children, null, childrenBoundingVolumeRegion, geometricError, geometricErrorFactor, version, refinement, use10); + var tileset = TreeSerializer.ToTileset(children, null, childrenBoundingVolumeRegion, geometricError, geometricErrorFactor, version, refinement, use10, tilesetVersion); var childGeometricError = GeometricErrorCalculator.GetGeometricError(geometricError, geometricErrorFactor, splitLevel); tileset.geometricError = childGeometricError; diff --git a/src/b3dm.tileset/TilesetClasses.cs b/src/b3dm.tileset/TilesetClasses.cs index 53da3819..6044a2b2 100644 --- a/src/b3dm.tileset/TilesetClasses.cs +++ b/src/b3dm.tileset/TilesetClasses.cs @@ -6,9 +6,9 @@ namespace B3dm.Tileset; public class TileSet { + public Asset asset { get; set; } public double geometricError { get; set; } public Root root { get; set; } - public Asset asset { get; set; } } public class Child : ICloneable @@ -61,4 +61,6 @@ public class Asset public string generator { get; set; } public string version { get; set; } + + public string tilesetVersion { get; set; } } diff --git a/src/b3dm.tileset/TreeSerializer.cs b/src/b3dm.tileset/TreeSerializer.cs index 6430d98f..d7727c2d 100644 --- a/src/b3dm.tileset/TreeSerializer.cs +++ b/src/b3dm.tileset/TreeSerializer.cs @@ -10,11 +10,11 @@ namespace B3dm.Tileset; public static class TreeSerializer { - public static TileSet ToImplicitTileset(double[] transform, double[] box, double maxGeometricError, int availableLevels, int subtreeLevels, Version version = null, bool createGltf = false) + public static TileSet ToImplicitTileset(double[] transform, double[] box, double maxGeometricError, int availableLevels, int subtreeLevels, Version version = null, bool createGltf = false, string tilesetVersion = "") { var ext = createGltf ? ".glb" : ".b3dm"; var geometricError = maxGeometricError; - var tileset = GetTilesetObject(version, maxGeometricError); + var tileset = GetTilesetObject(version, maxGeometricError, false, tilesetVersion); var t = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0,1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, @@ -28,9 +28,9 @@ public static TileSet ToImplicitTileset(double[] transform, double[] box, double return tileset; } - public static TileSet ToTileset(List tiles, double[] transform, double[] region, double geometricError, double geometricErrorFactor = 2, Version version = null, string refine="ADD", bool use10 = false) + public static TileSet ToTileset(List tiles, double[] transform, double[] region, double geometricError, double geometricErrorFactor = 2, Version version = null, string refine="ADD", bool use10 = false, string tilesetVersion = "") { - var tileset = GetTilesetObject(version, geometricError, use10); + var tileset = GetTilesetObject(version, geometricError, use10, tilesetVersion); var t = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0,1.0, 0.0, 0.0, @@ -55,10 +55,13 @@ public static TileSet ToTileset(List tiles, double[] transform, double[] r return tileset; } - public static TileSet GetTilesetObject(Version version, double geometricError, bool use10 = false) + public static TileSet GetTilesetObject(Version version, double geometricError, bool use10 = false, string tilesetVersion = "") { var version3DTiles = use10 ? "1.0" : "1.1"; var tileset = new TileSet { asset = new Asset() { version = $"{version3DTiles}", generator = $"pg2b3dm {version}" } }; + if(!string.IsNullOrEmpty(tilesetVersion)) { + tileset.asset.tilesetVersion = tilesetVersion; + } tileset.geometricError = geometricError; return tileset; } diff --git a/src/b3dm.tileset/b3dm.tileset.csproj b/src/b3dm.tileset/b3dm.tileset.csproj index 6f7116b4..2b9cabcf 100644 --- a/src/b3dm.tileset/b3dm.tileset.csproj +++ b/src/b3dm.tileset/b3dm.tileset.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/pg2b3dm/Options.cs b/src/pg2b3dm/Options.cs index ff951639..4ea33416 100644 --- a/src/pg2b3dm/Options.cs +++ b/src/pg2b3dm/Options.cs @@ -54,6 +54,9 @@ public class Options public string ShadersColumn { get; set; } // cesium specific options + [Option("tileset_version", Required = false, Default = "", HelpText = "Tileset version (Cesium)", SetName = "Cesium")] + public string TilesetVersion { get; set; } + [Option("max_features_per_tile", Required = false, Default = 1000, HelpText = "maximum features per tile (Cesium)", SetName = "Cesium")] public int MaxFeaturesPerTile { get; set; } @@ -78,6 +81,7 @@ public class Options [Option("skip_create_tiles", Required = false, Default = false, HelpText = "Skip creating tiles, only create tileset.json files (Cesium)", SetName = "Cesium")] public bool SkipCreateTiles { get; set; } + // mapbox specific options [Option("zoom", Required = false, Default = 15, HelpText = "Zoom level (Mapbox)", SetName = "Mapbox")] public int Zoom { get; set; } diff --git a/src/pg2b3dm/Program.cs b/src/pg2b3dm/Program.cs index 14ef16c4..c8115acd 100644 --- a/src/pg2b3dm/Program.cs +++ b/src/pg2b3dm/Program.cs @@ -62,6 +62,7 @@ static void Main(string[] args) var shadersColumn = o.ShadersColumn; var attributeColumns = o.AttributeColumns; var copyright = o.Copyright; + var tilesetVersion = o.TilesetVersion; var query = o.Query; @@ -163,6 +164,9 @@ static void Main(string[] args) Console.WriteLine($"Add outlines: {addOutlines}"); Console.WriteLine($"Use 3D Tiles 1.1 implicit tiling: {o.UseImplicitTiling}"); + if(!tilesetVersion.Equals(string.Empty)) { + Console.WriteLine($"Tileset version: {tilesetVersion}"); + } var rootBoundingVolumeRegion = bbox.ToRadians().ToRegion(zmin, zmax); @@ -180,10 +184,10 @@ static void Main(string[] args) if (tiles.Count(tile => tile.Available) > 0) { if (useImplicitTiling) { - CesiumTiler.CreateImplicitTileset(version, createGltf, outputDirectory, translation, o.GeometricError, rootBoundingVolumeRegion, subtreesDirectory, tiles); + CesiumTiler.CreateImplicitTileset(version, createGltf, outputDirectory, translation, o.GeometricError, rootBoundingVolumeRegion, subtreesDirectory, tiles, tilesetVersion); } else { - CesiumTiler.CreateExplicitTilesetsJson(version, outputDirectory, translation, o.GeometricError, o.GeometricErrorFactor, refinement, use10, rootBoundingVolumeRegion, tile, tiles); + CesiumTiler.CreateExplicitTilesetsJson(version, outputDirectory, translation, o.GeometricError, o.GeometricErrorFactor, refinement, use10, rootBoundingVolumeRegion, tile, tiles, tilesetVersion); } } Console.WriteLine(); diff --git a/src/pg2b3dm/pg2b3dm.csproj b/src/pg2b3dm/pg2b3dm.csproj index 15fccc04..b35bd257 100644 --- a/src/pg2b3dm/pg2b3dm.csproj +++ b/src/pg2b3dm/pg2b3dm.csproj @@ -6,10 +6,10 @@ ./nupkg true pg2b3dm - 2.17.0 + 2.18.0 Console tool for converting PostGIS geometries to 3D Tiles - 2.17.0 - 2.17.0 + 2.18.0 + 2.18.0 true MIT Geodan @@ -17,7 +17,7 @@ https://github.com/geodan/pg2b3dm https://github.com/geodan/pg2b3dm git - Add support datetime, fix inner polygons triangulation, add skip create tiles option + Add option tilesetVersion 3dtiles b3dm gltf cesium false