Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tileset version option, release 2.18 #215

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/b3dm.tileset/CesiumTiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tile> tiles)
public static void CreateImplicitTileset(Version version, bool createGltf, string outputDirectory, double[] translation, double geometricError, double[] rootBoundingVolumeRegion, string subtreesDirectory, List<Tile> tiles, string tilesetVersion="")
{
if (!Directory.Exists(subtreesDirectory)) {
Directory.CreateDirectory(subtreesDirectory);
Expand All @@ -28,20 +28,20 @@ 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");
Console.WriteLine($"Writing {file}...");
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<Tile> tiles)
public static void CreateExplicitTilesetsJson(Version version, string outputDirectory, double[] translation, double geometricError, double geometricErrorFactor, string refinement, bool use10, double[] rootBoundingVolumeRegion, Tile tile, List<Tile> 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);

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/b3dm.tileset/TilesetClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,4 +61,6 @@ public class Asset
public string generator { get; set; }

public string version { get; set; }

public string tilesetVersion { get; set; }
}
13 changes: 8 additions & 5 deletions src/b3dm.tileset/TreeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,9 +28,9 @@ public static TileSet ToImplicitTileset(double[] transform, double[] box, double
return tileset;
}

public static TileSet ToTileset(List<Tile> tiles, double[] transform, double[] region, double geometricError, double geometricErrorFactor = 2, Version version = null, string refine="ADD", bool use10 = false)
public static TileSet ToTileset(List<Tile> 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,
Expand All @@ -55,10 +55,13 @@ public static TileSet ToTileset(List<Tile> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/b3dm.tileset/b3dm.tileset.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.4" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="subtree" Version="1.5.0" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/pg2b3dm/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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; }
Expand Down
8 changes: 6 additions & 2 deletions src/pg2b3dm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/pg2b3dm/pg2b3dm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<PackageOutputPath>./nupkg</PackageOutputPath>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ToolCommandName>pg2b3dm</ToolCommandName>
<Version>2.17.0</Version>
<Version>2.18.0</Version>
<Description>Console tool for converting PostGIS geometries to 3D Tiles</Description>
<AssemblyVersion>2.17.0</AssemblyVersion>
<FileVersion>2.17.0</FileVersion>
<AssemblyVersion>2.18.0</AssemblyVersion>
<FileVersion>2.18.0</FileVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Company>Geodan</Company>
<Authors>Bert Temme</Authors>
<PackageProjectUrl>https://github.com/geodan/pg2b3dm</PackageProjectUrl>
<RepositoryUrl>https://github.com/geodan/pg2b3dm</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Add support datetime, fix inner polygons triangulation, add skip create tiles option</PackageReleaseNotes>
<PackageReleaseNotes>Add option tilesetVersion</PackageReleaseNotes>
<PackageTags>3dtiles b3dm gltf cesium</PackageTags>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
Expand Down